knitr::opts_chunk$set(echo = TRUE)
library(PFCdetective)
options(digits = 8)

Introduction

This document demonstrates R functions that interact with the ChemCalc website. These include functions to convert molecular formulas into neutral and charged monoisotopic masses, and functions to fit elemental compositions to experimental and theoretical monoisotopic masses. Currently, there are six (6) functions for interacting with the ChemCalc website:

The add_proton() and subtract_proton() functions use H^+^ = 1.007277 u. In future work, other adducts (e.g., Na^+^) and odd electron molecular ions will be added.

The functions are saved in an R package called "PFCdetective", which will ultimately include additional functions to compare detected monoisotopic masses to lists of known perfluorinated compounds (PFCs), and to compute and group detected monoisotopic masses by their Kendrick mass defects (repeating unit = CF2).

Converting Molecular Formulas to Monoisotopic Masses

1 Molecular Formula to 1 Neutral Monoisotopic Mass

A molecular formula can be converted to its neutral monoisotopic mass using the get_neutral_monoisotopic() function.

formula <- "C8HF15O2"                  ## perfluorooctanoic acid (PFOA)
get_neutral_monoisotopic(formula)

In addition, the get_neutral_monoisotopic() function is robust to formatting differences.

formula <- "H1 O2 F15 C8"              ## PFOA in disarray
get_neutral_monoisotopic(formula)

1 Molecular Formula to 1 Protonated Monoisotopic Mass

The get_neutral_monoisotopic() and add_proton() functions can be combined to compute a protonated monoisotopic mass.

formula <- "C8HF15O2"                  ## PFOA
formula %>%
  get_neutral_monoisotopic() %>%
  add_proton()

1 Molecular Formula to 1 Deprotonated Monoisotopic Mass

To get a deprotonated monoisotopic mass, the get_neutral_monoisotopic() function can be combined, instead, with the subtract_proton() function.

formula <- "C8HF15O2"                  ## PFOA
formula %>%
  get_neutral_monoisotopic() %>%
  subtract_proton()

Multiple Molecular Formulas to Their Neutral Monoisotopic Masses

The multiple_get_neutral_monoisotopic() function can be used to generate a group of monoisotopic masses from their respective molecular formulas.

formulas <- c("C8HF15O2",              ##  PFOA
              "C9H7F9O2",
              "C13H7F17O2")
multiple_get_neutral_monoisotopic(formulas)

Multiple Molecular Formulas to Their Protonated Monoisotopic Masses

The multiple_get_neutral_monoisotopic() and add_proton() functions can be combined to compute the protonated monoisotopic masses of a group of molecular formulas.

formulas <- c("C8HF15O2",              ## PFOA
              "C9H7F9O2",
              "C13H7F17O2")
formulas %>%
  multiple_get_neutral_monoisotopic() %>%
  add_proton()

Multiple Molecular Formulas to Their Deprotonated Monoisotopic Masses

In a similar way, the multiple_get_neutral_monoisotopic() and subtract_proton() functions can be combined to compute the deprotonated monoisotopic mass of a group of molecular formulas.

formulas <- c("C8HF15O2",              ## PFOA
              "C9H7F9O2",
              "C13H7F17O2")
formulas %>%
  multiple_get_neutral_monoisotopic() %>%
  subtract_proton()

Converting Monoisotopic Masses to Molecular Formulas

Fitting Elemental Compositions to 1 Neutral Monoisotopic Mass

A neutral experimental monoisotopic mass can be used to generate a group of possible elemental compositions using the get_neutral_formulas() function.

neutral_mass <- 413.9735               ## PFOA with small error
get_neutral_formulas(neutral_mass)

The get_neutral_formulas() function also allows users to specify the number of elemental compositions to return with the "num_formulas" parameter (default = 10), and to specify the expected range of elemental compositions with the "mfRange" parameter (default = "C3-50 H0-100 O0-10 F2-30"). In the following example, more restrictive limits on both the number of elemental compositions (num_formulas = 5) and the expected range of elemental compositions (mfRange = "C3-10 H0-20 O0-5 F2-30") influence the elemental compositions that are returned.

