Hello,
My R code worked fine until recently. I’m trying to retrieve KEGG metabolic pathways from metabolite names. However, recently I noticed that the API wasn’t working and consequently my code wasn’t working either. I’ve tried several types of script, updated packages … But it seems that the error is coming from the server, because using the code in the “MetaboAnalyst” tutorial
name.vec <- c("1,3-Diaminopropane;2-Ketobutyric acid;2-Hydroxybutyric acid;2-Methoxyestrone")
toSend = list(queryList = name.vec, inputType = "name")
library(httr)
# 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
# Parse 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")
query_results_json <- rjson::fromJSON(query_results_text, flatten = TRUE)
query_results_table <- t(rbind.data.frame(query_results_json))
rownames(query_results_table) <- query_results_table[,1]
I get code 502 (query_results$status_code==200 egal FALSE) and then it’s impossible to get the results of the query "query_results_json ← rjson::fromJSON(query_results_text)
Error in rjson::fromJSON(query_results_text) :
not all data was parsed (0 chars were parsed out of a total of 3376 chars).
Thank you for your help, I am a novice in bioinformatics and maybe this is due to a misunderstanding on my part. I can’t wait to find the solution to my problem !!!