Skip to content

Commit

Permalink
fix order-sensitive parsing of elemental counts from formula in CoreM…
Browse files Browse the repository at this point in the history
…S to peakData conversion
  • Loading branch information
clabornd committed Dec 4, 2024
1 parent d4c2b9a commit 334a055
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions R/coreMSDataToFtmsData.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ coreMSDataToFtmsData <- function(cmsObj) {
`Calibrated m/z` = mean(.data[[calib_mass]])) %>%
dplyr::select(Mass, .data[[formula]], `Calibrated m/z`, .data[[calc_mass]],
.data[[heteroatom]], .data[[ion_type]]) %>%
dplyr::distinct() %>%
tidyr::separate(col = .data[[formula]], into = element_cnames, sep = " ") %>%
dplyr::mutate_at(element_cnames, ~ as.integer(gsub("[^0-9]", "", .x))) %>%
dplyr::distinct()

counts_df = lapply(element_cnames, ftmsRanalysis:::atom_count_vectorizer, e_meta[[formula]]) %>% as.data.frame(col.names = element_cnames)

e_meta[element_cnames] <- counts_df

e_meta <- e_meta %>%
dplyr::select(Mass, all_of(element_cnames), `Calibrated m/z`, .data[[calc_mass]],
.data[[heteroatom]], .data[[ion_type]]) %>%
dplyr::arrange(Mass)
Expand Down

0 comments on commit 334a055

Please sign in to comment.