Extracting hierarchical clustering pattern of the genes from heatmap
1
0
Entering edit mode
9.5 years ago
mjoyraj ▴ 80

I have prepared a heatmap using the log2 normalized FPKM value using the following script

alpha4 <- read.table(file.choose(), header=TRUE, sep=",")
alpha5 <- as.matrix(alpha4)
alpha6 <- t(alpha5)

library(gplots)

pdf("Rdataoutput1.pdf")
heatmap.2((alpha6), trace="none", scale="row", density.info="none", col=redblue(2766))
dev.off()

I got the heatmap like this

Next, I want to extract the exact hierarchical clustering pattern of the genes as in the heatmap and obtain cluster, for which I used the following script

hc <- hclust(dist(alpha6))

pdf("test_clustering_tree1.pdf")
plot(hc)
clusters_name <- cutree(hc, h=20)
rect.hclust(hc, h=20)
dev.off()

with the scripts, I obtained the below given hierarchical pattern. My question is did I extracted the same hierarchical clustering pattern of the genes as in the heatmap?

R • 5.0k views
ADD COMMENT
0
Entering edit mode

Sorry, the images did not came.

ADD REPLY
0
Entering edit mode

You have to upload the images elsewhere and link to them.

ADD REPLY
0
Entering edit mode

If you give your mail ID, I can send the images..

ADD REPLY
2
Entering edit mode
9.5 years ago
alolex ▴ 960

Hello,

I don't think I need to see the images to know what your asking, as I had the same question a while ago. The problem is that heatmap.2 does it's own clustering, which can be displayed different from hclust (although not always). To prevent possible discrepancies in the figures you need to reverse your order of operations. Do hclust FIRST, then pass that object to heatmap.2 like such:

hc <- hclust(dist(alpha6))
heatmap.2((alpha6), Colv=as.dendrogram(hc), trace="none", scale="row", density.info="none", col=redblue(2766))

Notice the added Colv parameter. If it is the rows you want, then use Rowv instead. If it is a symmetrical square matrix (like a correlation matrix), you can pass the same hclust object to both Rowv and Colv at the same time. This way you ensure the order the data is displayed with heatmap.2 is the same as what hclust produces. In addition, you can also use the ColSideColors and RowSideColors to indicate the clusters as a color bar under the dendrogram, but you'll have to make a vector of colors based off of the cutree object.

ADD COMMENT
0
Entering edit mode

Thanks for the important suggestion. I made the dendrogram and obtained the cluster with the following script given below. Accordingly I have 40 clusters. How can I include the same 40 cluster info in the heatmap using ColSideColors or RowSideColors?

hc <- hclust(dist(alpha6))
pdf("clustering_tree1.pdf")
plot(hc)
clusters_name <- cutree(hc, h=20)
rect.hclust(hc, h=20)
dev.off()
ADD REPLY
0
Entering edit mode

You should be able to just pass in the following:

RowSideColors=as.character(clusters_name)

Unless you want to specify different colors other than the defaults. In that case you can use the revalue() function and pass that vector into RowSideColors or ColSideColors:

new_colors <- revalue(as.character(clusters_name), c("1"="red", "2"="purple","3"="gold","4"="white"))
ADD REPLY
0
Entering edit mode

Many thanks again....

ADD REPLY

Login before adding your answer.

Traffic: 2504 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6