Provides a comprehensive suite of functions to efficiently annotate mass spectra data. Motivated by the need for rapid and accurate chemical identification in high-resolution mass spectrometry, it integrates built-in chemical databases and high-performance C++ algorithms. Users can perform mass-to-charge (m/Z) and retention time searches, determine elemental compositions of molecules using heuristic rules, including specific isotopes, and annotate MS2 spectra with structural metrics using configurable chemistry rules.

Spec2Annot is an R package which implement different ways to annotate and query mass spectra.
You can install the development version of Spec2Annot from GitHub with:
# install.packages("devtools")
devtools::install_github("odisce/Spec2Annot")
Spec2Annot has built-in tables containings useful informations on:
Spec2Annot::Adduct_dbSpec2Annot::Losses_dbSpec2Annot::Isotopes_dbSpec2Annot::db_monochargeSpec2Annot::ions_databaseSpec2Annot::ElementThose 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:
Spec2Annot::mz_from_string("C6H12O3")Spec2Annot::mz_from_string("C6H12O3-H2O+H")Spec2Annot::mz_from_string("[C6H2O3-H2O+H]+")Spec2Annot::mz_from_string("C6H12O3_13C2")Calculate mass:
Spec2Annot::mz_range(120.2532, ppm = 10)Spec2Annot::mz_ppm(120.2532, 120.2540)Spec2Annot::mz_calc_ion(120.2532, form = "-H")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
)
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().
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"
)