sneumann / CAMERA

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

Bug in labelling and/or legend of plotEICs #2

Open sneumann opened 9 years ago

sneumann commented 9 years ago

Reported by Andre Kleensang (Johns Hopkins University):

Die peakannotatioten sind anders in beiden Graphiken und damit ist unklar, ob der höchste peak (6e06) 132.099 [M1+H]+ (laut maxlabel=5) oder nicht zugeordnet ist (laut maxlabel=10).

As you can see the color labels are pointing to different peaks in the two versions of the same spectra.

maxlabel5 eps maxlabel10 eps

sneumann commented 9 years ago

So, the color palette and the indexing to the peaks seems garbled:

library(CAMERA)
file <- system.file('mzdata/MM14.mzdata', package = "CAMERA")
xs   <- xcmsSet(file, method="centWave",ppm=30, peakwidth=c(5,10))
an   <- xsAnnotate(xs)
an   <- groupFWHM(an)
an   <- findIsotopes(an)
an   <- findAdducts(an, polarity="positive")

par(mfrow=c(2,3))
plotEICs(an, pspec=2, maxlabel=0)
plotEICs(an, pspec=2, maxlabel=1)
plotEICs(an, pspec=2, maxlabel=2)

plotEICs(an, pspec=2, maxlabel=6)
plotEICs(an, pspec=2, maxlabel=7)
plotEICs(an, pspec=2, maxlabel=99)

The problem is likely to be here: https://github.com/sneumann/CAMERA/blob/master/R/xsVisualise.R#L113

jmosl01 commented 5 years ago

I seem to have tracked down the troublesome indices. Reproducing the example from @sneumann

library(CAMERA)
file <- system.file('mzdata/MM14.mzdata', package = "CAMERA")
xs   <- xcmsSet(file, method="centWave",ppm=30, peakwidth=c(5,10))
an   <- xsAnnotate(xs)
an   <- groupFWHM(an)
an   <- findIsotopes(an)
an   <- findAdducts(an, polarity="positive")

par(mfrow=c(2,3))
plotEICs(an, pspec=2, maxlabel=0)
plotEICs(an, pspec=2, maxlabel=1)
plotEICs(an, pspec=2, maxlabel=2)

plotEICs(an, pspec=2, maxlabel=6)
plotEICs(an, pspec=2, maxlabel=7)
plotEICs(an, pspec=2, maxlabel=99)

gives this color coding scheme ploteics_example_original

However, if I change the indexing in xsVisualize.R ever so slightly here: https://github.com/sneumann/CAMERA/blob/master/R/xsVisualise.R#L101-L112 to the code below

for (j in eicidx[o]) {
      pts <- xeic@eic[[ps]][[j]]
      points(pts, type = "l", col = lcol[cnt]);
      peakrange <- peaks[,c("rtmin","rtmax"), drop=FALSE]
      ptsidx <- pts[,"rt"] >= peakrange[j,1] & pts[,"rt"] <= peakrange[j,2]
      if (naps[j]){ 
        points(pts[ptsidx, ], type = "l", col = col[cnt], lwd=1.3, lty=3)
      } else {
        points(pts[ptsidx, ], type = "l", col = col[cnt], lwd=1.3)
      }
      cnt <- cnt + 1;
    }

then I get this (apparently correct) color-coding scheme ploteics_example_fixed

wilmelz commented 4 years ago

Hello Steffen,

It does not appear that this issue has been addressed at all. I am still seeing the same error with the color labels when using the plotEICs function of CAMERA. The bug fix that was suggested above by Jonathan Mosley seems to fix the problem.

The bug fix is the following:

Modify the following lines of code under the plotEICs method in xsVisualise.R from

for (j in eicidx[o]) {
      pts <- xeic@eic[[ps]][[j]]
      points(pts, type = "l", col = lcol[cnt]);
      cnt <- cnt + 1;
      peakrange <- peaks[,c("rtmin","rtmax"), drop=FALSE]
      ptsidx <- pts[,"rt"] >= peakrange[j,1] & pts[,"rt"] <= peakrange[j,2]
      if (naps[j]){ 
        points(pts[ptsidx, ], type = "l", col = col[j], lwd=1.3, lty=3)
      } else {
        points(pts[ptsidx, ], type = "l", col = col[j], lwd=1.3)
      }
    }

to the following

for (j in eicidx[o]) { pts <- xeic@eic[[ps]][[j]] points(pts, type = "l", col = lcol[cnt]); peakrange <- peaks[,c("rtmin","rtmax"), drop=FALSE] ptsidx <- pts[,"rt"] >= peakrange[j,1] & pts[,"rt"] <= peakrange[j,2] if (naps[j]){ points(pts[ptsidx, ], type = "l", col = col[cnt], lwd=1.3, lty=3) } else { points(pts[ptsidx, ], type = "l", col = col[cnt], lwd=1.3) } cnt <- cnt + 1; }

Note that these changes are very minor. What do you think?

Regards,

Wilson Melendez

jmosl01 commented 4 years ago

Hello @sneumann ,

I would be happy to contribute to the CAMERA code to fix this issue. I found a guide to follow for contributing code for a bug fix, so I will try my hand at this and let you know how it goes!

Regards,

Jonathan Mosley