ClavelLab / maldipickr

Dereplicate And Cherry-pick Mass Spectrometry Spectra
https://clavellab.github.io/maldipickr/
GNU General Public License v3.0
2 stars 0 forks source link

add function to gather spectra checks stats #45

Closed cpauvert closed 10 hours ago

cpauvert commented 4 months ago

Is your feature request related to a problem? Please describe. I'm always frustrated when I need to compute how many raw spectra were analyzed, how many valid, and why they were rejected.

Describe the solution you'd like This function below is an untested, undocumented attempt:

gather_spectra_stats <- function(check_vectors){
  # check_vectors from maldipickr::check_spectra
  # src: https://stackoverflow.com/a/51140480/21085566
  aggregated_checks <- Reduce(`|`, check_vectors)
  check_stats <- vapply(check_vectors, sum, FUN.VALUE = integer(1)) %>%
    tibble::as_tibble_row()
  tibble::tibble(
    "n_spectra" = length(aggregated_checks),
    "n_valid_spectra" = n_spectra - sum(aggregated_checks)
  ) %>%
    dplyr::bind_cols(check_stats) %>% 
    return()
}