R/9_convert_metabolite_id.R
convert_metabolite_id_chemspider.RdConverts metabolite IDs from one format to another using the ChemSpider API.
convert_metabolite_id_chemspider(
query = "BQJCRHHNABKAKU-KBQPJGBKSA-N",
from = "InChIKey",
to = "InChI",
top = 1,
chemspider_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. 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.
A data frame with the original query and converted metabolite ID(s).
# \donttest{
# Example 1: Convert from InChIKey to InChI using ChemSpider (API key required)
# Replace 'your_chemspider_api_key' with your actual API key
convert_metabolite_id_chemspider(
query = "BQJCRHHNABKAKU-KBQPJGBKSA-N",
from = "InChIKey",
to = "InChI",
chemspider_apikey = "your_chemspider_api_key"
)
#> InChIKey InChI
#> 1 BQJCRHHNABKAKU-KBQPJGBKSA-N NA
# Example 2: Convert from a metabolite ID in "csid" format
# Assuming '12345' is a valid ChemSpider ID
convert_metabolite_id_chemspider(
query = "12345",
from = "ChemSpider",
to = "InChI",
chemspider_apikey = "your_chemspider_api_key"
)
#> ChemSpider InChI
#> 1 12345 NA
# }