Repository navigation
Add mapMetabolites(): metabolite identifier conversion through the MetaboAnalyst API - #284
Open
Cvicnaire wants to merge 1 commit into
Conversation
…yst API One exported function over MetaboAnalyst's public mapcompounds endpoint, built on the searchExternal HTTP plumbing so tests mock externalPostJson(). Inputs are cleaned and sent in chunks of 200; the reply's "NA" strings and JSON nulls both become NA. The URL is overridable through options(sigrepo.metaboanalyst_url). When tested live on 2026-10-15 only from = "name" returned matches; the documented id input types are passed through as documented but came back unmatched, which the roxygen and NEWS say. Closes #281. Serves #171. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #281. Serves #171.
What
mapMetabolites(ids, from = "name", timeout = 120)converts metabolite names or identifiers between HMDB, PubChem, ChEBI, KEGG, METLIN and SMILES through MetaboAnalyst's public compound-mapping endpoint (POST https://rest.xialab.ca/api/mapcompounds). One row per distinct input, in input order, with amatchedflag and the canonical compound name. No login, no new dependency.How
R/mapMetabolites.R: the exported function, an input cleaner (trim, drop empty and NA-like values, de-duplicate, refuse values containing the service's;separator), a fetch step throughexternalPostJson()and a parse step that reads both the string"NA"and JSONnullas missing. Long lists go in chunks of 200 because the service takes about 20 to 30 s per request plus a fraction of a second per compound (1000 ids took 117 s in one request; 2500 timed out).externalUrl("metaboanalyst")with thesigrepo.metaboanalyst_urloption, next to the Rummagene, RummaGEO and CORESH entries.tests/testthat/test_mapMetabolites.R: 11 tests, 37 assertions, HTTP mocked, fixture captured from the live service on 2026-10-15.Caveat worth knowing
When tested live on 2026-10-15, only
from = "name"returned matches. The five identifier input types MetaboAnalyst documents (hmdb,pubchem,chebi,kegg,metlin) came back unmatched for known-good ids, whatever the field name or casing. The function passes them through as documented and the roxygen and NEWS say so; checkmatchedbefore relying on an id-based lookup.Tests
Full suite with
devtools::load_all()+testthat::test_dir(): 1204 pass, 0 fail, 84 skip (the database-gated tests, no local stack configured).Out of scope
Enrichment or pathway analysis via MetaboAnalystR, writing mapped ids into
metabolite_xref, and any server, MCP or Shiny exposure.🤖 Generated with Claude Code