Skip to content

Commit

Permalink
Refactoring MS1 adducts (#141, #144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adafede committed Jul 2, 2024
1 parent 0bd0931 commit a5a7af8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Fix library/adducts confusion (#123)
* Fix some incorrect adduct differences annotations
* Refactored adducts / neutral losses / dimers annotation to allow for more flexibility (#141, #144)

# timaR 2.9.5

Expand Down
13 changes: 8 additions & 5 deletions R/annotate_masses.R
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ annotate_masses <-
# TODO dictionary of adducts (example 2H2O in mzmine)

df_addlossed_min <- df_addlossed |>
tidytable::distinct(mz_1, label) |>
tidytable::rowwise() |>
tidytable::mutate(mass = calculate_mass_from_adduct(adduct_string = label, mass = mz_1))
tidytable::mutate(mass = calculate_mass_from_adduct(adduct_string = label, mass = mz_1)) |>
tidytable::ungroup()

## Safety
df_addlossed_min_1 <- df_addlossed_min |>
Expand All @@ -453,8 +453,11 @@ annotate_masses <-

if (nrow(df_addlossed_min_2) != 0) {
message("Some adducts were unproperly detected, defaulting to (de)protonated")
# TODO
df_addlossed_min_2
df_addlossed_min_2 <- df_addlossed_min_2 |>
tidytable::mutate(label = switch(ms_mode, "pos" = "[M+H]+", "neg" = "[M-H]-")) |>
tidytable::rowwise() |>
tidytable::mutate(mass = calculate_mass_from_adduct(adduct_string = label, mass = mz_1)) |>
tidytable::ungroup()
}

df_addlossed_rdy <- df_addlossed_min_1 |>
Expand All @@ -463,7 +466,7 @@ annotate_masses <-
# TODO if same, say unrecognized and switch to M+H or M-H by default

log_debug("joining within given mz tol to exact mass library \n")
df_addlossed_em <- df_addlossed |>
df_addlossed_em <- df_addlossed_rdy |>
dplyr::inner_join(df_add_em,
by = dplyr::join_by(
mz_1 >= value_min,
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@
"SystemRequirements": null
},
"keywords": ["metaboliteannotation", "chemotaxonomy", "scoringsystem", "naturalproducts", "computationalmetabolomics", "taxonomicdistance", "specializedmetabolome"],
"fileSize": "4384.938KB",
"fileSize": "4385.035KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand Down
17 changes: 9 additions & 8 deletions tests/testthat/_snaps/shinytest2/001.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
"gnps_workflow": "fbmn",
"launch": 0,
"ms_add_neg": [
"[1M-(H)2]2-",
"[1M-(H)1]1-",
"[2M-(H)1]1-"
"[M-H2]2-",
"[M-H]-",
"[2M-H]-"
],
"ms_add_pos": [
"[1M+(H)2]2+",
"[1M+(H)1]1+",
"[1M+(H)4(N)1]1+",
"[1M+(Na)1]1+",
"[2M+(H)1]1+"
"[M+H2]2+",
"[M+H]+",
"[M+H4N]+",
"[M+Na]+",
"[2M+H]+"
],
"ms_clu_neg": [
"H2O",
Expand All @@ -74,6 +74,7 @@
"ms_tol_mas_ppm_ms1": 10,
"ms_tol_mas_ppm_ms2": 10,
"ms_tol_rt_min": 0.05,
"names_adduct": "best ion",
"names_extension": true,
"names_features": "row ID",
"names_filename": "filename",
Expand Down

0 comments on commit a5a7af8

Please sign in to comment.