Skip to contents

Introduction

The data in this vignette is shipped with the cellatlas repository. The count matrix and metadata are provided in the cellatlas/examples folder as an AnnData object. We will begin by loading the object and converting it to a SingleCellExperiment object.

if (!file.exists("10x_nuclei.rds"))
    download.file("https://github.com/pachterlab/voyager/raw/documentation-devel/vignettes/10x_nuclei.rds", destfile = "10x_nuclei.rds")
sce <- readRDS("10x_nuclei.rds")
is_mito <- str_detect(rowData(sce)$gene_name, regex("^mt-", ignore_case=TRUE))
sum(is_mito)
#> [1] 37
sce <- addPerCellQCMetrics(sce, subsets = list(mito = is_mito))
names(colData(sce))
#> [1] "sum"                   "detected"              "subsets_mito_sum"     
#> [4] "subsets_mito_detected" "subsets_mito_percent"  "total"
plotColData(sce, "sum") +
    plotColData(sce, "detected") +
    plotColData(sce, "subsets_mito_percent")
#> Warning: Removed 2931 rows containing non-finite outside the scale range
#> (`stat_ydensity()`).
#> Warning: Removed 2931 rows containing missing values or values outside the scale range
#> (`position_quasirandom()`).

plotColData(sce, x = "sum", y = "detected", bins = 100) +
    scale_fill_distiller(palette = "Blues", direction = 1)
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.

plotColData(sce, x = "sum", y = "subsets_mito_detected", bins = 100) +
    scale_fill_distiller(palette = "Blues", direction = 1)
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.

sce <- sce[, which(sce$subsets_mito_percent < 20)]
sce <- sce[rowSums(counts(sce)) > 0,]

sce
#> class: SingleCellExperiment 
#> dim: 5260 9091 
#> metadata(0):
#> assays(1): counts
#> rownames(5260): ENSG00000142611.17 ENSG00000142655.13 ...
#>   ENSG00000225685.2 ENSG00000291031.1
#> rowData names(2): gene_name subsets_mito
#> colnames(9091): AAACCCAAGACCATAA AAACCCAAGGTTTGAA ... TTTGTTGTCATCTGTT
#>   TTTGTTGTCCTCCACA
#> colData names(6): sum detected ... subsets_mito_percent total
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
sessionInfo()
#> R version 4.4.2 (2024-10-31)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 22.04.5 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> time zone: UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] Voyager_1.8.1                  scater_1.34.0                 
#>  [3] ggplot2_3.5.1                  scuttle_1.16.0                
#>  [5] SpatialFeatureExperiment_1.9.4 SpatialExperiment_1.16.0      
#>  [7] SingleCellExperiment_1.28.1    SummarizedExperiment_1.36.0   
#>  [9] Biobase_2.66.0                 GenomicRanges_1.58.0          
#> [11] GenomeInfoDb_1.42.0            IRanges_2.40.0                
#> [13] S4Vectors_0.44.0               BiocGenerics_0.52.0           
#> [15] MatrixGenerics_1.18.0          matrixStats_1.4.1             
#> [17] Matrix_1.7-1                   stringr_1.5.1                 
#> 
#> loaded via a namespace (and not attached):
#>   [1] RColorBrewer_1.1-3        jsonlite_1.8.9           
#>   [3] wk_0.9.4                  magrittr_2.0.3           
#>   [5] ggbeeswarm_0.7.2          TH.data_1.1-2            
#>   [7] magick_2.8.5              farver_2.1.2             
#>   [9] rmarkdown_2.29            fs_1.6.5                 
#>  [11] zlibbioc_1.52.0           ragg_1.3.3               
#>  [13] vctrs_0.6.5               spdep_1.3-6              
#>  [15] DelayedMatrixStats_1.28.0 RCurl_1.98-1.16          
#>  [17] terra_1.7-83              htmltools_0.5.8.1        
#>  [19] S4Arrays_1.6.0            BiocNeighbors_2.0.0      
#>  [21] Rhdf5lib_1.28.0           s2_1.1.7                 
#>  [23] SparseArray_1.6.0         rhdf5_2.50.0             
#>  [25] LearnBayes_2.15.1         sass_0.4.9               
#>  [27] spData_2.3.3              KernSmooth_2.23-24       
#>  [29] bslib_0.8.0               htmlwidgets_1.6.4        
#>  [31] desc_1.4.3                sandwich_3.1-1           
#>  [33] zoo_1.8-12                cachem_1.1.0             
#>  [35] igraph_2.1.1              lifecycle_1.0.4          
#>  [37] pkgconfig_2.0.3           rsvd_1.0.5               
#>  [39] R6_2.5.1                  fastmap_1.2.0            
#>  [41] GenomeInfoDbData_1.2.13   digest_0.6.37            
#>  [43] ggnewscale_0.5.0          colorspace_2.1-1         
#>  [45] patchwork_1.3.0           RSpectra_0.16-2          
#>  [47] irlba_2.3.5.1             dqrng_0.4.1              
#>  [49] textshaping_0.4.0         beachmat_2.22.0          
#>  [51] labeling_0.4.3            fansi_1.0.6              
#>  [53] spatialreg_1.3-5          httr_1.4.7               
#>  [55] abind_1.4-8               compiler_4.4.2           
#>  [57] proxy_0.4-27              withr_3.0.2              
#>  [59] tiff_0.1-12               BiocParallel_1.40.0      
#>  [61] viridis_0.6.5             DBI_1.2.3                
#>  [63] HDF5Array_1.34.0          R.utils_2.12.3           
#>  [65] MASS_7.3-61               DelayedArray_0.32.0      
#>  [67] bluster_1.16.0            rjson_0.2.23             
#>  [69] classInt_0.4-10           tools_4.4.2              
#>  [71] units_0.8-5               vipor_0.4.7              
#>  [73] beeswarm_0.4.0            R.oo_1.27.0              
#>  [75] glue_1.8.0                nlme_3.1-166             
#>  [77] EBImage_4.48.0            rhdf5filters_1.18.0      
#>  [79] grid_4.4.2                sf_1.0-19                
#>  [81] cluster_2.1.6             memuse_4.2-3             
#>  [83] generics_0.1.3            gtable_0.3.6             
#>  [85] R.methodsS3_1.8.2         class_7.3-22             
#>  [87] data.table_1.16.2         ScaledMatrix_1.14.0      
#>  [89] BiocSingular_1.22.0       sp_2.1-4                 
#>  [91] utf8_1.2.4                XVector_0.46.0           
#>  [93] ggrepel_0.9.6             pillar_1.9.0             
#>  [95] limma_3.62.1              splines_4.4.2            
#>  [97] dplyr_1.1.4               lattice_0.22-6           
#>  [99] survival_3.7-0            deldir_2.0-4             
#> [101] tidyselect_1.2.1          locfit_1.5-9.10          
#> [103] sfheaders_0.4.4           knitr_1.49               
#> [105] gridExtra_2.3             edgeR_4.4.0              
#> [107] xfun_0.49                 statmod_1.5.0            
#> [109] DropletUtils_1.26.0       stringi_1.8.4            
#> [111] UCSC.utils_1.2.0          fftwtools_0.9-11         
#> [113] yaml_2.3.10               boot_1.3-31              
#> [115] evaluate_1.0.1            codetools_0.2-20         
#> [117] tibble_3.2.1              cli_3.6.3                
#> [119] systemfonts_1.1.0         munsell_0.5.1            
#> [121] jquerylib_0.1.4           Rcpp_1.0.13-1            
#> [123] zeallot_0.1.0             coda_0.19-4.1            
#> [125] png_0.1-8                 parallel_4.4.2           
#> [127] pkgdown_2.1.1             jpeg_0.1-10              
#> [129] sparseMatrixStats_1.18.0  bitops_1.0-9             
#> [131] viridisLite_0.4.2         mvtnorm_1.3-2            
#> [133] scales_1.3.0              e1071_1.7-16             
#> [135] crayon_1.5.3              scico_1.5.0              
#> [137] rlang_1.1.4               cowplot_1.1.3            
#> [139] multcomp_1.4-26