[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M73H7YQ19AZGS2RDMZT3NCTH":3,"skill-same:01M73H7YQ19AZGS2RDMZT3NCTH":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M73H7YQ19AZGS2RDMZT3NCTH","metabolomics-workbench-database",null,"Query Metabolomics Workbench REST API (4,200+ NIH studies) for metabolite ID, study discovery, RefMet standardization, m\u002Fz precursor searches, and gene\u002Fprotein annotations. Quirks: compound input_item rejects `name` (use pubchem_cid\u002Fkegg_id\u002Finchi_key\u002Fetc.); free-text → compound is a two-step refmet\u002Fmatch→refmet\u002Fname flow; moverz endpoint returns TSV text, not JSON. Use hmdb-database for local XML; pubchem-compound-search for general compound lookup.","bg-szy\u002FTOP-SKILLS","bg-szy","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F106576190?v=4","01M73A4E8KPV67SFXRY8XZGNBX","ShuZhiyong","01M73A4E96MQ294MHM74TZBVQD",6,"CC-BY-4.0","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fawesome-skills\u002Fmetabolomics-workbench-database\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: \"metabolomics-workbench-database\"\ndescription: \"Query Metabolomics Workbench REST API (4,200+ NIH studies) for metabolite ID, study discovery, RefMet standardization, m\u002Fz precursor searches, and gene\u002Fprotein annotations. Quirks: compound input_item rejects `name` (use pubchem_cid\u002Fkegg_id\u002Finchi_key\u002Fetc.); free-text → compound is a two-step refmet\u002Fmatch→refmet\u002Fname flow; moverz endpoint returns TSV text, not JSON. Use hmdb-database for local XML; pubchem-compound-search for general compound lookup.\"\nlicense: \"CC-BY-4.0\"\n---\n\n# Metabolomics Workbench Database — REST API Access\n\n## Overview\n\nThe Metabolomics Workbench (MW) REST API at `https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\u002F` exposes 4,200+ metabolomics studies hosted at UCSD under NIH Common Fund sponsorship. URL pattern is `\u002F{context}\u002F{input_item}\u002F{input_value}\u002F{output_item}\u002F{format}`. Contexts include `compound`, `refmet`, `moverz`, `study`, `analysis`, `metabolite`, `gene`, `protein`. Notable quirks discovered live:\n\n- `compound\u002Fname\u002F{x}` is **rejected** — `name` is not an allowed input_item. Use `pubchem_cid`, `kegg_id`, `inchi_key`, `hmdb_id`, `regno`, `lm_id`, `formula`, `smiles`, or `abbrev`. For free-text input, go through `refmet\u002Fmatch\u002F{x}` first.\n- `refmet\u002Fname\u002F{x}\u002Fall` requires the **exact** RefMet name (e.g. `Glucose`, not `D-glucose`); use `refmet\u002Fmatch\u002F{x}` for fuzzy normalisation first.\n- `moverz\u002F{REFMET|LIPIDS|MB}\u002F{mz}\u002F{ion}\u002F{tol}\u002Ftxt` returns **TSV text** (no JSON variant).\n- The `metstat\u002Ffilter\u002F...` endpoint shown in older examples returns `[]` — replace with `study\u002F{context}\u002F{value}\u002Fsummary` (or `\u002Fmetabolites`) + client-side filtering.\n\nNo authentication required.\n\n## When to Use\n\n- Searching metabolite records by PubChem CID, KEGG ID, InChIKey, HMDB ID, formula, or SMILES\n- Discovering studies by species, disease, last_name, institute, analysis_type, or polarity\n- Standardising metabolite names to RefMet nomenclature for cross-study integration\n- Identifying unknown compounds from MS m\u002Fz values with adduct-aware matching (`moverz`)\n- Retrieving experimental metabolite tables (analyses, abundances) from published studies\n- Querying gene\u002Fprotein annotations linked to metabolomics pathways\n- Downloading raw mwTab files for local analysis\n- For local 220K-metabolite XML parsing with NMR\u002FMS spectra use `hmdb-database` instead\n- For live 110M-compound property lookups use `pubchem-compound-search` instead\n\n## Prerequisites\n\n- **Python packages**: `requests`, `pandas`\n- **No API key required**: publicly accessible\n- **Rate limits**: MW does not enforce strict limits; add `time.sleep(0.3)` between bulk requests\n- **Base URL**: `https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest`\n\n```bash\npip install requests pandas\n```\n\n## Quick Start\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\n# Two-step free-text → compound (the API rejects compound\u002Fname\u002F...)\ndef lookup_by_name(name):\n    # 1) Normalise to RefMet name\n    r = requests.get(f\"{BASE}\u002Frefmet\u002Fmatch\u002F{name}\", timeout=30)\n    r.raise_for_status()\n    refmet = r.json()\n    if not refmet.get(\"refmet_name\"):\n        return None\n    # 2) Pull full compound record by RefMet name (or by pubchem_cid)\n    r2 = requests.get(f\"{BASE}\u002Frefmet\u002Fname\u002F{refmet['refmet_name']}\u002Fall\", timeout=30)\n    rec = r2.json() if r2.json() else {}\n    return rec if isinstance(rec, dict) else None\n\nc = lookup_by_name(\"glucose\")\nprint(f\"{c['name']}: formula={c['formula']}, PubChem CID={c['pubchem_cid']}, \"\n      f\"InChIKey={c['inchi_key']}\")\n# Glucose: formula=C6H12O6, PubChem CID=5793, InChIKey=WQZGKKKJIJFFOK-GASJEMHNSA-N\n```\n\n## Core API\n\n### Module 1: Compound Queries\n\n`compound\u002F{input_item}\u002F{input_value}\u002Fall\u002Fjson` — `input_item` must be one of `regno`, `formula`, `inchi_key`, `lm_id`, `pubchem_cid`, `hmdb_id`, `kegg_id`, `smiles`, `abbrev`. The legacy `name` input is rejected by the server.\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\n# By PubChem CID\nr = requests.get(f\"{BASE}\u002Fcompound\u002Fpubchem_cid\u002F5793\u002Fall\u002Fjson\", timeout=30)\nglucose = r.json()\nprint(f\"PubChem 5793 -> {glucose['name']}, formula={glucose['formula']}, \"\n      f\"HMDB={glucose.get('hmdb_id')}, KEGG={glucose.get('kegg_id')}\")\n\n# By KEGG ID\nr = requests.get(f\"{BASE}\u002Fcompound\u002Fkegg_id\u002FC00031\u002Fall\u002Fjson\", timeout=30)\nprint(\"KEGG C00031 ->\", r.json()[\"name\"])\n\n# By InChIKey\nr = requests.get(f\"{BASE}\u002Fcompound\u002Finchi_key\u002FWQZGKKKJIJFFOK-GASJEMHNSA-N\u002Fall\u002Fjson\", timeout=30)\nprint(\"InChIKey -> regno:\", r.json()[\"regno\"])\n```\n\n```python\n# Compound by formula returns a paged dict (multiple matches)\nimport requests\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\nr = requests.get(f\"{BASE}\u002Fcompound\u002Fformula\u002FC6H12O6\u002Fall\u002Fjson\", timeout=30)\nmatches = r.json()\nprint(f\"Compounds with formula C6H12O6: {len(matches)}\")\nfor k in list(matches)[:3]:\n    print(f\"  regno={matches[k]['regno']}  name={matches[k]['name']}\")\n```\n\n### Module 2: Study Discovery\n\n`study\u002F{input_item}\u002F{input_value}\u002F{output}` — `input_item` includes `study_id`, `study_title`, `last_name`, `institute`, `analysis_id`, `metabolite_id`, `kegg_id`, `refmet_name`. `output` includes `summary`, `metabolites`, `factors`, `data`, `available_studies`, `species`, `disease`. `summary` for `study_id` returns a dict (keyed by accession when multiple); for `last_name`\u002F`institute` it returns a list.\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\n# Single-study summary — `study\u002Fstudy_id\u002F{id}\u002Fsummary` returns a flat dict\n# (keys: study_id, study_title, species, institute, analysis_type, ...)\nr = requests.get(f\"{BASE}\u002Fstudy\u002Fstudy_id\u002FST000001\u002Fsummary\", timeout=30)\ns = r.json()\nprint(f\"{s['study_id']}: {s['study_title'][:60]}\")\nprint(f\"  Species : {s.get('species')}  Institute: {s.get('institute')}\")\nprint(f\"  Submit  : {s.get('submission_date')}\")\n```\n\n```python\n# Studies that detected a metabolite — `study\u002Frefmet_name\u002F{x}\u002Fsummary` returns\n# a thin index of (refmet_name, kegg_id, study_id) rows. Chain study_id → full summary\n# to get title and species.\nimport requests, pandas as pd\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\nr = requests.get(f\"{BASE}\u002Fstudy\u002Frefmet_name\u002FGlucose\u002Fsummary\", timeout=60)\nd = r.json()\nrows = list(d.values()) if isinstance(d, dict) else d\nprint(f\"Studies referencing 'Glucose': {len(rows)}\")\nprint(pd.DataFrame(rows).head(5).to_string(index=False))\n# refmet_name kegg_id  study_id\n#     Glucose  C00031  ST000001\n#     Glucose  C00031  ST000002\n#     ...\n```\n\n### Module 3: RefMet Standardisation\n\n`refmet\u002Fmatch\u002F{user_text}` is a fuzzy normaliser — returns the standard RefMet record (no `pubchem_cid`\u002F`kegg_id` though). `refmet\u002Fname\u002F{exact_refmet_name}\u002Fall` returns the full record including IDs. Use them as a two-step pipeline.\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef normalise_to_refmet(user_text):\n    r = requests.get(f\"{BASE}\u002Frefmet\u002Fmatch\u002F{user_text}\", timeout=30)\n    r.raise_for_status()\n    m = r.json()\n    if not m or not m.get(\"refmet_name\"):\n        return None\n    return m[\"refmet_name\"]\n\ndef refmet_full(refmet_name):\n    r = requests.get(f\"{BASE}\u002Frefmet\u002Fname\u002F{refmet_name}\u002Fall\", timeout=30)\n    r.raise_for_status()\n    rec = r.json()\n    return rec if isinstance(rec, dict) and rec else None\n\nname = normalise_to_refmet(\"alpha-D-glucose\")  # -> 'Glucose'\nprint(f\"Normalised: {name}\")\nrec = refmet_full(name)\nprint(f\"  PubChem CID : {rec['pubchem_cid']}\")\nprint(f\"  InChIKey    : {rec['inchi_key']}\")\nprint(f\"  Super class : {rec['super_class']} \u002F {rec['main_class']} \u002F {rec['sub_class']}\")\n```\n\n### Module 4: Study Filtering (replaces broken `metstat`)\n\nThe older `metstat\u002Ffilter\u002F...` endpoint returns `[]`. Use the study context endpoints with client-side filtering instead.\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef study_ids_for_metabolite(refmet_name):\n    \"\"\"Return the study_id list that report a given RefMet name.\"\"\"\n    r = requests.get(f\"{BASE}\u002Fstudy\u002Frefmet_name\u002F{refmet_name}\u002Fsummary\", timeout=60)\n    r.raise_for_status()\n    d = r.json()\n    rows = list(d.values()) if isinstance(d, dict) else d\n    return sorted({row[\"study_id\"] for row in rows if row.get(\"study_id\")})\n\ndef study_summary(study_id):\n    \"\"\"Pull full summary (title, species, institute, dates) for one study_id.\n    Response is a flat dict with keys study_id\u002Fstudy_title\u002Fspecies\u002Finstitute\u002F...\"\"\"\n    return requests.get(f\"{BASE}\u002Fstudy\u002Fstudy_id\u002F{study_id}\u002Fsummary\", timeout=30).json()\n\n# Find glucose studies, then enrich the first few\nids = study_ids_for_metabolite(\"Glucose\")\nprint(f\"Studies referencing 'Glucose': {len(ids)}\")\nrows = [study_summary(sid) for sid in ids[:5]]\ndf = pd.DataFrame(rows)\nprint(df[[\"study_id\", \"study_title\", \"species\"]].head().to_string(index=False))\n```\n\n### Module 5: m\u002Fz Precursor Search (`moverz`)\n\n`moverz\u002F{REFMET|LIPIDS|MB}\u002F{mz}\u002F{ion}\u002F{tolerance}\u002Ftxt` returns **tab-separated text** (not JSON). The first DB selector (`REFMET`, `LIPIDS`, or `MB`) is required — `mz` as the first segment is rejected.\n\n```python\nimport requests, io, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef moverz_search(db, mz, ion, tolerance=0.005):\n    \"\"\"Search precursor m\u002Fz in REFMET \u002F LIPIDS \u002F MB and return a DataFrame.\n    Response is TSV text — no JSON variant.\"\"\"\n    assert db in {\"REFMET\", \"LIPIDS\", \"MB\"}\n    r = requests.get(f\"{BASE}\u002Fmoverz\u002F{db}\u002F{mz}\u002F{ion}\u002F{tolerance}\u002Ftxt\", timeout=30)\n    r.raise_for_status()\n    return pd.read_csv(io.StringIO(r.text), sep=\"\\t\")\n\ndf = moverz_search(\"REFMET\", 180.063, \"M+H\", 0.005)\nprint(f\"Candidates at m\u002Fz 180.063 [M+H]+ (REFMET): {len(df)}\")\nprint(df.head(5).to_string(index=False))\n```\n\n```python\n# Same query against the LIPIDS database\nimport requests, io, pandas as pd\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\nr = requests.get(f\"{BASE}\u002Fmoverz\u002FLIPIDS\u002F760.585\u002FM+H\u002F0.01\u002Ftxt\", timeout=30)\ndf_lipids = pd.read_csv(io.StringIO(r.text), sep=\"\\t\")\nprint(f\"Lipid candidates at m\u002Fz 760.585: {len(df_lipids)}\")\nprint(df_lipids.head(3).to_string(index=False))\n```\n\n### Module 6: Genes and Proteins\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\nr = requests.get(f\"{BASE}\u002Fgene\u002Fgene_symbol\u002FHMGCR\u002Fall\", timeout=30)\ng = r.json()\nprint(f\"{g['gene_symbol']} -> MGP: {g.get('mgp_id')}  ({g.get('gene_name', '')[:60]})\")\n\n# Protein by UniProt accession\nr2 = requests.get(f\"{BASE}\u002Fprotein\u002Funiprot_id\u002FP04035\u002Fall\", timeout=30)\np = r2.json()\nprint(f\"UniProt P04035: {p.get('protein_name', '')[:60]}  organism={p.get('organism')}\")\n```\n\n## Key Concepts\n\n### Allowed `input_item` Values per Context\n\n| Context | Valid input_item | Notes |\n|---------|------------------|-------|\n| `compound` | `regno`, `formula`, `inchi_key`, `lm_id`, `pubchem_cid`, `hmdb_id`, `kegg_id`, `smiles`, `abbrev` | `name` is **rejected** — go via `refmet\u002Fmatch` first |\n| `refmet` | `match`, `name`, `formula`, `exactmass`, `inchi_key`, `pubchem_cid`, `regno` | `match` is fuzzy; `name` requires the canonical RefMet name |\n| `study` | `study_id`, `study_title`, `last_name`, `institute`, `analysis_id`, `metabolite_id`, `kegg_id`, `refmet_name` | `summary` for `study_id` is a dict keyed by accession; for `last_name`\u002F`institute` it's a list |\n| `moverz` | (path) `REFMET` \u002F `LIPIDS` \u002F `MB` | First segment is the DB, not `mz` |\n| `gene` | `gene_id`, `gene_symbol`, `gene_name`, `mgp_id` | Returns a dict |\n| `protein` | `mgp_id`, `gene_id`, `uniprot_id`, `gene_symbol` | Returns a dict |\n\n### Output Type Conventions\n\n- `output=summary` returns a **dict** when the input identifier is unique (e.g. `study_id`), a **list** when it isn't (e.g. `last_name`).\n- Appending `\u002Fjson` to `study\u002F...\u002Fsummary` flips the response to TSV. Omit the format suffix — JSON is the default.\n- `moverz` only emits `\u002Ftxt` (TSV); there is no JSON variant.\n\n### `refmet\u002Fmatch` vs `refmet\u002Fname`\n\n- `refmet\u002Fmatch\u002F{user_text}` — fuzzy. Always returns a single dict with `refmet_name`, `formula`, `exactmass`, classification. Does **not** include `pubchem_cid`\u002F`inchi_key`.\n- `refmet\u002Fname\u002F{exact_refmet_name}\u002Fall` — requires the canonical RefMet name. Returns the full record including IDs. Returns an empty list if the name isn't canonical.\n\n## Common Workflows\n\n### Workflow 1: Free-Text → Full Compound Record\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef resolve_to_compound(user_text):\n    # 1) Normalise via refmet\u002Fmatch\n    rm = requests.get(f\"{BASE}\u002Frefmet\u002Fmatch\u002F{user_text}\", timeout=30).json()\n    if not rm.get(\"refmet_name\"):\n        return None\n    name = rm[\"refmet_name\"]\n    # 2) Fetch full RefMet record (includes pubchem_cid \u002F inchi_key)\n    full = requests.get(f\"{BASE}\u002Frefmet\u002Fname\u002F{name}\u002Fall\", timeout=30).json()\n    if not isinstance(full, dict) or not full:\n        return None\n    # 3) Optionally pull the matching compound record via PubChem CID\n    cid = full.get(\"pubchem_cid\")\n    compound = None\n    if cid:\n        compound = requests.get(f\"{BASE}\u002Fcompound\u002Fpubchem_cid\u002F{cid}\u002Fall\u002Fjson\",\n                                timeout=30).json()\n    return {\n        \"input\": user_text,\n        \"refmet_name\": name,\n        \"formula\": full.get(\"formula\"),\n        \"pubchem_cid\": cid,\n        \"hmdb_id\": compound.get(\"hmdb_id\") if compound else None,\n        \"kegg_id\": compound.get(\"kegg_id\") if compound else None,\n        \"inchi_key\": full.get(\"inchi_key\"),\n    }\n\nqueries = [\"glucose\", \"alpha-D-glucose\", \"L-tyrosine\", \"cholesterol\"]\ndf = pd.DataFrame([resolve_to_compound(q) for q in queries])\nprint(df.to_string(index=False))\ndf.to_csv(\"name_resolution.csv\", index=False)\n```\n\n### Workflow 2: Annotate MS Hit List\n\n**Goal**: Take a list of measured m\u002Fz values and assign RefMet candidate compounds.\n\n```python\nimport requests, io, pandas as pd, time\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef annotate_peaks(mz_values, ion=\"M+H\", tolerance=0.005):\n    out = []\n    for mz in mz_values:\n        r = requests.get(f\"{BASE}\u002Fmoverz\u002FREFMET\u002F{mz}\u002F{ion}\u002F{tolerance}\u002Ftxt\", timeout=30)\n        if r.status_code != 200 or not r.text.strip():\n            time.sleep(0.3); continue\n        df = pd.read_csv(io.StringIO(r.text), sep=\"\\t\")\n        for _, row in df.iterrows():\n            out.append({\n                \"query_mz\": mz,\n                \"matched_mz\": row[\"Matched m\u002Fz\"],\n                \"delta\": row[\"Delta\"],\n                \"name\": row[\"Name\"],\n                \"formula\": row[\"Formula\"],\n                \"ion\": row[\"Ion\"],\n                \"main_class\": row.get(\"Main class\"),\n            })\n        time.sleep(0.3)\n    return pd.DataFrame(out)\n\npeaks = [180.063, 166.086, 90.055]   # glucose, phenylalanine, alanine\ndf_ann = annotate_peaks(peaks)\nprint(df_ann.head(10).to_string(index=False))\ndf_ann.to_csv(\"ms_annotations.csv\", index=False)\n```\n\n### Workflow 3: Find Studies Detecting a Metabolite\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef studies_with(refmet_name, enrich_n=20):\n    \"\"\"Return a DataFrame: study_id rows that report the metabolite, enriched with\n    title + species for the first `enrich_n` IDs (via study\u002Fstudy_id\u002F...\u002Fsummary).\"\"\"\n    r = requests.get(f\"{BASE}\u002Fstudy\u002Frefmet_name\u002F{refmet_name}\u002Fsummary\", timeout=60)\n    r.raise_for_status()\n    d = r.json()\n    rows = list(d.values()) if isinstance(d, dict) else d\n    ids = sorted({row[\"study_id\"] for row in rows if row.get(\"study_id\")})\n    enriched = []\n    for sid in ids[:enrich_n]:\n        enriched.append(requests.get(\n            f\"{BASE}\u002Fstudy\u002Fstudy_id\u002F{sid}\u002Fsummary\", timeout=30).json())\n    return pd.DataFrame(enriched)\n\ndf = studies_with(\"Glucose\", enrich_n=20)\nprint(f\"Glucose-detecting studies (first 20 enriched): {len(df)}\")\nprint(df.groupby(\"species\").size().sort_values(ascending=False).head(8))\n```\n\n## Key Parameters\n\n| Parameter | Endpoint | Default | Range \u002F Options | Effect |\n|-----------|----------|---------|-----------------|--------|\n| `context` | path | required | `compound`, `refmet`, `moverz`, `study`, `analysis`, `metabolite`, `gene`, `protein` | API context selector |\n| `input_item` | path | required | depends on context (see \"Allowed `input_item` Values per Context\") | Identifier type |\n| `input_value` | path | required | string | The actual identifier or value |\n| `output_item` | path | `all` | `all`, `summary`, `metabolites`, `factors`, `data`, etc. | What aspect to return |\n| `format` | path | (varies) | `json`, `txt` | `moverz` only emits `txt`; do NOT append `\u002Fjson` to `study\u002F...\u002Fsummary` |\n| `mz` \u002F `ion` \u002F `tolerance` | `moverz` path | required | float \u002F `M+H`, `M-H`, `M+Na`, `M+K`, etc. \u002F float | Mass tolerance in Da |\n\n## Best Practices\n\n1. **Use `refmet\u002Fmatch` first for free-text input.** `compound\u002Fname\u002F...` is rejected by the server (`name` is not an allowed `input_item`).\n2. **`moverz` is TSV-only.** Parse with `pd.read_csv(io.StringIO(r.text), sep=\"\\t\")` — never call `.json()` on the response.\n3. **Don't append `\u002Fjson` to `study\u002F...\u002Fsummary`.** The default is JSON; the suffix flips the response to TSV.\n4. **`refmet\u002Fname\u002F{x}\u002Fall` needs the canonical RefMet name.** If you have user text, run it through `refmet\u002Fmatch` first.\n5. **Compound results paged by formula come keyed `'1','2',...`** — iterate `dict.values()` or pass to `pd.DataFrame.from_dict(orient=\"index\")`.\n6. **Always `time.sleep(0.3)` in batch loops** — no rate limit is published but the server is shared.\n\n## Common Recipes\n\n### Recipe: Cross-Database ID Mapping (PubChem ↔ KEGG ↔ HMDB)\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef cross_refs(refmet_name):\n    rm = requests.get(f\"{BASE}\u002Frefmet\u002Fname\u002F{refmet_name}\u002Fall\", timeout=30).json()\n    if not isinstance(rm, dict) or not rm:\n        return None\n    cid = rm.get(\"pubchem_cid\")\n    if not cid:\n        return {\"refmet\": refmet_name, \"pubchem_cid\": None}\n    c = requests.get(f\"{BASE}\u002Fcompound\u002Fpubchem_cid\u002F{cid}\u002Fall\u002Fjson\", timeout=30).json()\n    return {\"refmet\": refmet_name,\n            \"pubchem_cid\": cid,\n            \"kegg_id\": c.get(\"kegg_id\"),\n            \"hmdb_id\": c.get(\"hmdb_id\"),\n            \"inchi_key\": rm.get(\"inchi_key\")}\n\ndf = pd.DataFrame([cross_refs(n) for n in [\"Glucose\", \"L-Tyrosine\", \"Cholesterol\"]])\nprint(df.to_string(index=False))\n```\n\n### Recipe: Pull a Study's Metabolite Table\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\nr = requests.get(f\"{BASE}\u002Fstudy\u002Fstudy_id\u002FST000001\u002Fmetabolites\", timeout=60)\nr.raise_for_status()\nrows = list(r.json().values())\ndf = pd.DataFrame(rows)\nprint(f\"ST000001 metabolites: {len(df)}\")\nprint(df[[\"analysis_id\", \"analysis_summary\", \"metabolite_name\", \"refmet_name\"]].head(5).to_string(index=False))\n```\n\n### Recipe: Gene → Metabolomics Pathways\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\ng = requests.get(f\"{BASE}\u002Fgene\u002Fgene_symbol\u002FHMGCR\u002Fall\", timeout=30).json()\nprint({k: g.get(k) for k in [\"gene_symbol\", \"gene_id\", \"mgp_id\",\n                              \"gene_name\", \"gene_synonyms\"]})\n```\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| `\"This input item (name) is not allowed...\"` | `compound\u002Fname\u002F...` is rejected | Use one of the allowed `input_item` values (`pubchem_cid`, `kegg_id`, `inchi_key`, `hmdb_id`, etc.); for free text, go through `refmet\u002Fmatch\u002F{x}` first |\n| `JSONDecodeError` on `moverz` response | `moverz` returns TSV text, not JSON | Parse with `pd.read_csv(io.StringIO(r.text), sep=\"\\t\")` |\n| Empty list from `refmet\u002Fname\u002F{x}\u002Fall` | Need the canonical RefMet name (case-sensitive) | Normalise via `refmet\u002Fmatch\u002F{user_text}` first, then plug `refmet_name` into `refmet\u002Fname\u002F...\u002Fall` |\n| `metstat\u002Ffilter\u002F...` returns `[]` | Endpoint syntax is non-functional | Use `study\u002F{refmet_name|last_name|institute|...}\u002F{value}\u002Fsummary` and filter client-side |\n| `study\u002F...\u002Fsummary` returns TSV instead of JSON | The `\u002Fjson` suffix flips to TSV | Drop the trailing `\u002Fjson` — JSON is the default |\n| Compound query by formula returns a dict, not a list | Server pages multiple matches as `{'1': {...}, '2': {...}}` | Iterate `dict.values()` (or `pd.DataFrame.from_dict(d, orient='index')`) |\n| `refmet\u002Fmatch` response lacks `pubchem_cid` | `match` returns the lightweight record | Use `refmet\u002Fname\u002F{refmet_name}\u002Fall` for the full record |\n\n## Related Skills\n\n- `hmdb-database` — Local HMDB XML (220K metabolites, NMR\u002FMS spectra, disease links) for offline queries\n- `pubchem-compound-search` — General compound property lookups (110M+ compounds) via PubChemPy\n- `kegg-database` — Pathway and orthology data complementary to MW's study\u002Fmetabolite hits\n- `chembl-database-bioactivity` — Bioactivity data for the same compounds\n\n## References\n\n- [Metabolomics Workbench home](https:\u002F\u002Fwww.metabolomicsworkbench.org\u002F)\n- [REST API documentation (PDF)](https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Ftools\u002FMWRestAPIv1.0.pdf)\n- [RefMet nomenclature](https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Fdatabases\u002Frefmet\u002Findex.php)\n- Sud M et al. \"Metabolomics Workbench: An international repository for metabolomics data and metadata.\" *Nucleic Acids Research* 44(D1): D463–D470 (2016). https:\u002F\u002Fdoi.org\u002F10.1093\u002Fnar\u002Fgkv1042\n","# Metabolomics Workbench Database — REST API Access\n\n## Overview\n\nThe Metabolomics Workbench (MW) REST API at `https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\u002F` exposes 4,200+ metabolomics studies hosted at UCSD under NIH Common Fund sponsorship. URL pattern is `\u002F{context}\u002F{input_item}\u002F{input_value}\u002F{output_item}\u002F{format}`. Contexts include `compound`, `refmet`, `moverz`, `study`, `analysis`, `metabolite`, `gene`, `protein`. Notable quirks discovered live:\n\n- `compound\u002Fname\u002F{x}` is **rejected** — `name` is not an allowed input_item. Use `pubchem_cid`, `kegg_id`, `inchi_key`, `hmdb_id`, `regno`, `lm_id`, `formula`, `smiles`, or `abbrev`. For free-text input, go through `refmet\u002Fmatch\u002F{x}` first.\n- `refmet\u002Fname\u002F{x}\u002Fall` requires the **exact** RefMet name (e.g. `Glucose`, not `D-glucose`); use `refmet\u002Fmatch\u002F{x}` for fuzzy normalisation first.\n- `moverz\u002F{REFMET|LIPIDS|MB}\u002F{mz}\u002F{ion}\u002F{tol}\u002Ftxt` returns **TSV text** (no JSON variant).\n- The `metstat\u002Ffilter\u002F...` endpoint shown in older examples returns `[]` — replace with `study\u002F{context}\u002F{value}\u002Fsummary` (or `\u002Fmetabolites`) + client-side filtering.\n\nNo authentication required.\n\n## When to Use\n\n- Searching metabolite records by PubChem CID, KEGG ID, InChIKey, HMDB ID, formula, or SMILES\n- Discovering studies by species, disease, last_name, institute, analysis_type, or polarity\n- Standardising metabolite names to RefMet nomenclature for cross-study integration\n- Identifying unknown compounds from MS m\u002Fz values with adduct-aware matching (`moverz`)\n- Retrieving experimental metabolite tables (analyses, abundances) from published studies\n- Querying gene\u002Fprotein annotations linked to metabolomics pathways\n- Downloading raw mwTab files for local analysis\n- For local 220K-metabolite XML parsing with NMR\u002FMS spectra use `hmdb-database` instead\n- For live 110M-compound property lookups use `pubchem-compound-search` instead\n\n## Prerequisites\n\n- **Python packages**: `requests`, `pandas`\n- **No API key required**: publicly accessible\n- **Rate limits**: MW does not enforce strict limits; add `time.sleep(0.3)` between bulk requests\n- **Base URL**: `https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest`\n\n```bash\npip install requests pandas\n```\n\n## Quick Start\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\n# Two-step free-text → compound (the API rejects compound\u002Fname\u002F...)\ndef lookup_by_name(name):\n    # 1) Normalise to RefMet name\n    r = requests.get(f\"{BASE}\u002Frefmet\u002Fmatch\u002F{name}\", timeout=30)\n    r.raise_for_status()\n    refmet = r.json()\n    if not refmet.get(\"refmet_name\"):\n        return None\n    # 2) Pull full compound record by RefMet name (or by pubchem_cid)\n    r2 = requests.get(f\"{BASE}\u002Frefmet\u002Fname\u002F{refmet['refmet_name']}\u002Fall\", timeout=30)\n    rec = r2.json() if r2.json() else {}\n    return rec if isinstance(rec, dict) else None\n\nc = lookup_by_name(\"glucose\")\nprint(f\"{c['name']}: formula={c['formula']}, PubChem CID={c['pubchem_cid']}, \"\n      f\"InChIKey={c['inchi_key']}\")\n# Glucose: formula=C6H12O6, PubChem CID=5793, InChIKey=WQZGKKKJIJFFOK-GASJEMHNSA-N\n```\n\n## Core API\n\n### Module 1: Compound Queries\n\n`compound\u002F{input_item}\u002F{input_value}\u002Fall\u002Fjson` — `input_item` must be one of `regno`, `formula`, `inchi_key`, `lm_id`, `pubchem_cid`, `hmdb_id`, `kegg_id`, `smiles`, `abbrev`. The legacy `name` input is rejected by the server.\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\n# By PubChem CID\nr = requests.get(f\"{BASE}\u002Fcompound\u002Fpubchem_cid\u002F5793\u002Fall\u002Fjson\", timeout=30)\nglucose = r.json()\nprint(f\"PubChem 5793 -> {glucose['name']}, formula={glucose['formula']}, \"\n      f\"HMDB={glucose.get('hmdb_id')}, KEGG={glucose.get('kegg_id')}\")\n\n# By KEGG ID\nr = requests.get(f\"{BASE}\u002Fcompound\u002Fkegg_id\u002FC00031\u002Fall\u002Fjson\", timeout=30)\nprint(\"KEGG C00031 ->\", r.json()[\"name\"])\n\n# By InChIKey\nr = requests.get(f\"{BASE}\u002Fcompound\u002Finchi_key\u002FWQZGKKKJIJFFOK-GASJEMHNSA-N\u002Fall\u002Fjson\", timeout=30)\nprint(\"InChIKey -> regno:\", r.json()[\"regno\"])\n```\n\n```python\n# Compound by formula returns a paged dict (multiple matches)\nimport requests\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\nr = requests.get(f\"{BASE}\u002Fcompound\u002Fformula\u002FC6H12O6\u002Fall\u002Fjson\", timeout=30)\nmatches = r.json()\nprint(f\"Compounds with formula C6H12O6: {len(matches)}\")\nfor k in list(matches)[:3]:\n    print(f\"  regno={matches[k]['regno']}  name={matches[k]['name']}\")\n```\n\n### Module 2: Study Discovery\n\n`study\u002F{input_item}\u002F{input_value}\u002F{output}` — `input_item` includes `study_id`, `study_title`, `last_name`, `institute`, `analysis_id`, `metabolite_id`, `kegg_id`, `refmet_name`. `output` includes `summary`, `metabolites`, `factors`, `data`, `available_studies`, `species`, `disease`. `summary` for `study_id` returns a dict (keyed by accession when multiple); for `last_name`\u002F`institute` it returns a list.\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\n# Single-study summary — `study\u002Fstudy_id\u002F{id}\u002Fsummary` returns a flat dict\n# (keys: study_id, study_title, species, institute, analysis_type, ...)\nr = requests.get(f\"{BASE}\u002Fstudy\u002Fstudy_id\u002FST000001\u002Fsummary\", timeout=30)\ns = r.json()\nprint(f\"{s['study_id']}: {s['study_title'][:60]}\")\nprint(f\"  Species : {s.get('species')}  Institute: {s.get('institute')}\")\nprint(f\"  Submit  : {s.get('submission_date')}\")\n```\n\n```python\n# Studies that detected a metabolite — `study\u002Frefmet_name\u002F{x}\u002Fsummary` returns\n# a thin index of (refmet_name, kegg_id, study_id) rows. Chain study_id → full summary\n# to get title and species.\nimport requests, pandas as pd\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\nr = requests.get(f\"{BASE}\u002Fstudy\u002Frefmet_name\u002FGlucose\u002Fsummary\", timeout=60)\nd = r.json()\nrows = list(d.values()) if isinstance(d, dict) else d\nprint(f\"Studies referencing 'Glucose': {len(rows)}\")\nprint(pd.DataFrame(rows).head(5).to_string(index=False))\n# refmet_name kegg_id  study_id\n#     Glucose  C00031  ST000001\n#     Glucose  C00031  ST000002\n#     ...\n```\n\n### Module 3: RefMet Standardisation\n\n`refmet\u002Fmatch\u002F{user_text}` is a fuzzy normaliser — returns the standard RefMet record (no `pubchem_cid`\u002F`kegg_id` though). `refmet\u002Fname\u002F{exact_refmet_name}\u002Fall` returns the full record including IDs. Use them as a two-step pipeline.\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef normalise_to_refmet(user_text):\n    r = requests.get(f\"{BASE}\u002Frefmet\u002Fmatch\u002F{user_text}\", timeout=30)\n    r.raise_for_status()\n    m = r.json()\n    if not m or not m.get(\"refmet_name\"):\n        return None\n    return m[\"refmet_name\"]\n\ndef refmet_full(refmet_name):\n    r = requests.get(f\"{BASE}\u002Frefmet\u002Fname\u002F{refmet_name}\u002Fall\", timeout=30)\n    r.raise_for_status()\n    rec = r.json()\n    return rec if isinstance(rec, dict) and rec else None\n\nname = normalise_to_refmet(\"alpha-D-glucose\")  # -> 'Glucose'\nprint(f\"Normalised: {name}\")\nrec = refmet_full(name)\nprint(f\"  PubChem CID : {rec['pubchem_cid']}\")\nprint(f\"  InChIKey    : {rec['inchi_key']}\")\nprint(f\"  Super class : {rec['super_class']} \u002F {rec['main_class']} \u002F {rec['sub_class']}\")\n```\n\n### Module 4: Study Filtering (replaces broken `metstat`)\n\nThe older `metstat\u002Ffilter\u002F...` endpoint returns `[]`. Use the study context endpoints with client-side filtering instead.\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef study_ids_for_metabolite(refmet_name):\n    \"\"\"Return the study_id list that report a given RefMet name.\"\"\"\n    r = requests.get(f\"{BASE}\u002Fstudy\u002Frefmet_name\u002F{refmet_name}\u002Fsummary\", timeout=60)\n    r.raise_for_status()\n    d = r.json()\n    rows = list(d.values()) if isinstance(d, dict) else d\n    return sorted({row[\"study_id\"] for row in rows if row.get(\"study_id\")})\n\ndef study_summary(study_id):\n    \"\"\"Pull full summary (title, species, institute, dates) for one study_id.\n    Response is a flat dict with keys study_id\u002Fstudy_title\u002Fspecies\u002Finstitute\u002F...\"\"\"\n    return requests.get(f\"{BASE}\u002Fstudy\u002Fstudy_id\u002F{study_id}\u002Fsummary\", timeout=30).json()\n\n# Find glucose studies, then enrich the first few\nids = study_ids_for_metabolite(\"Glucose\")\nprint(f\"Studies referencing 'Glucose': {len(ids)}\")\nrows = [study_summary(sid) for sid in ids[:5]]\ndf = pd.DataFrame(rows)\nprint(df[[\"study_id\", \"study_title\", \"species\"]].head().to_string(index=False))\n```\n\n### Module 5: m\u002Fz Precursor Search (`moverz`)\n\n`moverz\u002F{REFMET|LIPIDS|MB}\u002F{mz}\u002F{ion}\u002F{tolerance}\u002Ftxt` returns **tab-separated text** (not JSON). The first DB selector (`REFMET`, `LIPIDS`, or `MB`) is required — `mz` as the first segment is rejected.\n\n```python\nimport requests, io, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef moverz_search(db, mz, ion, tolerance=0.005):\n    \"\"\"Search precursor m\u002Fz in REFMET \u002F LIPIDS \u002F MB and return a DataFrame.\n    Response is TSV text — no JSON variant.\"\"\"\n    assert db in {\"REFMET\", \"LIPIDS\", \"MB\"}\n    r = requests.get(f\"{BASE}\u002Fmoverz\u002F{db}\u002F{mz}\u002F{ion}\u002F{tolerance}\u002Ftxt\", timeout=30)\n    r.raise_for_status()\n    return pd.read_csv(io.StringIO(r.text), sep=\"\\t\")\n\ndf = moverz_search(\"REFMET\", 180.063, \"M+H\", 0.005)\nprint(f\"Candidates at m\u002Fz 180.063 [M+H]+ (REFMET): {len(df)}\")\nprint(df.head(5).to_string(index=False))\n```\n\n```python\n# Same query against the LIPIDS database\nimport requests, io, pandas as pd\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\nr = requests.get(f\"{BASE}\u002Fmoverz\u002FLIPIDS\u002F760.585\u002FM+H\u002F0.01\u002Ftxt\", timeout=30)\ndf_lipids = pd.read_csv(io.StringIO(r.text), sep=\"\\t\")\nprint(f\"Lipid candidates at m\u002Fz 760.585: {len(df_lipids)}\")\nprint(df_lipids.head(3).to_string(index=False))\n```\n\n### Module 6: Genes and Proteins\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\nr = requests.get(f\"{BASE}\u002Fgene\u002Fgene_symbol\u002FHMGCR\u002Fall\", timeout=30)\ng = r.json()\nprint(f\"{g['gene_symbol']} -> MGP: {g.get('mgp_id')}  ({g.get('gene_name', '')[:60]})\")\n\n# Protein by UniProt accession\nr2 = requests.get(f\"{BASE}\u002Fprotein\u002Funiprot_id\u002FP04035\u002Fall\", timeout=30)\np = r2.json()\nprint(f\"UniProt P04035: {p.get('protein_name', '')[:60]}  organism={p.get('organism')}\")\n```\n\n## Key Concepts\n\n### Allowed `input_item` Values per Context\n\n| Context | Valid input_item | Notes |\n|---------|------------------|-------|\n| `compound` | `regno`, `formula`, `inchi_key`, `lm_id`, `pubchem_cid`, `hmdb_id`, `kegg_id`, `smiles`, `abbrev` | `name` is **rejected** — go via `refmet\u002Fmatch` first |\n| `refmet` | `match`, `name`, `formula`, `exactmass`, `inchi_key`, `pubchem_cid`, `regno` | `match` is fuzzy; `name` requires the canonical RefMet name |\n| `study` | `study_id`, `study_title`, `last_name`, `institute`, `analysis_id`, `metabolite_id`, `kegg_id`, `refmet_name` | `summary` for `study_id` is a dict keyed by accession; for `last_name`\u002F`institute` it's a list |\n| `moverz` | (path) `REFMET` \u002F `LIPIDS` \u002F `MB` | First segment is the DB, not `mz` |\n| `gene` | `gene_id`, `gene_symbol`, `gene_name`, `mgp_id` | Returns a dict |\n| `protein` | `mgp_id`, `gene_id`, `uniprot_id`, `gene_symbol` | Returns a dict |\n\n### Output Type Conventions\n\n- `output=summary` returns a **dict** when the input identifier is unique (e.g. `study_id`), a **list** when it isn't (e.g. `last_name`).\n- Appending `\u002Fjson` to `study\u002F...\u002Fsummary` flips the response to TSV. Omit the format suffix — JSON is the default.\n- `moverz` only emits `\u002Ftxt` (TSV); there is no JSON variant.\n\n### `refmet\u002Fmatch` vs `refmet\u002Fname`\n\n- `refmet\u002Fmatch\u002F{user_text}` — fuzzy. Always returns a single dict with `refmet_name`, `formula`, `exactmass`, classification. Does **not** include `pubchem_cid`\u002F`inchi_key`.\n- `refmet\u002Fname\u002F{exact_refmet_name}\u002Fall` — requires the canonical RefMet name. Returns the full record including IDs. Returns an empty list if the name isn't canonical.\n\n## Common Workflows\n\n### Workflow 1: Free-Text → Full Compound Record\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef resolve_to_compound(user_text):\n    # 1) Normalise via refmet\u002Fmatch\n    rm = requests.get(f\"{BASE}\u002Frefmet\u002Fmatch\u002F{user_text}\", timeout=30).json()\n    if not rm.get(\"refmet_name\"):\n        return None\n    name = rm[\"refmet_name\"]\n    # 2) Fetch full RefMet record (includes pubchem_cid \u002F inchi_key)\n    full = requests.get(f\"{BASE}\u002Frefmet\u002Fname\u002F{name}\u002Fall\", timeout=30).json()\n    if not isinstance(full, dict) or not full:\n        return None\n    # 3) Optionally pull the matching compound record via PubChem CID\n    cid = full.get(\"pubchem_cid\")\n    compound = None\n    if cid:\n        compound = requests.get(f\"{BASE}\u002Fcompound\u002Fpubchem_cid\u002F{cid}\u002Fall\u002Fjson\",\n                                timeout=30).json()\n    return {\n        \"input\": user_text,\n        \"refmet_name\": name,\n        \"formula\": full.get(\"formula\"),\n        \"pubchem_cid\": cid,\n        \"hmdb_id\": compound.get(\"hmdb_id\") if compound else None,\n        \"kegg_id\": compound.get(\"kegg_id\") if compound else None,\n        \"inchi_key\": full.get(\"inchi_key\"),\n    }\n\nqueries = [\"glucose\", \"alpha-D-glucose\", \"L-tyrosine\", \"cholesterol\"]\ndf = pd.DataFrame([resolve_to_compound(q) for q in queries])\nprint(df.to_string(index=False))\ndf.to_csv(\"name_resolution.csv\", index=False)\n```\n\n### Workflow 2: Annotate MS Hit List\n\n**Goal**: Take a list of measured m\u002Fz values and assign RefMet candidate compounds.\n\n```python\nimport requests, io, pandas as pd, time\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef annotate_peaks(mz_values, ion=\"M+H\", tolerance=0.005):\n    out = []\n    for mz in mz_values:\n        r = requests.get(f\"{BASE}\u002Fmoverz\u002FREFMET\u002F{mz}\u002F{ion}\u002F{tolerance}\u002Ftxt\", timeout=30)\n        if r.status_code != 200 or not r.text.strip():\n            time.sleep(0.3); continue\n        df = pd.read_csv(io.StringIO(r.text), sep=\"\\t\")\n        for _, row in df.iterrows():\n            out.append({\n                \"query_mz\": mz,\n                \"matched_mz\": row[\"Matched m\u002Fz\"],\n                \"delta\": row[\"Delta\"],\n                \"name\": row[\"Name\"],\n                \"formula\": row[\"Formula\"],\n                \"ion\": row[\"Ion\"],\n                \"main_class\": row.get(\"Main class\"),\n            })\n        time.sleep(0.3)\n    return pd.DataFrame(out)\n\npeaks = [180.063, 166.086, 90.055]   # glucose, phenylalanine, alanine\ndf_ann = annotate_peaks(peaks)\nprint(df_ann.head(10).to_string(index=False))\ndf_ann.to_csv(\"ms_annotations.csv\", index=False)\n```\n\n### Workflow 3: Find Studies Detecting a Metabolite\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef studies_with(refmet_name, enrich_n=20):\n    \"\"\"Return a DataFrame: study_id rows that report the metabolite, enriched with\n    title + species for the first `enrich_n` IDs (via study\u002Fstudy_id\u002F...\u002Fsummary).\"\"\"\n    r = requests.get(f\"{BASE}\u002Fstudy\u002Frefmet_name\u002F{refmet_name}\u002Fsummary\", timeout=60)\n    r.raise_for_status()\n    d = r.json()\n    rows = list(d.values()) if isinstance(d, dict) else d\n    ids = sorted({row[\"study_id\"] for row in rows if row.get(\"study_id\")})\n    enriched = []\n    for sid in ids[:enrich_n]:\n        enriched.append(requests.get(\n            f\"{BASE}\u002Fstudy\u002Fstudy_id\u002F{sid}\u002Fsummary\", timeout=30).json())\n    return pd.DataFrame(enriched)\n\ndf = studies_with(\"Glucose\", enrich_n=20)\nprint(f\"Glucose-detecting studies (first 20 enriched): {len(df)}\")\nprint(df.groupby(\"species\").size().sort_values(ascending=False).head(8))\n```\n\n## Key Parameters\n\n| Parameter | Endpoint | Default | Range \u002F Options | Effect |\n|-----------|----------|---------|-----------------|--------|\n| `context` | path | required | `compound`, `refmet`, `moverz`, `study`, `analysis`, `metabolite`, `gene`, `protein` | API context selector |\n| `input_item` | path | required | depends on context (see \"Allowed `input_item` Values per Context\") | Identifier type |\n| `input_value` | path | required | string | The actual identifier or value |\n| `output_item` | path | `all` | `all`, `summary`, `metabolites`, `factors`, `data`, etc. | What aspect to return |\n| `format` | path | (varies) | `json`, `txt` | `moverz` only emits `txt`; do NOT append `\u002Fjson` to `study\u002F...\u002Fsummary` |\n| `mz` \u002F `ion` \u002F `tolerance` | `moverz` path | required | float \u002F `M+H`, `M-H`, `M+Na`, `M+K`, etc. \u002F float | Mass tolerance in Da |\n\n## Best Practices\n\n1. **Use `refmet\u002Fmatch` first for free-text input.** `compound\u002Fname\u002F...` is rejected by the server (`name` is not an allowed `input_item`).\n2. **`moverz` is TSV-only.** Parse with `pd.read_csv(io.StringIO(r.text), sep=\"\\t\")` — never call `.json()` on the response.\n3. **Don't append `\u002Fjson` to `study\u002F...\u002Fsummary`.** The default is JSON; the suffix flips the response to TSV.\n4. **`refmet\u002Fname\u002F{x}\u002Fall` needs the canonical RefMet name.** If you have user text, run it through `refmet\u002Fmatch` first.\n5. **Compound results paged by formula come keyed `'1','2',...`** — iterate `dict.values()` or pass to `pd.DataFrame.from_dict(orient=\"index\")`.\n6. **Always `time.sleep(0.3)` in batch loops** — no rate limit is published but the server is shared.\n\n## Common Recipes\n\n### Recipe: Cross-Database ID Mapping (PubChem ↔ KEGG ↔ HMDB)\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\n\ndef cross_refs(refmet_name):\n    rm = requests.get(f\"{BASE}\u002Frefmet\u002Fname\u002F{refmet_name}\u002Fall\", timeout=30).json()\n    if not isinstance(rm, dict) or not rm:\n        return None\n    cid = rm.get(\"pubchem_cid\")\n    if not cid:\n        return {\"refmet\": refmet_name, \"pubchem_cid\": None}\n    c = requests.get(f\"{BASE}\u002Fcompound\u002Fpubchem_cid\u002F{cid}\u002Fall\u002Fjson\", timeout=30).json()\n    return {\"refmet\": refmet_name,\n            \"pubchem_cid\": cid,\n            \"kegg_id\": c.get(\"kegg_id\"),\n            \"hmdb_id\": c.get(\"hmdb_id\"),\n            \"inchi_key\": rm.get(\"inchi_key\")}\n\ndf = pd.DataFrame([cross_refs(n) for n in [\"Glucose\", \"L-Tyrosine\", \"Cholesterol\"]])\nprint(df.to_string(index=False))\n```\n\n### Recipe: Pull a Study's Metabolite Table\n\n```python\nimport requests, pandas as pd\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\nr = requests.get(f\"{BASE}\u002Fstudy\u002Fstudy_id\u002FST000001\u002Fmetabolites\", timeout=60)\nr.raise_for_status()\nrows = list(r.json().values())\ndf = pd.DataFrame(rows)\nprint(f\"ST000001 metabolites: {len(df)}\")\nprint(df[[\"analysis_id\", \"analysis_summary\", \"metabolite_name\", \"refmet_name\"]].head(5).to_string(index=False))\n```\n\n### Recipe: Gene → Metabolomics Pathways\n\n```python\nimport requests\n\nBASE = \"https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Frest\"\ng = requests.get(f\"{BASE}\u002Fgene\u002Fgene_symbol\u002FHMGCR\u002Fall\", timeout=30).json()\nprint({k: g.get(k) for k in [\"gene_symbol\", \"gene_id\", \"mgp_id\",\n                              \"gene_name\", \"gene_synonyms\"]})\n```\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| `\"This input item (name) is not allowed...\"` | `compound\u002Fname\u002F...` is rejected | Use one of the allowed `input_item` values (`pubchem_cid`, `kegg_id`, `inchi_key`, `hmdb_id`, etc.); for free text, go through `refmet\u002Fmatch\u002F{x}` first |\n| `JSONDecodeError` on `moverz` response | `moverz` returns TSV text, not JSON | Parse with `pd.read_csv(io.StringIO(r.text), sep=\"\\t\")` |\n| Empty list from `refmet\u002Fname\u002F{x}\u002Fall` | Need the canonical RefMet name (case-sensitive) | Normalise via `refmet\u002Fmatch\u002F{user_text}` first, then plug `refmet_name` into `refmet\u002Fname\u002F...\u002Fall` |\n| `metstat\u002Ffilter\u002F...` returns `[]` | Endpoint syntax is non-functional | Use `study\u002F{refmet_name|last_name|institute|...}\u002F{value}\u002Fsummary` and filter client-side |\n| `study\u002F...\u002Fsummary` returns TSV instead of JSON | The `\u002Fjson` suffix flips to TSV | Drop the trailing `\u002Fjson` — JSON is the default |\n| Compound query by formula returns a dict, not a list | Server pages multiple matches as `{'1': {...}, '2': {...}}` | Iterate `dict.values()` (or `pd.DataFrame.from_dict(d, orient='index')`) |\n| `refmet\u002Fmatch` response lacks `pubchem_cid` | `match` returns the lightweight record | Use `refmet\u002Fname\u002F{refmet_name}\u002Fall` for the full record |\n\n## Related Skills\n\n- `hmdb-database` — Local HMDB XML (220K metabolites, NMR\u002FMS spectra, disease links) for offline queries\n- `pubchem-compound-search` — General compound property lookups (110M+ compounds) via PubChemPy\n- `kegg-database` — Pathway and orthology data complementary to MW's study\u002Fmetabolite hits\n- `chembl-database-bioactivity` — Bioactivity data for the same compounds\n\n## References\n\n- [Metabolomics Workbench home](https:\u002F\u002Fwww.metabolomicsworkbench.org\u002F)\n- [REST API documentation (PDF)](https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Ftools\u002FMWRestAPIv1.0.pdf)\n- [RefMet nomenclature](https:\u002F\u002Fwww.metabolomicsworkbench.org\u002Fdatabases\u002Frefmet\u002Findex.php)\n- Sud M et al. \"Metabolomics Workbench: An international repository for metabolomics data and metadata.\" *Nucleic Acids Research* 44(D1): D463–D470 (2016). https:\u002F\u002Fdoi.org\u002F10.1093\u002Fnar\u002Fgkv1042\n",{"name":5,"license":15,"description":7},"master","63f17866001c5ca854bf2fa0b678ce277133de5b","skills\u002Fawesome-skills\u002Fmetabolomics-workbench-database",0,"https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS","https:\u002F\u002Fbg-szy.github.io\u002FTOP-SKILLS\u002F","https:\u002F\u002Fgithub.com\u002Fbg-szy","https:\u002F\u002Fwww.ecust.edu.cn\u002F","a student of East China University of Science and Technology","2026-11-15 03:38:02",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add bg-szy\u002FTOP-SKILLS --skill metabolomics-workbench-database",{"tool":40,"command":41},"bunx","bunx skills add bg-szy\u002FTOP-SKILLS --skill metabolomics-workbench-database",{"tool":43,"command":44},"pnpm","pnpm dlx skills add bg-szy\u002FTOP-SKILLS --skill metabolomics-workbench-database","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fawesome-skills\u002Fmetabolomics-workbench-database\u002FSKILL.md",true,[],[49,58,65,72,79,86],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":57},"01M7DXW9N826PKXK174PVW3038","serpmaven","Scrape Google search results (SERP) to JSON with SERP Maven (serpmaven) - a real Chrome browser on a residential proxy with sticky sessions. Run it as a CLI, a Python library, a local HTTP search API (`serve`), an MCP server or a Docker image; set the proxy login, workers, pages and cost tracking. Use when the user wants Google results, rank tracking, a self-hosted SERP API, or live Google search for an AI agent.","MIT","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Fserpmaven\u002FSKILL.md",[],[],"2026-11-15 14:19:17",{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":57},"01M7DXVHSTWDV65475QEQ915M7","revnu-landing-page-audit","Find out why a landing page isn't turning visitors into signups, demos or sales. Audits one page against what the ad, post or search that sends people there promised, then checks the first screen, proof, call to action, friction and mobile. Returns at most 7 prioritized fixes, plus what is fine and what could not be checked; rewrites specific lines and fixes the page in the repo when asked. Never promises a conversion lift. Works without a Revnu account. Use when the user says or asks: \"audit my landing page\", \"why isn't this page converting\", \"review my homepage\", \"my ads get clicks but no signups\", \"people bounce from the pricing page\", \"CRO review\", \"improve conversion rate\", \"is my hero section clear\", \"roast my landing page\", \"rewrite my headline\", \"what's wrong with this page\", \"landing page feedback\", \"make the signup page convert better\". Not for SEO or AI-search audits, page speed engineering on its own, or building a new page from scratch.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Frevnu-landing-page-audit\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":57},"01M7DXV8X2D7B3VTD4HHYYHTGR","revnu-growth-context","Write down once who buys, what they're stuck on, what it costs, what proof you have and what you've already tried, so every growth task starts from facts instead of a questionnaire. Creates or updates .agents\u002Frevnu-growth.md from the repo, the live site and the user, and imports an existing product-marketing.md. Use when the user says \"set up our marketing context\", \"who is our ideal customer\", \"write our ICP\", \"describe the product for marketing\", \"positioning doc\", \"what's our brand voice\", \"remember this about our customers\", \"log what we tried\", \"what have we learned from marketing\", \"we changed pricing, update the context\", \"update our growth notes\", \"summarize the business for the agent\", \"import my product-marketing.md\", \"start a growth doc\", or before a first marketing, SEO, outreach or launch task when no context file exists. Works without a Revnu account.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Frevnu-growth-context\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":57},"01M7DXV0DGJ1G0A60PAHC6J3C5","revnu-get-listed","Get onto the third-party pages AI answers and search cite when buyers ask for the best tool in your category: \"best X\" roundups, directories, review sites, GitHub awesome lists, community threads and comparison pages. Finds which ones are cited, ranks them by fit and effort, and drafts each submission, PR or pitch by the target's own rules. Use when the user says \"get us listed\", \"which directories should we submit to\", \"how do we get into best-of lists\", \"why does ChatGPT recommend competitors and not us\", \"get mentioned in AI answers\", \"submit to awesome lists\", \"get on G2\", \"where are our competitors listed\", \"pitch listicle authors\", \"find backlink opportunities\", \"launch directories\", \"get into roundups\", \"Product Hunt alternatives\", \"where should we be listed\", \"get cited by Perplexity\". Never submits, pays or posts without a yes. Works without a Revnu account.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Frevnu-get-listed\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":57},"01M7DXTSPMGT9D6DSS0HP9BSTA","revnu-ai-readiness-audit","Audit whether your website gives ChatGPT, Perplexity, Claude, Gemini and Google's AI Overviews something worth quoting, and fix the pages that don't. Use when the user says or asks \"is my site ready for AI search\", \"audit my site for AI answers\", \"AEO audit\", \"GEO audit\", \"why doesn't ChatGPT quote our pricing\", \"make our pages citable by AI\", \"do I need llms.txt\", \"does schema help with ChatGPT\", \"check our structured data\", \"is our content visible without JavaScript\", \"AI SEO audit\", \"optimize our homepage for AI answers\", \"LLM SEO check\", \"why does AI get our product wrong\", \"fix our site for AI Overviews\". Checks fetchability and indexability, answers in the raw HTML, entity facts, schema (including JS-injected markup), headings, dates and llms.txt, then gives at most 10 prioritised fixes and edits the repo when asked. Works without a Revnu account.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Frevnu-ai-readiness-audit\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":57},"01M7DXSZHCVTRS620GC3S97JZV","proxy-troubleshooting","Diagnose residential proxy failures, with NodeMaven's gateway as the reference - 407 with correct credentials, 406, 410, 500, a connection that hangs, ERR_TUNNEL_CONNECTION_FAILED in a browser, Playwright or Puppeteer ignoring proxy credentials, a sticky session that changes IP, geo-targeting that is silently ignored, passwords with special characters, and unexpected traffic from headless Chrome. Use when a proxy connection fails, returns the wrong location, or costs more traffic than expected.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Fproxy-troubleshooting\u002FSKILL.md",[],[]]