joinPeaks: Join (map) peaks of two spectra

Description Usage Arguments Value Implementation notes Author(s) Examples

View source: R/peaks-functions.R

Description

These functions map peaks from two spectra with each other if the difference between their m/z values is smaller than defined with parameters tolerance and ppm. All functions take two matrices

Usage

1
joinPeaks(x, y, type = "outer", tolerance = 0, ppm = 10, ...)

Arguments

x

matrix with two columns "mz" and "intensity" containing the m/z and intensity values of the mass peaks of a spectrum.

y

matrix with two columns "mz" and "intensity" containing the m/z and intensity values of the mass peaks of a spectrum.

type

For joinPeaks: character(1) specifying the type of join that should be performed. See function description for details.

tolerance

numeric(1) defining a constant maximal accepted difference between m/z values of peaks from the two spectra to be matched/mapped.

ppm

numeric(1) defining a relative, m/z-dependent, maximal accepted difference between m/z values of peaks from the two spectra to be matched/mapped.

...

option parameters.

Value

All functions return a list of elements "x" and "y" each being a two column matrix with m/z (first column) and intensity values (second column). The two matrices contain the matched peaks between input matrices x and y and hence have the same number of rows. Peaks present in x but not in the y input matrix have m/z and intensity values of NA in the result matrix for y (and vice versa).

Implementation notes

A mapping function must take two numeric matrices x and y as input and must return list with two elements named "x" and "y" that represent the aligned input matrices. The function should also have ... in its definition. Parameters ppm and tolerance are suggested but not required.

Author(s)

Johannes Rainer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
x <- cbind(c(31.34, 50.14, 60.3, 120.9, 230, 514.13, 874.1),
    1:7)
y <- cbind(c(12, 31.35, 70.3, 120.9 + ppm(120.9, 5),
    230 + ppm(230, 10), 315, 514.14, 901, 1202),
    1:9)

## No peaks with identical m/z
joinPeaks(x, y, ppm = 0, type = "inner")

## With ppm 10 two peaks are overlapping
joinPeaks(x, y, ppm = 10, type = "inner")

## Outer join: contain all peaks from x and y
joinPeaks(x, y, ppm = 10, type = "outer")

## Left join: keep all peaks from x and those from y that match
joinPeaks(x, y, ppm = 10, type = "left")

## Right join: keep all peaks from y and those from x that match. Using
## a constant tolerance of 0.01
joinPeaks(x, y, tolerance = 0.01, type = "right")

Spectra documentation built on Nov. 27, 2020, 2 a.m.