From e07350cecdba81676c063bfcb64d50b64d20e690 Mon Sep 17 00:00:00 2001 From: Jan Stanstrup Date: Thu, 17 Apr 2014 10:14:48 +0200 Subject: [PATCH 1/6] Added expansion factors for the mz and rt range used in fillPeaks.chrom. --- R/MPI.R | 12 ++++++++++++ R/xcmsSet.R | 6 ++++-- man/fillPeaks.chrom-methods.Rd | 4 +++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/R/MPI.R b/R/MPI.R index 7166c3826..b0324ef96 100644 --- a/R/MPI.R +++ b/R/MPI.R @@ -333,6 +333,8 @@ fillPeaksChromPar <- function(arg) { prof <- params$prof rtcor <- params$rtcor peakrange <- params$peakrange + expand.mz <- params$expand.mz + expand.rt <- params$expand.rt gvals <- params$gvals$gvals lcraw <- xcmsRaw(arg$file, profmethod=params$prof$method, profstep = 0) @@ -358,6 +360,16 @@ 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) + + + + 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..21a27b93d 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) { ## development mockup: if (FALSE) { library(xcms) @@ -1440,7 +1440,9 @@ 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)) } }) diff --git a/man/fillPeaks.chrom-methods.Rd b/man/fillPeaks.chrom-methods.Rd index 1e637953d..5eebd4337 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)} } }} @@ -20,6 +20,8 @@ \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 rentention time range used for integration.} } \details{ After peak grouping, there will always be peak groups that do not From 8cc179080e5fe4b733d91d24722bf658c0f063bf Mon Sep 17 00:00:00 2001 From: Jan Stanstrup Date: Mon, 28 Apr 2014 02:15:00 +0200 Subject: [PATCH 2/6] Making sure the expanded peakrange doesn't exceed the RT range in the file --- R/MPI.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/MPI.R b/R/MPI.R index b0324ef96..c760c4332 100644 --- a/R/MPI.R +++ b/R/MPI.R @@ -368,7 +368,12 @@ fillPeaksChromPar <- function(arg) { peakrange[,"rtmin"] <- peakrange[,"rtmin"] - ( (peakrange[,"rtmax"]-peakrange[,"rtmin"])/2 )*(expand.rt-1) + # 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])) From 88dd594f27c7b89f7efaa5057a6e59295fc392bb Mon Sep 17 00:00:00 2001 From: Jan Stanstrup Date: Mon, 28 Apr 2014 02:17:40 +0200 Subject: [PATCH 3/6] for getPeaks the input is an xcmsRaw not xcmsSet --- man/getPeaks-methods.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 7402f14134a5b41d3bdd957755d1dc9c71b416a3 Mon Sep 17 00:00:00 2001 From: Jan Stanstrup Date: Wed, 30 Apr 2014 14:33:30 +0200 Subject: [PATCH 4/6] Added min.width.mz and min.width.rt for fillPeaks.chrom --- R/MPI.R | 16 ++++++++++++++-- R/xcmsSet.R | 6 ++++-- man/fillPeaks.chrom-methods.Rd | 6 ++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/R/MPI.R b/R/MPI.R index c760c4332..f50f43e2c 100644 --- a/R/MPI.R +++ b/R/MPI.R @@ -335,6 +335,8 @@ fillPeaksChromPar <- function(arg) { 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) @@ -368,9 +370,19 @@ fillPeaksChromPar <- function(arg) { 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") ] ) -min.width.mz/2 + peakrange[idx.expand.mz,"mzmax"] = rowMeans( peakrange[ idx.expand.mz , c("mzmin","mzmax") ] ) +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("mzmin","mzmax") ] ) -min.width.rt/2 + peakrange[idx.expand.rt,"rtmax"] = rowMeans( peakrange[ idx.expand.rt , c("mzmin","mzmax") ] ) +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) + peakrange[ peakrange[,"rtmin"]max(lcraw@scantime) ,"rtmax"] <- max(lcraw@scantime) diff --git a/R/xcmsSet.R b/R/xcmsSet.R index 21a27b93d..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,expand.mz=1,expand.rt=1) { +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) @@ -1442,7 +1442,9 @@ assign("gvals", gvals, envir = gvals_env) rtcor=object@rt$corrected[[as.numeric(x["id"])]], peakrange=peakrange, expand.mz=expand.mz, - expand.rt=expand.rt)) + 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 5eebd4337..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,expand.mz=1,expand.rt=1)} + \code{fillPeaks.chrom(object, nSlaves=0,expand.mz=1,expand.rt=1,min.width.mz=0,min.width.rt=0)} } }} @@ -21,7 +21,9 @@ \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 rentention time 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 From fccbb69b9829a2f6ff1e73661cdb9c0c7d74d8fd Mon Sep 17 00:00:00 2001 From: Jan Stanstrup Date: Thu, 1 May 2014 15:54:53 +0200 Subject: [PATCH 5/6] Copy/paste bug fixed. --- R/MPI.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/MPI.R b/R/MPI.R index f50f43e2c..5b0cca546 100644 --- a/R/MPI.R +++ b/R/MPI.R @@ -376,8 +376,8 @@ fillPeaksChromPar <- function(arg) { peakrange[idx.expand.mz,"mzmax"] = rowMeans( peakrange[ idx.expand.mz , c("mzmin","mzmax") ] ) +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("mzmin","mzmax") ] ) -min.width.rt/2 - peakrange[idx.expand.rt,"rtmax"] = rowMeans( peakrange[ idx.expand.rt , c("mzmin","mzmax") ] ) +min.width.rt/2 + peakrange[idx.expand.rt,"rtmin"] = rowMeans( peakrange[ idx.expand.rt , c("rtmin","rtmax") ] ) -min.width.rt/2 + peakrange[idx.expand.rt,"rtmax"] = rowMeans( peakrange[ idx.expand.rt , c("rtmin","rtmax") ] ) +min.width.rt/2 # Making sure the expanded peakrange doesn't exceed the RT range in the file From 5107d8ba51d08482adf30a76a070e787fb4ce8df Mon Sep 17 00:00:00 2001 From: Jan Stanstrup Date: Fri, 13 Jun 2014 10:22:37 +0200 Subject: [PATCH 6/6] Fixed bug found by Cole Wunderlich. RowMeans need a matrix so the peakrange matrix must not be coersed to a vector when there is only one peak to expand. --- R/MPI.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/MPI.R b/R/MPI.R index 5b0cca546..feb541770 100644 --- a/R/MPI.R +++ b/R/MPI.R @@ -372,12 +372,12 @@ fillPeaksChromPar <- function(arg) { # 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") ] ) -min.width.mz/2 - peakrange[idx.expand.mz,"mzmax"] = rowMeans( peakrange[ idx.expand.mz , c("mzmin","mzmax") ] ) +min.width.mz/2 + 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") ] ) -min.width.rt/2 - peakrange[idx.expand.rt,"rtmax"] = rowMeans( peakrange[ idx.expand.rt , c("rtmin","rtmax") ] ) +min.width.rt/2 + 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