UCell 2.2.0
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.
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
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)
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-")
)
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
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
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)
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.
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.
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] reshape2_1.4.4 scater_1.26.0
## [3] scuttle_1.8.0 patchwork_1.1.2
## [5] ggplot2_3.3.6 sp_1.5-0
## [7] SeuratObject_4.1.2 Seurat_4.2.0
## [9] UCell_2.2.0 scRNAseq_2.11.0
## [11] SingleCellExperiment_1.20.0 SummarizedExperiment_1.28.0
## [13] Biobase_2.58.0 GenomicRanges_1.50.0
## [15] GenomeInfoDb_1.34.0 IRanges_2.32.0
## [17] S4Vectors_0.36.0 BiocGenerics_0.44.0
## [19] MatrixGenerics_1.10.0 matrixStats_0.62.0
## [21] 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 abind_1.4-5
## [63] GenomicFeatures_1.50.0 httpuv_1.6.6
## [65] tools_4.2.1 bookdown_0.29
## [67] ellipsis_0.3.2 spatstat.core_2.4-4
## [69] jquerylib_0.1.4 RColorBrewer_1.1-3
## [71] ggridges_0.5.4 Rcpp_1.0.9
## [73] plyr_1.8.7 sparseMatrixStats_1.10.0
## [75] progress_1.2.2 zlibbioc_1.44.0
## [77] purrr_0.3.5 RCurl_1.98-1.9
## [79] prettyunits_1.1.1 rpart_4.1.19
## [81] deldir_1.0-6 viridis_0.6.2
## [83] pbapply_1.5-0 cowplot_1.1.1
## [85] zoo_1.8-11 ggrepel_0.9.1
## [87] cluster_2.1.4 magrittr_2.0.3
## [89] magick_2.7.3 data.table_1.14.4
## [91] scattermore_0.8 lmtest_0.9-40
## [93] RANN_2.6.1 ProtGenerics_1.30.0
## [95] fitdistrplus_1.1-8 hms_1.1.2
## [97] mime_0.12 evaluate_0.17
## [99] xtable_1.8-4 XML_3.99-0.12
## [101] gridExtra_2.3 compiler_4.2.1
## [103] biomaRt_2.54.0 tibble_3.1.8
## [105] KernSmooth_2.23-20 crayon_1.5.2
## [107] htmltools_0.5.3 mgcv_1.8-41
## [109] later_1.3.0 tidyr_1.2.1
## [111] DBI_1.1.3 ExperimentHub_2.6.0
## [113] dbplyr_2.2.1 MASS_7.3-58.1
## [115] rappdirs_0.3.3 Matrix_1.5-1
## [117] cli_3.4.1 parallel_4.2.1
## [119] igraph_1.3.5 pkgconfig_2.0.3
## [121] GenomicAlignments_1.34.0 plotly_4.10.0
## [123] spatstat.sparse_3.0-0 xml2_1.3.3
## [125] vipor_0.4.5 bslib_0.4.0
## [127] XVector_0.38.0 stringr_1.4.1
## [129] digest_0.6.30 sctransform_0.3.5
## [131] RcppAnnoy_0.0.20 spatstat.data_3.0-0
## [133] Biostrings_2.66.0 rmarkdown_2.17
## [135] leiden_0.4.3 uwot_0.1.14
## [137] DelayedMatrixStats_1.20.0 restfulr_0.0.15
## [139] curl_4.3.3 shiny_1.7.3
## [141] Rsamtools_2.14.0 rjson_0.2.21
## [143] nlme_3.1-160 lifecycle_1.0.3
## [145] jsonlite_1.8.3 BiocNeighbors_1.16.0
## [147] viridisLite_0.4.1 fansi_1.0.3
## [149] pillar_1.8.1 lattice_0.20-45
## [151] KEGGREST_1.38.0 fastmap_1.1.0
## [153] httr_1.4.4 survival_3.4-0
## [155] interactiveDisplayBase_1.36.0 glue_1.6.2
## [157] png_0.1-7 BiocVersion_3.16.0
## [159] bit_4.0.4 stringi_1.7.8
## [161] sass_0.4.2 blob_1.2.3
## [163] BiocSingular_1.14.0 AnnotationHub_3.6.0
## [165] memoise_2.0.1 dplyr_1.0.10
## [167] irlba_2.3.5.1 future.apply_1.9.1