neutral_mass <- 413.9735               ## PFOA with small error
get_neutral_formulas(neutral_mass, num_formulas = 5, mfRange = "C3-15 H0-20 O0-5 F2-30")

Fitting Elemental Compositions to 1 Protonated Monoisotopic Mass

A protonated monoisotopic mass (e.g., a m/z value detected by ESI+ high resolution mass spectrometery) can be used to generate a series of possible elemental compositions by using the subtract_proton() and get_neutral_formulas() functions together.

mz <- 414.9808                         ## protonated PFOA with small error
mz %>% 
  subtract_proton() %>% 
  get_neutral_formulas(num_formulas = 5, mfRange = "C3-15 H0-20 O0-5 F2-30")

Fitting Elemental Compositions to 1 Deprotonated Monoisotopic Mass

A deprotonated monoisotopic mass (e.g., a m/z value detected by ESI- high resolution mass spectrometery) can be used to generate a series of possible elemental compositions by using the add_proton() and get_neutral_formulas() functions together.

mz <- 412.9664                         ## deprotonated PFOA with small error
mz %>% 
  add_proton() %>% 
  get_neutral_formulas(num_formulas = 5, mfRange = "C3-15 H0-20 O0-5 F2-30")

Fitting Elemental Compositions to Multiple Neutral Monoisotopic Masses

The multiple_get_neutral_formulas function uses the get_neutral_formulas function (described above) to convert a group of neutral monoisotopic masses to a list of their respective elemental compositions, where each list element is named by the associated monoisotopic mass. Each list element can be displayed or accessed for any other purpose using its name.

neutral_masses <- c(413.9735,          ## deprotonated C8HF15O2 (PFOA) with small error
                    318.0301,          ## deprotonated C9H7F9O2 with small error
                    518.0175)          ## deprotonated C13H7F17O2 with small error 
neutral_mass_list <- multiple_get_neutral_formulas(neutral_masses, num_formulas = 5, mfRange = "C3-15 H0-20 O0-5 F2-30")
neutral_mass_list[["413.9735"]]
neutral_mass_list[["318.0301"]]
neutral_mass_list[["518.0175"]]

Fitting Elemental Compositions to Multiple Protonated Monoisotopic Masses

A group of protonoted monoisotopic masses can be used to generate a list of their respective elemental compositions by using the subtract_proton() and multiple_get_neutral_formulas() functions together.

mzs <- c(414.9808,                     ## protonated C8HF15O2 (PFOA) with small error
         319.0374,                     ## protonated C9H7F9O2 with small error
         519.0248)                     ## protonated C13H7F17O2 with small error 
protonated_mass_list <- mzs %>%
  purrr::map(subtract_proton) %>%
  multiple_get_neutral_formulas(num_formulas = 5, mfRange = "C3-15 H0-20 O0-5 F2-30")
protonated_mass_list[1]

The list is named by the computed neutral monoisotopic masses, but the list elements can be renamed and displayed or accessed instead with the original protonated mzs.

names(protonated_mass_list) <- mzs
protonated_mass_list["414.9808"]

Fitting Elemental Compositions to Multiple Deprotonated Monoisotopic Masses

Similarly, a group of deprotonoted monoisotopic masses can be used to generate a list of their respective elemental compositions by using the add_proton() and multiple_get_neutral_formulas() functions together.

mzs <- c(412.9662,                     ## protonated C8HF15O2 (PFOA) with small error
         317.0228,                     ## protonated C9H7F9O2 with small error
         517.0102)                     ## protonated C13H7F17O2 with small error 
deprotonated_mass_list <- mzs %>%
  purrr::map(add_proton) %>%
  multiple_get_neutral_formulas(num_formulas = 5, mfRange = "C3-15 H0-20 O0-5 F2-30")
names(deprotonated_mass_list) <- mzs
deprotonated_mass_list[["412.9662"]]


robertyoung3/PFCdetective documentation built on June 5, 2020, 2:37 p.m.