MetaboCoreUtils 1.0.0
Package: MetaboCoreUtils
Authors: Johannes Rainer [aut, cre] (https://orcid.org/0000-0002-6977-7147),
Michael Witting [aut] (https://orcid.org/0000-0002-1462-4426)
Last modified: 2021-05-19 15:26:15
Compiled: Wed May 19 18:03:58 2021
The MetaboCoreUtils
defines metabolomics-related core functionality provided
as low-level functions to allow a data structure-independent usage across
various R packages. This includes functions to calculate between ion (adduct)
and compound mass-to-charge ratios and masses or functions to work with chemical
formulas. The package provides also a set of adduct definitions and information
on some commercially available internal standard mixes commonly used in MS
experiments.
For a full list of function, see
library("MetaboCoreUtils")
ls(pos = "package:MetaboCoreUtils")
## [1] "addElements" "adductNames"
## [3] "adducts" "containsElements"
## [5] "countElements" "internalStandardMixNames"
## [7] "internalStandards" "mass2mz"
## [9] "mz2mass" "pasteElements"
## [11] "standardizeFormula" "subtractElements"
or the reference page on the package webpage.
The package can be installed with the BiocManager
package. To
install BiocManager
use install.packages("BiocManager")
and, after that,
BiocManager::install("MetaboCoreUtils")
to install this package.
The functions defined in this package utilise basic classes with the aim of being reused in packages that provide a more formal, high-level interface.
The examples below demonstrate the basic usage of the functions from the package.
library(MetaboCoreUtils)
The mass2mz
and mz2mass
functions allow to convert between compound masses
and ion (adduct) mass-to-charge ratios (m/z). The MetaboCoreUtils
package
provides definitions of common ion adducts generated by electrospray ionization
(ESI). These can be listed with the adductNames
function.
adductNames()
## [1] "[M+3H]3+" "[M+2H+Na]3+" "[M+H+Na2]3+"
## [4] "[M+Na3]3+" "[M+2H]2+" "[M+H+NH4]2+"
## [7] "[M+H+K]2+" "[M+H+Na]2+" "[M+C2H3N+2H]2+"
## [10] "[M+2Na]2+" "[M+C4H6N2+2H]2+" "[M+C6H9N3+2H]2+"
## [13] "[M+H]+" "[M+Li]+" "[M+2Li-H]+"
## [16] "[M+NH4]+" "[M+H2O+H]+" "[M+Na]+"
## [19] "[M+CH4O+H]+" "[M+K]+" "[M+C2H3N+H]+"
## [22] "[M+2Na-H]+" "[M+C3H8O+H]+" "[M+C2H3N+Na]+"
## [25] "[M+2K-H]+" "[M+C2H6OS+H]+" "[M+C4H6N2+H]+"
## [28] "[2M+H]+" "[2M+NH4]+" "[2M+Na]+"
## [31] "[2M+K]+" "[2M+C2H3N+H]+" "[2M+C2H3N+Na]+"
## [34] "[3M+H]+" "[M+H-NH3]+" "[M+H-H2O]+"
## [37] "[M+H-Hexose-H2O]+" "[M+H-H4O2]+" "[M+H-CH2O2]+"
With that we can use the mass2mz
function to calculate the m/z for a set of
compounds assuming the generation of certain ions. In the example below we
define masses for some theoretical compounds and calculate their expected m/z
assuming that ions "[M+H]+"
and "[M+Na]+"
are generated.
masses <- c(123, 842, 324)
mass2mz(masses, adduct = c("[M+H]+", "[M+Na]+"))
## [M+H]+ [M+Na]+
## [1,] 124.0073 145.9892
## [2,] 843.0073 864.9892
## [3,] 325.0073 346.9892
As a result we get a matrix
with each row representing one compound and each
column the m/z for one of the defined adducts. With the mz2mass
we could
perform the reverse calculation, i.e. from m/z to compound masses.
The lack of consistency in the format in which chemical formulas are written
poses a big problem comparing formulas coming from different resources. The
MetaboCoreUtils
package provides functions to standardize formulas as well
as combine formulas or substract elements from formulas. Below we use an
artificial example to show this functionality. First we standardize a chemical
formula with the standardizeFormula
function.
frml <- "Na3C4"
frml <- standardizeFormula(frml)
frml
## [1] "C4Na3"
Next we add "H2O"
to the formula using the addElements
function.
frml <- addElements(frml, "H2O")
frml
## [1] "C4H2ONa3"
We can also substract elements with the subtractElements
function:
frml <- subtractElements(frml, "H")
frml
## [1] "C4HONa3"
The counts for individual elements in a chemical formula can be calculated with
the countElements
function.
countElements(frml)
## C H O Na
## 4 1 1 3
If you would like to contribute any low-level functionality, please open a GitHub issue to discuss it. Please note that any contributions should follow the style guide and will require an appropriate unit test.
If you wish to reuse any functions in this package, please just go ahead. If you would like any advice or seek help, please either open a GitHub issue.
## R version 4.1.0 (2021-05-18)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.2 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.13-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.13-bioc/R/lib/libRlapack.so
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] MetaboCoreUtils_1.0.0 BiocStyle_2.20.0
##
## loaded via a namespace (and not attached):
## [1] bookdown_0.22 digest_0.6.27 R6_2.5.0
## [4] jsonlite_1.7.2 magrittr_2.0.1 evaluate_0.14
## [7] stringi_1.6.2 rlang_0.4.11 jquerylib_0.1.4
## [10] bslib_0.2.5.1 rmarkdown_2.8 tools_4.1.0
## [13] stringr_1.4.0 xfun_0.23 yaml_2.2.1
## [16] compiler_4.1.0 BiocManager_1.30.15 htmltools_0.5.1.1
## [19] knitr_1.33 sass_0.4.0