Spec2Annot

Spec2Annot is an R package which implement different ways to annotate and query mass spectra.

Installation

You can install the development version of Spec2Annot from GitHub with:

# install.packages("devtools")
# devtools::install_github("odisce/Spec2Annot")
install.packages("Spec2Annot", repos = c('https://odisce.r-universe.dev', 'https://cloud.r-project.org'))

Exemples

Basic functions

Spec2Annot has built-in tables containings useful informations on:

Those tables are used to search as chemical-knowledge to annotate ions, but the package contains a set of functions to calculate mass from strings, like:

Calculate mass:

Very fast mZ/rt search between two tables: Spec2Annot::search_db_cpp() this function written in C++ use a combination of sequential moving search range + a binary search algorithm implemented in std::lower/upper_bound.

## Exemple on simulated exemple data, normally the function is used to search between two different tables.
require(Spec2Annot)
search_db_cpp(
  in_db = spectra_full[, .(id = paste0("Database_", seq_len(.N)), mz, rt = rnorm(.N, 10, 10))],
  in_exp = spectra_full[sample(seq_len(.N), .N, replace = TRUE), .(id = paste0("Experimental_", seq_len(.N)), mz, rt = rnorm(.N, 10, 10))],
  ppmtol = 5,
  rttol = 5
)

Elemental composition finder

Spec2Annot contains also more advanced function like a combinatory-search algorithm in C++ to find any elemental composition from an exact mass. This algorithm can find common element but also any isotops or isotopologs. By default it will use the "seven golden rules" from Kind & Fiehn (2007) and the most common atomic element found in organic compounds, but any composition can be used.

Spec2Annot::find_compo_from_mass(
  mass_target = 120.25325,
  ppm = 5,
  use_golden_ratio = TRUE,
  elements_vc = NULL
)

For more advanced usage you can access the underlying function here: Spec2Annot::brute_force_const().

Spectra annotation

Spec2Annot contains a wrapper to calculate the elemental composition of a mass spectra by adding restriction of a known formula (useful with MS2 spectra of known precursor) or not. It will also add some chemical scores/metrics like the Double Bond Equivalent (DBE), Nitrogen rule (nrule) or Senior score (adapted from Morikawa and Newbold, 2003).

Spec2Annot::annotate_mz(
  input_spectrum = spectra_ms2,
  ppm = 3,
  polarity = 1,
  compo = "C10H12N5O6P1"
)