sneumann / CAMERA

This is the git repository matching the Bioconductor package CAMERA: Collection of annotation related methods for mass spectrometry data
11 stars 22 forks source link

Error in plotPsSpectrum(): missing value where TRUE/FALSE needed #8

Open sneumann opened 8 years ago

sneumann commented 8 years ago

Hi, this was reported by Mike at http://www.metabolomics-forum.com/viewtopic.php?f=24&t=911&p=2705#p2705.

library(xcms)
library(CAMERA)
library(faahKO)
xset1 = group(faahko, bw = 3, minfrac = 0.9, mzwid = 0.05)
xset2 = retcor(xset1, plottype = "none")
xset3 = group(xset2, bw = 3)
xset4 = fillPeaks(xset3)
xset4 = xsAnnotate(xset4)
xset5 = groupFWHM(xset4, perfwhm = 0.6)
xset6 = groupCorr(xset5, cor_eic_th=0.75, pval=0.05, calcCiS = TRUE, cor_exp_th=0.75)
xset7 = findIsotopes(xset6)
xset8 = findAdducts(xset7, polarity="positive")
plotPsSpectrum(xset8, pspec=1, maxlabel=5)

Confirmed with

other attached packages:
[1] faahKO_1.10.0       CAMERA_1.27.1       xcms_1.47.3        
hhabra commented 7 years ago

Has this issue been solved yet? I'm encountering the same error. The instruction manual here (https://bioconductor.org/packages/release/bioc/vignettes/CAMERA/inst/doc/CAMERA.pdf) makes it seem so easy.

sneumann commented 7 years ago

Hi Hani, I am afraid this is still unfixed. Patches welcome. Yours, Steffen

thomasjtaylor commented 7 years ago

I was able to work around this error by setting xsAnnotate@sample to a numeric.

Presumably, this is from not setting @sample in xsAnnotate(xs=xset4, sample=NA, nSlaves=1, polarity=NULL).

It appears that xsAnnotate@sample affects the intensity scale in the plotPsSpectrum plot.

Here's the workaround starting from xset8:

# check the value
xset8@sample
# [1] NA
plotPsSpectrum(xset8, pspec=1, maxlabel=5)
#  Error in if (!is.numeric(index) && index > length(sampnames(xs)) | index <  : 
#   missing value where TRUE/FALSE needed
traceback()
# 3: getPeaks(object@xcmsSet, index = object@sample)
# 2: plotPsSpectrum(xset8, pspec = 1, maxlabel = 5)
# 1: plotPsSpectrum(xset8, pspec = 1, maxlabel = 5)

xset8@sample <- 1   # setting to 2, 3, ... 12 effects the intensity scale in PsSpectrum
plotPsSpectrum(xset8, pspec=1, maxlabel=5)  # works

xset8@sample <- c(1:12)
plotPsSpectrum(xset8, maxlabel=5)  # works with warnings
# WARNING: In if (is.na(object@sample)) { ...: the condition has length >1 and only the first element will be used

Starting from xset3...

xset4 <- xsAnnotate(p_xset, sample=c(1:12), polarity="positive")
xset5 <- groupFWHM(xset4, perfwhm = 0.6)
xset6 <- groupCorr(xset5, cor_eic_th=0.75, pval=0.05, calcCiS = TRUE, cor_exp_th=0.75)
xset7 <- findIsotopes(xset6)
xset8 <- findAdducts(xset7, polarity="positive")
plotPsSpectrum(xset8, pspec=1, maxlabel=5) # works with several warnings
# Warning messages:
# 1: In if (!is.numeric(index) && index > length(sampnames(xs)) | index <  :
#   the condition has length > 1 and only the first element will be used
# 2: In if (index == -1) { :
#   the condition has length > 1 and only the first element will be used
# 3: In if (is.na(object@sample)) { :
#   the condition has length > 1 and only the first element will be used

I've found that setting xsAnnotate@sample <- 1 seems to work best.

thomasjtaylor commented 7 years ago

It looks like changing CAMERA/R/xsVisualise.R#323 from:

##
## Loop through all requested pspectra
##
  if (length(object@sample)<1) {    #323
    gvals <- groupval(object@xcmsSet);
    peakmat <- object@xcmsSet@peaks;
    groupmat <- groups(object@xcmsSet);
    #calculate highest peak
    max_mat  <- apply(gvals, 1, function(x, peakmat){peakmat[x, value]}, peakmat);
  }else{
    peakmat <- getPeaks(object@xcmsSet, index=object@sample); #330
    maxo  <- peakmat[,value]
  }

to:

if (is.na(object@sample) || length(object@sample)<1) { #323

might resolve the problem. However, the error actually occurs on line 330 peakmat <- getPeaks(object@xcmsSet, index=object@sample)

from the XCMS documentation for findPeaks, the method signature is findPeaks(xcmsSet, peakrange, step=0.1), which doesn't match the call on line 330. Unless this is supposed to be a call to CAMERA:::findPeaks(xcmsSet,psPeak,...).

From this thread, the suggestion is to use fillPeaks(xcmsSet,...) instead of findPeaks(xcmsSet,...).

I'd rather not make the code change myself, as I may inadvertently break or change the expected behavior.

breidan commented 4 years ago

When will this fix make it into BioC? It is not in CAMERA 1.44.

sneumann commented 4 years ago

Now pushed to BioC as Version: 1.45.1, should be on bioconductor.org/packages/devel/bioc/html/CAMERA.html in a few days. Yours, Steffen