sgibb / MALDIquant

Quantitative Analysis of Mass Spectrometry Data
https://strimmerlab.github.io/software/maldiquant/
60 stars 25 forks source link

MALDIquant::binpeaks() silently propagates values to empty MassPeaks objects #61

Closed chasemc closed 5 years ago

chasemc commented 5 years ago

If you have a MassPeaks object and have 0-length values for mass and intensity MALDIquant::binpeaks() will silently propagate values to that object.

Workaround is to check MALDIquant::isEmpty() and remove empty spectra before binPeaks function.

s <- createMassPeaks(mass=1:100, intensity=rnorm(100)^2,
                     metaData=list(name="example peaks"))

s2 <- createMassPeaks(mass= numeric(0), intensity=numeric(0),
                     metaData=list(name="example peaks"))

binPeaks(c(s, s2))
[[1]]
S4 class type            : MassPeaks            
Number of m/z values     : 100                  
Range of m/z values      : 1 - 100              
Range of intensity values: 3.395e-04 - 1.108e+01
Range of snr values      : NA - NA              
Memory usage             : 3.82 KiB             
Name                     : example peaks        

[[2]]
S4 class type            : MassPeaks            
Number of m/z values     : 100                  
Range of m/z values      : 1 - 100              
Range of intensity values: 3.395e-04 - 1.108e+01
Range of snr values      : NA - NA              
Memory usage             : 3.82 KiB             
Name                     : example peaks  

Also, it seems to only be silent if there are an equal number of empty and non-empty objects.

sgibb commented 5 years ago

Thanks for this bug report! It was due to the recycling of list elements in mapply. It is fixed in MALDIquant 1.19.2 (on its way to CRAN).