YuLab-SMU / ProjectYulab

:next_track_button: Small coding tasks that enable you to participate in our development
33 stars 3 forks source link

Re-implement `Seurat::DotPlot` #19

Closed GuangchuangYu closed 11 months ago

GuangchuangYu commented 11 months ago
DotPlot(pbmc, features = c("MS4A1", "GNLY", "CD3E", 
                           "CD14", "FCER1A", "FCGR3A", 
                           "LYZ", "PPBP", "CD8A"),
        group.by = 'seurat_clusters')

image

An equivalent implementation in ggsc is still missing and it would be nice to have one.

noriakis commented 11 months ago

Dear Prof. Yu,

Thank you for developing the ggsc package. I have been using the package and it is very useful. I would like to try to implement this feature in the name with something like sc_dot. If it is okay, may I make a pull request to the branch of the repository?

Sincerely,

Noriaki Sato

GuangchuangYu commented 11 months ago

@noriakis You are welcome to make a PR with your sc_dot implementation.

noriakis commented 11 months ago

@GuangchuangYu Thank you very much for your kind words. I will make a pull request when the implementation is ready.

GuangchuangYu commented 11 months ago

@noriakis I try to use sc_dot to visualize the spe object presented in https://yulab-smu.top/ggsc/visualizing-singlecellexperiment-or-spatialexperiment-objects.html and find it is not compatible. Can you figure it out?

noriakis commented 11 months ago

Dear Prof. Yu,

Thank you very much for your feedback. I have tested the codes below from the documentation, and in my environment the plot was shown as attached without errors. The sessionInfo() is attached below the codes. I may have missed something, but I would be grateful for your guidance.

Sincerely, Noriaki Sato

library(BiocParallel)
library(ggsc)
library(scater)
library(scran)
library(ggplot2)
library(STexampleData)

eh <- ExperimentHub()
myfiles <- query(eh, "STexampleData")
spe <- myfiles[["EH7538"]]
spe <- addPerCellQC(spe, subsets=list(Mito=grep("^MT-", rowData(spe)$gene_name)))
spe <- spe[, spe$in_tissue == 1]
clusters <- quickCluster(
    spe,
    BPPARAM = BiocParallel::MulticoreParam(workers=2),
    block.BPPARAM = BiocParallel::MulticoreParam(workers=2)
)

spe <- computeSumFactors(spe, clusters = clusters, BPPARAM = BiocParallel::MulticoreParam(workers=2))
spe <- logNormCounts(spe)

dec <- modelGeneVar(spe)

top.hvgs <- getTopHVGs(dec, prop=0.15)
spe <- runPCA(spe, subset_row=top.hvgs)

output <- getClusteredPCs(reducedDim(spe), BPPARAM = BiocParallel::MulticoreParam(workers=2))
npcs <- metadata(output)$chosen
reducedDim(spe, "PCAsub") <- reducedDim(spe, "PCA")[,1:npcs,drop=FALSE]

g <- buildSNNGraph(spe, use.dimred="PCAsub", BPPARAM = MulticoreParam(workers=2))
cluster <- igraph::cluster_walktrap(g)$membership
colLabels(spe) <- factor(cluster)
set.seed(123)
spe <- runTSNE(spe, dimred="PCAsub", BPPARAM = MulticoreParam(workers=2))

genes <- c('MOBP', 'PCP4', 'SNAP25', 'HBB', 'IGKC', 'NPY')
target.features <- rownames(spe)[match(genes, rowData(spe)$gene_name)]
sc_dot(spe, target.features, slot="logcounts")

test_sc_dot

sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /usr/local/package/r/4.3.0/lib64/R/lib/libRblas.so 
LAPACK: /usr/local/package/r/4.3.0/lib64/R/lib/libRlapack.so;  LAPACK version 3.11.0

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

time zone: Asia/Tokyo
tzcode source: system (glibc)

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

other attached packages:
 [1] STexampleData_1.8.0        
 [2] SpatialExperiment_1.10.0   
 [3] ExperimentHub_2.8.1        
 [4] AnnotationHub_3.8.0        
 [5] BiocFileCache_2.8.0        
 [6] dbplyr_2.3.3               
 [7] scran_1.28.2               
 [8] scater_1.28.0              
 [9] ggplot2_3.4.2              
