loadMSLibraryMoNAJSON: Load MS library data from MassBank of North America (MoNA)

View source: R/mslibrary-json.R

loadMSLibraryMoNAJSONR Documentation

Load MS library data from MassBank of North America (MoNA)

Description

This function loads, verifies and curates MS library data from MoNA.json’ files.

Usage

loadMSLibraryMoNAJSON(
  file,
  prefCalcChemProps = TRUE,
  neutralChemProps = FALSE,
  potAdducts = TRUE,
  potAdductsLib = TRUE,
  absMzDev = 0.002,
  calcSPLASH = TRUE
)

Arguments

file

A character string that specifies the file path to the JSON library.

prefCalcChemProps

If TRUE then calculated chemical properties such as the formula and InChIKey are preferred over what is already present in the MS library. For efficiency reasons it is recommended to set this to TRUE. See the ⁠Validating and calculating chemical properties⁠ section for more details.

neutralChemProps

If TRUE then the neutral form of the molecule is considered to calculate SMILES, formulae etc. Enabling this may improve feature matching when considering common adducts (e.g. [M+H]+, [M-H]-). See the ⁠Validating and calculating chemical properties⁠ section for more details.

potAdducts, potAdductsLib

If and how missing adducts (Precursor_type data) are guessed, potAdducts should be either:

  • FALSE: do not perform adduct guessing.

  • TRUE: guesses adducts based on a common set of known adducts (currently based on GenFormAdducts and MetFragAdducts). If potAdductsLib is TRUE then also any adducts specified in the library are used.

  • A list with adduct objects or character vector that can be converted with as.adduct. Only the specified adducts will be used for guessing missing values.

absMzDev

The maximum absolute m/z deviation when guessing missing adducts.

calcSPLASH

If set to TRUE then missing SPLASH values will be calculated (see below).

Details

This function uses an efficient C++ JSON loader to load MS library data. This function is called when calling loadMSLibrary with algorithm="json".

This function uses C++ with Rcpp and rapidjsonr to efficiently load and parse JSON files from MoNA. An advantage compared to loadMSLibraryMSP is that this function supports loading spectral annotations.

The record field names are converted to those used in ‘.msp’ files.

Value

The loaded data is returned in an MSLibrary object.

Automatic curation of library data

Several strategies are applied to automatically verify and improve library data. This is important, since library records may have inconsistent or erroneous data, which makes them unsuitable in automated workflows such as compounds annotation with generateCompoundsLibrary.

The loaded library data is post-treated as follows:

  • The DB# field is renamed to DB_ID to improve compatibility with R column names.

  • Synonyms (Synon fields) are merged together, mainly to save memory usage.

  • Inconsistently formatted NA data (e.g. "n/a", "N/A" or empty strings) are set to regular R NA values.

  • The case of record field names are made consistent.

  • The Formula and ExactMass fields are renamed to formula and neutralMass, respectively. This is for consistency with other data generated with patRoon.

  • character field data is trimmed from leading/trailing whitespace.

  • Mass data is verified to be properly numeric, and set to NA otherwise.

  • The format of formulae data is made consistent: ionic species (with or without square brackets) or converted to a regular formula format.

  • Chemical identifiers such as SMILES and formulae are verified and missing values are calculated if possible. See below for more details.

  • Shortened data in the Ion_mode field (P/N) is converted to the long format (POSITIVE/NEGATIVE).

  • Many different adduct flavors typically found as Precursor_type data are converted and normalized to the generic textual format used by patRoon (see as.adduct).

  • If potAdducts!=FALSE then missing or invalid adduct data in Precursor_type is guessed based on the difference between the neutral and ionic mass. If multiple adducts explain the mass difference the result is NA.

  • Missing ion m/z data (PrecursorMZ field) is calculated from adduct data, if possible.

  • Missing SPLASH data is calculated with the splashR package if calcSPLASH=TRUE.

Validating and calculating chemical properties

Chemical properties such as SMILES, InChIKey and formula in the MS library are automatically validated and calculated if missing/invalid.

The internal validation/calculation process performs the following steps:

  • Validation of SMILES, InChI, InChIKey and formula data (if present). Invalid entries will be set to NA.

  • If neutralChemProps=TRUE then chemical data (SMILES, formulae etc.) is neutralized by (de-)protonation (using the --neutralized option of OpenBabel). An additional column molNeutralized is added to mark those molecules that were neutralized. Note that neutralization requires either SMILES or InChI data to be available.

  • The SMILES and InChI data are used to calculate missing or invalid SMILES, InChI, InChIKey and formula data. If prefCalcChemProps=TRUE then existing InChIKey and formula data is overwritten by calculated values whenever possible.

  • The chemical formulae which were not calculated are verified and normalized. This process may be time consuming, and is potentially largely avoided by setting prefCalcChemProps=TRUE.

  • Neutral masses are calculated for missing values (prefCalcChemProps=FALSE) or whenever possible (prefCalcChemProps=TRUE).

Note that calculation of formulae for molecules that are isotopically labelled is currently only supported for deuterium (2H) elements.

This functionality relies heavily on OpenBabel, please make sure it is installed.

Source

Guessing adducts from neutral/ionic mass differences was inspired from MetFrag.

References

\insertRef

Wohlgemuth2016patRoon

\insertRefRuttkies2016patRoon

\addCitationsRcpp1

\addCitationsRcpp2

\addCitationsRcpp3

\insertRef

OBoyle2011patRoon

See Also

loadMSLibrary for more details and other algorithms.

The MSLibrary documentation for various methods to post-process the data and generateCompoundsLibrary for annotation of features with the library data.


rickhelmus/patRoon documentation built on Nov. 22, 2024, 3:11 p.m.