sneumann / xcms

This is the git repository matching the Bioconductor package xcms: LC/MS and GC/MS Data Analysis
Other
180 stars 80 forks source link

Coersion from `XCMSnExp` to `xcmsSet` gets an array of lists in `groups` slot due to the additional ms_level column #528

Closed zhuxr11 closed 3 years ago

zhuxr11 commented 3 years ago

Hi, recently I upgraded my xcms from 3.9.1 to 3.10.0. After this, I discovered an additional column ms_level to the right of the DataFrame from featureDefinitions(), as added by df$ms_level <- as.integer(msLevel). When I coerce an XCMSnExp object to an xcmsSet object, the code xs@groups <- S4Vectors::as.matrix(fgs[, -ncol(fgs)]) actually removes ms_level column instead of the peakidx column as it did in 3.9.1, causing problems when using it with other packages such as CAMERA (updated to 1.44.0), since CAMERA is expecting a traditional numeric matrix in the groups slot but it actually gets an S4 matrix with a list column peakidx now.

Now I use an XCMSnExp object created from faahKO dataset to illustrate the issue. Please note that batch_tibble$xcms_set_list[[1]] is the created XCMSnExp object, pulled out from a tibble.

Here are what I got in xcms 3.9.1:

> colnames(featureDefinitions(batch_tibble$xcms_set_list[[1]]))
 [1] "mzmed"   "mzmin"   "mzmax"   "rtmed"   "rtmin"   "rtmax"   "npeaks"  "KO"      "WT"     
[10] "peakidx"

> colnames(xcms::groups(as(batch_tibble$xcms_set_list[[1]], "xcmsSet")))
Note: you might want to set/adjust the 'sampclass' of the returned xcmSet object before proceeding with the analysis.
[1] "mzmed"  "mzmin"  "mzmax"  "rtmed"  "rtmin"  "rtmax"  "npeaks" "KO"     "WT"   # COLUMN peakidx REMOVED

> class(xcms::groups(as(batch_tibble$xcms_set_list[[1]], "xcmsSet")))
Note: you might want to set/adjust the 'sampclass' of the returned xcmSet object before proceeding with the analysis.
[1] "matrix"  # A TRADITIONAL MATRIX

> xcms::groups(as(batch_tibble$xcms_set_list[[1]], "xcmsSet")) %>% "["(1,1)
Note: you might want to set/adjust the 'sampclass' of the returned xcmSet object before proceeding with the analysis.
mzmed   # NOTE: NO $ SIGN HERE, NUMERIC
200.1

> CAMERA::xsAnnotate(as(batch_tibble$xcms_set_list[[1]], "xcmsSet"), polarity = "positive")
Note: you might want to set/adjust the 'sampclass' of the returned xcmSet object before proceeding with the analysis.
An "xsAnnotate" object!
With 0 groups (pseudospectra)
With 12 samples and 634 peaks
Polarity mode is set to:  positive 
Using automatic sample selection
Memory usage: 3.99 MB

Here are what I get now in xcms 3.10.0:

> colnames(featureDefinitions(batch_tibble$xcms_set_list[[1]]))
 [1] "mzmed"    "mzmin"    "mzmax"    "rtmed"    "rtmin"   
 [6] "rtmax"    "npeaks"   "KO"       "WT"       "peakidx" 
[11] "ms_level"  # ADDITIONAL COLUMN

> colnames(xcms::groups(as(batch_tibble$xcms_set_list[[1]], "xcmsSet")))
Note: you might want to set/adjust the 'sampclass' of the returned xcmSet object before proceeding with the analysis.
 [1] "mzmed"   "mzmin"   "mzmax"   "rtmed"   "rtmin"   "rtmax"  
 [7] "npeaks"  "KO"      "WT"      "peakidx"  # COLUMN peakidx IS NOT REMOVED

> class(xcms::groups(as(batch_tibble$xcms_set_list[[1]], "xcmsSet")))
Note: you might want to set/adjust the 'sampclass' of the returned xcmSet object before proceeding with the analysis.
[1] "matrix" "array"   # ADDITIOAL LIST ARRAY HERE

> xcms::groups(as(batch_tibble$xcms_set_list[[1]], "xcmsSet")) %>% "["(1,1)
Note: you might want to set/adjust the 'sampclass' of the returned xcmSet object before proceeding with the analysis.
$mzmed  # NOTE: $ SIGN HERE, INDICATING A LIST?
[1] 200.1

> CAMERA::xsAnnotate(as(batch_tibble$xcms_set_list[[1]], "xcmsSet"), polarity = "positive")
Note: you might want to set/adjust the 'sampclass' of the returned xcmSet object before proceeding with the analysis.
Error in round(groupmat[, "mzmed"], 1)  # FINALLY AN ERROR

Could you please keep the peakidx removed in the groups slot after coersion to xcmsSet, so that the new version of xcms is still compatible with other packages that build on it such as CAMERA? Many thanks.

jorainer commented 3 years ago

Thanks @zhuxr11 for the bug report. Note however that this was already fixed in xcms version 3.10.2 (which you can install e.g. using devtools::install_github("sneumann/xcms", ref = "RELEASE_3_11")) - or even better by calling BiocManager::install() and updating all packages (you might have to install the BiocManager package if you don't have it with install.packages("BiocManager")).

I'm closing this issue - feel free to re-open if even after updating of xcms you still have the problem.