[10] scuttle_1.10.3             
[11] SingleCellExperiment_1.22.0
[12] SummarizedExperiment_1.30.2
[13] Biobase_2.60.0             
[14] GenomicRanges_1.52.1       
[15] GenomeInfoDb_1.36.4        
[16] IRanges_2.34.1             
[17] S4Vectors_0.38.1           
[18] BiocGenerics_0.46.0        
[19] MatrixGenerics_1.12.3      
[20] matrixStats_1.0.0          
[21] ggsc_1.1.1.003             
[22] testthat_3.1.10            
[23] BiocParallel_1.34.2        

loaded via a namespace (and not attached):
  [1] fs_1.6.3                     
  [2] spatstat.sparse_3.0-3        
  [3] bitops_1.0-7                 
  [4] devtools_2.4.5               
  [5] httr_1.4.6                   
  [6] RColorBrewer_1.1-3           
  [7] profvis_0.3.8                
  [8] tools_4.3.0                  
  [9] sctransform_0.4.1            
 [10] utf8_1.2.3                   
 [11] R6_2.5.1                     
 [12] HDF5Array_1.28.1             
 [13] lazyeval_0.2.2               
 [14] uwot_0.1.16                  
 [15] rhdf5filters_1.12.1          
 [16] urlchecker_1.0.1             
 [17] withr_2.5.0                  
 [18] sp_2.1-1                     
 [19] prettyunits_1.1.1            
 [20] gridExtra_2.3                
 [21] progressr_0.14.0             
 [22] textshaping_0.3.6            
 [23] cli_3.6.1                    
 [24] spatstat.explore_3.2-5       
 [25] fastDummies_1.7.3            
 [26] labeling_0.4.2               
 [27] Seurat_5.0.1                 
 [28] spatstat.data_3.0-3          
 [29] ggridges_0.5.4               
 [30] pbapply_1.7-2                
 [31] systemfonts_1.0.4            
 [32] yulab.utils_0.1.0            
 [33] R.utils_2.12.3               
 [34] parallelly_1.36.0            
 [35] sessioninfo_1.2.2            
 [36] limma_3.56.2                 
 [37] rstudioapi_0.15.0            
 [38] RSQLite_2.3.3                
 [39] generics_0.1.3               
 [40] ica_1.0-3                    
 [41] spatstat.random_3.2-1        
 [42] dplyr_1.1.2                  
 [43] Matrix_1.6-3                 
 [44] ggbeeswarm_0.7.2             
 [45] fansi_1.0.4                  
 [46] abind_1.4-5                  
 [47] R.methodsS3_1.8.2            
 [48] lifecycle_1.0.3              
 [49] yaml_2.3.7                   
 [50] edgeR_3.42.4                 
 [51] rhdf5_2.44.0                 
 [52] Rtsne_0.16                   
 [53] grid_4.3.0                   
 [54] blob_1.2.4                   
 [55] promises_1.2.1               
 [56] dqrng_0.3.1                  
 [57] crayon_1.5.2                 
 [58] miniUI_0.1.1.1               
 [59] lattice_0.21-8               
 [60] beachmat_2.16.0              
 [61] cowplot_1.1.1                
 [62] KEGGREST_1.40.1              
 [63] magick_2.8.1                 
 [64] pillar_1.9.0                 
 [65] metapod_1.8.0                
 [66] rjson_0.2.21                 
 [67] future.apply_1.11.0          
 [68] codetools_0.2-19             
 [69] leiden_0.4.3.1               
 [70] glue_1.6.2                   
 [71] ggfun_0.1.3                  
 [72] data.table_1.14.8            
 [73] remotes_2.4.2.1              
 [74] vctrs_0.6.3                  
 [75] png_0.1-8                    
 [76] spam_2.10-0                  
 [77] gtable_0.3.3                 
 [78] cachem_1.0.8                 
 [79] DropletUtils_1.20.0          
 [80] S4Arrays_1.0.5               
 [81] mime_0.12                    
 [82] survival_3.5-5               
 [83] statmod_1.5.0                
 [84] bluster_1.10.0               
 [85] interactiveDisplayBase_1.38.0
 [86] ellipsis_0.3.2               
 [87] fitdistrplus_1.1-11          
 [88] ROCR_1.0-11                  
 [89] nlme_3.1-162                 
 [90] usethis_2.2.2                
 [91] bit64_4.0.5                  
 [92] filelock_1.0.2               
 [93] RcppAnnoy_0.0.21             
 [94] rprojroot_2.0.3              
 [95] irlba_2.3.5.1                
 [96] vipor_0.4.5                  
 [97] KernSmooth_2.23-20           
 [98] colorspace_2.1-0             
 [99] DBI_1.1.3                    
