diff --git a/DESCRIPTION b/DESCRIPTION index 62340b6a97100c13b45bc80c42e3550bef9bcb89..a43d8e3d46eac1adcf6edb4a5c1128ee26f9f5c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,10 +19,12 @@ Roxygen: list(markdown = TRUE) Collate: 'mix.R' 'run.R' -Imports: +Depends: RMassBank, + RChemMass +Imports: parallel, yaml, mzR, RColorBrewer, - RChemMass + curl diff --git a/R/mix.R b/R/mix.R index 81458b0a7491a4f0a7af3882d75e0da34a256ce5..ae0be4ba276612962675f4ffadc12e190f689349 100644 --- a/R/mix.R +++ b/R/mix.R @@ -315,6 +315,51 @@ RMB_EIC_prescreen_df <- function (wd, RMB_mode, FileList, cmpd_list, row.names = F) } +##' Helper function for rendersmiles2 +##' +##' @title Render Compound from an Online Resource +##' @param depictURL The URL of the object to plot. +##' @param coords The positioning of the image (in data coords). +##' @param filename Temp filename. +##' @return Nothing useful. +##' @author Todor Kondić +renderurl <- function(depictURL,coords=c(0,0,100,100), filename=tempfile(fileext=".svg")) { + h <- new_handle() + curl::handle_setopt(h, ssl_verifyhost = 0, ssl_verifypeer=0) + curl::curl_download(url=depictURL,filename,handle=h) + img <- rsvg(filename) + if (length(img)>2) { + rasterImage(img,xleft=coords[1],ybottom=coords[2],xright=coords[3],ytop=coords[4]) + } +} + + +## rendersmiles <- function(smiles, kekulise=TRUE, coords=c(0,0,100,100), width=200, height=200, +## zoom=1.3,style="cow", annotate="off", abbr="on",suppressh=TRUE, +## showTitle=FALSE, smaLimit=100, sma=NULL) { +## dep <- get.depictor(width = width, height = height, zoom = zoom, style = style, annotate = annotate, +## abbr = abbr, suppressh = suppressh, showTitle = showTitle, smaLimit = smaLimit, +## sma = NULL) +## library(rcdk) +## library(RChemMass) +## mol <- getMolecule(smiles) +## img <- view.image.2d(mol, depictor=dep) +## rasterImage(img, coords[1],coords[2], coords[3],coords[4]) + +## } + +##' Render smiles from an online resource. +##' +##' @title Turn SMILES to an Image Using Online Resource +##' @param smiles The SMILES string. +##' @param ... Hand over to renderurl. +##' @return Nothing useful. +##' @author Todor Kondić +rendersmiles2 <- function(smiles,...) { + dpurl <- buildCDKdepictURL(smiles) + renderurl(dpurl,filename=tempfile(fileext=".svg"),...) +} + ##' Plot the output of prescreen. ##' ##' @title Plot the Output of Prescreen @@ -339,16 +384,16 @@ presc.plot <- function(wd,mode,out="prescreen.pdf",pal="Dark2",cex=0.75,rt_digit wd1 <- wd[[1]] df <- read.csv(file=get_cmpd_l_fn(wd1),stringsAsFactors = F) - smiles <- df$SMILES - no_cmpds <- length(smiles) + osmesi <- df$SMILES + no_cmpds <- length(osmesi) # reconf(wd1) - masses <- lapply(smiles,function (smile) { - #smiles <- tryCatch(RMassBank::findSmiles(i), error = function(e) NA) + masses <- lapply(osmesi,function (smile) { + #osmesi <- tryCatch(RMassBank::findSmiles(i), error = function(e) NA) zz <- RChemMass::getSuspectFormulaMass(smile) zz[[modemap[[mode]]]] }) #message("Masses:",masses) - #return(masses) + # return(osmesi) ## Get the basenames of eic files. eics <- list.files(path=dfdir[[1]],patt=".*eic.csv") @@ -389,19 +434,28 @@ presc.plot <- function(wd,mode,out="prescreen.pdf",pal="Dark2",cex=0.75,rt_digit - rt_rng <- 1.1*range(sapply(dfs,function(x) x$rt)) - int_rng <- 1.3*range(sapply(append(dfs_kids,dfs),function(x) x$intensity)) + rt_rng <- 1.2*range(sapply(dfs,function(x) x$rt)) + int_rng <- 1.4*range(sapply(append(dfs_kids,dfs),function(x) x$intensity)) plot.window(rt_rng,int_rng) box() cols <- RColorBrewer::brewer.pal(n=length(dfs),name=pal) lgnd <- Map(function(k,v) paste(k,"= ",formatC(v,format="f",digits=rt_digits),sep=''),symbs,rt_max) linfo <- legend("topleft",horiz=T,legend=lbls,col=cols,fill=cols,bty="n",cex=cex) legend(x=linfo$rect$left,y=linfo$rect$top-0.5*linfo$rect$h,horiz=T,legend=lgnd,fill=cols,bty="n",cex=cex) - text(x=rt_rng[[2]],y=0.5*int_rng[[2]],smiles[[i]],cex=cex,srt=90) - x1=1.1*linfo$rect$left - y2=0.9*linfo$rect$top - x2=1.1*x1 - y1=0.9*y2 + #text(x=rt_rng[[2]],y=0.5*int_rng[[2]],osmesi[[i]],cex=cex,srt=90) + fxmin=rt_rng[1]+0.75*(rt_rng[2]-rt_rng[1]) + fxmax=fxmin+0.3*(rt_rng[2]-rt_rng[1]) + fymin=int_rng[1]+0.6*(int_rng[2]-int_rng[1]) + fymax=fymin+0.3*(int_rng[2]-int_rng[1]) + + xcmp=c(fxmin,fxmax) + ycmp=c(fymin,fymax) + #xcmp=c(0.99*rt_rng[[1]],rt_rng[[2]]) + + #ycmp=c(0.99*int_rng[[1]],int_rng[[2]]) + rendersmiles2(osmesi[i],coords=c(xcmp[1],ycmp[1],xcmp[2],ycmp[2])) + # RChemMass::renderSMILES.rcdk(osmesi[i],coords=c(xcmp[[1]],ycmp[[1]],xcmp[[2]],ycmp[[2]]),width=xcmp[[2]]-xcmp[[1]],height=ycmp[[2]]-ycmp[[1]]) + cols_kids <- cols[indkids] lgnd_kids <- Map(function(k,v) paste(k,"= ",formatC(v,digits=rt_digits,format="f"),sep=''),symbs_kids,rt_max_kids) if (length(lgnd_kids)>0) legend(x="bottomleft",horiz=T,legend=lgnd_kids,fill=cols[indkids],bty="n",cex=cex) diff --git a/README.org b/README.org index 06b9fd789b83db4635a05c0ce3d5c38bdd80740d..c112fdc49037f141dbe4827591c9448e99daa902 100644 --- a/README.org +++ b/README.org @@ -14,7 +14,7 @@ 2. Plot, #+BEGIN_SRC R require(rmbmix) - presc.plot(list.files(".",patt="2.*POS",include.dirs=T),cex=0.7,digits=4) + presc.plot(list.files(".",patt="2.*POS",include.dirs=T),mode="pH",cex=0.7,rt_digits=2,m_digits=4,pal="Dark2",out="prescreen.pdf") #+END_SRC The only argument is a sequence of absolute paths to directories containing the prescreen data. The resulting plot file is going diff --git a/man/RMB_EIC_prescreen_intrn.Rd b/man/RMB_EIC_prescreen_intrn.Rd deleted file mode 100644 index ef62fcf4a02b13673a6841a21aa2a0f98bb411eb..0000000000000000000000000000000000000000 --- a/man/RMB_EIC_prescreen_intrn.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/mix.R -\name{RMB_EIC_prescreen_intrn} -\alias{RMB_EIC_prescreen_intrn} -\title{Prescreen} -\usage{ -RMB_EIC_prescreen_intrn(archive_name, RMB_mode, FileList, cmpd_list, - ppm_limit_fine = 10, EIC_limit = 0.001) -} -\arguments{ -\item{archive_name}{...} - -\item{RMB_mode}{...} - -\item{FileList}{...} - -\item{cmpd_list}{...} - -\item{ppm_limit_fine}{...} - -\item{EIC_limit}{...} -} -\description{ -Prescreens. Ripped off from ReSOLUTION -} -\author{ -Emma Schymanski, Todor Kondić -} diff --git a/man/gen_file_table.Rd b/man/gen_file_table.Rd deleted file mode 100644 index c7daf7fffef65943d64f3e7215b682ffe5a52cdd..0000000000000000000000000000000000000000 --- a/man/gen_file_table.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/mix.R -\name{gen_file_table} -\alias{gen_file_table} -\title{Generate and Load the RMassBank Settings File} -\usage{ -gen_file_table(fn_data, n_cmpd, wd) -} -\arguments{ -\item{fn_data}{The mzML filename.} - -\item{n_cmpd}{Number of compounds.} - -\item{wd}{Directory under which results are archived.} -} -\value{ -File path of the file table. -} -\description{ -Generates file table. -} -\author{ -Todor Kondić -} diff --git a/man/presc.p.Rd b/man/presc.p.Rd deleted file mode 100644 index 3df93cb98e5e0d39843666c80f6138b2e35498d9..0000000000000000000000000000000000000000 --- a/man/presc.p.Rd +++ /dev/null @@ -1,31 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/mix.R -\name{presc.p} -\alias{presc.p} -\title{Parallel version of presc.single} -\usage{ -presc.p(cl, fn_data, fn_cmpd_l, mode, ppm_lim_fine = 10, - EIC_limit = 0.001) -} -\arguments{ -\item{cl}{Cluster object.} - -\item{fn_data}{Sequence of mzML files.} - -\item{fn_cmpd_l}{Filename of the compound list.} - -\item{mode}{RMB mode.} - -\item{ppm_lim_fine}{See ReSOLUTION.} - -\item{EIC_limit}{See ReSOLUTION.} -} -\value{ -Nothing useful. -} -\description{ -Parallel version of presc.single. -} -\author{ -Todor Kondić -} diff --git a/man/presc.plot.Rd b/man/presc.plot.Rd index fd6139b74ffce5b6d5dd5dfd15aa91dc9caf3fa3..7c16067865ce25b4bf7a2fe2ec4e81057e956a1d 100644 --- a/man/presc.plot.Rd +++ b/man/presc.plot.Rd @@ -4,18 +4,24 @@ \alias{presc.plot} \title{Plot the Output of Prescreen} \usage{ -presc.plot(wd, out = "prescreen.pdf", pal = "Dark2", cex = 0.75, - digits = 6) +presc.plot(wd, mode, out = "prescreen.pdf", pal = "Dark2", + cex = 0.75, rt_digits = 2, m_digits = 4) } \arguments{ \item{wd}{Sequence of data dirs containing the prescreen subdir.} +\item{mode}{RMB mode.} + \item{out}{The name of the output file.} \item{pal}{ColorBrewer palette name.} \item{cex}{As in legend.} +\item{rt_digits}{Number of digits after the point for the retention time.} + +\item{m_digits}{Number of digits after the point for the mass.} + \item{digits}{Number of significant digits for peak ret times.} } \value{ diff --git a/man/presc.single.Rd b/man/presc.single.Rd deleted file mode 100644 index 4263e0275508b796961bdbfba983c1748ee37b06..0000000000000000000000000000000000000000 --- a/man/presc.single.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/mix.R -\name{presc.single} -\alias{presc.single} -\title{Wrapper for RMB_EIC_Prescreen} -\usage{ -presc.single(fn_data, stgs_alist, wd, mode, fn_cmpd_l, ppm_lim_fine = 10, - EIC_limit = 0.001) -} -\arguments{ -\item{fn_data}{The mzML filename.} - -\item{stgs_alist}{Settings named list, or a settings filename.} - -\item{wd}{Directory under which results are archived.} - -\item{mode}{RMB mode.} - -\item{fn_cmpd_l}{Filename of the compound list.} - -\item{ppm_lim_fine}{The ppm_limit_fine argument to RMB_EIC_Prescreen} - -\item{EIC_limit}{Passed down to RMB_EIC_Prescreen.} -} -\value{ -result of RMB_EIC_Prescreen -} -\description{ -Wrapper for a single prescreening call. Produces output in the -usual mix method places. -} -\author{ -Todor Kondić -} diff --git a/man/presc.v.Rd b/man/presc.v.Rd deleted file mode 100644 index 2728a2e62887ba26efa543c8cc86a80991cd35d6..0000000000000000000000000000000000000000 --- a/man/presc.v.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/mix.R -\name{presc.v} -\alias{presc.v} -\title{Vectorises presc.single} -\usage{ -presc.v(fn_data, fn_cmpd_l, mode, ppm_lim_fine = 10, EIC_limit = 0.001) -} -\arguments{ -\item{fn_data}{Sequence of mzML filenames.} - -\item{fn_cmpd_l}{Compound list filename.} - -\item{mode}{RMB mode.} - -\item{ppm_lim_fine}{Prescreen fine limit (see ReSOLUTION prescreening function).} - -\item{EIC_limit}{Prescreen EIC limit (see ReSOLUTION prescreening function).} -} -\value{ -Nothing useful. -} -\description{ -Vectorises presc.single. -} -\author{ -Todor Kondić -} diff --git a/man/rendersmiles2.Rd b/man/rendersmiles2.Rd new file mode 100644 index 0000000000000000000000000000000000000000..279a92aa984b1216358816bf6cad419878e0e272 --- /dev/null +++ b/man/rendersmiles2.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mix.R +\name{rendersmiles2} +\alias{rendersmiles2} +\title{Turn SMILES to an Image Using Online Resource} +\usage{ +rendersmiles2(smiles, ...) +} +\arguments{ +\item{smiles}{The SMILES string.} + +\item{...}{Hand over to renderurl.} +} +\value{ +Nothing useful. +} +\description{ +Render smiles from an online resource. +} +\author{ +Todor Kondić +} diff --git a/man/renderurl.Rd b/man/renderurl.Rd new file mode 100644 index 0000000000000000000000000000000000000000..b1a143f46a0f5ba9655608ae19b03b45155be6d3 --- /dev/null +++ b/man/renderurl.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mix.R +\name{renderurl} +\alias{renderurl} +\title{Render Compound from an Online Resource} +\usage{ +renderurl(depictURL, coords = c(0, 0, 100, 100), + filename = tempfile(fileext = ".svg")) +} +\arguments{ +\item{depictURL}{The URL of the object to plot.} + +\item{coords}{The positioning of the image (in data coords).} + +\item{filename}{Temp filename.} +} +\value{ +Nothing useful. +} +\description{ +Helper function for rendersmiles2 +} +\author{ +Todor Kondić +}