satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.31k stars 919 forks source link

Taking the Average Gene Expression of Alternative Identities #6657

Closed atly2000 closed 2 years ago

atly2000 commented 2 years ago

I am planning on plotting a heatmap showing the gene expression three categories of cells from my scRNA-seq data. Unlike Seurat-assigned clusters, I specify these barcodes from an external analysis.

Using subset, I assigned three new categories to my Seurat Object as identities: cat_1, cat_2, and cat_3.

anno_1 <- subset(pbmc, cells=cat1_barcodes)
pbmc_cat1$cat <- "cat_1"

anno_2 <- subset(pbmc, cells=cat2_barcodes)
pbmc_cat2$cat <- "cat_2"

anno_3 <- subset(pbmc, cells=cat3_barcodes)
pbmc_cat3$cat <- "cat_3"
alldata <- merge(pbmc_cat1, y= c(pbmc_cat2,pbmc_cat3))

I would like to plot the average gene expression within each of these identities as a heatmap.

I have tried the following:

average_of_anno <- AverageExpression(object = alldata,group.by="cat",return.seurat = TRUE)
head(average_of_anno)

But I get this after using head:

                  orig.ident nCount_RNA nFeature_RNA
cat_1       Average      10000        17804
cat_2       Average      10000        17173
cat_3       Average      10000        21068

I expected to see a matrix with cell barcodes and other metadata, but I do not see any barcodes at all.

Next, when I perform DoHeatmap, I get three columns as I expected. However, I am unsure if the cells have been properly plotted on the heatmap. How can I be sure that these columns correspond to cat_1, cat_2, and cat_3?

Also, is there a way to label each column as cat_1, cat_2, and cat_3? image

I appreciate your help.

timoast commented 2 years ago

AverageExpression averages the cells, so you're losing the per-cell information. It sounds like you just want a normal single-cell heatmap (running DoHeatmap on the original object) grouped by dataset. You can do this by skipping the averaging step, and run DoHeatmap with group.by = "cat"