This function removes impossible metabolite annotations based on the chemical formula and detected adducts. It checks for impossible adducts such as multiple losses of water (e.g., `-H2O`, `-2H2O`) that cannot be supported by the molecular formula's hydrogen and oxygen content.

remove_impossible_annotations(match_result)

Arguments

match_result

A data frame containing matched metabolites, including the columns `Formula` and `Adduct`.

Value

A data frame with impossible annotations removed. The `Formula` column is dropped from the final output.

Details

The function analyzes the `Formula` and `Adduct` columns to identify impossible matches. For adducts that suggest a loss of water (e.g., `-H2O`, `-2H2O`), the function compares the number of hydrogens and oxygens in the molecular formula to see if the loss of water is feasible. If the molecular formula cannot support the loss, the annotation is removed.

Specifically, the function: * Extracts the number of hydrogens (`H`) and oxygens (`O`) from the molecular formula. * Calculates whether the number of hydrogens and oxygens can support the indicated loss of water in the adduct. * Removes annotations where the molecular formula has insufficient hydrogen or oxygen atoms for the adduct.

Examples

if (FALSE) { # \dontrun{
# Example data frame with matched metabolites
match_result <- data.frame(
  Formula = c("C6H12O6", "C5H10O5", "C7H14O7"),
  Adduct = c("(M-H2O)+", "(M-2H2O)+", "(M+H)+"),
  stringsAsFactors = FALSE
)

# Remove impossible annotations
cleaned_results <- remove_impossible_annotations(match_result)
print(cleaned_results)
} # }