# Using UCell with Seurat

# Introduction

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.

# 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)
    colnames(exp.mat) <- paste0(colnames(exp.mat), seq(1,ncol(exp.mat)))

Save it as a Seurat object

    library(Seurat)
    seurat.object <- CreateSeuratObject(counts = exp.mat,
                                        project = "Zilionis_immune")

# 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","NCR1","NKG7","CD3D-","CD3E-"),
        Plasma_cell = c("MZB1","DERL3","CD19-")
    )

# Run UCell on Seurat object

    library(UCell)
    seurat.object <- AddModuleScore_UCell(seurat.object,
                                          features=signatures, name=NULL)
    head(seurat.object[[]])

    ##              orig.ident nCount_RNA nFeature_RNA Tcell   Myeloid NK Plasma_cell
    ## bcHTNA1 Zilionis_immune       7516         2613     0 0.5227121  0  0.00000000
    ## bcHNVA2 Zilionis_immune       5684         1981     0 0.5112892  0  0.00000000
    ## bcALZN3 Zilionis_immune       4558         1867     0 0.3584502  0  0.07540874
    ## bcFWBP4 Zilionis_immune       2915         1308     0 0.1546426  0  0.00000000
    ## bcBJYE5 Zilionis_immune       3576         1548     0 0.4629927  0  0.00000000
    ## bcGSBJ6 Zilionis_immune       2796         1270     0 0.5452238  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)[1:2]) &
      theme(aspect.ratio = 1,
            axis.ticks = element_blank(),
            axis.text = element_blank(),
            axis.title = element_blank())

# 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 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")) &
        theme(aspect.ratio = 1,
            axis.ticks = element_blank(),
            axis.text = element_blank(),
            axis.title = element_blank())

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"
    FeaturePlot(seurat.object, reduction = "umap", features = genes) &
      theme(aspect.ratio = 1)

    DefaultAssay(seurat.object) <- "RNA_smooth"
    FeaturePlot(seurat.object, reduction = "umap", features = genes) &
      theme(aspect.ratio = 1)

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

# 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
- Hao, Yuhan, et al. (2021) Integrated analysis of multimodal single-cell data Cell

# Session Info

    sessionInfo()

    ## R version 4.6.0 (2026-04-24)
    ## Platform: x86_64-pc-linux-gnu
    ## Running under: Ubuntu 24.04.4 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.26.so;  LAPACK version 3.12.0
    ##
    ## locale:
    ##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    ##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
    ##  [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: Etc/UTC
    ## tzcode source: system (glibc)
    ##
    ## attached base packages:
    ## [1] stats4    stats     graphics  grDevices utils     datasets  methods
    ## [8] base
    ##
    ## other attached packages:
    ##  [1] patchwork_1.3.2             scater_1.40.0
    ##  [3] scuttle_1.20.0              UCell_2.16.0
    ##  [5] Seurat_5.5.0                SeuratObject_5.4.0
    ##  [7] sp_2.2-1                    ggplot2_4.0.3
    ##  [9] scRNAseq_2.24.0             SingleCellExperiment_1.34.0
    ## [11] SummarizedExperiment_1.42.0 Biobase_2.72.0
    ## [13] GenomicRanges_1.64.0        Seqinfo_1.2.0
    ## [15] IRanges_2.46.0              S4Vectors_0.50.0
    ## [17] BiocGenerics_0.58.0         generics_0.1.4
    ## [19] MatrixGenerics_1.24.0       matrixStats_1.5.0
    ## [21] BiocStyle_2.40.0
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] ProtGenerics_1.44.0      spatstat.sparse_3.1-0    bitops_1.0-9
    ##   [4] httr_1.4.8               RColorBrewer_1.1-3       tools_4.6.0
    ##   [7] sctransform_0.4.3        alabaster.base_1.10.0    R6_2.6.1
    ##  [10] HDF5Array_1.40.0         lazyeval_0.2.3           uwot_0.2.4
    ##  [13] rhdf5filters_1.22.0      withr_3.0.2              gridExtra_2.3
    ##  [16] progressr_0.19.0         cli_3.6.6                spatstat.explore_3.8-0
    ##  [19] fastDummies_1.7.6        alabaster.se_1.12.0      labeling_0.4.3
    ##  [22] sass_0.4.10              S7_0.2.2                 spatstat.data_3.1-9
    ##  [25] ggridges_0.5.7           pbapply_1.7-4            Rsamtools_2.28.0
    ##  [28] parallelly_1.47.0        RSQLite_2.4.6            BiocIO_1.22.0
    ##  [31] ica_1.0-3                spatstat.random_3.4-5    dplyr_1.2.1
    ##  [34] Matrix_1.7-5             ggbeeswarm_0.7.3         abind_1.4-8
    ##  [37] lifecycle_1.0.5          yaml_2.3.12              rhdf5_2.54.1
    ##  [40] SparseArray_1.12.0       BiocFileCache_3.2.0      Rtsne_0.17
    ##  [43] grid_4.6.0               blob_1.3.0               promises_1.5.0
    ##  [46] ExperimentHub_3.2.0      crayon_1.5.3             miniUI_0.1.2
    ##  [49] lattice_0.22-9           beachmat_2.26.0          cowplot_1.2.0
    ##  [52] GenomicFeatures_1.64.0   cigarillo_1.2.0          KEGGREST_1.52.0
    ##  [55] sys_3.4.3                maketools_1.3.2          pillar_1.11.1
    ##  [58] knitr_1.51               rjson_0.2.23             future.apply_1.20.2
    ##  [61] codetools_0.2-20         glue_1.8.1               spatstat.univar_3.1-7
    ##  [64] data.table_1.18.2.1      vctrs_0.7.3              png_0.1-9
    ##  [67] gypsum_1.6.0             spam_2.11-3              gtable_0.3.6
    ##  [70] cachem_1.1.0             xfun_0.57                S4Arrays_1.12.0
    ##  [73] mime_0.13                survival_3.8-6           fitdistrplus_1.2-6
    ##  [76] ROCR_1.0-12              nlme_3.1-169             bit64_4.8.0
    ##  [79] alabaster.ranges_1.10.0  filelock_1.0.3           RcppAnnoy_0.0.23
    ##  [82] GenomeInfoDb_1.48.0      bslib_0.10.0             irlba_2.3.7
    ##  [85] vipor_0.4.7              KernSmooth_2.23-26       otel_0.2.0
    ##  [88] DBI_1.3.0                ggrastr_1.0.2            tidyselect_1.2.1
    ##  [91] bit_4.6.0                compiler_4.6.0           curl_7.1.0
    ##  [94] httr2_1.2.2              BiocNeighbors_2.4.0      h5mread_1.4.0
    ##  [97] DelayedArray_0.38.0      plotly_4.12.0            rtracklayer_1.72.0
    ## [100] scales_1.4.0             lmtest_0.9-40            rappdirs_0.3.4
    ## [103] stringr_1.6.0            digest_0.6.39            goftest_1.2-3
    ## [106] spatstat.utils_3.2-2     alabaster.matrix_1.12.0  rmarkdown_2.31
    ## [109] XVector_0.52.0           htmltools_0.5.9          pkgconfig_2.0.3
    ## [112] dbplyr_2.5.2             fastmap_1.2.0            ensembldb_2.36.0
    ## [115] rlang_1.2.0              htmlwidgets_1.6.4        UCSC.utils_1.8.0
    ## [118] shiny_1.13.0             farver_2.1.2             jquerylib_0.1.4
    ## [121] zoo_1.8-15               jsonlite_2.0.0           BiocParallel_1.46.0
    ## [124] BiocSingular_1.28.0      RCurl_1.98-1.18          magrittr_2.0.5
    ## [127] dotCall64_1.2            Rhdf5lib_1.32.0          Rcpp_1.1.1-1.1
    ## [130] viridis_0.6.5            reticulate_1.46.0        stringi_1.8.7
    ## [133] alabaster.schemas_1.10.0 MASS_7.3-65              AnnotationHub_4.2.0
    ## [136] plyr_1.8.9               parallel_4.6.0           listenv_0.10.1
    ## [139] ggrepel_0.9.8            deldir_2.0-4             Biostrings_2.80.0
    ## [142] splines_4.6.0            tensor_1.5.1             igraph_2.3.0
    ## [145] spatstat.geom_3.7-3      RcppHNSW_0.6.0           buildtools_1.0.0
    ## [148] reshape2_1.4.5           ScaledMatrix_1.20.0      BiocVersion_3.23.1
    ## [151] XML_3.99-0.23            evaluate_1.0.5           BiocManager_1.30.27
    ## [154] httpuv_1.6.17            RANN_2.6.2               tidyr_1.3.2
    ## [157] purrr_1.2.2              polyclip_1.10-7          future_1.70.0
    ## [160] scattermore_1.2          alabaster.sce_1.12.0     rsvd_1.0.5
    ## [163] xtable_1.8-8             restfulr_0.0.16          AnnotationFilter_1.36.0
    ## [166] RSpectra_0.16-2          later_1.4.8              viridisLite_0.4.3
    ## [169] tibble_3.3.1             memoise_2.0.1            beeswarm_0.4.0
    ## [172] AnnotationDbi_1.74.0     GenomicAlignments_1.48.0 cluster_2.1.8.2
    ## [175] globals_0.19.1