jspaezp / sctree

Tree based marker finding and gating visualization for single cell rna seq data
Apache License 2.0
4 stars 1 forks source link

Duplicate legend in plot_gates output #15

Open thomasveith opened 2 years ago

thomasveith commented 2 years ago

I have a Seurat object, its active.ident is a factor with four levels. When I run DimPlot or plot_flowstyles the legend has my four cluster labels displayed correctly. However, when I run plot_gates I see two legends, one of which shows grey for every cluster.

tsneNCIN87.pdf upClosePanelG(2,3).pdf gatingNCIN87.pdf

Here is the code I'm running to produce the gate panels (where X is my Seurat object):

markers <- FindAllMarkers(
  X,
  warn.imp.method = FALSE, 
  test.use = "RangerDE")

 top_markers = markers$gene[1:6]

tree_fit <- fit_ctree(X,
                      genes_use = top_markers,
                      cluster = "ALL")

plot_gates(X, tree_fit, "6")

Any advice? Thanks in advance.

jspaezp commented 2 years ago

Hello @thomasveith, let me look into it a little bit, I have not able to reproduce it with a quick attempt. Would you mind providing your session info, im suspecting we have a different version of ggplot ? (output of sessionInfo())

thomasveith commented 2 years ago

Thanks for getting back to me. That is quite possible! Here is my session info.

> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] xlsx_0.6.5         sctree_0.0.8.0000  SeuratObject_4.0.2 Seurat_4.0.3      

loaded via a namespace (and not attached):
  [1] wrapr_2.0.9            sn_2.0.0               plyr_1.8.6             igraph_1.2.6          
  [5] lazyeval_0.2.2         splines_4.1.1          listenv_0.8.0          scattermore_0.7       
  [9] GenomeInfoDb_1.28.1    ggplot2_3.3.5          TH.data_1.0-10         digest_0.6.27         
 [13] htmltools_0.5.1.1      viridis_0.6.1          fansi_0.5.0            magrittr_2.0.1        
 [17] memoise_2.0.0          tensor_1.5             cluster_2.1.2          ROCR_1.0-11           
 [21] globals_0.14.0         Biostrings_2.60.2      matrixStats_0.60.0     sandwich_3.0-1        
 [25] spatstat.sparse_2.0-0  colorspace_2.0-2       rvest_1.0.1            blob_1.2.2            
 [29] ggrepel_0.9.1          rbibutils_2.2.3        dplyr_1.0.7            libcoin_1.0-9         
 [33] crayon_1.4.1           RCurl_1.98-1.4         jsonlite_1.7.2         spatstat.data_2.1-0   
 [37] survival_3.2-12        zoo_1.8-9              ape_5.5                glue_1.4.2            
 [41] polyclip_1.10-0        gtable_0.3.0           zlibbioc_1.38.0        XVector_0.32.0        
 [45] leiden_0.3.9           future.apply_1.8.1     BiocGenerics_0.38.0    abind_1.4-5           
 [49] scales_1.1.1           mvtnorm_1.1-2          DBI_1.1.1              GGally_2.1.2          
 [53] miniUI_0.1.1.1         Rcpp_1.0.7             isoband_0.2.5          metap_1.4             
 [57] plotrix_3.8-1          viridisLite_0.4.0      xtable_1.8-4           tmvnsim_1.0-2         
 [61] reticulate_1.24        spatstat.core_2.3-0    bit_4.0.4              Formula_1.2-4         
 [65] stats4_4.1.1           htmlwidgets_1.5.3      httr_1.4.2             RColorBrewer_1.1-2    
 [69] TFisher_0.2.0          ellipsis_0.3.2         ica_1.0-2              farver_2.1.0          
 [73] rJava_1.0-4            pkgconfig_2.0.3        reshape_0.8.8          uwot_0.1.10           
 [77] deldir_1.0-6           utf8_1.2.2             labeling_0.4.2         tidyselect_1.1.1      
 [81] rlang_0.4.11           reshape2_1.4.4         later_1.3.0            AnnotationDbi_1.54.1  
 [85] munsell_0.5.0          tools_4.1.1            cachem_1.0.5           generics_0.1.0        
 [89] RSQLite_2.2.7          ranger_0.13.1          mathjaxr_1.4-0         ggridges_0.5.3        
 [93] stringr_1.4.0          fastmap_1.1.0          goftest_1.2-2          bit64_4.0.5           
 [97] fitdistrplus_1.1-5     purrr_0.3.4            RANN_2.6.1             KEGGREST_1.32.0       
