annotateMz: Annotate m/z values for ion adducts

Description Usage Arguments Value Author(s) Examples

Description

annotateMz annotates m/z values using either a data.frame containing compound definitions or a CompDb() and a user provided list of potential (expected) adducts. In detail, the function calculates for each input m/z value the masses of the potential ion adducts and compares these with (monoisotopic) masses provided in the reference annotation. A hit is returned if the mass difference is smaller than ppm.

For object being a numeric and compounds a data.frame or equivalend class, the function returns a list of subsets of compounds with rows matching the adducts' mass. If no match is found for the mass of any adducts, a row of compounds with all values set to NA is returned. Note that if compounds is [CompDb()], alistofdata.frame's is returned.s

Usage

1
2
3
4
5
6
7
8
## S4 method for signature 'numeric,DataFrameOrEquivalent'
annotateMz(object, compounds, adduct = adducts(), ppm = 10, ...)

## S4 method for signature 'DataFrameOrEquivalent,DataFrameOrEquivalent'
annotateMz(object, compounds, adduct = adducts(), ppm = 10, mzcol = "mz", ...)

## S4 method for signature 'numericOrDataFrameOrEquivalent,CompDb'
annotateMz(object, compounds, adduct = adducts(), ppm = 10, ...)

Arguments

object

either a numeric of m/z values or a data.frame (or equivalent) with a column containing the m/z values.

compounds

either a data.frame (or equivalent) or a CompDb() with the reference annotations. A column named "mass" is mandatory if compounds is a data.frame.

adduct

adduct definition. Either a data.frame as returned by adducts() or a character with the names of the adduct(s) in that data.frame.

ppm

numeric(1) defining the allowed mass difference in ppm.

...

additional parameters for the compounds call if compounds is a CompDb.

mzcol

for object being a data.frame: character(1) defining the column name in object containing the m/z values. Defaults to "mz".

Value

See description above for details.

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
22
23
24
25
26
27
28
29
## Read compound annotations from a package-internal SDF file containing
## a small subset of HMDB annotations
fl <- system.file("sdf/HMDB_sub.sdf.gz", package = "CompoundDb")
cmps <- compound_tbl_sdf(fl)
cmps

## Annotate provided m/z values assuming they represent mass-to-charge
## values for [M+H]+ adducts.
mzs <- c(105.0546, 75.09168, 127.0365, 113.04756, 113.1210)

res <- annotateMz(mzs, cmps, adduct = "[M+H]+")

## res is a `list` with the matching hits for each m/z and the specified
## adduct. If no match was found the result contains only `NA` values.
res

## Annotating using all adducts defined by `adducts()` and accepting a
## 20ppm difference between the masses
annotateMz(mzs, cmps, ppm = 20)

## It is also possible to annotate an input data.frame, in which case each
## input will be duplicated depending on the number of hits for each m/z
mzs_df <- data.frame(id = letters[1:5], mzmed = mzs)

res <- annotateMz(mzs_df, cmps, mzcol = "mzmed", adduct = "[M+H]+")
res

## Note that `compounds` could also be `CompDb` database, in which a search
## against the annotations provided in that database would be performed.

michaelwitting/CompoundDb documentation built on April 29, 2020, 8:42 p.m.