Seurat: group order in Heatmap in Seurat v3.0.1

Created on 28 May 2019  路  15Comments  路  Source: satijalab/seurat

Dear Seurat Developers,

I upgraded to seurat v3.0.1 recently and found that the groups in the heatmap are ordered according to the alphabetical order of the group names rather than the factor levels. I checked the code and guess that the group.use needs to be re-factorized after the line 'groups.use <- object[[group.by]][cells, , drop = FALSE]'. You have defined something that is inaccessible outside Seurat so I cannot check where exactly the problem is.

Hope you can fix this soon.

Best,
Steven

Most helpful comment

This is what I do, (works in v3.0.0.9150) it's a bit manual but it gets the job done:

# cluster re-assignment occurs, which re-assigns clustering in my_levels (assuming you have 12 clusters in total)
my_levels <- c(7, 6, 4, 3, 1, 2, 5, 10, 8, 0, 9, 11, 12)

# Re-level object@ident
[email protected] <- factor(x = [email protected], levels = my_levels)

Hope that helps!

All 15 comments

image

Me too

This is what I do, (works in v3.0.0.9150) it's a bit manual but it gets the job done:

# cluster re-assignment occurs, which re-assigns clustering in my_levels (assuming you have 12 clusters in total)
my_levels <- c(7, 6, 4, 3, 1, 2, 5, 10, 8, 0, 9, 11, 12)

# Re-level object@ident
[email protected] <- factor(x = [email protected], levels = my_levels)

Hope that helps!

Hi,

The groups in the heatmap should be ordered by the factor levels so @Dragonmasterx87 suggestion should work. If you're running the latest development version, you could also use the levels function directly on the Seurat object to achieve the same effect. E.g.

levels(yourseuratobject) <- my_levels

Hi all, both the methods here are not working to relevel the active ident in my Seurat 3.0.1. Order of idents in heatmap is still sorted in default alpha not my levels. What happened to the group order option of DoHeatmap?

@cemalley are you using the current version on the develop branch? This was addressed in #1632

@timoast I'm using Seurat_3.0.1.9015

data(pbmc_small)
DoHeatmap(pbmc_small)

Screen Shot 2019-06-05 at 3 37 08 PM

> levels(pbmc_small)
[1] "0" "1" "2"
> levels(pbmc_small) <- c("2", "1", "0")
> levels(pbmc_small)
[1] "2" "1" "0"
DoHeatmap(pbmc_small)

Screen Shot 2019-06-05 at 3 36 51 PM

Can you provide an example where it doesn't work?

@andrewwbutler

aggr4
An object of class Seurat
13212 features across 960 samples within 1 assay
Active assay: RNA (13212 features)
2 dimensional reductions calculated: pca, tsne

levels(aggr4) <- c('LAday0','LAday7','Lday7','Aday7')

levels(aggr4)
[1] "LAday0" "LAday7" "Lday7" "Aday7"

DoHeatmap(aggr4, features = c('POU5F1','ESRG','NANOG','POU5F1B','FOXD3-AS1'), raster=F) + scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 10, name = "RdBu")) ) + guides(color=FALSE)

wrong_levels

Hmm, can you share aggr4 or a similar object that reproduces the problem?

I cannot, it is not published yet. Only workaround I have is to rename idents with numbers preceding like "1_LAday0", "2_LAday7".

Hi, I am also having the identical problem - it seems to default to alphabetical order so yes the only solution is a prefix as per @cemalley
a fix would be greatly appreciated!
thanks
sid lawrence

I'm not able to reproduce the issue on several objects that I've tried and it seems to have been resolved for others (#1632) as well. Are you able to recreate the issue with any of the public datasets we use in any of the tutorials?

Hi, I am also having this problem at the moment on an integrated assay object. I have the develop version now. I just followed all steps in the "Tutorial: Integrating stimulated vs. control PBMC datasets to learn cell-type specific responses" and before running the "FindAllMarkers" function I added:
levels(immune.combined)=factor(0:18) #because I have 18 clusters.
Then I run the DoHeatmap and it still orders the clusters as =,1,10,11,12 etc.

I have a similar indexing issue where the clusters are being grouped 1, 10, 11, 12, etc, as shown in the snippette attached below. I have 22 clusters in my graph from DoHeatmap. When I reassign levels, using levels(object) <- factor(1:20), I still get the incorrect indexing.

Capture

Here is a snapshot of my code:
levels(SeuratObj) <- c("1","0","2","3","4","5","6","7","8","9","10","11","12","13",
"14","15","16","17","18","19","20","21","22")
top10 <- SeuratObj.tsne_markers %>% group_by(cluster) %>% top_n(n = 10, wt = avg_logFC)
top10HM <- DoHeatmap(SeuratObj, features = top10$gene,group.by = "levels") + NoLegend()

I wanted to confirm that I have also encountered this index in issue.

Hi,

I was having the same issue in which setting levels to be my desired order didn't change the order plotted with DoHeatmap - but after playing around with it I realized that removing the "group.by" variable from the DoHeatmap input solved the problem. Just make sure to set Idents(seurat_obj) to whatever you want to group by before running DoHeatmap, then no "group.by" input is required. Hopefully this helps others having the same issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

htc502 picture htc502  路  3Comments

kathirij picture kathirij  路  3Comments

RuiyangLiu94 picture RuiyangLiu94  路  3Comments

Biogitte picture Biogitte  路  3Comments

bio-la picture bio-la  路  3Comments