lgatto / MSnbase

Base Classes and Functions for Mass Spectrometry and Proteomics
http://lgatto.github.io/MSnbase/
123 stars 50 forks source link

XIC without data in one sample #549

Closed hvaret closed 2 years ago

hvaret commented 2 years ago

Hi,

I open this issue for a possible bug when using the plot(..., type="XIC") function. When analyzing my LCMS data I wanted to plot the XIC of several samples using a specific m/z-RT area, and it happened there was no data in this area for at least one of them. The strange behavior is that I actually obtained a plot for all the samples.

Below is a toy reproducible example using the data from the msdata package:

library(msdata)
library(MSnbase)
od <- readMSData(dir(system.file("sciex", package = "msdata"),
                     full.names = TRUE), mode = "onDisk")
# centroiding
od <- pickPeaks(od)
# data for both samples between mz=106.04 and 106.06
serine <- filterMz(filterRt(od, rt = c(175, 190)), mz = c(106.04, 106.06))
plot(serine, type = "XIC")
# no data between mz=106.053 and 106.056 for the second sample to reproduce the bug
serine <- filterMz(filterRt(od, rt = c(175, 190)), mz = c(106.053, 106.056))
plot(serine, type = "XIC")

Note that a plot is produced for the first sample (as expected) but not for the second one (error) when we try separately:

serine <- filterMz(filterRt(od[which(fromFile(od) == 1)], rt = c(175, 190)), mz = c(106.053, 106.056))
plot(serine, type = "XIC")
serine <- filterMz(filterRt(od[which(fromFile(od) == 2)], rt = c(175, 190)), mz = c(106.053, 106.056))
plot(serine, type = "XIC")

When looking at the source code my feeling is that the error is in https://github.com/lgatto/MSnbase/blob/80e3b08bff43dea8bd11e86737589254f10babbf/R/functions-MSnExp.R#L623 with x and fns that have different lengths.

Here is my sessionInfo():

R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.5.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] MSnbase_2.18.0      ProtGenerics_1.24.0 S4Vectors_0.30.0    mzR_2.26.1          Rcpp_1.0.6         
[6] Biobase_2.52.0      BiocGenerics_0.38.0 msdata_0.32.0      

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1      purrr_0.3.4           lattice_0.20-44       colorspace_2.0-1      vctrs_0.3.8          
 [6] generics_0.1.0        vsn_3.60.0            utf8_1.2.1            XML_3.99-0.6          rlang_0.4.11         
[11] pillar_1.6.1          glue_1.4.2            DBI_1.1.1             BiocParallel_1.26.0   affy_1.70.0          
[16] affyio_1.62.0         foreach_1.5.1         lifecycle_1.0.0       plyr_1.8.6            mzID_1.30.0          
[21] zlibbioc_1.38.0       munsell_0.5.0         pcaMethods_1.84.0     gtable_0.3.0          codetools_0.2-18     
[26] IRanges_2.26.0        doParallel_1.0.16     fansi_0.5.0           preprocessCore_1.54.0 scales_1.1.1         
[31] BiocManager_1.30.15   limma_3.48.0          MsCoreUtils_1.4.0     impute_1.66.0         ggplot2_3.3.3        
[36] digest_0.6.27         dplyr_1.0.6           ncdf4_1.17            grid_4.1.0            clue_0.3-59          
[41] tools_4.1.0           magrittr_2.0.1        tibble_3.1.2          cluster_2.1.2         crayon_1.4.1         
[46] pkgconfig_2.0.3       MASS_7.3-54           ellipsis_0.3.2        assertthat_0.2.1      iterators_1.0.13     
[51] R6_2.5.0              MALDIquant_1.19.3     compiler_4.1.0

Best regards,

Hugo

lgatto commented 2 years ago

Thank you for the report @hvaret.

@jorainer, what do you think?

jorainer commented 2 years ago

Thanks for reporting @hvaret , I will have a look at it.

hvaret commented 2 years ago

Hi, thanks a lot @jorainer and @lgatto for the fast answer. I tried with the updated code and everything is now OK on my real data.