[100] tidyselect_1.2.0             
[101] processx_3.8.2               
[102] bit_4.0.5                    
[103] compiler_4.3.0               
[104] curl_5.0.1                   
[105] BiocNeighbors_1.18.0         
[106] desc_1.4.2                   
[107] DelayedArray_0.26.7          
[108] plotly_4.10.2                
[109] scales_1.2.1                 
[110] lmtest_0.9-40                
[111] callr_3.7.3                  
[112] rappdirs_0.3.3               
[113] stringr_1.5.0                
[114] digest_0.6.33                
[115] goftest_1.2-3                
[116] spatstat.utils_3.0-4         
[117] XVector_0.40.0               
[118] htmltools_0.5.6              
[119] pkgconfig_2.0.3              
[120] sparseMatrixStats_1.12.2     
[121] fastmap_1.1.1                
[122] rlang_1.1.1                  
[123] htmlwidgets_1.6.2            
[124] shiny_1.7.4.1                
[125] DelayedMatrixStats_1.22.6    
[126] farver_2.1.1                 
[127] zoo_1.8-12                   
[128] jsonlite_1.8.7               
[129] R.oo_1.25.0                  
[130] BiocSingular_1.16.0          
[131] RCurl_1.98-1.13              
[132] magrittr_2.0.3               
[133] GenomeInfoDbData_1.2.10      
[134] dotCall64_1.1-0              
[135] patchwork_1.1.3              
[136] Rhdf5lib_1.22.1              
[137] munsell_0.5.0                
[138] Rcpp_1.0.11                  
[139] viridis_0.6.4                
[140] reticulate_1.34.0            
[141] stringi_1.7.12               
[142] brio_1.1.3                   
[143] zlibbioc_1.46.0              
[144] MASS_7.3-58.4                
[145] plyr_1.8.9                   
[146] pkgbuild_1.4.2               
[147] parallel_4.3.0               
[148] listenv_0.9.0                
[149] ggrepel_0.9.4                
[150] deldir_2.0-2                 
[151] Biostrings_2.68.1            
[152] splines_4.3.0                
[153] tensor_1.5                   
[154] locfit_1.5-9.8               
[155] ps_1.7.5                     
[156] igraph_1.5.1                 
[157] spatstat.geom_3.2-7          
[158] RcppHNSW_0.5.0               
[159] reshape2_1.4.4               
[160] ScaledMatrix_1.8.1           
[161] pkgload_1.3.2.1              
[162] BiocVersion_3.17.1           
[163] SeuratObject_5.0.1           
[164] RcppParallel_5.1.7           
[165] BiocManager_1.30.22          
[166] httpuv_1.6.11                
[167] RANN_2.6.1                   
[168] tidyr_1.3.0                  
[169] purrr_1.0.2                  
[170] polyclip_1.10-6              
[171] future_1.33.0                
[172] scattermore_1.2              
[173] rsvd_1.0.5                   
[174] xtable_1.8-4                 
[175] RSpectra_0.16-1              
[176] tidydr_0.0.5                 
[177] later_1.3.1                  
[178] ragg_1.2.5                   
[179] viridisLite_0.4.2            
[180] tibble_3.2.1                 
[181] memoise_2.0.1                
[182] beeswarm_0.4.0               
[183] AnnotationDbi_1.64.1         
[184] cluster_2.1.4                
[185] globals_0.16.2