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

binPeaks-functions

Align Peaks into discrete bins.


Description

This function looks for similar peaks (mass) across MassPeaks objects and equalizes their mass.

Usage

binPeaks(l, method=c("strict", "relaxed"), tolerance=0.002)

Arguments

l

list, list of MassPeaks objects.

method

bin creation rule. "strict" creates bins never containing two or more peaks of the sampe sample. "relaxed" allows multiple peaks of the same sample in one bin.

tolerance

double, maximal relative deviation of a peak position (mass) to be considered as identical. Must be multiplied by 10^-6 for ppm, e.g. use tolerance=5e-6 for 5 ppm.

Details

The algorithm is based on the following workflow:

  1. Put all mass in a sorted vector.

  2. Calculate differences between each neighbor.

  3. Divide the mass vector at the largest gap (largest difference) and form a left and a right bin.

  4. Rerun step 3 for the left and/or the right bin if they don't fulfill the following criteria:

    • All peaks in a bin are near to the mean (abs(mass-meanMass)/meanMass < tolerance).

    • method == "strict": The bin doesn't contain two or more peaks of the same sample.

method == "strict": The new peak positions (mass value) are the mean mass of a bin.
method == "relaxed": The new peak positions for the highest peaks of each sample in a bin are generated by the mean mass of this peaks. The lower peaks are not changed.

Value

Returns a list of mass adjusted MassPeaks objects.

Author(s)

Sebastian Gibb mail@sebastiangibb.de

See Also

Examples

## load package
library("MALDIquant")

## create two MassPeaks objects
p <- list(createMassPeaks(mass=seq(100, 500, 100), intensity=1:5),
          createMassPeaks(mass=c(seq(100.2, 300.2, 100), 395), intensity=1:4))

binnedPeaks <- binPeaks(p, tolerance=0.002)

## compare result
iM1 <- intensityMatrix(p)
iM2 <- intensityMatrix(binnedPeaks)

all(dim(iM1) == c(2, 9)) # TRUE
all(dim(iM2) == c(2, 6)) # TRUE

show(iM2)

## increase tolerance
binnedPeaks <- binPeaks(p, tolerance=0.1)

iM3 <- intensityMatrix(binnedPeaks)

all(dim(iM3) == c(2, 5)) # TRUE

show(iM3)

## differences between "strict" and "relaxed"
p <- c(createMassPeaks(mass=c(1, 1.01, 3), intensity=c(2, 1, 1)),
       createMassPeaks(mass=c(0.99, 3), intensity=rep(1, 2)),
       createMassPeaks(mass=c(1.02, 3), intensity=rep(1, 2)))

intensityMatrix(binPeaks(p, method="strict", tolerance=0.05))
intensityMatrix(binPeaks(p, method="relaxed", tolerance=0.05))

MALDIquant

Quantitative Analysis of Mass Spectrometry Data

v1.19.3
GPL (>= 3)
Authors
Sebastian Gibb [aut, cre] (<https://orcid.org/0000-0001-7406-4443>), Korbinian Strimmer [ths] (<https://orcid.org/0000-0001-7917-2056>)
Initial release
2019-05-12

We don't support your browser anymore

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