Closed eterlova closed 2 years ago
This puzzles me - the parameter add
was added to findChromPeaks,XCMSnExp
in version 3.9.2 and has not been removed. On what object are you calling findChromPeaks
with the parameter add = TRUE
? Is it an OnDiskMSnExp
(the object returned by readMSData
) or an XCMSnExp
object? Note that for the former no such parameter is defined. So, the first peak detection (presumably on MS1) should be performed without add = TRUE
, but a subsequent findChromPeaks
on the result object from the first peak detection supports add = TRUE
.
@jorainer, thanks for the clarification -- I couldn't quite figure out which of these objects to use from the function description, so I tried both. The reason why I thought it was not working is that after these steps:
xdata <- findChromPeaks(rawdata_cent, param = cw_param)
xdata <- findChromPeaks(xdata, param = CentWaveParam(), msLevel = 2L, add=TRUE)
xdata_pp <- refineChromPeaks(xdata, mpp)
xdata_grouped1 <- groupChromPeaks(xdata_pp, param = PeakDensityParam())
xdata_rtaligned <- adjustRtime(xdata_grouped1, param = ObiwarpParam())
xdata_grouped2 <- groupChromPeaks(xdata_rtaligned, param = PeakDensityParam())
xdata_grouped2 <- groupChromPeaks(xdata_rtaligned, add = TRUE, msLevel = 2L)
I get an error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘groupChromPeaks’ for signature ‘"XCMSnExp", "missing"’
Calls: groupChromPeaks -> <Anonymous>
Which I think it means that groupChromPeaks does not find the peaks to group? Any idea why my peaks are getting lost?
Best, Lisa
The reason for the error message is that you called groupChromPeaks
without specifying the parameter object. It should work if you use
xdata_grouped2 <- groupChromPeaks(xdata_rtaligned, param = PeakDensityParam(), add = TRUE, msLevel = 2L)
instead of the last line you used above
@jorainer Thanks for spotting this, it was not intentional, but unfortunately even with that I end up with an error
xdata_rtaligned <- adjustRtime(xdata, param = ObiwarpParam())
xdata_grouped <- groupChromPeaks(xdata_rtaligned, param = PeakDensityParam())
xdata_grouped <- groupChromPeaks(xdata_rtaligned, param = PeakDensityParam(), add = TRUE, msLevel = 2L)
From the .out file:
Apply retention time correction performed on MS1 to spectra from all MS levels
Applying retention time adjustment to the identified chromatographic peaks ... OK
Processing 253328 mz slices ... OK
Processing 259646 mz slices ... OK
Error in .local(object, param, ...) :
No feature definitions for MS level 1 present. Please run 'groupChromPeaks' first.
Calls: fillChromPeaks -> fillChromPeaks -> .local
Execution halted
Do you know in which of the two commands the error is thrown?
Can you please run the commands separately to see which call throws the error? Also, please check after each if features are presents, i.e. call hasFeatures(xdata_rtaligned)
? Maybe even seprately for each MS level, i.e. hasFeatures(xdata_rtaligned, msLevel = 1)
and hasFeatures(xdata_rtaligned, msLevel = 2)
?
@jorainer I was not able to reproduce the same error when I run the script line by line, but here is what I get:
> xdata <- findChromPeaks(rawdata_cent, param =CentWaveParam())
Error in x$.self$finalize() : attempt to apply non-function
Detecting mass traces at 32 ppm ... OK
Detecting chromatographic peaks in 45697 regions of interest ... OK: 4039 found.
Detecting mass traces at 32 ppm ... OK
Detecting chromatographic peaks in 83042 regions of interest ... OK: 7048 found.
Detecting mass traces at 32 ppm ... OK
Detecting chromatographic peaks in 85141 regions of interest ... OK: 7593 found.
Detecting mass traces at 32 ppm ... OK
Detecting chromatographic peaks in 65843 regions of interest ... OK: 9027 found.
> hasFeatures(xdata, msLevel = 1)
[1] FALSE
> xdata <- findChromPeaks(xdata, param = CentWaveParam(), msLevel = 2L, add=TRUE)
Detecting mass traces at 32 ppm ... OK
Detecting chromatographic peaks in 20523 regions of interest ... OK: 2778 found.
Detecting mass traces at 32 ppm ... OK
Detecting chromatographic peaks in 38996 regions of interest ... OK: 4541 found.
Detecting mass traces at 32 ppm ... OK
Detecting chromatographic peaks in 33806 regions of interest ... OK: 4535 found.
Detecting mass traces at 32 ppm ... OK
Detecting chromatographic peaks in 35617 regions of interest ... OK: 5206 found.
> hasFeatures(xdata, msLevel = 1)
[1] FALSE
> hasFeatures(xdata, msLevel = 2)
[1] FALSE
> xdata_pp <- refineChromPeaks(xdata, param=MergeNeighboringPeaksParam())
Evaluating 581 peaks in file DA_metabolomics2021_sample_127.mzML for merging ... OK
Evaluating 1147 peaks in file DA_metabolomics2021_sample_143.mzML for merging ... OK
Evaluating 1088 peaks in file DA_metabolomics2021_sample_111.mzML for merging ... OK
Evaluating 1497 peaks in file DA_metabolomics2021_sample_050.mzML for merging ... OK
Merging reduced 44767 chromPeaks to 44452.
> hasFeatures(xdata_pp, msLevel = 1)
[1] FALSE
> hasFeatures(xdata_pp, msLevel = 2)
[1] FALSE
> xdata_grouped1 <- groupChromPeaks(xdata_pp, param = PeakDensityParam())
Processing 253240 mz slices ...
OK
> hasFeatures(xdata_grouped1, msLevel = 1)
[1] TRUE
> hasFeatures(xdata_grouped1, msLevel = 2)
[1] FALSE
> xdata_grouped1 <- groupChromPeaks(xdata_pp, param= PeakDensityParam(), add=TRUE, msLevel = 2L)
Processing 259377 mz slices ... OK
> hasFeatures(xdata_grouped1, msLevel = 1)
[1] FALSE
> hasFeatures(xdata_grouped1, msLevel = 2)
[1] TRUE
I figured here is where I am losing my MS2 peaks, so I tried to back up a little:
> xdata_rtaligned <- adjustRtime(xdata_pp, param = ObiwarpParam())
Sample number 2 used as center sample.
Aligning DA_metabolomics2021_sample_050.mzML against DA_metabolomics2021_sample_111.mzML ... OK
Aligning DA_metabolomics2021_sample_127.mzML against DA_metabolomics2021_sample_111.mzML ... OK
Aligning DA_metabolomics2021_sample_143.mzML against DA_metabolomics2021_sample_111.mzML ... OK
Apply retention time correction performed on MS1 to spectra from all MS levels
Applying retention time adjustment to the identified chromatographic peaks ... OK
> hasFeatures(xdata_rtaligned, msLevel = 1)
[1] FALSE
> hasFeatures(xdata_rtaligned, msLevel = 2)
[1] FALSE
> xdata_grouped2 <- groupChromPeaks(xdata_rtaligned, param = PeakDensityParam())
Processing 253240 mz slices ... OK
> hasFeatures(xdata_grouped2, msLevel = 1)
[1] TRUE
> hasFeatures(xdata_grouped2, msLevel = 2)
[1] FALSE
> xdata_grouped2 <- groupChromPeaks(xdata_rtaligned, param = PeakDensityParam(), add = TRUE, msLevel = 2L)
Processing 259377 mz slices ... OK
> hasFeatures(xdata_grouped2, msLevel = 2)
[1] TRUE
> hasFeatures(xdata_grouped2, msLevel = 1)
[1] FALSE
So I think it is impossible to have groupings MS1 and MS2 peaks in the same object, is that right? I think @sneumann said something to that effect?
Best, Lisa
Thanks for the info! OK, so it seems MS1 features get dropped when MS2 features are added. I'll have a look into the code. Just out of curiosity - what MS2 data do you have? Usually I'm grouping peaks in MS1 to define the features, but I'm not grouping MS2 chrom peaks but use them "only" for annotation of the MS1 signals (which I use for quantification).
@jorainer Thank you for looking into this! I am trying to analyze my MS/MSe data using RAMClustR. Corey told me that I don't have to split my spectra into two separate files (one for MS and one for MSe) if I use these functions. I thought it was a much more elegant solution, but it seems not to be working
Yes, can well be that there's a bug - I don't have such MSe data available to run unit tests on it. That's maybe why it never showed up. I'll dig into the code and would then ask you to test.
Checked the code and all should be good with the add
parameter. But then I checked your example code again, and the reason that you don't have MS1 and MS2 features in your object is that you're doing the peak grouping twice on the same input object (i.e. xdata_rtaligned
). You would run the second peak grouping on MS2 on the xdata_grouped2
to add the features to the already defined features.
So, using
xdata_rtaligned <- adjustRtime(xdata_pp, param = ObiwarpParam())
xdata_grouped2 <- groupChromPeaks(xdata_rtaligned, param = PeakDensityParam())
xdata_grouped2 <- groupChromPeaks(xdata_grouped2, param = PeakDensityParam(), add = TRUE, msLevel = 2L)
should work: you need to first run the peak grouping on the aligned XCMSnExp
object and then the second round of peak grouping on MS2 on the same XCMSnExp
object (to add them to the already existing one).
Thank you so much! Of course this worked!
> hasFeatures(xdata_grouped2, msLevel = 1)
[1] TRUE
> hasFeatures(xdata_grouped2, msLevel = 2)
[1] TRUE
Gonna close the issue now
Hello all,
I want to perform peak picking on both MS1 and MS2, and keep both in the same
XCMSnExp
object.I think that at some point it was possible to run
findChromPeaks(... msLevel=2L, add=TRUE)
, is that not an option anymore?I get an error:
Error in .local(object, param, ...) : unused argument (add = TRUE)
If you deprecated this option, is there another one that could perform the same function?