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}")import { SmartsBio } from '@smartsbio/sdk';
const client = new SmartsBio({ apiKey: 'sk_live_...' });
const [workspace] = await client.workspaces.list();
// 1. Upload raw mzML
const raw = await client.files.upload('./sample_pos.mzML', {
workspaceId: workspace.id,
path: 'ms/raw/',
});
console.log('Uploaded:', raw.key);
// 2. Feature detection + metabolite identification
const result = await client.tools.run('metabolite_identify', {
input: {
filePath: raw.key,
workspaceId: workspace.id,
ionization: 'ESI+',
databases: ['HMDB', 'METLIN', 'KEGG'],
ppmTolerance: 5.0,
rtTolerance: 0.3,
outputPath: 'ms/annotated/',
},
});
console.log('Features detected :', result.nFeatures);
console.log('Metabolites matched:', result.nMatched);
result.topHits.slice(0, 5).forEach((h: { name: string; mz: number; database: string }) => {
console.log(` ${h.name.padEnd(30)} m/z=${h.mz.toFixed(4)} db=${h.database}`);
});
// 3. Download annotated table
const localPath = await client.files.download(result.outputPath, workspace.id, './output/');
console.log('Saved to', localPath);# 1. Upload raw mzML
FILE_PATH=$(curl -s -X POST https://api.smarts.bio/v1/files/upload \
-H "Authorization: Bearer sk_live_..." \
-F "file=@sample_pos.mzML" -F "workspace_id=ws_abc123" -F "path=ms/raw/" \
| jq -r '.data.path')
# 2. Feature detection + metabolite identification
curl -s -X POST https://api.smarts.bio/v1/tools/metabolite_identify/run \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{"input": {"file_path": "'"$FILE_PATH"'", "workspace_id": "ws_abc123", "ionization": "ESI+", "databases": ["HMDB","METLIN","KEGG"], "ppm_tolerance": 5.0, "rt_tolerance": 0.3, "output_path": "ms/annotated/"}}' \
| jq '{n_features, n_matched, top_hits: .top_hits[:5]}'# 1. Upload the raw mzML file smarts file upload sample_pos.mzML --to ms/raw/ # 2. Feature detection + metabolite identification smarts tool run metabolite_identify \ --param file_path=ms/raw/sample_pos.mzML \ --param ionization=ESI+ \ --param databases=HMDB,METLIN,KEGG \ --param ppm_tolerance=5.0 \ --param rt_tolerance=0.3 \ --param output_path=ms/annotated/ # 3. Download the annotated feature table smarts file download ms/annotated/ -o ./output/
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()import { SmartsBio } from '@smartsbio/sdk';
const client = new SmartsBio({ apiKey: 'sk_live_...' });
const result = await client.tools.run('hmdb_search', {
input: {
queryType: 'mz',
mz: 181.0733,
ionization: 'ESI+',
adduct: '[M+H]+',
ppmTolerance: 5.0,
},
});
result.metabolites.slice(0, 3).forEach((hit: {
hmdb_id: string; name: string; formula: string;
monoisotopic_mass: number; pathways: string[];
}) => {
console.log('HMDB ID :', hit.hmdb_id);
console.log('Name :', hit.name);
console.log('Formula :', hit.formula);
console.log('MonoMass :', hit.monoisotopic_mass.toFixed(4));
console.log('Pathways :', hit.pathways.slice(0, 3).join(', '));
console.log();
});curl -X POST https://api.smarts.bio/v1/tools/hmdb_search/run \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"input": {
"query_type": "mz",
"mz": 181.0733,
"ionization": "ESI+",
"adduct": "[M+H]+",
"ppm_tolerance": 5.0
}
}' | jq '.metabolites[:3][] | {hmdb_id, name, formula, monoisotopic_mass, pathways: .pathways[:3]}'# Search HMDB by exact m/z smarts tool run hmdb_search \ --param query_type=mz \ --param mz=181.0733 \ --param ionization=ESI+ \ --param "adduct=[M+H]+" \ --param ppm_tolerance=5.0
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}")import { SmartsBio } from '@smartsbio/sdk';
const client = new SmartsBio({ apiKey: 'sk_live_...' });
const [workspace] = await client.workspaces.list();
const sigMetabolites = [
'HMDB0000641', 'HMDB0000883', 'HMDB0000161', 'HMDB0001311', 'HMDB0000064',
];
const enrichment = await client.tools.run('metabolite_pathway_enrichment', {
input: {
hmdbIds: sigMetabolites,
databases: ['KEGG', 'Reactome'],
species: 'Homo sapiens',
workspaceId: workspace.id,
outputPath: 'ms/pathways/',
},
});
enrichment.pathways.slice(0, 5).forEach((p: { name: string; pvalue: number; hits: number; total: number }) => {
console.log(` ${p.name.padEnd(40)} p=${p.pvalue.toExponential(2)} hits=${p.hits}/${p.total}`);
});
const [svg, csv] = await Promise.all([
client.files.download(enrichment.svgPath, workspace.id, './pathways/'),
client.files.download(enrichment.tablePath, workspace.id, './pathways/'),
]);
console.log('Pathway map:', svg);
console.log('Summary CSV:', csv);curl -X POST https://api.smarts.bio/v1/tools/metabolite_pathway_enrichment/run \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"input": {
"hmdb_ids": ["HMDB0000641","HMDB0000883","HMDB0000161","HMDB0001311","HMDB0000064"],
"databases": ["KEGG","Reactome"],
"species": "Homo sapiens",
"workspace_id": "ws_abc123",
"output_path": "ms/pathways/"
}
}' | jq '{pathways: .pathways[:5], svg_path, table_path}'# Map significant metabolites to KEGG/Reactome pathways smarts tool run metabolite_pathway_enrichment \ --param hmdb_ids=HMDB0000641,HMDB0000883,HMDB0000161,HMDB0001311,HMDB0000064 \ --param databases=KEGG,Reactome \ --param species="Homo sapiens" \ --param output_path=ms/pathways/ # Download the pathway map SVG + summary table smarts file download ms/pathways/ -o ./pathways/