Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added expansion factors for the mz and rt range used in fillPeaks.chrom. #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions R/MPI.R
Expand Up @@ -333,6 +333,10 @@ fillPeaksChromPar <- function(arg) {
prof <- params$prof
rtcor <- params$rtcor
peakrange <- params$peakrange
expand.mz <- params$expand.mz
expand.rt <- params$expand.rt
min.width.mz <- params$min.width.mz
min.width.rt <- params$min.width.rt
gvals <- params$gvals$gvals

lcraw <- xcmsRaw(arg$file, profmethod=params$prof$method, profstep = 0)
Expand All @@ -358,6 +362,31 @@ fillPeaksChromPar <- function(arg) {
warning("(corrected) retention time vector length mismatch for ", basename(arg$file))
}


# Expanding the peakrange
peakrange[,"mzmax"] <- peakrange[,"mzmax"] + ( (peakrange[,"mzmax"]-peakrange[,"mzmin"])/2 )*(expand.mz-1)
peakrange[,"mzmin"] <- peakrange[,"mzmin"] - ( (peakrange[,"mzmax"]-peakrange[,"mzmin"])/2 )*(expand.mz-1)
peakrange[,"rtmax"] <- peakrange[,"rtmax"] + ( (peakrange[,"rtmax"]-peakrange[,"rtmin"])/2 )*(expand.rt-1)
peakrange[,"rtmin"] <- peakrange[,"rtmin"] - ( (peakrange[,"rtmax"]-peakrange[,"rtmin"])/2 )*(expand.rt-1)


# Setting a minimum peakwidth for mz and rt range
idx.expand.mz = (peakrange[,"mzmax"] - peakrange[,"mzmin"]) < min.width.mz
peakrange[idx.expand.mz,"mzmin"] = rowMeans( peakrange[ idx.expand.mz , c("mzmin","mzmax") ,drop=F] ) -min.width.mz/2
peakrange[idx.expand.mz,"mzmax"] = rowMeans( peakrange[ idx.expand.mz , c("mzmin","mzmax") ,drop=F] ) +min.width.mz/2

idx.expand.rt = (peakrange[,"rtmax"] - peakrange[,"rtmin"]) < min.width.rt
peakrange[idx.expand.rt,"rtmin"] = rowMeans( peakrange[ idx.expand.rt , c("rtmin","rtmax") ,drop=F] ) -min.width.rt/2
peakrange[idx.expand.rt,"rtmax"] = rowMeans( peakrange[ idx.expand.rt , c("rtmin","rtmax") ,drop=F] ) +min.width.rt/2


# Making sure the expanded peakrange doesn't exceed the RT range in the file
peakrange[ peakrange[,"rtmin"]<min(lcraw@scantime) ,"rtmin"] <- min(lcraw@scantime)
peakrange[ peakrange[,"rtmax"]>max(lcraw@scantime) ,"rtmax"] <- max(lcraw@scantime)




naidx <- which(is.na(gvals[,myID]))

newpeaks <- getPeaks(lcraw, peakrange[naidx,,drop=FALSE], step = prof$step)
Expand Down
8 changes: 6 additions & 2 deletions R/xcmsSet.R
Expand Up @@ -1368,7 +1368,7 @@ setMethod("plotrt", "xcmsSet", function(object, col = NULL, ty = NULL, leg = TRU

setGeneric("fillPeaks.chrom", function(object, ...) standardGeneric("fillPeaks.chrom"))

setMethod("fillPeaks.chrom", "xcmsSet", function(object, nSlaves=NULL) {
setMethod("fillPeaks.chrom", "xcmsSet", function(object, nSlaves=NULL,expand.mz=1,expand.rt=1,min.width.mz=0,min.width.rt=0) {
## development mockup:
if (FALSE) {
library(xcms)
Expand Down Expand Up @@ -1440,7 +1440,11 @@ assign("gvals", gvals, envir = gvals_env)
dataCorrection=object@dataCorrection,
polarity=object@polarity,
rtcor=object@rt$corrected[[as.numeric(x["id"])]],
peakrange=peakrange))
peakrange=peakrange,
expand.mz=expand.mz,
expand.rt=expand.rt,
min.width.mz=min.width.mz,
min.width.rt=min.width.rt))
}
})

Expand Down
6 changes: 5 additions & 1 deletion man/fillPeaks.chrom-methods.Rd
Expand Up @@ -12,14 +12,18 @@
\section{Methods}{
\describe{
\item{object = "xcmsSet"}{
\code{fillPeaks.chrom(object, nSlaves=0)}
\code{fillPeaks.chrom(object, nSlaves=0,expand.mz=1,expand.rt=1,min.width.mz=0,min.width.rt=0)}
}
}}

\arguments{
\item{object}{the \code{xcmsSet} object}
\item{nSlaves}{number of slaves/cores to be used for parallel peak filling.
MPI is used if installed, otherwise the snow package is employed for multicore support.}
\item{expand.mz}{Expansion factor for the m/z range used for integration.}
\item{expand.rt}{Expansion factor for the retention time range used for integration.}
\item{min.width.mz}{Minimum m/z range used for integration.}
\item{min.width.rt}{Minimum retention time range used for integration.}
}
\details{
After peak grouping, there will always be peak groups that do not
Expand Down
2 changes: 1 addition & 1 deletion man/getPeaks-methods.Rd
Expand Up @@ -15,7 +15,7 @@
}
}}
\arguments{
\item{object}{the \code{xcmsSet} object}
\item{object}{the \code{xcmsRaw} object}
\item{peakrange}{
matrix or data frame with 4 columns: \code{mzmin}, \code{mzmax},
\code{rtmin}, \code{rtmax} (they must be in that order or named)
Expand Down