MangiolaLaboratory / sccomp

Testing differences in cell type proportions from single-cell data.
https://stemangiola.github.io/sccomp/
GNU General Public License v3.0
94 stars 7 forks source link

Column named "count" silently used when running in proportions mode #146

Open william-hutchison opened 5 months ago

william-hutchison commented 5 months ago

Running sccomp with cell type proportions silently uses a column named "count" from the input data.

The following code constructs a model using cell type proportion values. The column "count" is included incidentally and is not supplied to the function. This code runs correctly.

library(dplyr)
library(tidyr)
library(sccomp)
data("seurat_obj")
data("sce_obj")
data("counts_obj")

counts_obj = 
  counts_obj |>
  mutate(count = count+1) |> 
  with_groups(sample, ~ .x |> mutate(proportion = count/sum(count)))

set.seed(1)
counts_obj_results_with_count <- 
    counts_obj |>
    sccomp_estimate(
        formula_composition = ~ type , 
        .sample = sample,  
        .cell_group = cell_group, 
        .count = proportion
    )

counts_obj_results_without_count |>
    sccomp_test() |>
    sccomp_boxplot(factor = "type")

When "count" is removed, sccomp_estimate runs but some downstream analysis functions do not.

counts_obj <-
    counts_obj |>
    select(- count)

set.seed(1)
counts_obj_results_without_count <- 
    counts_obj |>
    sccomp_estimate(
        formula_composition = ~ type , 
        .sample = sample,  
        .cell_group = cell_group, 
        .count = proportion
    )

counts_obj_results_without_count |>
    sccomp_test() |>
    sccomp_boxplot(factor = "type")

Here, sccomp_boxplot produces the error:

Error in `select()`:
! Can't select columns that don't exist.
✖ Column `count` doesn't exist.

The "count" column also appears to be used for some calculations. In boxplots, the blue outline is flattened if count is set to all equal 0.

> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /stornext/Home/data/allstaff/h/hutchison.w/Environments/micromamba/lib/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Australia/Melbourne
tzcode source: system (glibc)

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] gpg_1.2.9                       sccomp_1.7.15                  
 [3] tidySummarizedExperiment_1.12.0 ttservice_0.4.0                
 [5] SummarizedExperiment_1.32.0     Biobase_2.62.0                 
 [7] GenomicRanges_1.54.1            GenomeInfoDb_1.38.8            
 [9] IRanges_2.36.0                  S4Vectors_0.40.2               
[11] BiocGenerics_0.48.1             MatrixGenerics_1.14.0          
[13] matrixStats_1.3.0               qs_0.26.1                      
[15] lubridate_1.9.3                 forcats_1.0.0                  
[17] stringr_1.5.1                   dplyr_1.1.4                    
[19] purrr_1.0.2                     readr_2.1.5                    
[21] tidyr_1.3.1                     tibble_3.2.1                   
[23] ggplot2_3.5.1                   tidyverse_2.0.0                

loaded via a namespace (and not attached):
 [1] bitops_1.0-7                gridExtra_2.3              
 [3] inline_0.3.19               rlang_1.1.3                
 [5] magrittr_2.0.3              compiler_4.3.3             
 [7] loo_2.7.0                   systemfonts_1.0.6          
 [9] vctrs_0.6.5                 pkgconfig_2.0.3            
[11] crayon_1.5.2                fastmap_1.2.0              
[13] XVector_0.42.0              ellipsis_0.3.2             
[15] labeling_0.4.3              utf8_1.2.4                 
[17] tzdb_0.4.0                  ragg_1.3.0                 
[19] bit_4.0.5                   zlibbioc_1.48.2            
[21] jsonlite_1.8.8              DelayedArray_0.28.0        
[23] parallel_4.3.3              R6_2.5.1                   
[25] stringi_1.8.4               StanHeaders_2.32.6         
[27] parallelly_1.37.1           boot_1.3-30                
[29] Rcpp_1.0.12                 rstan_2.32.6               
[31] future.apply_1.11.2         Matrix_1.6-5               
[33] timechange_0.3.0            tidyselect_1.2.1           
[35] abind_1.4-5                 stringfish_0.16.0          
[37] codetools_0.2-20            listenv_0.9.1              
[39] pkgbuild_1.4.4              lattice_0.22-6             
[41] withr_3.0.0                 future_1.33.2              
[43] RcppParallel_5.1.7          pillar_1.9.0               
[45] plotly_4.10.4               generics_0.1.3             
[47] vroom_1.6.5                 sp_2.1-3                   
[49] RCurl_1.98-1.14             hms_1.1.3                  
[51] rstantools_2.4.0            munsell_0.5.1              
[53] scales_1.3.0                RApiSerialize_0.1.2        
[55] globals_0.16.3              glue_1.7.0                 
[57] lazyeval_0.2.2              tools_4.3.3                
[59] data.table_1.15.4           dotCall64_1.1-1            
[61] grid_4.3.3                  QuickJSR_1.1.3             
[63] colorspace_2.1-0            SingleCellExperiment_1.24.0
[65] GenomeInfoDbData_1.2.11     patchwork_1.2.0            
[67] cli_3.6.2                   textshaping_0.3.7          
[69] spam_2.10-0                 fansi_1.0.6                
[71] S4Arrays_1.2.1              viridisLite_0.4.2          
[73] gtable_0.3.5                digest_0.6.35              
[75] progressr_0.14.0            SparseArray_1.2.4          
[77] ggrepel_0.9.5               farver_2.1.2               
[79] htmlwidgets_1.6.4           SeuratObject_5.0.1         
[81] htmltools_0.5.8.1           lifecycle_1.0.4            
[83] httr_1.4.7                  bit64_4.0.5  
stemangiola commented 4 months ago

Thanks for spotting this out, would you ming creating a pull request to fix this? And be part of the sccomp family ;)