This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Differential analysis heatmap without hclust

Hello,

I did a differential analysis between 160 tumor and 90 normal samples. I'm using edgeR package. I used the following code to make a differential analysis heatmap. I selected differential expressed genes based on FC > 2 and FDR < 0.05. This gave me 614 DEGs.

logCPM <- cpm(y, prior.count=2, log=TRUE)
o <- order(tr$table$PValue)
logCPM <- logCPM[o[1:614],] 
logCPM <- t(scale(t(logCPM)))
dim(logCPM)

library(matrixStats)
library(gplots)
library(ComplexHeatmap)
library(circlize)
library(RColorBrewer)

#Set annotation
ann <- data.frame(TvsN$Type)
colnames(ann) <- c("Type")
colours <- list("Type"=c("Tumor"="black","Normal"="brown"))
colAnn <- HeatmapAnnotation(df=ann, which="col", col=colours, annotation_width=unit(c(1, 4), "cm"), gap=unit(1, "mm"))

myCol <- colorRampPalette(c("navyblue", "white", "red"))(100)
myBreaks <- seq(-2,2, length.out=100)
hmap <- Heatmap(logCPM, name = "Z-Score",  col = colorRamp2(myBreaks, myCol), 
                show_row_names = FALSE, show_column_names = FALSE, cluster_rows = TRUE,
                cluster_columns = TRUE, show_column_dend = FALSE, show_row_dend = TRUE,
                row_dend_reorder = TRUE, column_dend_reorder = TRUE, clustering_method_rows = "ward.D2",
                clustering_method_columns = "ward.D2", width = unit(100, "mm"),
                top_annotation=colAnn)
draw(hmap, heatmap_legend_side="left", annotation_legend_side="right")

The heatmap was made using complex heatmap like above. I see that DEGs showing samples are clustered.

![heatmap][1]

I wanted to select 614 DEGs and sort the samples acc to their Type without using hclust like above. May I know how to do this?

thanq

rna-seq heatmap complexheatmap r hclust

2 answers

Read the docs about clustering in ComplexHeatmap. You can suppress clustering (and provide the data in the order you want) or give a custom clustering function or precomputed dendrogram.

In your case it would be cluster_rows which needs to be set to FALSE as by default it is TRUE and then uses Complete linkeage to cluster the rows. As Jean-Karim Heriche says, please read the manual, it is outstandingly comprehensive with an example plot for like every possible option.

You can do this in dittoSeq. dittoHeatmap() will even automatically grab the proper genes data subset and automaatically generate metadata annotations.

# Import full dataset from edgeR DGEList to the format dittoSeq understands
RNAdata <- importDittoBulk(your_DGEList_object)

# If your `type` data was stored within the DGEList, it might be imported automatically
# but to give example code if not...
# Adding the 'Type' metadata
RNAdata$Type <- types_data

# Make the heatmap
dittoHeatmap(
    object = RNAdata,
    genes = DEG.genes,
    annot.by = "Type",
    order.by = "Type",
    cluster_cols = FALSE)

Note on dittoSeq installation: If you are in R 4.0, you can install through Bioconductor with BiocManager::install("dittoSeq"). If not, you can still install it via the github (I have tested myself for R≥3.6.2, but this method should let you install in any R version.) BiocManager::install("dtm2451/dittoSeq")

Additional tweaks to the plot can be made by providing additional ?dittoHeatmap or ?pheatmap inputs, but the above code should accomplish the goals that you mention here.

Log in to answer this question.