HI, I was trying to perform Compound name mapping by API in section 3.2 here:
https://www.metaboanalyst.ca/MetaboAnalyst/docs/RTutorial.xhtml
As other posts have mentioned, it seems to only work when querying by name but not other types of ID (such as KEGG ID). I was wondering if this issue has been solved? thank you very much for your help.
Related posts are here:
here is my code record:
library(httr)
using compound name to query:
name.vec<-c(“1,3-Diaminopropane”)
toSend = list(queryList = name.vec, inputType = “name”)The MetaboAnalyst API url
call ← “https://www.xialab.ca/api/mapcompounds”
Use httr::POST to send the request to the MetaboAnalyst API
The response will be saved in query_results
query_results ← httr::POST(call, body = toSend, encode = “json”)
Check if response is ok (TRUE)
200 is ok! 401 means an error has occured on the user’s end.
query_results$status_code==200
[1] TRUEParse the response into a table
Will show mapping to “hmdb_id”, “kegg_id”, “pubchem_id”, “chebi_id”, “metlin_id”, “smiles”
query_results_text ← content(query_results, “text”, encoding = “UTF-8”)
fromJSON takes JSON strings
query_results_text2 ← gsub(“'”, ‘"’, query_results_text)
query_results_text2 ← purrr::map(query_results_text2, jsonlite::fromJSON)
query_results_table ← do.call(cbind, lapply(query_results_text2, data.frame, stringsAsFactors = FALSE))
rownames(query_results_table) ← query_results_table[,1]
print(query_results_table)
Query Match HMDB PubChem ChEBI KEGG METLIN SMILES Comment
1,3-Diaminopropane 1,3-Diaminopropane 1,3-Diaminopropane HMDB0000002 428 15725 C00986 5081 NCCCN 1using kegg ID to query:
name.vec<-c(“C00986”)
toSend = list(queryList = name.vec, inputType = “kegg”)The MetaboAnalyst API url
call ← “https://www.xialab.ca/api/mapcompounds”
Use httr::POST to send the request to the MetaboAnalyst API
The response will be saved in query_results
query_results ← httr::POST(call, body = toSend, encode = “json”)
Check if response is ok (TRUE)
200 is ok! 401 means an error has occured on the user’s end.
query_results$status_code==200
[1] TRUEParse the response into a table
Will show mapping to “hmdb_id”, “kegg_id”, “pubchem_id”, “chebi_id”, “metlin_id”, “smiles”
query_results_text ← content(query_results, “text”, encoding = “UTF-8”)
fromJSON takes JSON strings
query_results_text2 ← gsub(“'”, ‘"’, query_results_text)
query_results_text2 ← purrr::map(query_results_text2, jsonlite::fromJSON)
query_results_table ← do.call(cbind, lapply(query_results_text2, data.frame, stringsAsFactors = FALSE))
rownames(query_results_table) ← query_results_table[,1]
print(query_results_table)
Query Match HMDB PubChem ChEBI KEGG METLIN SMILES Comment
C00986 C00986 NA NA NA NA NA NA NA 0
======
sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
other attached packages:
[1] httr_1.4.7
loaded via a namespace (and not attached):
[1] Rcpp_1.0.11         urlchecker_1.0.1    pillar_1.9.0        compiler_4.1.1      BiocManager_1.30.22 later_1.3.1
[7] remotes_2.4.2.1     profvis_0.3.8       tools_4.1.1         digest_0.6.33       pkgbuild_1.4.3      pkgload_1.3.3
[13] jsonlite_1.8.8      memoise_2.0.1       lifecycle_1.0.4     tibble_3.2.1        pkgconfig_2.0.3     rlang_1.1.2
[19] shiny_1.8.0         cli_3.6.1           rstudioapi_0.15.0   curl_5.1.0          fastmap_1.1.1       dplyr_1.1.4
[25] stringr_1.5.1       generics_0.1.3      fs_1.6.3            vctrs_0.6.5         htmlwidgets_1.6.4   devtools_2.4.5
[31] tidyselect_1.2.0    glue_1.6.2          R6_2.5.1            fansi_1.0.5         sessioninfo_1.2.2   purrr_1.0.2
[37] magrittr_2.0.3      usethis_2.2.2       promises_1.2.1      ellipsis_0.3.2      htmltools_0.5.7     mime_0.12
[43] xtable_1.8-4        httpuv_1.6.12       utf8_1.2.4          stringi_1.8.2       miniUI_0.1.1.1      cachem_1.0.8