carmonalab / UCell

Gene set scoring for single-cell data
GNU General Public License v3.0
137 stars 16 forks source link

Help with plotting Ucell score in UMAP or TNSE from sce object #15

Closed joachimsiaw closed 2 years ago

joachimsiaw commented 2 years ago

Hi, I am new scRNAseq analysis. First of all, thank you for your recent update on ScoreSignatures_UCell function to ScoreSignatures_UCell_sce in order to support singleCellEexperiment object. I need help with how to make UMAP and TSNE plots which show the Ucell signature scores stored in sce object. I will be very grateful if you could share a piece of codes with me on how to do this as you demonstrated with using seurate object.

Example with seurate object: FeaturePlot(seurat.object, reduction = "umap", features = signature.names, ncol = 3, order = T)

Thank you.

mass-a commented 2 years ago

Hello!

One way of doing this can be through the scater package, which has convenient dim-red and plotting functions. See an example below for tSNE and UMAP.

library(UCell)
library(scater)
library(patchwork)

mat <- UCell::sample.matrix
my.sce <- SingleCellExperiment(list(logcounts=mat))
gene.sets <- list(Naive = c("LEF1","SELL","TCF7"),
                   Cytotoxic = c("GZMA","GZMB","PRF1"))

#Run UCell
my.sce <- ScoreSignatures_UCell_sce(my.sce, features=gene.sets, assay = 'logcounts')

#PCA
my.sce <- runPCA(my.sce, scale=T, ncomponents=10)

#tSNE
set.seed(1234)
my.sce <- runTSNE(my.sce, dimred="PCA", perplexity=20)
a <- plotTSNE(my.sce, colour_by = "Naive_UCell", by_exprs_values = "UCell")
b <- plotTSNE(my.sce, colour_by = "Cytotoxic_UCell", by_exprs_values = "UCell")
a | b

#UMAP
set.seed(1234)
my.sce <- runUMAP(my.sce, dimred="PCA")
a <- plotUMAP(my.sce, colour_by = "Naive_UCell", by_exprs_values = "UCell")
b <- plotUMAP(my.sce, colour_by = "Cytotoxic_UCell", by_exprs_values = "UCell")
a | b
joachimsiaw commented 2 years ago

Thank you @mass-a for the help. Very helpful. I appreciate it.