[101] pbapply_1.4-3          future_1.21.0          nlme_3.1-152           mime_0.11             
[105] xml2_1.3.2             compiler_4.1.1         rstudioapi_0.13        plotly_4.9.4.1        
[109] png_0.1-7              spatstat.utils_2.2-0   tibble_3.1.3           stringi_1.7.3         
[113] lattice_0.20-44        Matrix_1.3-4           multtest_2.48.0        vctrs_0.3.8           
[117] mutoss_0.1-12          pillar_1.6.2           lifecycle_1.0.0        spatstat.geom_2.4-0   
[121] Rdpack_2.1.2           lmtest_0.9-38          RcppAnnoy_0.0.19       data.table_1.14.0     
[125] cowplot_1.1.1          bitops_1.0-7           irlba_2.3.3            httpuv_1.6.1          
[129] patchwork_1.1.1        R6_2.5.0               promises_1.2.0.1       KernSmooth_2.23-20    
[133] gridExtra_2.3          IRanges_2.26.0         parallelly_1.27.0      codetools_0.2-18      
[137] MASS_7.3-54            assertthat_0.2.1       xlsxjars_0.6.1         withr_2.4.2           
[141] sctransform_0.3.2      mnormt_2.0.2           multcomp_1.4-17        S4Vectors_0.30.0      
[145] GenomeInfoDbData_1.2.6 mgcv_1.8-36            parallel_4.1.1         grid_4.1.1            
[149] rpart_4.1-15           tidyr_1.1.3            inum_1.0-4             Rtsne_0.15            
[153] pbdZMQ_0.3-5           partykit_1.2-15        numDeriv_2016.8-1.1    Biobase_2.52.0        
[157] shiny_1.6.0           
jspaezp commented 2 years ago

Hey @thomasveith !

Sorry for the late reply ... Nontheless I think I was able to figure out how to fix it ... Would you mind trying out the fix before I move it to the master branch ... You can install the patched version with the following command

remotes::install_github("jspaezp/sctree", ref="bugfix/multiple_fix_double_legend")
thomasveith commented 2 years ago

So I'm actually getting a different error now. It seems that, no matter what I choose I get an error like the following:

> plot_gates(X, tree_fit, "15")
Error in plot_gates(X, tree_fit, "15") : 
  15 is not a terminal node in the provided tree fit, try one of: 
7, 8, 9, 10, 11, 13, 14, 15
jspaezp commented 2 years ago

found the error ... I just screwed up on a logical expression to give a "better" error code ...

https://github.com/jspaezp/sctree/blob/739114b7f90da7182185e3afb271c2fbcbb4e822/R/print_tree_rules.R#L445

MB on not running the tests after adding that message ...

thomasveith commented 2 years ago

No worries. I really appreciate your help! Is there a new patched version I should install?

jspaezp commented 2 years ago

This guy should have the "updated" patch version, right now its a work in progress since I am also fixing several other issues caused by changes in the API of some dependencies.

remotes::install_github("jspaezp/sctree", ref="bugfix/multiple_fix_double_legend")
jspaezp commented 2 years ago

as it is right now, it is working with this example Rmd document https://gist.github.com/jspaezp/93cf300d4aaeb94c410edfefab9c8124