--- title: "Core Utils for Metabolomics Data" package: MetaboCoreUtils output: BiocStyle::html_document: toc_float: true vignette: > %\VignetteIndexEntry{Core Utils for Metabolomics Data} %\VignetteEngine{knitr::rmarkdown} %%\VignetteKeywords{Mass Spectrometry, MS, MSMS, Metabolomics, Infrastructure, Quantitative } %\VignetteEncoding{UTF-8} --- ```{r style, echo = FALSE, results = 'asis'} BiocStyle::markdown() ``` **Package**: `r BiocStyle::Biocpkg("MetaboCoreUtils")`
**Authors**: `r packageDescription("MetaboCoreUtils")[["Author"]] `
**Last modified:** `r file.info("MetaboCoreUtils.Rmd")$mtime`
**Compiled**: `r date()` # Introduction 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 ```{r, message = FALSE} library("MetaboCoreUtils") ls(pos = "package:MetaboCoreUtils") ``` or the [reference page](https://rformassspectrometry.github.io/MetaboCoreUtils/reference/index.html) on the package webpage. # Installation 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. # Examples 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. ```{r} library(MetaboCoreUtils) ``` ## Conversion between ion m/z and compound masses 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. ```{r} adductNames() ``` 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. ```{r} masses <- c(123, 842, 324) mass2mz(masses, adduct = c("[M+H]+", "[M+Na]+")) ``` 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. ## Working with chemical formulas 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. ```{r} frml <- "Na3C4" frml <- standardizeFormula(frml) frml ``` Next we add `"H2O"` to the formula using the `addElements` function. ```{r} frml <- addElements(frml, "H2O") frml ``` We can also substract elements with the `subtractElements` function: ```{r} frml <- subtractElements(frml, "H") frml ``` The counts for individual elements in a chemical formula can be calculated with the `countElements` function. ```{r} countElements(frml) ``` # Contributions If you would like to contribute any low-level functionality, please [open a GitHub issue](https://github.com/RforMassSpectrometry/MetaboCoreUtils/issues) to discuss it. Please note that any [contributions](https://rformassspectrometry.github.io/RforMassSpectrometry/articles/RforMassSpectrometry.html#contributions) should follow the [style guide](https://rformassspectrometry.github.io/RforMassSpectrometry/articles/RforMassSpectrometry.html#coding-style) 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](https://github.com/RforMassSpectrometry/MetaboCoreUtils/issues). # Session information {-} ```{r sessioninfo, echo=FALSE} sessionInfo() ```