diff --git a/R/MPI.R b/R/MPI.R index 7166c3826..feb541770 100644 --- a/R/MPI.R +++ b/R/MPI.R @@ -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) @@ -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"]max(lcraw@scantime) ,"rtmax"] <- max(lcraw@scantime) + + + + naidx <- which(is.na(gvals[,myID])) newpeaks <- getPeaks(lcraw, peakrange[naidx,,drop=FALSE], step = prof$step) diff --git a/R/xcmsSet.R b/R/xcmsSet.R index 33fabf25e..2104765ed 100755 --- a/R/xcmsSet.R +++ b/R/xcmsSet.R @@ -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) @@ -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)) } }) diff --git a/man/fillPeaks.chrom-methods.Rd b/man/fillPeaks.chrom-methods.Rd index 1e637953d..9dca091ab 100644 --- a/man/fillPeaks.chrom-methods.Rd +++ b/man/fillPeaks.chrom-methods.Rd @@ -12,7 +12,7 @@ \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)} } }} @@ -20,6 +20,10 @@ \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 diff --git a/man/getPeaks-methods.Rd b/man/getPeaks-methods.Rd index e7154972d..25f4bca6e 100644 --- a/man/getPeaks-methods.Rd +++ b/man/getPeaks-methods.Rd @@ -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)