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

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, 06-05-2026, 10:09 AM
              0 responses
              10 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-04-2026, 08:59 AM
              0 responses
              22 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-02-2026, 12:03 PM
              0 responses
              28 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-02-2026, 11:40 AM
              0 responses
              22 views
              0 reactions
              Last Post SEQadmin2  
              Working...