1 Introduction

In single-cell RNA-seq analysis, gene signature (or “module”) scoring constitutes a simple yet powerful approach to evaluate the strength of biological signals, typically associated to a specific cell type or biological process, in a transcriptome.

UCell is an R package for evaluating gene signatures in single-cell datasets. UCell signature scores, based on the Mann-Whitney U statistic, are robust to dataset size and heterogeneity, and their calculation demands less computing time and memory than other available methods, enabling the processing of large datasets in a few minutes even on machines with limited computing power. UCell can be applied to any single-cell data matrix, and includes functions to directly interact with Seurat objects.

2 Quick start

To test your installation, load a small sample dataset and run UCell:

library(UCell)

data(sample.matrix)
gene.sets <- list(Tcell_signature = c("CD2","CD3E","CD3D"),
                  Myeloid_signature = c("SPI1","FCER1G","CSF1R"))

scores <- ScoreSignatures_UCell(sample.matrix, features=gene.sets)
head(scores)
##                       Tcell_signature_UCell Myeloid_signature_UCell
## L5_ATTTCTGAGGTCGTGA               0.8993333                       0
## L4_TCACTATTCATCTCTA               0.6904444                       0
## L1_TCCTTCTTCTTTACAC               0.5935556                       0
## L5_AAAGTGAAGGCGCTCT               0.6093333                       0
## E2L3_CCTCAGTAGTGCAGGT             0.8508889                       0
## L5_CCCTCTCGTTCTAAGC               0.6562222                       0

3 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)

4 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-")
)

5 Run UCell

Run ScoreSignatures_UCell and get directly signature scores for all cells

u.scores <- ScoreSignatures_UCell(exp.mat,features=signatures)
head(u.scores)
##        Tcell_UCell Myeloid_UCell NK_UCell Plasma_cell_UCell
## bcHTNA           0     0.5234000        0        0.00000000
## bcHNVA           0     0.5120000        0        0.01991667
## bcALZN           0     0.3593333        0        0.00000000
## bcFWBP           0     0.1558000        0        0.00000000
## bcBJYE           0     0.4639333        0        0.00000000
## bcGSBJ           0     0.5460000        0        0.00000000

Show the distribution of predicted scores

library(reshape2)
library(ggplot2)
melted <- reshape2::melt(u.scores)
colnames(melted) <- c("Cell","Signature","UCell_score")
p <- ggplot(melted, aes(x=Signature, y=UCell_score)) + 
    geom_violin(aes(fill=Signature), scale = "width") +
    geom_boxplot(width=0.1, outlier.size=0) +
    theme_bw() + theme(axis.text.x=element_blank())
p

6 Pre-calculating gene rankings

The time- and memory-demanding step in UCell is the calculation of gene rankings for each individual cell. If we plan to experiment with signatures, editing them or adding new cell subtypes, it is possible to pre-calculate the gene rankings once and for all and then apply new signatures over these pre-calculated ranks. Run the StoreRankings_UCell function to pre-calculate gene rankings over a dataset:

set.seed(123)
ranks <- StoreRankings_UCell(exp.mat)
ranks[1:5,1:5]
## 5 x 5 sparse Matrix of class "dgCMatrix"
##           bcHTNA bcHNVA bcALZN bcFWBP bcBJYE
## 5S_rRNA        .      .      .      .      .
## 5_8S_rRNA      .      .      .      .      .
## 7SK            .      .      .      .      .
## A1BG           .      .      .      .      .
## A1BG-AS1       .      .      .      .      .

Then, we can apply our signature set, or any other new signature to the pre-calculated ranks. The calculations will be considerably faster.

set.seed(123)
u.scores.2 <- ScoreSignatures_UCell(features=signatures,
                                    precalc.ranks = ranks)

melted <- reshape2::melt(u.scores.2)
colnames(melted) <- c("Cell","Signature","UCell_score")
p <- ggplot(melted, aes(x=Signature, y=UCell_score)) + 
    geom_violin(aes(fill=Signature), scale = "width") +
    geom_boxplot(width=0.1, outlier.size = 0) + 
    theme_bw() + theme(axis.text.x=element_blank())
p

new.signatures <- list(Mast.cell = c("TPSAB1","TPSB2","CPA3","MS4A2"),
                       Lymphoid = c("LCK"))

u.scores.3 <- ScoreSignatures_UCell(features=new.signatures,
                                    precalc.ranks = ranks)
melted <- reshape2::melt(u.scores.3)
colnames(melted) <- c("Cell","Signature","UCell_score")
p <- ggplot(melted, aes(x=Signature, y=UCell_score)) + 
    geom_violin(aes(fill=Signature), scale = "width") +
    geom_boxplot(width=0.1, outlier.size=0) + 
    theme_bw() + theme(axis.text.x=element_blank())
p

7 Multi-core processing

If your machine has multi-core capabilities and enough RAM, running UCell in parallel can speed up considerably your analysis. The example below runs on a single core - you may modify this behavior by setting e.g. workers=4 to parallelize to 4 cores:

BPPARAM <- BiocParallel::MulticoreParam(workers=1)
u.scores <- ScoreSignatures_UCell(exp.mat,features=signatures,
                                  BPPARAM=BPPARAM)

8 Interacting with SingleCellExperiment or Seurat

SingleCellExperiment and Seurat are popular environments for single-cell analysis. The UCell package implements functions to interact directly with these pipelines, as described in dedicated demos available on the Bioc landing page.

9 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.

10 References

Appendix

  • 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

A Session Info

sessionInfo()
## R version 4.3.0 RC (2023-04-13 r84269)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.2 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.17-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## 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       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] reshape2_1.4.4              scater_1.28.0              
##  [3] scuttle_1.10.0              patchwork_1.1.2            
##  [5] ggplot2_3.4.2               SeuratObject_4.1.3         
##  [7] Seurat_4.3.0                UCell_2.4.0                
##  [9] scRNAseq_2.13.0             SingleCellExperiment_1.22.0
## [11] SummarizedExperiment_1.30.0 Biobase_2.60.0             
## [13] GenomicRanges_1.52.0        GenomeInfoDb_1.36.0        
## [15] IRanges_2.34.0              S4Vectors_0.38.0           
## [17] BiocGenerics_0.46.0         MatrixGenerics_1.12.0      
## [19] matrixStats_0.63.0          BiocStyle_2.28.0           
## 
## loaded via a namespace (and not attached):
##   [1] RcppAnnoy_0.0.20              splines_4.3.0                
##   [3] later_1.3.0                   BiocIO_1.10.0                
##   [5] bitops_1.0-7                  filelock_1.0.2               
##   [7] tibble_3.2.1                  polyclip_1.10-4              
##   [9] XML_3.99-0.14                 lifecycle_1.0.3              
##  [11] globals_0.16.2                lattice_0.21-8               
##  [13] ensembldb_2.24.0              MASS_7.3-59                  
##  [15] magrittr_2.0.3                plotly_4.10.1                
##  [17] sass_0.4.5                    rmarkdown_2.21               
##  [19] jquerylib_0.1.4               yaml_2.3.7                   
##  [21] httpuv_1.6.9                  sctransform_0.3.5            
##  [23] spatstat.sparse_3.0-1         sp_1.6-0                     
##  [25] reticulate_1.28               cowplot_1.1.1                
##  [27] pbapply_1.7-0                 DBI_1.1.3                    
##  [29] RColorBrewer_1.1-3            abind_1.4-5                  
##  [31] zlibbioc_1.46.0               Rtsne_0.16                   
##  [33] purrr_1.0.1                   AnnotationFilter_1.24.0      
##  [35] RCurl_1.98-1.12               rappdirs_0.3.3               
##  [37] GenomeInfoDbData_1.2.10       ggrepel_0.9.3                
##  [39] irlba_2.3.5.1                 spatstat.utils_3.0-2         
##  [41] listenv_0.9.0                 goftest_1.2-3                
##  [43] spatstat.random_3.1-4         fitdistrplus_1.1-11          
##  [45] parallelly_1.35.0             DelayedMatrixStats_1.22.0    
##  [47] leiden_0.4.3                  codetools_0.2-19             
##  [49] DelayedArray_0.26.0           xml2_1.3.3                   
##  [51] tidyselect_1.2.0              farver_2.1.1                 
##  [53] viridis_0.6.2                 ScaledMatrix_1.8.0           
##  [55] spatstat.explore_3.1-0        BiocFileCache_2.8.0          
##  [57] GenomicAlignments_1.36.0      jsonlite_1.8.4               
##  [59] BiocNeighbors_1.18.0          ellipsis_0.3.2               
##  [61] progressr_0.13.0              ggridges_0.5.4               
##  [63] survival_3.5-5                tools_4.3.0                  
##  [65] progress_1.2.2                ica_1.0-3                    
##  [67] Rcpp_1.0.10                   glue_1.6.2                   
##  [69] gridExtra_2.3                 xfun_0.39                    
##  [71] dplyr_1.1.2                   withr_2.5.0                  
##  [73] BiocManager_1.30.20           fastmap_1.1.1                
##  [75] fansi_1.0.4                   rsvd_1.0.5                   
##  [77] digest_0.6.31                 R6_2.5.1                     
##  [79] mime_0.12                     colorspace_2.1-0             
##  [81] scattermore_0.8               tensor_1.5                   
##  [83] spatstat.data_3.0-1           biomaRt_2.56.0               
##  [85] RSQLite_2.3.1                 utf8_1.2.3                   
##  [87] tidyr_1.3.0                   generics_0.1.3               
##  [89] data.table_1.14.8             rtracklayer_1.60.0           
##  [91] prettyunits_1.1.1             httr_1.4.5                   
##  [93] htmlwidgets_1.6.2             uwot_0.1.14                  
##  [95] pkgconfig_2.0.3               gtable_0.3.3                 
##  [97] blob_1.2.4                    lmtest_0.9-40                
##  [99] XVector_0.40.0                htmltools_0.5.5              
## [101] bookdown_0.33                 ProtGenerics_1.32.0          
## [103] scales_1.2.1                  png_0.1-8                    
## [105] knitr_1.42                    rjson_0.2.21                 
## [107] nlme_3.1-162                  curl_5.0.0                   
## [109] cachem_1.0.7                  zoo_1.8-12                   
## [111] stringr_1.5.0                 BiocVersion_3.17.1           
## [113] KernSmooth_2.23-20            vipor_0.4.5                  
## [115] parallel_4.3.0                miniUI_0.1.1.1               
## [117] AnnotationDbi_1.62.0          restfulr_0.0.15              
## [119] pillar_1.9.0                  grid_4.3.0                   
## [121] vctrs_0.6.2                   RANN_2.6.1                   
## [123] promises_1.2.0.1              BiocSingular_1.16.0          
## [125] beachmat_2.16.0               dbplyr_2.3.2                 
## [127] xtable_1.8-4                  cluster_2.1.4                
## [129] beeswarm_0.4.0                evaluate_0.20                
## [131] magick_2.7.4                  GenomicFeatures_1.52.0       
## [133] cli_3.6.1                     compiler_4.3.0               
## [135] Rsamtools_2.16.0              rlang_1.1.0                  
## [137] crayon_1.5.2                  future.apply_1.10.0          
## [139] labeling_0.4.2                ggbeeswarm_0.7.1             
## [141] plyr_1.8.8                    stringi_1.7.12               
## [143] deldir_1.0-6                  viridisLite_0.4.1            
## [145] BiocParallel_1.34.0           munsell_0.5.0                
## [147] Biostrings_2.68.0             lazyeval_0.2.2               
## [149] spatstat.geom_3.1-0           Matrix_1.5-4                 
## [151] ExperimentHub_2.8.0           hms_1.1.3                    
## [153] sparseMatrixStats_1.12.0      bit64_4.0.5                  
## [155] future_1.32.0                 KEGGREST_1.40.0              
## [157] shiny_1.7.4                   highr_0.10                   
## [159] interactiveDisplayBase_1.38.0 AnnotationHub_3.8.0          
## [161] ROCR_1.0-11                   igraph_1.4.2                 
## [163] memoise_2.0.1                 bslib_0.4.2                  
## [165] bit_4.0.5