R/9_convert_metabolite_id.R
convert_metabolite_id.RdThis function converts metabolite identifiers from one database format to another using different online services, including CTS FiehnLab, ChemSpider, and OpenAI.
convert_metabolite_id(
query = "C00001",
from = "KEGG",
to = "Chemical Name",
top = 1,
server = c("cts.fiehnlab", "chemspider", "openai"),
chemspider_apikey = "",
openai_apikey = ""
)Character. The metabolite ID to convert (e.g., "C00001").
Character. The source database (e.g., "KEGG", "InChIKey").
Character. The target database or chemical name format (e.g., "Chemical Name", "InChI").
Integer. The number of top matches to return.
Character. The server to use for conversion. Options: `"cts.fiehnlab"`, `"chemspider"`, `"openai"`.
Character. API key for ChemSpider (required if using `"chemspider"` server). **How to Obtain a ChemSpider API Key:** 1. Go to the **Royal Society of Chemistry (RSC) Developer Portal**: [https://developer.rsc.org/](https://developer.rsc.org/) 2. Sign in or create an account. 3. Navigate to **My Account** > **API Keys**. 4. Apply for access to the **ChemSpider API**. 5. Once approved, generate your API key and copy it for use. 6. Use this key as the `chemspider_apikey` argument in the function.
Character. API key for OpenAI (required if using `"openai"` server).
A data frame with the original query and converted metabolite ID(s).
convert_metabolite_id(query = "C00001", from = "KEGG",
to = "Chemical Name", server = "cts.fiehnlab")
#> KEGG Chemical Name
#> 1 C00001 oxidane
convert_metabolite_id(query = "BQJCRHHNABKAKU-KBQPJGBKSA-N",
from = "InChIKey", to = "InChI", server = "chemspider", chemspider_apikey = "your_key")
#> InChIKey InChI
#> 1 BQJCRHHNABKAKU-KBQPJGBKSA-N NA
convert_metabolite_id(query = "C00001", from = "KEGG",
to = "Chemical Name", server = "openai", openai_apikey = "your_key")
#> Error in curl::curl_fetch_memory(url, handle = handle): Timeout was reached [api.openai.com]:
#> Connection timed out after 10007 milliseconds