rformassspectrometry / Spectra

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

hasMz or containsMz #96

Closed michaelwitting closed 4 years ago

michaelwitting commented 4 years ago

Following up on the discussion PR#52 at MsCoreUtils I was thinking about this function. I guess the consens was to have one function for the neutral loss and for the product ions. However, when searching for a neutral loss the m/z that shall be searched is dependent on the precursor m/z. When using hasMz (or whatever we will call it) that accepts only static m/z it would not be useful for the neutral loss search. I would therefore argue for two functions, one for the product m/z and one for the neutral loss. That way both functions can be also used with lapply. I hope it is clear what I mean.

jorainer commented 4 years ago

What should the function do? should it just return TRUE for the spectra that matches the condition?

For Spectra I would be OK to have a specific function that does what you suggest, say, a hasNeutralLoss function that then, uses the spectrum's precursorMz to check if it has a certain m/z peak.

michaelwitting commented 4 years ago

Yes, should return TRUE or FALSE

jorainer commented 4 years ago

Implementing this in Spectra might not be that easy if you're not familiar with the internals of the code. Could you eventually define what the function is supposed to do and I can try to implement it. What I mean is: given the precursor m/z, which m/z should we look for? what intensity should it have? what parameters do you need (I guess also tolerance and ppm).

michaelwitting commented 4 years ago

hasNeutralLoss would take a Spectra, then it needs to check if it is a MS2 and contains a precursorMz. A m/z value for a putative candidate for the neutral loss fragment is calculated by precursorMz - neutralLoss. Then it checks if the m/z values contain a fragment that matches precursorMz - neutralLoss within a given tolerance and ppm

Arguments for the function would be:

x A Spectra object neutralLoss A neutral loss mass, e.g. 18.010565 for a loss of H2O tolerance ppm

return would be TRUE or FALSE

jorainer commented 4 years ago

Has been added.