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

silent fail when metadata did not merge with cluster_df in the picking function #6

Closed cpauvert closed 1 year ago

cpauvert commented 1 year ago

from the example of the picking function:

clusters <- readRDS(system.file("clusters_tibble.RDS", package = "maldipickr"))
# Simulate OD600 values with uniform distribution
#  for each of the colonies we measured with
#  the Bruker MALDI Biotyper
set.seed(104)
metadata <- dplyr::transmute(clusters, name = name, OD600 = runif(n = nrow(clusters)))

# Pick the spectra based on the highest OD600 value per cluster
pick_spectra(clusters, metadata, "OD600")

gives correctly:

# A tibble: 6 × 8
  name         membership cluster_size   SNR peaks is_reference OD600 to_pick
  <chr>             <int>        <int> <dbl> <dbl> <lgl>        <dbl> <lgl>  
1 species1_G2           1            4  5.09    21 FALSE        0.364 FALSE  
2 species2_E11          2            2  5.54    22 FALSE        0.772 TRUE   
3 species2_E12          2            2  5.63    23 TRUE         0.735 FALSE  
4 species3_F7           1            4  4.89    26 FALSE        0.973 TRUE   
5 species3_F8           1            4  5.56    25 TRUE         0.740 FALSE  
6 species3_F9           1            4  5.40    25 FALSE        0.201 FALSE 

However, when the provided metadata cannot be merged,there is no warning but NA in the column:

altered_metadata <- dplyr::mutate(metadata, name = gsub("species","",name))
pick_spectra(clusters, altered_metadata, "OD600")
# A tibble: 6 × 8
  name         membership cluster_size   SNR peaks is_reference OD600 to_pick
  <chr>             <int>        <int> <dbl> <dbl> <lgl>        <dbl> <lgl>  
1 species1_G2           1            4  5.09    21 FALSE           NA TRUE   
2 species2_E11          2            2  5.54    22 FALSE           NA TRUE   
3 species2_E12          2            2  5.63    23 TRUE            NA FALSE  
4 species3_F7           1            4  4.89    26 FALSE           NA FALSE  
5 species3_F8           1            4  5.56    25 TRUE            NA FALSE  
6 species3_F9           1            4  5.40    25 FALSE           NA FALSE