SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
cummeRbund-heatmap-dendrogram? Saro Bioinformatics 1 02-09-2013 02:58 AM
heatmap and heatmap.2 capricy Bioinformatics 2 06-20-2012 05:47 AM
R - problem in heatmap reading Chuckytah Bioinformatics 9 03-15-2012 12:51 PM
R: heatmap color palette akolman Bioinformatics 5 06-16-2011 11:51 AM
'heatmap' tool Livi81 General 0 07-14-2010 03:07 PM

Reply
 
Thread Tools
Old 07-25-2013, 05:22 AM   #1
crazyhottommy
Senior Member
 
Location: Gainesville

Join Date: Apr 2012
Posts: 140
Default 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
crazyhottommy is offline   Reply With Quote
Old 07-25-2013, 05:59 AM   #2
Simon Anders
Senior Member
 
Location: Heidelberg, Germany

Join Date: Feb 2010
Posts: 994
Default

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).
Simon Anders is offline   Reply With Quote
Old 07-25-2013, 06:25 AM   #3
crazyhottommy
Senior Member
 
Location: Gainesville

Join Date: Apr 2012
Posts: 140
Default

Quote:
Originally Posted by Simon Anders View Post
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!
crazyhottommy is offline   Reply With Quote
Old 04-25-2014, 09:21 AM   #4
sindrle
Senior Member
 
Location: Norway

Join Date: Aug 2013
Posts: 266
Default

I just get this error....

hc <- as.hclust( hm$rowDendrogram )
Error: all(vapply(s, is.integer, NA)) is not TRUE
sindrle is offline   Reply With Quote
Old 05-26-2014, 12:09 AM   #5
frymor
Senior Member
 
Location: Germany

Join Date: May 2010
Posts: 149
Default

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
File Type: pdf Rplots.pdf (8.0 KB, 20 views)

Last edited by frymor; 05-26-2014 at 12:26 AM.
frymor is offline   Reply With Quote
Old 11-20-2014, 09:45 AM   #6
zzta
Junior Member
 
Location: Hong Kong

Join Date: Dec 2013
Posts: 5
Default 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.

<confused>
zzta is offline   Reply With Quote
Old 11-24-2014, 09:45 AM   #7
crazyhottommy
Senior Member
 
Location: Gainesville

Join Date: Apr 2012
Posts: 140
Default

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


Quote:
Originally Posted by zzta View Post
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.

<confused>
crazyhottommy is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 04:58 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO