SEQanswers extract dendrogram information from heatmap generated by heatmap.2
 User Name Remember Me? Password
 Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 Similar Threads Thread Thread Starter Forum Replies Last Post Saro Bioinformatics 1 02-09-2013 03:58 AM capricy Bioinformatics 2 06-20-2012 06:47 AM Chuckytah Bioinformatics 9 03-15-2012 01:51 PM akolman Bioinformatics 5 06-16-2011 12:51 PM Livi81 General 0 07-14-2010 04:07 PM

 07-25-2013, 06:22 AM #1 crazyhottommy Senior Member   Location: Gainesville Join Date: Apr 2012 Posts: 140 extract dendrogram information from heatmap generated by heatmap.2 I asked the same question in Biostar, try my luck here: Hi all, I am having a hard time to extract the corresponding subgroup members in the heatmap generated by heatmap.2 in gplots. I have looked here: http://stackoverflow.com/questions/1...lustering-in-r and http://stackoverflow.com/questions/1...s-hierarchical and here https://stat.ethz.ch/pipermail/bioco...er/020521.html I have a matrix m, the heatmap can be generated by heatmap.2(m, colv=FALSE, dendrogram= "row", trace="none") it gave me very good looking heatmap, now I want to extract the subgroup members. I know I can use hclust and cutree to extract the information: hc.rows<- hclust(dist(m)) plot(hc.rows) # it gives me just the dendrogram, and it looks the same as the dendrogram appeared in the heatmap, only differ in the order. it seems to me the order is reversed. I can cut the tree based on either the number of group (k), or the height (h) ct<- cutree(hc.rows, h=10) # it gives me 6 groups rect.hclust(hc.rows, h=10) # draw red rectangles to mark the subgroups table(ct) ct 1 2 3 4 5 6 196 248 294 119 42 4 I can get the labels of each row, and the assigned the group number by: tableclust<- data.frame(m,ct) my question is that how do I map the cluster number here back to the dendrogram? cluster 6 has 4 members, but it looks like to me cluster 6 appears in the most left of the dendrogram, cluster 5 has 42 members, it appears in the second most left (based on the width of the red rectangle in the dendrogram), cluster 4 has 119 members, but it appears not next to cluster 5.... http://i43.tinypic.com/2hhktw9.png I am confused..... Thanks for your advice. Tommy Tang
 07-25-2013, 06:59 AM #2 Simon Anders Senior Member   Location: Heidelberg, Germany Join Date: Feb 2010 Posts: 994 Try this: Code: ```hm <- heatmap.2( m ) hc <- as.hclust( hm\$rowDendrogram ) cutree( hc, h=10 )``` The trick is that heatmap.2 returns an (invisible) list that contains an element "rowDendrogram" which you can feed to cutree (after converting it from a dendrogram object to an hclust object).
07-25-2013, 07:25 AM   #3
crazyhottommy
Senior Member

Location: Gainesville

Join Date: Apr 2012
Posts: 140

Quote:
 Originally Posted by Simon Anders Try this: Code: ```hm <- heatmap.2( m ) hc <- as.hclust( hm\$rowDendrogram ) cutree( hc, h=10 )``` The trick is that heatmap.2 returns an (invisible) list that contains an element "rowDendrogram" which you can feed to cutree (after converting it from a dendrogram object to an hclust object).
Thanks Simon!
I did not know that I can convert the dendrogram object to hclust object.

however, I can do the reverse way:
hc<- hclust(dist(m))
rowDend<- as.dendrogram(hc)
heatmap.2(m, Rowv=rowDend, colv=FALSE, dendrogram="row")

Anyway, I figured out I can get the cluster members using:
cutree(hc, h=10) [hc\$order]

in this way, I put the rows in the same cluster together, and the order is the same as appear in the heatmap. right?

Many thanks!

 04-25-2014, 10:21 AM #4 sindrle Senior Member   Location: Norway Join Date: Aug 2013 Posts: 266 I just get this error.... hc <- as.hclust( hm\$rowDendrogram ) Error: all(vapply(s, is.integer, NA)) is not TRUE
05-26-2014, 01:09 AM   #5
frymor
Senior Member

Location: Germany

Join Date: May 2010
Posts: 150

I am getting the same error massage.

I have tried the example from here and it works great.
Also when I am trying to do it the way crazyhottommy did, it also works

But when I try my data I get the same error message as sindrle.

I have tried several subsets of my data and got partial success. I uploaded here a subset of my data (subset.txt), where I get the same error message as well as the heatmap resulted from this data set.

This is what I tried:
mydata <- as.matrix(read.delim2("subset.txt", row.names=1, quote=""))
mydata <- apply(mydata, 2, as.numeric)
test <- heatmap.2(mydata)
dend <- as.hclust( test\$rowDendrogram )

But I get this error:
Code:
`Error: all(vapply(s, is.integer, NA)) is not TRUE`
Can it be, that the error happens due to the fact, that some of the genes (at a certain level) don't belong to any cluster at all?
Or maybe because a lot of the values are '0'?

Thanks
Assa

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] gplots_2.13.0

loaded via a namespace (and not attached):
[1] bitops_1.0-6 caTools_1.17 gdata_2.13.3 gtools_3.4.0
[5] KernSmooth_2.23-12 tools_3.1.0
Attached Files
 Rplots.pdf (8.0 KB, 20 views)

Last edited by frymor; 05-26-2014 at 01:26 AM.

 11-20-2014, 10:45 AM #6 zzta Junior Member   Location: Hong Kong Join Date: Dec 2013 Posts: 5 Tried getting dendrogram but no success Dear all, Sorry for reviving the thread, but I have plotted a heat map and was proceeding to tree-cutting. But the value rowDendrogram was no where to be found when I did: Code: ```> hm <- heatmap.2(log_tmm_selected_var_norm[,c(1,7,8,13)], scale='row', trace='none', col=redgreen(225)) > hm\$rowDendrogram NULL > hc <- as.hclust(hm\$rowDendrogram) Error in as.hclust.default(hm\$rowDendrogram) : argument 'x' cannot be coerced to class "hclust"character(0)``` I am not experienced with R and I keep getting this error. @@ I thought by default the dendrogram will be calculated for both rows and columns (that is why I see them on the device) but the value is absent.
11-24-2014, 10:45 AM   #7
crazyhottommy
Senior Member

Location: Gainesville

Join Date: Apr 2012
Posts: 140

Just try to plot the heatmap, do not assign it to hm. Do you see a heatmap?

Quote:
 Originally Posted by zzta Dear all, Sorry for reviving the thread, but I have plotted a heat map and was proceeding to tree-cutting. But the value rowDendrogram was no where to be found when I did: Code: ```> hm <- heatmap.2(log_tmm_selected_var_norm[,c(1,7,8,13)], scale='row', trace='none', col=redgreen(225)) > hm\$rowDendrogram NULL > hc <- as.hclust(hm\$rowDendrogram) Error in as.hclust.default(hm\$rowDendrogram) : argument 'x' cannot be coerced to class "hclust"character(0)``` I am not experienced with R and I keep getting this error. @@ I thought by default the dendrogram will be calculated for both rows and columns (that is why I see them on the device) but the value is absent.