satijalab / seurat

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

error when doing heatmap with AverageExpression. How to fix issue? #2794

Closed giovanegt closed 4 years ago

giovanegt commented 4 years ago

Hi all,

I am trying to build a heatmap using the average expression of genes within each cluster. Therefore, I first calculated the average expression of all the cells within each cluster cluster.averages <- AverageExpression(Merged.big) cluster.averages head(cluster.averages[["RNA"]][, 1:10])

Then, I tried to use it to plot a heatmap with the calculated values.

DoHeatmap(cluster.averages, features = unlist(c("Hk1", "Hk2", "Ldha", "Ldhb", "Eno1", "Pfkfb3", "Pfkl", "Pkm"))

But is is giving me the following error message

**Error in UseMethod(generic = "DefaultAssay", object = object) : no applicable method for 'DefaultAssay' applied to an object of class "list"** Even if I use a different code to set genes list, it is still returning the same error message.

DoHeatmap(cluster.averages, features = unlist(TopFeatures(Merged.bi[["pca"]], balanced = TRUE)), size = 3, draw.lines = FALSE)

Any help is appreciated,

I thank you all in advance.

I would like to end up with something like this, below.

image

Once again, thank you all.

KinSimon96 commented 4 years ago

Here is how i proceed for heatmaps:

combined_averages <- AverageExpression(combined, return.seurat = TRUE) DoHeatmap(combined_averages, features = c(rownames(markersC10)), label = FALSE ,draw.lines = FALSE) + scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n =4, name = "RdBu")))

(Il really advice you to use this Blue-Red palette, because the Seurat one isn't good if you wanna write a paper).

Focussing on your problem, you should work with dataframes instead of lists. So the first thing would be to convert your list into a df. This is weird because Seurat's functions return markers already in a dataframe. It is not the case?

giovanegt commented 4 years ago

Thanks a lot! It is working now. Great trick with the palette color. Once again, thank you very much.

On Wed, 1 Apr 2020 at 13:06 KinSimon96 notifications@github.com wrote:

Here is how i proceed for heatmaps:

combined_averages <- AverageExpression(combined, return.seurat = TRUE) DoHeatmap(combined_averages, features = c(rownames(markersC10)), label = FALSE ,draw.lines = FALSE) + scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n =4, name = "RdBu")))

(Il really advice you to use this Blue-Red palette, because the Seurat one isn't good if you wanna write a paper).

Focussing on your problem, you should work with dataframes instead of lists. So the first thing would be to convert your list into a df. This is weird because Seurat's functions return markers already in a dataframe. It is not the case?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/satijalab/seurat/issues/2794#issuecomment-607406261, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN543GP7ZTMHZSX3PUXHLITRKN7BZANCNFSM4LYASEXQ .

-- Giovane Tortelote, PhD

National Biobank for iPS cells

Federal University of Rio de Janeiro Rio de Janeiro - Brazil

EAC-T commented 3 years ago

Hi @KinSimon96 , I'm using your code but I'm not getting a heatmap, I'm getting this:

Range: Limits: 0 -- 1 any idea on how to deal with that? Thank you
KinSimon96 commented 3 years ago

Hello @EAC-T , Seems like it's an error message from ggplot2 package, you should look at your df in order to see if you don't have weird/NA values or something else.

Can't reproduce your error, sorry.