Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromatograms in row 1 have different mz #511

Open
antonwnk opened this issue Sep 30, 2020 · 5 comments
Open

Chromatograms in row 1 have different mz #511

antonwnk opened this issue Sep 30, 2020 · 5 comments

Comments

@antonwnk
Copy link
Contributor

antonwnk commented Sep 30, 2020

I get an error when trying to get the chromatograms (a call to the chromatogram function) of an XCMSnExp object with feature definitions present.

Traceback.

Error in .mz_chromatograms(object, mz = "mz"): Chromatograms in row 1 have different mz
Traceback:

1. chromatogram(a2def_acetone)
2. chromatogram(a2def_acetone)
3. .local(object, ...)
4. lapply(seq_len(nrow(res)), function(r) {
 .     fdev <- featureDefinitions(object, mz = mz(res)[r, ], rt = rt)
 .     if (nrow(fdev)) {
 .         fdev$row <- r
 .         .subset_features_on_chrom_peaks(fdev, chromPeaks(object), 
 .             pks_sub)
 .     }
 .     else DataFrame()
 . })
5. FUN(X[[i]], ...)
6. featureDefinitions(object, mz = mz(res)[r, ], rt = rt)
7. featureDefinitions(object, mz = mz(res)[r, ], rt = rt)
8. .local(object, ...)
9. mz(res)
10. mz(res)
11. .local(object, ...)
12. .mz_chromatograms(object, mz = "mz")
13. stop("Chromatograms in row ", i, " have different ", mz)

My XCMSnExp object, `a2def_acetone`: a set of "full-size" GC-MS samples `filterRt`-ed to where we expect to find acetone.

> a2def_acetone
MSn experiment data ("XCMSnExp")
Object size in memory: 10.31 Mb
- - - Spectra data - - -
 MS level(s): 1 
 Number of spectra: 29324 
 MSn retention times: 4:5 - 4:56 minutes
- - - Processing information - - -
Data loaded [Fri Sep 25 21:11:00 2020] 
Filter: select MS level(s) 1 [Fri Sep 25 21:11:08 2020] 
Filter: select retention time [70-1400] and MS level(s), 1 [Fri Sep 25 21:11:08 2020] 
Filter: trim MZ [35..250] on MS level(s) 1. 
Spectra of MS level(s) 1,  cleaned: Fri Sep 25 21:11:08 2020 
Removed 1208 empty spectra. [Fri Sep 25 21:16:04 2020] 
Filter: select retention time [245-296] and MS level(s), 1 [Wed Sep 30 09:24:53 2020] 
 MSnbase version: 2.12.0 
- - - Lazy processing queue content  - - -
 o  filterMz 
 o  clean 
- - - Meta data  - - -
phenoData
  rowNames: AS-021B-0-1139480.mzML AS-021B-1-1124475.mzML ...
    VIW-6-1-1139346.mzML (115 total)
  varLabels: sampleNames
  varMetadata: labelDescription
Loaded from:
  [1] AS-021B-0-1139480.mzML...  [115] VIW-6-1-1139346.mzML
  Use 'fileNames(.)' to see all files.
protocolData: none
featureData
  featureNames: F001.S1240 F001.S1241 ... F115.S1478 (29324 total)
  fvarLabels: fileIdx spIdx ... spectrum (35 total)
  fvarMetadata: labelDescription
experimentData: use 'experimentData(object)'
- - - xcms preprocessing - - -
Chromatographic peak detection:
 unknown method.
 6278 peaks identified in 115 samples.
 On average 54.6 chromatographic peaks per sample.
Correspondence:
 method: chromatographic peak density 
 128 features identified.
 Median mz range of features: 0.055494
 Median rt range of features: 8.7451

Trying to figure out what was going on I debugged the failing MSnbase:::.mz_chromatograms call and saw that the returned mz ranges have as lower bound the actual minimum mz found in the sample (as per filterFile(xcmsObj, n) %>% mz %>% unlist(use.names = FALSE) %>% min).

Browse[2]> rngs <- unique(do.call(rbind, lapply(x@.Data[i, ], getMethod(mz, "Chromatogram"))))
Browse[2]> rngs                                                                                                                                                               
                              [,1] [,2]
AS-021B-0-1139480.mzML    35.56396  250
AS-021B-1-1124475.mzML    35.56592  250
AS-023-0-1028176.mzML     35.56171  250
AS-023-1-1030346.mzML     35.56258  250
AS-024-0-11261-38.mzML    35.55937  250
[...]

Finally, another thing that I observed, which I don't know if is relevant. I have 2 objects (both fail the same way when trying to use chromatogram(.)):

  • an object, a2def, filtered with filterRt(., c(70, 1400)) and filterMz(., c(35, 250)) and processed to get featureDefinitions
  • a2def_acetone, the object corresponding to the stack trace and the debugger output showed above, obtained fromfilterRt(a2def, c(245, 296))

The numbers from the rngs variable in the debugger output correspond to the minimum mz values of the a2def object, rather than the minimum mz values in the a2def_acetone variable which was passed to the chromatogram function when debugging.

Thanks for the read and let me know what you think.

Edit:
Realized I am using a quite outdated XCMS version: 3.8.2

`sessionInfo()`

R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] xcms_3.8.2          MSnbase_2.12.0      ProtGenerics_1.18.0
 [4] S4Vectors_0.24.4    mzR_2.20.0          Rcpp_1.0.5         
 [7] BiocParallel_1.20.1 Biobase_2.46.0      BiocGenerics_0.32.0
[10] RColorBrewer_1.1-2  lattice_0.20-41     ggplot2_3.3.2      
[13] stringr_1.4.0       purrr_0.3.4         dplyr_1.0.1        
[16] magrittr_1.5       

loaded via a namespace (and not attached):
 [1] digest_0.6.25          foreach_1.5.0          IRdisplay_0.7.0       
 [4] R6_2.4.1               plyr_1.8.6             repr_1.1.0            
 [7] mzID_1.24.0            evaluate_0.14          pillar_1.4.6          
[10] zlibbioc_1.32.0        rlang_0.4.7            uuid_0.1-4            
[13] Matrix_1.2-18          preprocessCore_1.48.0  splines_3.6.0         
[16] munsell_0.5.0          compiler_3.6.0         pkgconfig_2.0.3       
[19] base64enc_0.1-3        multtest_2.42.0        pcaMethods_1.78.0     
[22] htmltools_0.5.0        tidyselect_1.1.0       tibble_3.0.3          
[25] RANN_2.6.1             IRanges_2.20.2         codetools_0.2-16      
[28] XML_3.99-0.3           crayon_1.3.4           withr_2.2.0           
[31] MASS_7.3-51.6          MassSpecWavelet_1.52.0 grid_3.6.0            
[34] jsonlite_1.7.0         gtable_0.3.0           lifecycle_0.2.0       
[37] affy_1.64.0            scales_1.1.1           ncdf4_1.17            
[40] stringi_1.4.6          impute_1.60.0          affyio_1.56.0         
[43] doParallel_1.0.15      limma_3.42.2           robustbase_0.93-6     
[46] ellipsis_0.3.1         generics_0.0.2         vctrs_0.3.2           
[49] IRkernel_1.1.1         iterators_1.0.12       tools_3.6.0           
[52] glue_1.4.1             DEoptimR_1.0-8         survival_3.2-3        
[55] colorspace_1.4-1       BiocManager_1.30.10    vsn_3.54.0            
[58] MALDIquant_1.19.3      pbdZMQ_0.3-3

@jorainer
Copy link
Collaborator

jorainer commented Oct 2, 2020

Uh, this is a really old version of xcms. Could you please check if you get the same error with the current version of xcms (3.10.2)?

@antonwnk
Copy link
Contributor Author

antonwnk commented Oct 2, 2020

I managed to update my environment but I seem to get the same error.

Traceback

> b = chromatogram(a, aggregationFun = "sum")
Error in .mz_chromatograms(object, mz = "mz") : 
  Chromatograms in row 1 have different mz
13: stop("Chromatograms in row ", i, " have different ", mz)
12: .mz_chromatograms(object, mz = "mz")
11: .local(object, ...)
10: mz(res)
9: mz(res)
8: .local(object, ...)
7: featureDefinitions(object, mz = mz(res)[r, ], rt = rt)
6: featureDefinitions(object, mz = mz(res)[r, ], rt = rt)
5: FUN(X[[i]], ...)
4: lapply(seq_len(nrow(res)), function(r) {
       fdev <- featureDefinitions(object, mz = mz(res)[r, ], rt = rt)
       if (nrow(fdev)) {
           fdev$row <- r
           .subset_features_on_chrom_peaks(fdev, chromPeaks(object), 
               pks_sub)
       }
       else DataFrame()
   })
3: .local(object, ...)
2: chromatogram(a, aggregationFun = "sum")
1: chromatogram(a, aggregationFun = "sum")

sessionInfo()

R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /rwthfs/rz/SW/R/R-4.0.2/lib64/R/lib/libRblas.so
LAPACK: /rwthfs/rz/SW/R/R-4.0.2/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] xcms_3.10.2         MSnbase_2.14.2      ProtGenerics_1.20.0
[4] S4Vectors_0.26.1    mzR_2.22.0          Rcpp_1.0.5         
[7] BiocParallel_1.22.0 Biobase_2.48.0      BiocGenerics_0.34.0

loaded via a namespace (and not attached):
 [1] SummarizedExperiment_1.18.2 tidyselect_1.1.0           
 [3] purrr_0.3.4                 lattice_0.20-41            
 [5] colorspace_1.4-1            vctrs_0.3.4                
 [7] generics_0.0.2              vsn_3.56.0                 
 [9] XML_3.99-0.5                rlang_0.4.7                
[11] pillar_1.4.6                glue_1.4.2                 
[13] affy_1.66.0                 RColorBrewer_1.1-2         
[15] matrixStats_0.57.0          affyio_1.58.0              
[17] GenomeInfoDbData_1.2.3      foreach_1.5.0              
[19] lifecycle_0.2.0             plyr_1.8.6                 
[21] mzID_1.26.0                 robustbase_0.93-6          
[23] zlibbioc_1.34.0             munsell_0.5.0              
[25] pcaMethods_1.80.0           gtable_0.3.0               
[27] codetools_0.2-16            IRanges_2.22.2             
[29] doParallel_1.0.15           GenomeInfoDb_1.24.2        
[31] MassSpecWavelet_1.54.0      preprocessCore_1.50.0      
[33] DEoptimR_1.0-8              scales_1.1.1               
[35] BiocManager_1.30.10         DelayedArray_0.14.1        
[37] limma_3.44.3                XVector_0.28.0             
[39] RANN_2.6.1                  impute_1.62.0              
[41] ggplot2_3.3.2               digest_0.6.25              
[43] dplyr_1.0.2                 ncdf4_1.17                 
[45] GenomicRanges_1.40.0        grid_4.0.2                 
[47] tools_4.0.2                 bitops_1.0-6               
[49] magrittr_1.5                RCurl_1.98-1.2             
[51] tibble_3.0.3                crayon_1.3.4               
[53] pkgconfig_2.0.3             Matrix_1.2-18              
[55] MASS_7.3-51.6               ellipsis_0.3.1             
[57] iterators_1.0.12            R6_2.4.1                   
[59] MALDIquant_1.19.3           compiler_4.0.2         

@jorainer
Copy link
Collaborator

jorainer commented Oct 6, 2020

Hm, strange. Could you eventually provide one or two files (or a subset of that) for which this happens so that I could check that locally and fix?

@RemyDeB
Copy link

RemyDeB commented Apr 19, 2023

Hi,
this is an old topic but i got the same error. This occure when i try to apply filterRt before chromatogram function. If i use chromatogram first them filterRt , it's work.
Hope this can help people.
Regards, Remy

@jorainer
Copy link
Collaborator

I'm working on a fix... thanks for reporting/reminding

jorainer added a commit that referenced this issue Apr 19, 2023
sneumann added a commit that referenced this issue Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants