Consuming CEU Mass Mediator RESTful API in R.
Thank you @albertogilf for your kindness and help!
Please find the CEU Mass Mediator source code repository: CEU Mass Mediator source code on GitHub
The CEU Mass Mediator Website: CEU Mass Mediator
Batch search http://ceumass.eps.uspceu.es/mediator/api/v3/batch
Advanced search http://ceumass.eps.uspceu.es/mediator/api/v3/advancedbatch
MS/MS search http://ceumass.eps.uspceu.es/mediator/api/msmssearch
CEU Mass Mediator is an online tool that aides researchers in identifying metabolites from mass spectrometry experiments. It is currently available as a web interface and a RESTful API. CMMR is a RESTful API implemented for R. This makes it easy to access CEU Mass Mediator programatically in R, integrating search results seamlessly into users custom pipelines and workflows.
To get a bug fix, or use a feature from the development version, you can install cmmr from GitHub.
Batch search all result in positive mode
library(cmmr)
batch_df_pos <- batch_search('http://ceumass.eps.uspceu.es/mediator/api/v3/batch',
'all-except-peptides',
'["all-except-mine"]',
'mz',
'positive',
'["M+H","M+Na"]',
100,
'ppm',
c(670.4623, 1125.2555, 602.6180))
head(batch_df_pos)
str(batch_df_pos)
Batch search all result in negative mode
library(cmmr)
batch_df_neg <- batch_search('http://ceumass.eps.uspceu.es/mediator/api/v3/batch',
'all-except-peptides',
'["all-except-mine"]',
'mz',
'negative',
'["M-H","M+Cl"]',
100,
'ppm',
c(670.4623, 1125.2555, 602.6180))
head(batch_df_neg)
str(batch_df_neg)
You may want to load your own list of m/zs from a csv or excel file to search the database.
unique_mz_file <- system.file("extdata", "unique_mz.csv", package = "cmmr")
unique_mz <- read.table(unique_mz_file, sep = ",", stringsAsFactors = FALSE, header = FALSE)
unique_mz <- as.array(unique_mz[, 1])
batch_df_neg <- batch_search('http://ceumass.eps.uspceu.es/mediator/api/v3/batch',
'all-except-peptides',
'["all-except-mine"]',
'mz',
'negative',
'["M-H","M+Cl"]',
10,
'ppm',
unique_mz)
And save it as a *.csv to the same folder or some other specified folder
# Save to the same folder of the unique_mz.csv
write.table(batch_df_neg, sub(".csv", "_db_search.csv", unique_mz_file),
sep = ",", row.names = FALSE)
Save to current working directory
library(cmmr)
advanced_batch_df <- advanced_batch_search(
cmm_url = paste0(
'http://ceumass.eps.uspceu.es/mediator/api/v3/',
'advancedbatch'),
chemical_alphabet = 'all',
modifiers_type = 'none',
metabolites_type = 'all-except-peptides',
databases = '["hmdb"]',
masses_mode = 'mz',
ion_mode = 'positive',
adducts = '["all"]',
deuterium = 'false',
tolerance = '7.5',
tolerance_mode = 'ppm',
masses = '[400.3432, 288.2174]',
all_masses = '[]',
retention_times = '[18.842525, 4.021555]',
all_retention_times = '[]',
composite_spectra = paste0(
'[[{ "mz": 400.3432, "intensity": 307034.88 }, ',
'{ "mz": 311.20145, "intensity": 400.03336 }]]'
))
head(advanced_batch_df)
str(advanced_batch_df)