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) colnames(exp.mat) <- paste0(colnames(exp.mat), seq(1,ncol(exp.mat)))
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-") )
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[[]])
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.