estimate_chemical_formula.Rd
Estimate chemical formula
estimate_chemical_formula(
query_mass,
isotope_summary,
penalization = "none",
penalization_multiplier = 0.001,
timeout = 10
)
amu of an unknown specie
isotopes that the unknown specie could be constructed with:
label
amu
count_lb (optional)
count_ub (optional)
prior_weight (optional)
If penalization = "prior", a variable named "prior" must be specified (larger weights are bad)".
the method of penalizing the optimization
none: minimize the absolute difference between predicted mass and "query_mass"
count: none + minimize sum of absolute atom counts
prior: none + minimize a weighted sum of absolute atom counts
multiplier for the penalization functions within the cost function
seconds until a timeout occurs
a list containing a summary of fit (absolute mass difference and penalization cost (if penalization != "none")) and isotope_summary with an added variable
library(dplyr)
probable_isotopes <- clamr::isotope_summaries %>%
dplyr::inner_join(
clamr::elemental_frequency_summary %>%
dplyr::filter(human_body > 0.0001) %>%
dplyr::select(element, human_body),
by = "element"
) %>%
dplyr::mutate(natural_freq = isotope_freq * human_body) %>%
dplyr::filter(natural_freq > 0.0001) %>%
dplyr::mutate(
count_lb = ifelse(element == "H", -8, -2),
count_lb = ifelse(element %in% c("C", "O"), -4, count_lb)
) %>%
dplyr::mutate(count_ub = -1 * count_lb) %>%
dplyr::rowwise() %>%
dplyr::mutate(label = paste0(element, "-", strsplit(as.character(amu), split = "\\.")[[1]][1])) %>%
dplyr::ungroup() %>%
dplyr::mutate(prior_weight = pmin(1 / 100 / natural_freq, 1))
query_mass <- -1.007825 + 13.003355 + 2 * 12
estimate_chemical_formula(query_mass, probable_isotopes, penalization = "count")
#> Error in loadNamespace(x): there is no package called ‘lpSolveAPI’