Skip to content
Snippets Groups Projects
Commit 73d8c544 authored by Todor Kondic's avatar Todor Kondic
Browse files

Merge branch 'dev' into 'master'

Dev

See merge request eci/rmb-mix-method!12
parents 43ca39c5 e6b2fc57
No related branches found
No related tags found
No related merge requests found
......@@ -19,10 +19,12 @@ Roxygen: list(markdown = TRUE)
Collate:
'mix.R'
'run.R'
Imports:
Depends:
RMassBank,
RChemMass
Imports:
parallel,
yaml,
mzR,
RColorBrewer,
RChemMass
curl
......@@ -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)
......
......@@ -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
......
% 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ć
}
......@@ -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{
......
% 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ć
}
% 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ć
}
% 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}
\name{rendersmiles2}
\alias{rendersmiles2}
\title{Turn SMILES to an Image Using Online Resource}
\usage{
gen_file_table(fn_data, n_cmpd, wd)
rendersmiles2(smiles, ...)
}
\arguments{
\item{fn_data}{The mzML filename.}
\item{smiles}{The SMILES string.}
\item{n_cmpd}{Number of compounds.}
\item{wd}{Directory under which results are archived.}
\item{...}{Hand over to renderurl.}
}
\value{
File path of the file table.
Nothing useful.
}
\description{
Generates file table.
Render smiles from an online resource.
}
\author{
Todor Kondić
......
% 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}
\name{renderurl}
\alias{renderurl}
\title{Render Compound from an Online Resource}
\usage{
presc.p(cl, fn_data, fn_cmpd_l, mode, ppm_lim_fine = 10,
EIC_limit = 0.001)
renderurl(depictURL, coords = c(0, 0, 100, 100),
filename = tempfile(fileext = ".svg"))
}
\arguments{
\item{cl}{Cluster object.}
\item{depictURL}{The URL of the object to plot.}
\item{fn_data}{Sequence of mzML files.}
\item{coords}{The positioning of the image (in data coords).}
\item{fn_cmpd_l}{Filename of the compound list.}
\item{mode}{RMB mode.}
\item{ppm_lim_fine}{See ReSOLUTION.}
\item{EIC_limit}{See ReSOLUTION.}
\item{filename}{Temp filename.}
}
\value{
Nothing useful.
}
\description{
Parallel version of presc.single.
Helper function for rendersmiles2
}
\author{
Todor Kondić
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment