rickhelmus / patRoon

Workflow solutions for mass-spectrometry based non-target analysis.
https://rickhelmus.github.io/patRoon/
GNU General Public License v3.0
58 stars 17 forks source link

Error: plotVenn() with featureGroupsComparison #107

Closed LeonSaal closed 2 months ago

LeonSaal commented 3 months ago

Hi Rick,

I was trying to visualize the results of different feature finding approaches with plotVenn() but got an error I don't understand:


> comp = comparison(fGroupsPO, fGroupsXCMS, groupAlgo="xcms3")
> plotVenn(comp)
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'i' in selecting a method for function '[': error in evaluating the argument 'x' in selecting a method for function '%in%': attempt to set an attribute on NULL

fGroupsPO was constructed with xcms::manualChromPeaks() and imported in patRoon with importFeatureGroupsXCMS3():

> library(magrittr)
> library(patRoon)
> ...
> msnexp = MSnbase::readMSData(files, mode = "onDisk")
> xcmsset = xcms::manualChromPeaks(msnexp, fmatrix)
> xcmsset = xcms::groupChromPeaks(xcmsset, xcms::PeakDensityParam(sampleGroups = ...))
> fGroupsPO = importFeatureGroupsXCMS3(xcmsset, anaInfo)

> fGroupsXCMS = findFeaturesXCMS3(anaInfo)
> fGroupsXCMS %<>% groupFeaturesXCMS3()

Do you have any idea, what could be going on here?

Kind regards,

Leon


Further information:

> class(fGroupsPO)
[1] "featureGroupsXCMS3"
attr(,"package")
[1] "patRoon"

> class(fGroupsXCMS)
[1] "featureGroupsXCMS3"
attr(,"package")
[1] "patRoon"

> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               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    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

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

other attached packages:
[1] fstcore_0.9.18 patRoon_2.3.1  magrittr_2.0.3

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3          rstudioapi_0.15.0           MultiAssayExperiment_1.28.0 MALDIquant_1.22.2          
  [5] fs_1.6.3                    zlibbioc_1.48.0             vctrs_0.6.5                 multtest_2.58.0            
  [9] memoise_2.0.1               RCurl_1.98-1.14             xcms_4.0.2                  htmltools_0.5.7            
 [13] S4Arrays_1.2.0              progress_1.2.3              SparseArray_1.2.3           mzID_1.40.0                
 [17] KernSmooth_2.23-22          plyr_1.8.9                  cachem_1.0.8                impute_1.76.0              
 [21] igraph_1.6.0                mime_0.12                   lifecycle_1.0.4             iterators_1.0.14           
 [25] pkgconfig_2.0.3             Matrix_1.6-1.1              R6_2.5.1                    fastmap_1.1.1              
 [29] GenomeInfoDbData_1.2.11     rbibutils_2.2.16            MatrixGenerics_1.14.0       shiny_1.8.0                
 [33] clue_0.3-65                 digest_0.6.34               pcaMethods_1.94.0           colorspace_2.1-0           
 [37] S4Vectors_0.40.2            RSQLite_2.3.5               GenomicRanges_1.54.1        Spectra_1.12.0             
 [41] fansi_1.0.6                 abind_1.4-5                 compiler_4.3.2              bit64_4.0.5                
 [45] withr_3.0.0                 doParallel_1.0.17           backports_1.4.1             BiocParallel_1.36.0        
 [49] DBI_1.2.1                   gplots_3.1.3                MASS_7.3-60                 MsExperiment_1.4.0         
 [53] DelayedArray_0.28.0         gtools_3.9.5                caTools_1.18.2              mzR_2.36.0                 
 [57] tools_4.3.2                 httpuv_1.6.13               fst_0.9.8                   glue_1.7.0                 
 [61] QFeatures_1.12.0            promises_1.2.1              grid_4.3.2                  checkmate_2.3.1            
 [65] cluster_2.1.4               generics_0.1.3              gtable_0.3.4                tzdb_0.4.0                 
 [69] preprocessCore_1.64.0       data.table_1.14.10          hms_1.1.3                   MetaboCoreUtils_1.10.0     
 [73] utf8_1.2.4                  XVector_0.42.0              BiocGenerics_0.48.1         RANN_2.6.1                 
 [77] foreach_1.5.2               pillar_1.9.0                stringr_1.5.1               vroom_1.6.5                
 [81] limma_3.58.1                later_1.3.2                 robustbase_0.99-1           splines_4.3.2              
 [85] dplyr_1.1.4                 lattice_0.21-9              survival_3.5-7              bit_4.0.5                  
 [89] tidyselect_1.2.0            IRanges_2.36.0              ProtGenerics_1.34.0         SummarizedExperiment_1.32.0
 [93] stats4_4.3.2                Biobase_2.62.0              statmod_1.5.0               MSnbase_2.28.1             
 [97] matrixStats_1.2.0           DEoptimR_1.1-3              stringi_1.8.3               lazyeval_0.2.2             
[101] codetools_0.2-19            MsCoreUtils_1.14.1          tibble_3.2.1                BiocManager_1.30.22        
[105] cli_3.6.2                   affyio_1.72.0               xtable_1.8-4                Rdpack_2.6                 
[109] munsell_0.5.0               Rcpp_1.0.12                 GenomeInfoDb_1.38.5         MassSpecWavelet_1.68.0     
[113] XML_3.99-0.16.1             parallel_4.3.2              ellipsis_0.3.2              blob_1.2.4                 
[117] ggplot2_3.4.4               readr_2.1.5                 prettyunits_1.2.0           AnnotationFilter_1.26.0    
[121] bitops_1.0-7                MsFeatures_1.10.0           scales_1.3.0                affy_1.80.0                
[125] ncdf4_1.22                  crayon_1.5.2                rlang_1.1.3                 vsn_3.70.0  
rickhelmus commented 3 months ago

Hi Leon,

Doesn't ring any bells here, perhaps some data is missing via the import, but that's just guessing. Would it be possible to share some of the objects (fGroupsPO, fGroupsXCMS, comp or just the whole session), so I can debug the problem myself?

Thanks, Rick

LeonSaal commented 3 months ago

Hi Rick,

thanks for the quick reply! I have a small update: I was playing around with the consensus-function and the same error occured, when the uniqueFrom-keyword was set to a single value:

> comp = comparison(fGroupsPO, fGroupsXCMS, groupAlgo="xcms3")
> uniquePO = consensus(comp, uniqueFrom=1, uniqueOuter=TRUE)
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'i' in selecting a method for function '[': error in evaluating the argument 'x' in selecting a method for function '%in%': attempt to set an attribute on NULL

With all or multiple values there is no problem:

> outer = consensus(comp, uniqueFrom=TRUE, uniqueOuter=TRUE)
Generating consensus features...Done!
Generating consensus feature groups...
  |==================================================================================================================| 100%

For further investigation, here are the fGroups: fGroups.zip

Kind regards,

Leon

LeonSaal commented 3 months ago

Further digging showed, the error is happening inside unique():

> outerFrom = 1
> which = names(comp)[outerFrom]
> patRoon::unique(comp@comparedFGroups, which = which)
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'i' in selecting a method for function '[': error in evaluating the argument 'x' in selecting a method for function '%in%': attempt to set an attribute on NULL

Snippet was based on: https://github.com/rickhelmus/patRoon/blob/7f36ee25494d189a76900dc75ad8bcf9e2440eee/R/feature_groups-comparison.R#L304-L309

rickhelmus commented 3 months ago

Hi Leon,

Thanks for the files and further investigation.

In the end it seems that the XCMS structure is incomplete, and the error happens somewhere in the XCMS code. Under some circumstances, patRoon tries to 'emulate' an XCMS object in case insufficient data is available. The comparison() function is an example of this: it sort-of creates pseudofeatures from the input fGroups objects, meaning that these have no information such as actual raw data with spectra. Where it goes wrong now is that when unique() is called, the analyses of the object are subset, triggering an synchronization of the internal XCMS object (xdata slot), which then gives the error. I will see if this is fixable, or otherwise perhaps simply disable the object synchronization for these edge cases.

Perhaps in the meanwhile you could switch to another algorithm where you call comparison()?

Thanks, Rick

rickhelmus commented 3 months ago

Hi @LeonSaal ,

I just pushed some small changes that should initialize some missing data. Could you please test it? I also hope it doesn't break anything else, so feedback for that is welcome too ;-)

Thanks, Rick

LeonSaal commented 3 months ago

Hi @rickhelmus,

thanks for the update! I tested my script with the new docker image (sha256:cb3ebbd12561c2e7e11850f9e900ab464a85ca718de43932759a30786a0709e6), but unfortunately, the error still persists with comparison(..., groupAlgo="xcms3"). However, as you suggested, with groupAlgo="openms", it works!

Kind regards, Leon

rickhelmus commented 2 months ago

Hi Leon,

Sorry for my late reply again...

But great things are working now for you. I totally forgot to mention, but even with the fix I pushed for xcms3 you would still need to clearout some of the cached data to avoid running in the problem. If it's not too much trouble, maybe you could re-try without cached data to see if it works? Then we can close this issue. Instead of wiping the whole cache, I think it would be sufficient to run clearCache("XCMS").

Thanks, Rick

LeonSaal commented 2 months ago

Hi Rick,

thanks for the tip with the cache! Indeed, it works now with the groupAlgo = "xcms3".

Kind regards, Leon