Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • crazyhottommy
    Senior Member
    • Apr 2012
    • 187

    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....



    I am confused.....

    Thanks for your advice.

    Tommy Tang
  • Simon Anders
    Senior Member
    • Feb 2010
    • 995

    #2
    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).

    Comment

    • crazyhottommy
      Senior Member
      • Apr 2012
      • 187

      #3
      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!

      Comment

      • sindrle
        Senior Member
        • Aug 2013
        • 266

        #4
        I just get this error....

        hc <- as.hclust( hm$rowDendrogram )
        Error: all(vapply(s, is.integer, NA)) is not TRUE

        Comment

        • frymor
          Senior Member
          • May 2010
          • 151

          #5
          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
          Last edited by frymor; 05-26-2014, 12:26 AM.

          Comment

          • zzta
            Junior Member
            • Dec 2013
            • 5

            #6
            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>

            Comment

            • crazyhottommy
              Senior Member
              • Apr 2012
              • 187

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


              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>

              Comment

              Latest Articles

              Collapse

              • SEQadmin2
                Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                by SEQadmin2



                Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                Today, 05:17 AM
              • GATTACAT
                Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                by GATTACAT
                Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
                07-01-2026, 11:43 AM
              • SEQadmin2
                Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                by SEQadmin2


                I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

                Here are nine questions we think about, in roughly the order they matter, before...
                06-18-2026, 07:11 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, Today, 10:08 AM
              0 responses
              6 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, Yesterday, 11:05 AM
              0 responses
              8 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-02-2026, 11:08 AM
              0 responses
              31 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-30-2026, 05:37 AM
              0 responses
              28 views
              0 reactions
              Last Post SEQadmin2  
              Working...