UCell 2.4.0
The function AddModuleScore_UCell()
allows operating directly on Seurat objects. UCell scores are calculated from raw counts or normalized data, and returned as metadata columns. The example below defines some simple signatures, and applies them on single-cell data stored in a Seurat object.
To see how this function differs from Seurat’s own AddModuleScore()
(not based on per-cell ranks) see this vignette.
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-")
)
library(UCell)
library(Seurat)
seurat.object <- CreateSeuratObject(counts = exp.mat,
project = "Zilionis_immune")
seurat.object <- AddModuleScore_UCell(seurat.object,
features=signatures, name=NULL)
head(seurat.object[[]])
## orig.ident nCount_RNA nFeature_RNA Tcell Myeloid NK Plasma_cell
## bcHTNA Zilionis_immune 7516 2613 0 0.5234000 0 0.00000000
## bcHNVA Zilionis_immune 5684 1981 0 0.5120000 0 0.01991667
## bcALZN Zilionis_immune 4558 1867 0 0.3593333 0 0.00000000
## bcFWBP Zilionis_immune 2915 1308 0 0.1558000 0 0.00000000
## bcBJYE Zilionis_immune 3576 1548 0 0.4639333 0 0.00000000
## bcGSBJ Zilionis_immune 2796 1270 0 0.5460000 0 0.00000000
Generate PCA and UMAP embeddings
seurat.object <- NormalizeData(seurat.object)
seurat.object <- FindVariableFeatures(seurat.object,
selection.method = "vst", nfeatures = 500)
seurat.object <- ScaleData(seurat.object)
seurat.object <- RunPCA(seurat.object, npcs = 20,
features=VariableFeatures(seurat.object))
seurat.object <- RunUMAP(seurat.object, reduction = "pca",
dims = 1:20, seed.use=123)
Visualize UCell scores on low-dimensional representation (UMAP)
library(ggplot2)
library(patchwork)
FeaturePlot(seurat.object, reduction = "umap", features = names(signatures))
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 Seurat objects to smooth UCell scores:
seurat.object <- SmoothKNN(seurat.object,
signature.names = names(signatures),
reduction="pca")
FeaturePlot(seurat.object, reduction = "umap", features = c("NK","NK_kNN"))
Smoothing (or imputation) has been designed for UCell scores, but it can be applied to any other data or metadata. For instance, we can perform knn-smoothing directly on gene expression measurements:
genes <- c("CD2","CSF1R")
seurat.object <- SmoothKNN(seurat.object, signature.names=genes,
assay="RNA", reduction="pca", k=20, suffix = "_smooth")
DefaultAssay(seurat.object) <- "RNA"
a <- FeaturePlot(seurat.object, reduction = "umap", features = genes)
DefaultAssay(seurat.object) <- "RNA_smooth"
b <- FeaturePlot(seurat.object, reduction = "umap", features = genes)
a / b
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.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] patchwork_1.1.2 ggplot2_3.4.2
## [3] SeuratObject_4.1.3 Seurat_4.3.0
## [5] UCell_2.4.0 scRNAseq_2.13.0
## [7] SingleCellExperiment_1.22.0 SummarizedExperiment_1.30.0
## [9] Biobase_2.60.0 GenomicRanges_1.52.0
## [11] GenomeInfoDb_1.36.0 IRanges_2.34.0
## [13] S4Vectors_0.38.0 BiocGenerics_0.46.0
## [15] MatrixGenerics_1.12.0 matrixStats_0.63.0
## [17] 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 leiden_0.4.3
## [47] codetools_0.2-19 DelayedArray_0.26.0
## [49] xml2_1.3.3 tidyselect_1.2.0
## [51] farver_2.1.1 spatstat.explore_3.1-0
## [53] BiocFileCache_2.8.0 GenomicAlignments_1.36.0
## [55] jsonlite_1.8.4 BiocNeighbors_1.18.0
## [57] ellipsis_0.3.2 progressr_0.13.0
## [59] ggridges_0.5.4 survival_3.5-5
## [61] tools_4.3.0 progress_1.2.2
## [63] ica_1.0-3 Rcpp_1.0.10
## [65] glue_1.6.2 gridExtra_2.3
## [67] xfun_0.39 dplyr_1.1.2
## [69] withr_2.5.0 BiocManager_1.30.20
## [71] fastmap_1.1.1 fansi_1.0.4
## [73] digest_0.6.31 R6_2.5.1
## [75] mime_0.12 colorspace_2.1-0
## [77] scattermore_0.8 tensor_1.5
## [79] spatstat.data_3.0-1 biomaRt_2.56.0
## [81] RSQLite_2.3.1 utf8_1.2.3
## [83] tidyr_1.3.0 generics_0.1.3
## [85] data.table_1.14.8 rtracklayer_1.60.0
## [87] prettyunits_1.1.1 httr_1.4.5
## [89] htmlwidgets_1.6.2 uwot_0.1.14
## [91] pkgconfig_2.0.3 gtable_0.3.3
## [93] blob_1.2.4 lmtest_0.9-40
## [95] XVector_0.40.0 htmltools_0.5.5
## [97] bookdown_0.33 ProtGenerics_1.32.0
## [99] scales_1.2.1 png_0.1-8
## [101] knitr_1.42 reshape2_1.4.4
## [103] rjson_0.2.21 nlme_3.1-162
## [105] curl_5.0.0 cachem_1.0.7
## [107] zoo_1.8-12 stringr_1.5.0
## [109] BiocVersion_3.17.1 KernSmooth_2.23-20
## [111] parallel_4.3.0 miniUI_0.1.1.1
## [113] AnnotationDbi_1.62.0 restfulr_0.0.15
## [115] pillar_1.9.0 grid_4.3.0
## [117] vctrs_0.6.2 RANN_2.6.1
## [119] promises_1.2.0.1 dbplyr_2.3.2
## [121] xtable_1.8-4 cluster_2.1.4
## [123] evaluate_0.20 magick_2.7.4
## [125] GenomicFeatures_1.52.0 cli_3.6.1
## [127] compiler_4.3.0 Rsamtools_2.16.0
## [129] rlang_1.1.0 crayon_1.5.2
## [131] future.apply_1.10.0 labeling_0.4.2
## [133] plyr_1.8.8 stringi_1.7.12
## [135] deldir_1.0-6 viridisLite_0.4.1
## [137] BiocParallel_1.34.0 munsell_0.5.0
## [139] Biostrings_2.68.0 lazyeval_0.2.2
## [141] spatstat.geom_3.1-0 Matrix_1.5-4
## [143] ExperimentHub_2.8.0 hms_1.1.3
## [145] bit64_4.0.5 future_1.32.0
## [147] KEGGREST_1.40.0 shiny_1.7.4
## [149] highr_0.10 interactiveDisplayBase_1.38.0
## [151] AnnotationHub_3.8.0 ROCR_1.0-11
## [153] igraph_1.4.2 memoise_2.0.1
## [155] bslib_0.4.2 bit_4.0.5