diff --git a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/.gitignore b/CTSgetR.Rcheck/00_pkg_src/CTSgetR/.gitignore deleted file mode 100644 index 436d0f4..0000000 --- a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -# History files -.Rhistory - -# Example code in package build process -*-Ex.R -.Rproj.user diff --git a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/DESCRIPTION b/CTSgetR.Rcheck/00_pkg_src/CTSgetR/DESCRIPTION deleted file mode 100644 index 3d41c39..0000000 --- a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/DESCRIPTION +++ /dev/null @@ -1,11 +0,0 @@ -Package: CTSgetR -Type: Package -Title: Translation between chemical identifiers using the Chemical - Translation Service (CTS) -Version: 1.0 -Date: 2013-04-20 -Author: Dmitry Grapov -Maintainer: -Description: Translate between "Chemical Name","InChIKey","InChI Code","PubChem CID","Pubchem SID","ChemDB","ZINC","Southern Research Institute","Specs","MolPort","ASINEX","ChemBank","MLSMR","Emory University Molecular Libraries Screening Center","ChemSpider","DiscoveryGate","Ambinter","Vitas-M Laboratory","ChemBlock" -License: TBA -Packaged: 2013-05-04 06:57:33 UTC; D diff --git a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/NAMESPACE b/CTSgetR.Rcheck/00_pkg_src/CTSgetR/NAMESPACE deleted file mode 100644 index 4c5e397..0000000 --- a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/NAMESPACE +++ /dev/null @@ -1,3 +0,0 @@ -exportPattern("^[[:alpha:]]+") -export(CTS.getR) -import(RCurl,RJSONIO) \ No newline at end of file diff --git a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/R/test.R b/CTSgetR.Rcheck/00_pkg_src/CTSgetR/R/test.R deleted file mode 100644 index 22a6d36..0000000 --- a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/R/test.R +++ /dev/null @@ -1,2 +0,0 @@ -#test -r \ No newline at end of file diff --git a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/README.md b/CTSgetR.Rcheck/00_pkg_src/CTSgetR/README.md deleted file mode 100644 index 2132b8b..0000000 --- a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/README.md +++ /dev/null @@ -1,18 +0,0 @@ -CTSgetR -======= - -R interface to the [Chemical Translation Service (CTS)] (http://uranus.fiehnlab.ucdavis.edu:8080/cts-2.0-beta-2/) - -```R -install.packages("devtools") -install.packages("RJSONIO") -#install.packages("RCurl") -library(devtools);library(RJSONIO)#;library(RCurl) -install_github(repo = "CTSgetR", username = "dgrapov") -library(CTSgetR) -``` - -Try an example translations documented [HERE] (https://github.com/dgrapov/CTSgetR/wiki/Chemical-Translation-Service-in-R). -```R -help(CTS.getR) -``` diff --git a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/man/CTS.getR.Rd b/CTSgetR.Rcheck/00_pkg_src/CTSgetR/man/CTS.getR.Rd deleted file mode 100644 index d03f337..0000000 --- a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/man/CTS.getR.Rd +++ /dev/null @@ -1,91 +0,0 @@ -\name{CTS.getR} -\alias{CTS.getR} -%- Also NEED an '\alias' for EACH other topic documented here. -\title{ -Tranlate between chemical identifiers. -} -\description{ -Use the Chemical Translation Service (CTS) to translate between the following molecular identifiers: - Chemical Name - InChIKey - InChI Code - PubChem CID - Pubchem SID - ChemDB - ZINC - Southern Research Institute - Specs - MolPort - ASINEX - ChemBank - MLSMR - Emory University Molecular Libraries Screening Center - ChemSpider - DiscoveryGate - Ambinter - Vitas-M Laboratory - ChemBlock -} -\usage{ -CTS.getR(id, from, to, progress = TRUE) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{id}{ -a vector of idenitifiers -} - \item{from}{ -type of object translating from -} - \item{to}{ -type of object translating to -} - \item{progress}{ -show progress -} -} -\details{ -%% ~~ If necessary, more details than the description above ~~ -} -\value{ -a 3 column data frame containing containning: -from, to and translated values -} -\references{ -http://uranus.fiehnlab.ucdavis.edu:8080/cts-2.0-beta-2/ -} -\author{ -Dmitry Grapov -} -\note{ -%% ~~further notes~~ -} - -%% ~Make other sections like Warning with \section{Warning }{....} ~ - -\seealso{ -%% ~~objects to See Also as \code{\link{help}}, ~~~ -} -\examples{ - -#translate from PubChem CID to InChIKey -id<-c(14242, 5760) -from<-"PubChem CID" -to<-"InChIKey" -CTS.getR(id,from,to) - -#translate from InchI to pubchem CID -id<- "ZPUCINDJVBIVPJ-LJISPDSOSA-N" -from<-"InChIKey" -to<-"PubChem CID" - -CTS.getR(id,from,to) #go ahead and google it - - - -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -%\keyword{ Chemical Translation Service} -%\keyword{CTS}% __ONLY ONE__ keyword per line -%\keyword{InchI} -%\keyword{CID} diff --git a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/man/CTSgetR-package.Rd b/CTSgetR.Rcheck/00_pkg_src/CTSgetR/man/CTSgetR-package.Rd deleted file mode 100644 index 5bbf1f3..0000000 --- a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/man/CTSgetR-package.Rd +++ /dev/null @@ -1,39 +0,0 @@ -\name{CTSgetR-package} -\alias{CTSgetR-package} -\alias{CTSgetR} -\docType{package} -\title{ -R interface to the Chemical Translation Service (CTS) -} -\description{ -Translate identifiers between the major biological databases including: -"Chemical Name","InChIKey","InChI Code","PubChem CID","Pubchem SID","ChemDB","ZINC","Southern Research Institute","Specs","MolPort","ASINEX","ChemBank","MLSMR","Emory University Molecular Libraries Screening Center","ChemSpider","DiscoveryGate","Ambinter","Vitas-M Laboratory","ChemBlock". -} -\details{ -\tabular{ll}{ -Package: \tab CTSgetR\cr -Type: \tab Package\cr -Version: \tab 1.0\cr -Date: \tab 2013-04-20\cr -License: \tab What license is it under?\cr -} -~~ An overview of how to use the package, including the most ~~ -~~ important functions ~~ -} -\author{ -Dmitry Grapov - -} -\references{ - -} -~~ Optionally other standard keywords, one per line, from file ~~ -~~ KEYWORDS in the R documentation directory ~~ -\keyword{ Chemical Translation Service } -\seealso{ -~~ Optional links to other man pages, e.g. ~~ -~~ \code{\link[:-package]{}} ~~ -} -\examples{ -~~ simple examples of the most important functions ~~ -} diff --git a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/zCTS.r b/CTSgetR.Rcheck/00_pkg_src/CTSgetR/zCTS.r deleted file mode 100644 index dd59ed6..0000000 --- a/CTSgetR.Rcheck/00_pkg_src/CTSgetR/zCTS.r +++ /dev/null @@ -1,113 +0,0 @@ -CTS.getR<-function(id,from,to,parallel=FALSE,server="http://cts.fiehnlab.ucdavis.edu/service/convert"){ - # id = vector of identifiers - #to/from = "Chemical Name","InChIKey","InChI Code","PubChem CID","Pubchem SID","ChemDB","ZINC","Southern Research Institute","Specs","MolPort","ASINEX","ChemBank","MLSMR","Emory University Molecular Libraries Screening Center","ChemSpider","DiscoveryGate","Ambinter","Vitas-M Laboratory","ChemBlock" - #result is a 3 column data frame of from, to and translated values - #check.get.packages(c("snow","doSNOW","foreach","RJSONIO","RCurl")) - - #may need to detach RCurl upon strange error - #detach("package:RCurl", unload=TRUE) - - options(warn=-1) # yehaw - - #get URL contents control the number of urls sent to avoid issues - message(cat("Getting translations...","\n")) - out<-CTS.translate(server=server,from=from,to=to,id=id,parallel=parallel) - #closeAllConnections() # trying to avoid loss of connection erro for later - - #fxn to parse JSON - .parseJSON<-function(obj){ - - if(any(obj=="[]")) # no value from server - { - final<-data.frame(matrix("error",nrow=4)) - } else { - final<-tryCatch(data.frame(RJSONIO::fromJSON(obj))[,1,drop=FALSE],error=function(e){data.frame(matrix("error",nrow=4))}) - } - return(final) - } - - message(cat("\n","Formatting output...","\n")) - if(parallel==TRUE){ # add progress bar - - cl.tmp = makeCluster(rep("localhost",Sys.getenv('NUMBER_OF_PROCESSORS')), type="SOCK") # windows specific - registerDoSNOW(cl.tmp) - #do work - out<-foreach(i=c(1:length(out))) %dopar% .parseJSON(out[i]) - stopCluster(cl.tmp) - } else { - out<-lapply(1:length(out),function(i,pb = txtProgressBar(min = 0, max = length(id), style = 3)){ - setTxtProgressBar(pb, i) - .parseJSON(out[i])}) - } - - #parse into a triple - tmp<-do.call("cbind",out) - tmp<-cbind(from=id,to=to,result=as.character(unlist(tmp[4,]))) - colnames(tmp)<-c(paste("from",from,sep=" :"),"to:",to) - return(tmp[,3,drop=FALSE]) - } - - -CTS.translate<-function(server,from,to,id,parallel=FALSE){ #arguably parallel, seems more connection stable than asynchronous - #require("RCurl") - # results are returned as JSON encoded strings - url<-paste(server,from,to,id,sep="/") - url<-gsub("\\ ","%20",url) # fix spaces - - if(parallel==TRUE){ # not clear if actuall improves speed, why RCurls was tried first - library(snow);library(doSNOW);library(foreach) - cl.tmp = makeCluster(rep("localhost",Sys.getenv('NUMBER_OF_PROCESSORS')), type="SOCK") # windows specific - registerDoSNOW(cl.tmp) - #do work - content<-as.character(unlist(foreach(i=c(1:length(id))) %dopar% readLines(url[i]))) - stopCluster(cl.tmp) - - } else { - content<-as.character(unlist(sapply(1:length(id), function(i, pb = txtProgressBar(min = 0, max = length(id), style = 3)) - { - setTxtProgressBar(pb, i) - tryCatch(readLines(url[i]),error=function(e){"error"}) - }))) - } - return(content) -} - -# get possible translations from CTS -CTS.options<-function(){ - options(warn=-1) - url<-readLines("http://cts.fiehnlab.ucdavis.edu/service/convert/toValues") - tmp<-unlist(strsplit(url[1],"")) - obj<-tmp[-c(1:2,(length(tmp)-2):length(tmp))] - unlist(strsplit(paste(obj[!obj=='\"'],collapse=""),",")) - } - -#using splitting and parallel/async web querry -# CTS.translate<-function(server,from,to,id,number=NULL){ # ussues with loss of connection, seems to be due to RCurl? - # #require("RCurl") - # # results are returned as JSON encoded strings - # url<-paste(server,from,to,id,sep="/") - # url<-gsub("\\ ","%20",url) # fix spaces - - # if(!is.null(number)) # control number of asyncronous calls getURL (too many can lead to connection problems) - # { - # if(number>length(id)){number<-length(id)} - # end.id<-c(1:length(id))[c(1:length(id))%%number==0] - # start.id<-end.id-number+1 - # extra<-length(id)-max(end.id)# for the ends - # start.id<-c(start.id,(max(end.id)+1)) - # end.id<-c(end.id,max(end.id+extra)) - - # content<-as.character(unlist(sapply(1:length(end.id), function(i,start=start.id, val=url, pb = txtProgressBar(min = 0, max = length(end.id), style = 3)) - # { - # setTxtProgressBar(pb, i) - # tmp<-val[start[i]:end.id[i]] - # as.character(unlist(getURL(tmp,ssl.verifypeer=FALSE))) - # closeAllConnections() # trying to avoid loss of connection... may want to create a dedicated connections and keep calling it - # }))) - - # } else { - # content<-as.character(unlist(getURL(url,ssl.verifypeer=FALSE))) - # } - - # return(content) -# } \ No newline at end of file diff --git a/CTSgetR.Rcheck/00check.log b/CTSgetR.Rcheck/00check.log deleted file mode 100644 index 4503cf1..0000000 --- a/CTSgetR.Rcheck/00check.log +++ /dev/null @@ -1,14 +0,0 @@ -* using log directory 'C:/Users/D/Dropbox/CTSgetR/CTSgetR.Rcheck' -* using R version 2.15.1 (2012-06-22) -* using platform: i386-pc-mingw32 (32-bit) -* using session charset: ISO8859-1 -* checking for file 'CTSgetR/DESCRIPTION' ... OK -* checking extension type ... Package -* this is package 'CTSgetR' version '1.0' -* checking package namespace information ... OK -* checking package dependencies ... ERROR -Namespace dependencies not required: - 'RCurl' 'RJSONIO' - -See the information on DESCRIPTION files in the chapter 'Creating R -packages' of the 'Writing R Extensions' manual. diff --git a/CTSgetR_1.0.tar.gz b/CTSgetR_1.0.tar.gz deleted file mode 100644 index 5ad20bf..0000000 Binary files a/CTSgetR_1.0.tar.gz and /dev/null differ diff --git a/DESCRIPTION b/DESCRIPTION index 8cbf75f..3c1aae3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,3 +7,5 @@ Author: Dmitry Grapov Maintainer: Description: Translate between > 200 of the most common biological databases identifiers. License: TBA +Imports: RCurl, jsonlite, KEGGREST, vwr, RJSONIO, utils +biocViews: Metabolomics diff --git a/NAMESPACE b/NAMESPACE index e154bfa..2cf72c5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,3 +2,7 @@ exportPattern("^[[:alpha:]]+") export(CTSgetR,CTS.options,multi.CTSgetR,KEGGtoName,NametoKEGG,CIDtoName,NametoPubChem,NametoInchI) import(RCurl) import(jsonlite) +import(KEGGREST) +import(vwr) +import(RJSONIO) +import(utils) diff --git a/R/CTS.R b/R/CTS.R index 97e4561..419532c 100644 --- a/R/CTS.R +++ b/R/CTS.R @@ -56,7 +56,7 @@ CTSgetR<-function(id,from,to,async=FALSE,limit.values=TRUE,progress=TRUE,server= } CTS.translate<-function(server,from,to,id,progress=TRUE){ #arguably parallel, seems more connection stable than asynchronous - #require("RCurl") + # results are returned as JSON encoded strings id<-as.character(unlist(id)) url<-paste(server,curlEscape(from),curlEscape(to),curlEscape(id),sep="/") # seperate encoding because can have forward slash in args @@ -72,7 +72,7 @@ CTS.translate<-function(server,from,to,id,progress=TRUE){ #arguably parallel, se #asynchronous, need to debug CTS.translate.async<-function(server,from,to,id,async.limit=100,...){ - require("RCurl") + # results are returned as JSON encoded strings # limit controls the maximum number of request per call to the server id<-as.character(unlist(id)) diff --git a/R/DB ID translation fxns.R b/R/DB_ID_translation_fxns.R similarity index 98% rename from R/DB ID translation fxns.R rename to R/DB_ID_translation_fxns.R index dab1883..dfa53ea 100644 --- a/R/DB ID translation fxns.R +++ b/R/DB_ID_translation_fxns.R @@ -1,6 +1,6 @@ #convert KEGG id to chemical name KEGGtoName<-function(id,all.values=FALSE,progress=TRUE){ - library(KEGGREST) + #should vectorize if(progress){pb = txtProgressBar(min = 0, max = length(id), style = 3)} results<-do.call("rbind",lapply(1:length(id),function(i) @@ -50,7 +50,7 @@ NametoKEGG<-function(name){ #CID to Name (Should make general PubChemtoName and sid support) CIDtoName<-function(cid){ - library(RCurl) + url<-paste0("https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/",cid,"/synonyms/TXT") content<-tryCatch(getURL(url, ssl.verifypeer = FALSE),error=function(e){character()}) res<-unlist(strsplit(content,"\n")) @@ -63,7 +63,7 @@ CIDtoName<-function(cid){ #going from name to CID NametoPubChem<-function(name,ID="cids", limit=FALSE){ - library(RCurl) + url<-paste0("https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/",gsub(" ","%20",name),"/",ID,"/TXT") content<-tryCatch(getURL(url, ssl.verifypeer = FALSE),error=function(e){character()}) res<-unlist(strsplit(content,"\n")) @@ -107,7 +107,7 @@ getIDEOM<-function(id,from,to,word.dist=0,agrep.dist=.15,progress=TRUE, DB = NUL #avoid duplicates< id<-make.unique(id) - library(vwr) + if(is.null(DB)){ DB<-IDEOMgetR() } @@ -157,8 +157,8 @@ getIDEOM<-function(id,from,to,word.dist=0,agrep.dist=.15,progress=TRUE, DB = NUL #check synonym via chemify http://cts.fiehnlab.ucdavis.edu/chemify/rest NametoInchI<-function(name,progress=TRUE){ - library(RCurl) - library(RJSONIO) + + url<-paste0("http://cts.fiehnlab.ucdavis.edu/chemify/rest/identify/",gsub("/","%2F",gsub(" ","%20",name))) if(progress){;message(cat("Getting Keys from CTS \n"));pb = txtProgressBar(min = 0, max = length(url), style = 3)} content<-lapply(1:length(url),function(i){ diff --git a/man/CTS.getR.Rd b/man/CTS.getR.Rd index 68b73ae..ed5137d 100644 --- a/man/CTS.getR.Rd +++ b/man/CTS.getR.Rd @@ -55,6 +55,7 @@ http://cts.fiehnlab.ucdavis.edu/ \seealso{ \code{\link{multi.CTSgetR}}, \code{\link{CTS.options}} } + \examples{ #translate between KEGG and PubChem CIDs id<-c("C15973","C00026","C05381","C15972","C00091","C00042","C05379","C00311","C00036","C00024","C00149","C00417","C00158","C00022","C05125","C16254","C00122","C16255","C00074") @@ -74,5 +75,3 @@ CTSgetR(id,from,to,limit.values=FALSE) } - - diff --git a/man/CTS.options.Rd b/man/CTS.options.Rd index bdbefee..9add92d 100644 --- a/man/CTS.options.Rd +++ b/man/CTS.options.Rd @@ -24,9 +24,6 @@ http://cts.fiehnlab.ucdavis.edu/ \author{ Dmitry Grapov } -\note{ -%% ~~further notes~~ -} %% ~Make other sections like Warning with \section{Warning }{....} ~ diff --git a/man/CTSgetR-package.Rd b/man/CTSgetR-package.Rd index 7ac825b..917c49b 100644 --- a/man/CTSgetR-package.Rd +++ b/man/CTSgetR-package.Rd @@ -1,6 +1,5 @@ \name{CTSgetR-package} \alias{CTSgetR-package} -\alias{CTSgetR} \docType{package} \title{ R interface to the Chemical Translation System (CTS) @@ -23,16 +22,7 @@ License: \tab TBA\cr Dmitry Grapov } -\references{ -} %~~ Optionally other standard keywords, one per line, from file ~~ %~~ KEYWORDS in the R documentation directory ~~ \keyword{Chemical Translation System} -\seealso{ -~~ Optional links to other man pages, e.g. ~~ -~~ \code{\link[:-package]{}} ~~ -} -\examples{ -~~ simple examples of the most important functions ~~ -} diff --git a/man/multi.CTSgetR.Rd b/man/multi.CTSgetR.Rd index 51b0d48..f9966df 100644 --- a/man/multi.CTSgetR.Rd +++ b/man/multi.CTSgetR.Rd @@ -25,11 +25,8 @@ Database name to translate \code{id} to. See \code{\link{CTS.options}}. \item{...}{ See \code{\link{CTSgetR}} options. } - -} -\details{ -%% ~~ If necessary, more details than the description above ~~ } + \value{ A data frame containing from and to translated values. Values not found in the database are returned as "". } @@ -39,11 +36,6 @@ http://cts.fiehnlab.ucdavis.edu/ \author{ Dmitry Grapov } -\note{ -%% ~~further notes~~ -} - -%% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ \code{\link[CTSgetR]{CTSgetR}} diff --git a/man/undocumented.Rd b/man/undocumented.Rd new file mode 100644 index 0000000..7473b39 --- /dev/null +++ b/man/undocumented.Rd @@ -0,0 +1,24 @@ +\name{Undocumented} + +\alias{CIDtoName} +\alias{CTS.translate} +\alias{CTS.translate.async} +\alias{KEGGtoName} +\alias{NametoInchI} +\alias{NametoKEGG} +\alias{NametoKeyID} +\alias{NametoPubChem} +\alias{fixlc} +\alias{fixln} +\alias{getIDEOM} +\alias{test} + + +\title{ +Undocumented functions +} +\description{ +Collection of undocumented functions used internally. +} + +\keyword{internal} \ No newline at end of file