Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

refineCentroids

Refine Peak Centroids


Description

This function refines the centroided values of a peak by weighting the y values in the neighbourhood that belong most likely to the same peak.

Usage

refineCentroids(x, y, p, k = 2L, threshold = 0.33, descending = FALSE)

Arguments

x

numeric, i.e. m/z values.

y

numeric, i.e. intensity values.

p

integer, indices of identified peaks/local maxima.

k

integer(1), number of values left and right of the peak that should be considered in the weighted mean calculation.

threshold

double(1), proportion of the maximal peak intensity. Just values above are used for the weighted mean calclulation.

descending

logical, if TRUE just values between the nearest valleys around the peak centroids are used.

Details

For descending = FALSE the function looks for the k nearest neighbouring data points and use their x for weighted mean with their corresponding y values as weights for calculation of the new peak centroid. If k are chosen too large it could result in skewed peak centroids, see example below. If descending = TRUE is used the k should be general larger because it is trimmed automatically to the nearest valleys on both sides of the peak so the problem with skewed centroids is rare.

Author(s)

Sebastian Gibb, Johannes Rainer

See Also

Other extreme value functions: .peakRegionMask(), localMaxima(), valleys()

Examples

ints <- c(5, 8, 12, 7, 4, 9, 15, 16, 11, 8, 3, 2, 3, 9, 12, 14, 13, 8, 3)
mzs <- seq_along(ints)

plot(mzs, ints, type = "h")

pidx <- as.integer(c(3, 8, 16))
points(mzs[pidx], ints[pidx], pch = 16)

## Use the weighted average considering the adjacent mz
mzs1 <- refineCentroids(mzs, ints, pidx,
                        k = 2L, descending = FALSE, threshold = 0)
mzs2 <- refineCentroids(mzs, ints, pidx,
                        k = 5L, descending = FALSE, threshold = 0)
mzs3 <- refineCentroids(mzs, ints, pidx,
                        k = 5L, descending = TRUE, threshold = 0)
points(mzs1, ints[pidx], col = "red", type = "h")
## please recognize the artificial moved centroids of the first peak caused
## by a too large k, here
points(mzs2, ints[pidx], col = "blue", type = "h")
points(mzs3, ints[pidx], col = "green", type = "h")
legend("topright",
       legend = paste0("k = ", c(2, 5, 5),
                       ", descending =", c("FALSE", "FALSE", "TRUE")),
       col = c("red", "blue", "green"), lwd = 1)

MsCoreUtils

Core Utils for Mass Spectrometry Data

v1.2.0
Artistic-2.0
Authors
RforMassSpectrometry Package Maintainer [cre], Laurent Gatto [aut] (<https://orcid.org/0000-0002-1520-2268>), Johannes Rainer [aut] (<https://orcid.org/0000-0002-6977-7147>), Sebastian Gibb [aut] (<https://orcid.org/0000-0001-7406-4443>), Adriaan Sticker [ctb], Sigurdur Smarason [ctb], Thomas Naake [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.