Open 13479776 opened 2 years ago
If I got you right, you have an experiment with some files that contain only MS1 data and some files with MS1 and MS2 data? In such cases xcms
will throw this error when you call chromPeakSpectra
or featureSpectra
. I will try to get that fixed.
The workaround at the moment is to make a subset of the data containing the files with MS1 and MS2 spectra and then call the functions on these. In the example code below I have a similar data set with some MS1-only files and some with MS1 and MS2 (with two different collision energies). Running the featureSpectra
on the full data set results in the same error:
> table(msLevel(data_WP))
1 2
8361 1226
> featureSpectra(data_WP)
Error: No MS level 2 spectra present.
The solution is to subset the data to the files with the MS1 and MS2 spectra. In my case the information on the type of aquisition (MS1 only or MS1 and MS2) is encoded in a column named "mode"
in the pData
of the xcms
object. Thus, what I'm doing below is getting the index of the files with the MS1 and MS2 data and using filterFile
> data_WP$mode
[1] "FS" "FS" "FS" "FS" "FS" "FS" "CE20" "CE30"
> data_ce <- filterFile(data_WP, grep("CE", data_WP$mode), keepFeatures = TRUE)
Importantly, you need to use keepFeatures = TRUE
, otherwise feature definitions will be dropped in the returned object. With that you can now call the function and you get the MS2 spectra for the features.
> feature_ms2 <- featureSpectra(data_ce)
> feature_ms2
MSpectra with 751 spectra and 2 metadata column(s):
msLevel rtime peaksCount | feature_id
<integer> <numeric> <integer> | <character>
FT0007.CP36983.F08.S0384 2 161.7605 3 | FT0007
FT0015.CPM42198.F07.S0200 2 83.6344 13 | FT0015
... ... ... ... . ...
FT7040.CP37143.F08.S0418 2 175.959 156 | FT7040
FT7041.CP68730.F08.S0378 2 158.887 43 | FT7041
peak_id
<character>
FT0007.CP36983.F08.S0384 CP36983
FT0015.CPM42198.F07.S0200 CPM42198
... ...
FT7040.CP37143.F08.S0418 CP37143
FT7041.CP68730.F08.S0378 CP68730
Works obviously also for chromPeakSpectra
:
> cpeak_ms2 <- chromPeakSpectra(data_ce)
> cpeak_ms2
MSpectra with 751 spectra and 1 metadata column(s):
msLevel rtime peaksCount | peak_id
<integer> <numeric> <integer> | <character>
CP34717.F07.S0119 2 41.3219 60 | CP34717
CP34719.F07.S0095 2 37.5071 13 | CP34719
... ... ... ... . ...
CP68688.F08.S0459 2 180.698 9 | CP68688
CP68730.F08.S0378 2 158.887 43 | CP68730
As said, I will fix that. But the workaround should also work for you.
Note: a second solution would be to use return.type = "Spectra"
or return.type = "List"
. In both cases the function should work on the full data set.
Hi, all,
I use the xcms3 to get the XCMSnExp object with dataset including full scan or DDA mode. The table(XCMSnExp) function can give me the MS1 and MS2 scan information.
However, when i use the chromPeakSpectra() function, the error "Error: No MS level 2 spectra present" was happened. Is it possible to process and got the (MS2) spectra associated with the features the dataset with mixture scan mode? such as mzML with full scan and mzML with DDA mode.
bes wishes, hees