output: html_document: highlight: tango keep_md: yes theme: readable
CTSgetR
provides a consitent interface to translation of chemical names and over 200 database identifiers including InChIKey
, HMDB
, KEGG
and PubChem
. Translation of chemical names is hard. Use CTSgetR
to robustly translate chemical names to other identifiers through 1) conversion to InChIKey
2) biological
or popularity
scoring and 3) translation to over 200 biological database identifiers. CTSgetR
uses a sqlite database to cache and speed all of your routine translations.
using R
install_github("dgrapov/CTSgetR")
library(CTSgetR)
GET('https://cts.fiehnlab.ucdavis.edu/services') %>%
http_status(.) %>%
{if( .$category != 'Success'){stop('Oops looks like https://cts.fiehnlab.ucdavis.edu/services is down!') }}
trans<-unlist(valid_from())
head(trans,10)
## [1] "BioCyc" "CAS"
## [3] "ChEBI" "Chemical Name"
## [5] "Human Metabolome Database" "InChIKey"
## [7] "KEGG" "LMSD"
## [9] "LipidMAPS" "PubChem CID"
want<-'CID'
trans[grepl(want,trans,ignore.case=TRUE)]
## [1] "PubChem CID"
db_name<-'ctsgetr.sqlite'
init_CTSgetR_db(db_name)
db_stats()
Chemical Name
to InChIKey
db_name<-'ctsgetr.sqlite' # local cache
id<-c("alanine",'lactic acid')
from<-"Chemical Name"
to<-"InChIKey"
CTSgetR(id,from,to,db_name=db_name)
## id InChIKey
## 1 alanine QNAYBMKLOCPYGJ-REOHCLBHSA-N
## 2 lactic acid JVTAAEKCZFNVCJ-UHFFFAOYSA-N
data.frame
input format for more complex queries.id<-c("alanine",'lactic acid')
from<-"Chemical Name"
to<- c( "PubChem CID", "KEGG","Human Metabolome Database")
CTSgetR(id,from,to,db_name=db_name)
## id Human Metabolome Database KEGG PubChem CID
## 1 alanine HMDB0000161 C00041 5950
## 2 lactic acid HMDB0144295 C01432 19789253
id
, from
to to
values. #from many to many
args <-structure(list(id = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 4L, 4L), .Label = c("alanine", "foo", "lactic acid", "HMDB0000161"
), class = "factor"), from = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L), .Label = c("Chemical Name", "Human Metabolome Database"
), class = "factor"), to = structure(c(1L, 1L, 1L, 2L, 2L, 2L,
3L, 3L, 3L, 2L, 1L), .Label = c("PubChem CID", "KEGG", "Human Metabolome Database"
), class = "factor")), class = "data.frame", row.names = c(NA,
-11L))
args
## id from to
## 1 alanine Chemical Name PubChem CID
## 2 foo Chemical Name PubChem CID
## 3 lactic acid Chemical Name PubChem CID
## 4 alanine Chemical Name KEGG
## 5 foo Chemical Name KEGG
## 6 lactic acid Chemical Name KEGG
## 7 alanine Chemical Name Human Metabolome Database
## 8 foo Chemical Name Human Metabolome Database
## 9 lactic acid Chemical Name Human Metabolome Database
## 10 HMDB0000161 Human Metabolome Database KEGG
## 11 HMDB0000161 Human Metabolome Database PubChem CID
args %>%
split(.,.$from) %>%
map(~CTSgetR(.$id,.$from,.$to,db_name=db_name)) %>%
bind_rows(.)
## id Human Metabolome Database KEGG PubChem CID
## 1 alanine HMDB0000161 C00041 5950
## 2 foo <NA> <NA> <NA>
## 3 lactic acid HMDB0144295 C01432 19789253
## 4 HMDB0000161 <NA> C00041 5950
Deploy
CTSgetR
as adocker
izedAPI
build
and run the CTSgetR
package as an opencpu based API
.CTSgetR
API
CTSgetR
image contains an opencpu and Rstudio serverlocalhost/ocpu/
: opencpu-serverlocalhost/rstudio/
: rstudio server (use user: opencpu and password: )image
build
export rstudio_pass=mypassword # rstudio server password for user opencpu
docker-compose -f docker-compose.yml build --force-rm
#mount to persist internal sqlite DB between updates
export ctsgetr_db_mount=<local path to save database e.g. /mypath>
docker-compose -f docker-compose.yml up -d
bash
curl http://localhost/ocpu/library/CTSgetR/R/heartbeat
R
library(ocpuclient)
base_url<-'http://localhost/ocpu/'
endpoint<-'library/CTSgetR/R/heartbeat'
url<-paste0(base_url,endpoint)
post_ocpu(url=url)
#translate
endpoint<-'library/CTSgetR/R/CTSgetR'
url<-paste0(base_url,endpoint)
id <-
c("C15973",
"C00026")
from <- "KEGG"
to <- "PubChem CID"
body<-list(id=id,from=from,to=to,db_name=db_name)
post_ocpu(url=url,body=body)
Launch
shiny
UI using asynchronousopencpu
API
shiny
module combined with futures
and promises
R
packages to connect to an opencpu
API uisng async calls.library(shiny)
library(tippy)
library(CTSgetR) # local calls
library(ocpuclient) # CTSgetR opencpu API calls
#one of local
Sys.setenv('ctsgetr_DB'='inst/ctsgetr.sqlite') #see section `in R` showing how to initialize a local databse
#or API
Sys.setenv('ctsgetr_DB'='/ctsgetr/inst/ctsgetr.sqlite') # in API docker for mount
Sys.setenv('CTSgetR_API'='http://localhost/ocpu/library/CTSgetR/R/CTSgetR') # url of API endpoint
````
#### User input translations
```r
library(promises)
library(future)
plan(multisession)
#module
ui <- fluidPage(
sidebarLayout(position = "left",
sidebarPanel(tagList(mod_CTSgetR_ui("translate"))),
mainPanel(verbatimTextOutput("main_out")))
)
server <- function(input, output, session) {
translation <- mod_CTSgetR_server('translate')
output$main_out <- renderPrint({
translation() %...>% print(.)
})
}
shinyApp(ui, server)
library(promises)
library(future)
plan(multisession)
#make `example` a reactive returning a data frame to update dynamically
example<-data.frame('chemical_name' = c('alanine','Pyruvic acid'))
#module
ui <- fluidPage(
sidebarLayout(position = "left",
sidebarPanel(tagList(mod_CTSgetR_ui("translate"))),
mainPanel(verbatimTextOutput("main_out")))
)
server <- function(input, output, session) {
translation <- mod_CTSgetR_server('translate',data=example)
output$main_out <- renderPrint({
translation() %...>% print(.)
})
}
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.