sneumann / xcms

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

findChromPeaks() called on a `MChromatograms` object or a `XCMSnExp` object #650

Open linlennypinawa opened 1 year ago

linlennypinawa commented 1 year ago

It supposes to call on a MChromatograms object according to the manual, and it returns a XChromatograms object, called object_1 for example.

However, it works with a MSnExp object as well. It also returns a XChromatograms object, called object_2 for example.

Here are codes to generate plotChromPeakDensity from object_1 .

a MSnExp object <- readMSData( .mzXML files)
a MChromatograms object <- chromatogram(a MSnExp object)
object_1 <- findChromPeaks(a MChromatograms object, param = cwp, BPPARAM = BPPARAM)
plotChromPeakDensity(object_1, param = pdp_param)

file_subset_chrom_peak_235_density

Here are codes to generate plotChromPeakDensity from object_2 .

a MSnExp object <- readMSData( .mzXML files)
z <- findChromPeaks(a MSnExp object, param = cwp, BPPARAM = BPPARAM)
object_2 <- chromatogram(z)
plotChromPeakDensity(object_2, param = pdp_param)

file_raw_subset_pks_chrom_235_density

Two plots look different. What is the appropriate route to group peaks?

linlennypinawa commented 1 year ago

When executing findChromPeaks on a MSnExp object of my data, I came across the message as follows: "Your data appears to be not centroided! CentWave works best on data in centroid mode."

This message helps me understand the MS data. The output of readMSData() is a XCMSnExp container in which data is not centroided. [a XCMSnExp]@featureData@data$centroided confirms it. Chromtogram() transforms the non-centroided data to centroided data. Centroid mode is the key for applying centWave approach to find peaks. In order to get centroided mode, I have to put argument centroided = TRUE in readMSData().

However, I tested findChromPeaks() on MChromatograms and XCMSExp containers of provided data at LCMS data preprocessing and analysis with xcms. I did not get "Your data appears to be not centroided! CentWave works best on data in centroid mode."

May I suggest adding centroided information to a XCMSnExp container file?

linlennypinawa commented 1 year ago

I tested findChromPeaks() on MChromatograms and XCMSExp containers of provided data at LCMS data preprocessing and analysis with xcms.

I followed the codes, and reproduced figure 6(left). In this case, apply findChromPeaks to the XCMSnExp object. demo_305_XCMSnExp

Apply findChromPeaks to the MChromatograms object, I got: demo_305_MChromatograms

jorainer commented 1 year ago

The preferred approach is to:

There is the possibility to run findChromPeaks also on MChromatograms objects, but the results (if you use CentWaveParam) can/will be different. The reason for that is a) the way centWave estimates the background noise. It can use the full data if it is done on a OnDiskMSnExp, but it can only use the data within the single MChromatograms if it is performed on the MChromatograms. Also, the centWave peak detection performs slightly different between the two, because for the MChromatograms there is no scattering of values in m/z dimension. So, the first step (detection of the region of interest ROI is omitted).

If you run centWave on a MChromatograms it can help to lower the value for the snthresh parameter to get comparable results.

jorainer commented 1 year ago

Regarding centroiding - usually, that information is encoded in mzML files, so, if your data is centroided and stored in mzML files, this information should be correctly imported. AFAIK mzXML do not support the centroided information.

Anyway, like you said, an alternative is to set centroided = TRUE in the readMSData call (if you are sure that the data is in fact centroided). Otherwise, you can call centroided(xdata) <- TRUE on a OnDiskMSnExp or XCMSnExp object to force setting the centroiding information.