rformassspectrometry / MetaboCoreUtils

Core utilities for metabolomics.
https://rformassspectrometry.github.io/MetaboCoreUtils/index.html
8 stars 6 forks source link

isotope detection #10

Closed jorainer closed 1 year ago

jorainer commented 4 years ago

Add a function to detect isotopes based on a numeric with m/z values and one with the related intensities. This could be implemented as a two-step function:

1) group peaks in m/z vector based on differences. 2) evaluate (filter) the peak groups checking if the intensities correspond to the expected relationships.

Alternatively, we could make a function similar to the OpenMS FeatureFinderMetabo that does everything in one go.

sgibb commented 4 years ago

A long time ago I needed a detection of the monoisotopic peak for MALDI data. Maybe you can recycle some of the code from https://github.com/sgibb/MALDIquant/blob/master/R/monoisotopic-functions.R

jorainer commented 4 years ago

Thanks @sgibb . Looks helpful - do you have also an example showing how these can be used?

jorainer commented 4 years ago

Note: to find potential isotope groups in a numeric of m/z values we could simply use the closest function (if we have the m/z of the main ion):

library(MsCoreUtils)
mzs <- c(123, 123.5, 124.03, 124.3, 125.04, 202)
mzs <- mzs + rnorm(length(mzs), 0, 0.001)
mz_ion <- 123

closest(mz_ion + c(0, 1.03, 2* 1.03), mzs, tolerance = 0.01, ppm = 20)
[1]  1  3 NA

closest(mz_ion + c(0, 1.03, 2* 1.03), mzs, tolerance = 0.01, ppm = 100)
[1] 1 3 5
sgibb commented 4 years ago

Thanks @sgibb . Looks helpful - do you have also an example showing how these can be used?

Unfortunately just a toy example in the manual: https://rdrr.io/cran/MALDIquant/man/monoisotopicPeaks-methods.html and an outdated example in an old manuscript with real data: https://github.com/sgibb/Culicoides/blob/master/analysis.R#L162-L164

Note: to find potential isotope groups in a numeric of m/z values we could simply use the closest function (if we have the m/z of the main ion):

That's exactly what monoisotopicis doing. It is using MALDIquant::match.closest (the predecessor of MsCoreUtils::closest) to find clusters of correct differences in mz values. The intensities of these potential isotopic patterns are matched against a poisson distribution as described in https://doi.org/10.1002/1522-2683(20000601)21:11%3C2243::AID-ELPS2243%3E3.0.CO;2-K

jorainer commented 3 years ago

Isotope detection function was added with PR https://github.com/rformassspectrometry/MetaboCoreUtils/pull/38 (thanks @andreavicini !) - this might need to be tuned/improved based on real-life examples and tests.