1 Introduction

SingleCellExperiment is Bioconductor’s data structure of choice for storing single-cell experiment data. The function ScoreSignatures_UCell() allows performing signature scoring with UCell directly on sce objects. UCell scores are returned in a altExp object: altExp(sce, 'UCell')

2 Get some testing data

For this demo, we will download a single-cell dataset of lung cancer (Zilionis et al. (2019) Immunity) through the scRNA-seq package. This dataset contains >170,000 single cells; for the sake of simplicity, in this demo will we focus on immune cells, according to the annotations by the authors, and downsample to 5000 cells.

library(scRNAseq)
lung <- ZilionisLungData()
immune <- lung$Used & lung$used_in_NSCLC_immune
lung <- lung[,immune]
lung <- lung[,1:5000]

exp.mat <- Matrix::Matrix(counts(lung),sparse = TRUE)

3 Define gene signatures

Here we define some simple gene sets based on the “Human Cell Landscape” signatures Han et al. (2020) Nature. You may edit existing signatures, or add new one as elements in a list.

signatures <- list(
    Tcell = c("CD3D","CD3E","CD3G","CD2","TRAC"),
    Myeloid = c("CD14","LYZ","CSF1R","FCER1G","SPI1","LCK-"),
    NK = c("KLRD1","NCAM1","NKG7","CD3D-","CD3E-"),
    Plasma_cell = c("IGKC","IGHG3","IGHG1","IGHA1","CD19-")
)

4 Run UCell on sce object

library(UCell)
library(SingleCellExperiment)

sce <- SingleCellExperiment(list(counts=exp.mat))
sce <- ScoreSignatures_UCell(sce, features=signatures, 
                                 assay = 'counts', name=NULL)
altExp(sce, 'UCell')
## class: SummarizedExperiment 
## dim: 4 5000 
## metadata(0):
## assays(1): UCell
## rownames(4): Tcell Myeloid NK Plasma_cell
## rowData names(0):
## colnames(5000): bcHTNA bcHNVA ... bcGVZB bcHGKL
## colData names(0):

Dimensionality reduction and visualization

library(scater)
library(patchwork)
#PCA
sce <- logNormCounts(sce)
sce <- runPCA(sce, scale=TRUE, ncomponents=20)

#UMAP
set.seed(1234)
sce <- runUMAP(sce, dimred="PCA")

Visualize UCell scores on low-dimensional representation (UMAP)

pll <- lapply(names(signatures), function(x) {
    plotUMAP(sce, colour_by = x, by_exprs_values = "UCell") + theme(aspect.ratio = 1)
})
wrap_plots(pll)

5 Signature smoothing

Single-cell data are sparse. It can be useful to ‘impute’ scores by neighboring cells and partially correct this sparsity. The function SmoothKNN performs smoothing of single-cell scores by weighted average of the k-nearest neighbors in a given dimensionality reduction. It can be applied directly on SingleCellExperiment objects to smooth UCell scores:

sce <- SmoothKNN(sce, signature.names = names(signatures), reduction="PCA")
a <- plotUMAP(sce, colour_by="Myeloid", by_exprs_values="UCell") +
      ggtitle("UCell") + theme(aspect.ratio = 1)

b <- plotUMAP(sce, colour_by="Myeloid", by_exprs_values="UCell_kNN") +
      ggtitle("Smoothed UCell") + theme(aspect.ratio = 1)

a | b

6 Resources

Please report any issues at the UCell GitHub repository.

More demos available on the Bioc landing page and at the UCell demo repository.

If you find UCell useful, you may also check out the scGate package, which relies on UCell scores to automatically purify populations of interest based on gene signatures.

See also SignatuR for easy storing and retrieval of gene signatures.

7 References

  • Andreatta, M., Carmona, S. J. (2021) UCell: Robust and scalable single-cell gene signature scoring Computational and Structural Biotechnology Journal
  • Zilionis, R., Engblom, C., …, Klein, A. M. (2019) Single-Cell Transcriptomics of Human and Mouse Lung Cancers Reveals Conserved Myeloid Populations across Individuals and Species Immunity
  • Amezquita, Robert A., et al. (2020) “Orchestrating single-cell analysis with Bioconductor.” Nature methods

8 Session Info

sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [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       
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] scater_1.26.0               scuttle_1.8.0              
##  [3] patchwork_1.1.2             ggplot2_3.3.6              
##  [5] sp_1.5-0                    SeuratObject_4.1.2         
##  [7] Seurat_4.2.0                UCell_2.2.0                
##  [9] scRNAseq_2.11.0             SingleCellExperiment_1.20.0
## [11] SummarizedExperiment_1.28.0 Biobase_2.58.0             
## [13] GenomicRanges_1.50.0        GenomeInfoDb_1.34.0        
## [15] IRanges_2.32.0              S4Vectors_0.36.0           
## [17] BiocGenerics_0.44.0         MatrixGenerics_1.10.0      
## [19] matrixStats_0.62.0          BiocStyle_2.26.0           
## 
## loaded via a namespace (and not attached):
##   [1] utf8_1.2.2                    reticulate_1.26              
##   [3] tidyselect_1.2.0              RSQLite_2.2.18               
##   [5] AnnotationDbi_1.60.0          htmlwidgets_1.5.4            
##   [7] grid_4.2.1                    BiocParallel_1.32.0          
##   [9] Rtsne_0.16                    ScaledMatrix_1.6.0           
##  [11] munsell_0.5.0                 codetools_0.2-18             
##  [13] ica_1.0-3                     future_1.28.0                
##  [15] miniUI_0.1.1.1                withr_2.5.0                  
##  [17] spatstat.random_3.0-0         colorspace_2.0-3             
##  [19] progressr_0.11.0              filelock_1.0.2               
##  [21] highr_0.9                     knitr_1.40                   
##  [23] ROCR_1.0-11                   tensor_1.5                   
##  [25] listenv_0.8.0                 labeling_0.4.2               
##  [27] GenomeInfoDbData_1.2.9        polyclip_1.10-4              
##  [29] farver_2.1.1                  bit64_4.0.5                  
##  [31] parallelly_1.32.1             vctrs_0.5.0                  
##  [33] generics_0.1.3                xfun_0.34                    
##  [35] BiocFileCache_2.6.0           R6_2.5.1                     
##  [37] ggbeeswarm_0.6.0              rsvd_1.0.5                   
##  [39] AnnotationFilter_1.22.0       bitops_1.0-7                 
##  [41] spatstat.utils_3.0-1          cachem_1.0.6                 
##  [43] DelayedArray_0.24.0           assertthat_0.2.1             
##  [45] promises_1.2.0.1              BiocIO_1.8.0                 
##  [47] scales_1.2.1                  beeswarm_0.4.0               
##  [49] rgeos_0.5-9                   gtable_0.3.1                 
##  [51] beachmat_2.14.0               globals_0.16.1               
##  [53] goftest_1.2-3                 ensembldb_2.22.0             
##  [55] rlang_1.0.6                   splines_4.2.1                
##  [57] rtracklayer_1.58.0            lazyeval_0.2.2               
##  [59] spatstat.geom_3.0-3           BiocManager_1.30.19          
##  [61] yaml_2.3.6                    reshape2_1.4.4               
##  [63] abind_1.4-5                   GenomicFeatures_1.50.0       
##  [65] httpuv_1.6.6                  tools_4.2.1                  
##  [67] bookdown_0.29                 ellipsis_0.3.2               
##  [69] spatstat.core_2.4-4           jquerylib_0.1.4              
##  [71] RColorBrewer_1.1-3            ggridges_0.5.4               
##  [73] Rcpp_1.0.9                    plyr_1.8.7                   
##  [75] sparseMatrixStats_1.10.0      progress_1.2.2               
##  [77] zlibbioc_1.44.0               purrr_0.3.5                  
##  [79] RCurl_1.98-1.9                prettyunits_1.1.1            
##  [81] rpart_4.1.19                  deldir_1.0-6                 
##  [83] viridis_0.6.2                 pbapply_1.5-0                
##  [85] cowplot_1.1.1                 zoo_1.8-11                   
##  [87] ggrepel_0.9.1                 cluster_2.1.4                
##  [89] magrittr_2.0.3                magick_2.7.3                 
##  [91] data.table_1.14.4             scattermore_0.8              
##  [93] lmtest_0.9-40                 RANN_2.6.1                   
##  [95] ProtGenerics_1.30.0           fitdistrplus_1.1-8           
##  [97] hms_1.1.2                     mime_0.12                    
##  [99] evaluate_0.17                 xtable_1.8-4                 
## [101] XML_3.99-0.12                 gridExtra_2.3                
## [103] compiler_4.2.1                biomaRt_2.54.0               
## [105] tibble_3.1.8                  KernSmooth_2.23-20           
## [107] crayon_1.5.2                  htmltools_0.5.3              
## [109] mgcv_1.8-41                   later_1.3.0                  
## [111] tidyr_1.2.1                   DBI_1.1.3                    
## [113] ExperimentHub_2.6.0           dbplyr_2.2.1                 
## [115] MASS_7.3-58.1                 rappdirs_0.3.3               
## [117] Matrix_1.5-1                  cli_3.4.1                    
## [119] parallel_4.2.1                igraph_1.3.5                 
## [121] pkgconfig_2.0.3               GenomicAlignments_1.34.0     
## [123] plotly_4.10.0                 spatstat.sparse_3.0-0        
## [125] xml2_1.3.3                    vipor_0.4.5                  
## [127] bslib_0.4.0                   XVector_0.38.0               
## [129] stringr_1.4.1                 digest_0.6.30                
## [131] sctransform_0.3.5             RcppAnnoy_0.0.20             
## [133] spatstat.data_3.0-0           Biostrings_2.66.0            
## [135] rmarkdown_2.17                leiden_0.4.3                 
## [137] uwot_0.1.14                   DelayedMatrixStats_1.20.0    
## [139] restfulr_0.0.15               curl_4.3.3                   
## [141] shiny_1.7.3                   Rsamtools_2.14.0             
## [143] rjson_0.2.21                  nlme_3.1-160                 
## [145] lifecycle_1.0.3               jsonlite_1.8.3               
## [147] BiocNeighbors_1.16.0          viridisLite_0.4.1            
## [149] fansi_1.0.3                   pillar_1.8.1                 
## [151] lattice_0.20-45               KEGGREST_1.38.0              
## [153] fastmap_1.1.0                 httr_1.4.4                   
## [155] survival_3.4-0                interactiveDisplayBase_1.36.0
## [157] glue_1.6.2                    png_0.1-7                    
## [159] BiocVersion_3.16.0            bit_4.0.4                    
## [161] stringi_1.7.8                 sass_0.4.2                   
## [163] blob_1.2.3                    BiocSingular_1.14.0          
## [165] AnnotationHub_3.6.0           memoise_2.0.1                
## [167] dplyr_1.0.10                  irlba_2.3.5.1                
## [169] future.apply_1.9.1