rformassspectrometry / Spectra

Low level infrastructure to handle MS spectra
https://rformassspectrometry.github.io/Spectra/
38 stars 25 forks source link

Create neutralLoss spectra #236

Closed jorainer closed 2 years ago

jorainer commented 2 years ago

Add a function neutralLoss to create neutral loss spectra versions of a Spectra. The function could be defined in the following way:

neutralLoss(x, msLevel. = 2L, peaks = c("all", "bigger", "smaller")) {
}

With x being a Spectra, msLevel. to define the MS level on which to perform the calculation (MS2 would make most sense obviously) and peaks allowing to define in addition if peaks should be pre-filtered:

Any feedback and suggestions welcome @michaelwitting

jorainer commented 2 years ago

I checked the (php) code of https://doi.org/10.1021/jasms.1c00343 (available here). Seems they are simply calculating precursor m/z - fragment m/z and report the intensity of the fragment peak. No additional filtering is done. Also, no special handling of negative m/z values etc is performed.

jorainer commented 2 years ago

Maybe better to have a parameter filterPeaks = c("none", "largerPmz") that also supports a user-specified function to filter the peaks matrix. "largerPmz" would remove all peaks with an m/z that is larger than the one from the precursor m/z ("Pmz").

sgibb commented 2 years ago

Maybe you could reuse code from here: https://github.com/lgatto/MSnbase/blob/master/R/functions-fragments.R (it is already reused/copied to PSMatch: https://github.com/rformassspectrometry/PSMatch/blob/main/R/fragments-calculate.R)

jorainer commented 2 years ago

Seems that type of neutral loss calculations are different than the one I had in mind (i.e. the neutral loss spectra from https://doi.org/10.1021/jasms.1c00343 that are defined as precursor m/z - fragment m/z and the hypothetical neutral loss from https://doi.org/10.1021/acs.analchem.0c02521).

Considering that, it would maybe be better to define neutralLoss as a method for Spectra that dispatches on a Param object which also defines the type of calculation that should be performed:

michaelwitting commented 2 years ago

The one I had in mind is precursor m/z - fragment m/z, but if we have the others as well that would be great.

jorainer commented 2 years ago

Working on it.