Skip to main content

Metabolomics

Upload raw LC-MS data, identify metabolites, map pathways, and download annotated results.

Upload mzML → identify metabolites → download annotated CSV

Upload a raw LC-MS file in mzML format, run metabolite identification against HMDB and METLIN, and download the annotated feature table.

from smartsbio import SmartsBio

client = SmartsBio(api_key="sk_live_...")
ws_id = client.workspaces.list()[0].id

# 1. Upload raw mzML file
raw = client.files.upload("sample_pos.mzML", workspace_id=ws_id, path="ms/raw/")
print(f"Uploaded: {raw['key']}")

# 2. Feature detection + metabolite ID
result = client.tools.run(
    tool_id="metabolite_identify",
    input={
        "file_path": raw["key"],
        "workspace_id": ws_id,
        "ionization": "ESI+",
        "databases": ["HMDB", "METLIN", "KEGG"],
        "ppm_tolerance": 5.0,
        "rt_tolerance": 0.3,       # minutes
        "output_path": "ms/annotated/",
    },
)
print(f"Features detected  : {result['n_features']}")
print(f"Metabolites matched: {result['n_matched']}")
for hit in result["top_hits"][:5]:
    print(f"  {hit['name']:<30}  m/z={hit['mz']:.4f}  db={hit['database']}")

# 3. Download annotated feature table
local = client.files.download(result["output_path"], workspace_id=ws_id, dest="./output/")
print(f"Saved to {local}")

HMDB metabolite lookup

Search the Human Metabolome Database by m/z or metabolite name for structured chemical and biological data.

from smartsbio import SmartsBio

client = SmartsBio(api_key="sk_live_...")

# Search by exact m/z
result = client.tools.run(
    tool_id="hmdb_search",
    input={
        "query_type": "mz",
        "mz": 181.0733,
        "ionization": "ESI+",
        "adduct": "[M+H]+",
        "ppm_tolerance": 5.0,
    },
)

for hit in result["metabolites"][:3]:
    print(f"HMDB ID    : {hit['hmdb_id']}")
    print(f"Name       : {hit['name']}")
    print(f"Formula    : {hit['formula']}")
    print(f"MonoMass   : {hit['monoisotopic_mass']:.4f}")
    print(f"Pathways   : {', '.join(hit['pathways'][:3])}")
    print()

Metabolite set pathway mapping

Upload a list of significant metabolites and map them to KEGG/Reactome pathways to identify the most affected metabolic routes.

from smartsbio import SmartsBio

client = SmartsBio(api_key="sk_live_...")
ws_id = client.workspaces.list()[0].id

# Significant metabolites from earlier identification step
sig_metabolites = [
    "HMDB0000641",  # Glutamine
    "HMDB0000883",  # Leucine
    "HMDB0000161",  # Alanine
    "HMDB0001311",  # Pyruvate
    "HMDB0000064",  # Citric acid (TCA)
]

# Run pathway enrichment
enrichment = client.tools.run(
    tool_id="metabolite_pathway_enrichment",
    input={
        "hmdb_ids": sig_metabolites,
        "databases": ["KEGG", "Reactome"],
        "species": "Homo sapiens",
        "workspace_id": ws_id,
        "output_path": "ms/pathways/",
    },
)

for p in enrichment["pathways"][:5]:
    print(f"  {p['name']:<40}  p={p['pvalue']:.2e}  hits={p['hits']}/{p['total']}")

# Download pathway map SVG + summary table
svg = client.files.download(enrichment["svg_path"], workspace_id=ws_id, dest="./pathways/")
csv = client.files.download(enrichment["table_path"], workspace_id=ws_id, dest="./pathways/")
print(f"Pathway map: {svg}")
print(f"Summary CSV: {csv}")