Question: Extracting hierarchical clustering pattern of the genes from heatmap
0
gravatar for mjoyraj
4.5 years ago by
mjoyraj50
Taiwan
mjoyraj50 wrote:

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 • 2.9k views
ADD COMMENTlink modified 4.5 years ago by alolex900 • written 4.5 years ago by mjoyraj50

Sorry, the images did not came.

ADD REPLYlink written 4.5 years ago by mjoyraj50

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

ADD REPLYlink written 4.5 years ago by Devon Ryan92k

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

ADD REPLYlink written 4.5 years ago by mjoyraj50
2
gravatar for alolex
4.5 years ago by
alolex900
United States
alolex900 wrote:

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 COMMENTlink written 4.5 years ago by alolex900

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 REPLYlink written 4.5 years ago by mjoyraj50

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 REPLYlink written 4.5 years ago by alolex900

Many thanks again....

ADD REPLYlink written 4.5 years ago by mjoyraj50
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1677 users visited in the last hour