Plotting an hclust sub-tree in WGCNA?
1
0
Entering edit mode
Keith Hughitt ▴ 150
@keith-hughitt-6740
Last seen 5 weeks ago
United States

Hello,

Does anyone know of a way to breakup the result of a call to hclust in order to generate new hclust instances representing sub-trees within the original result?

I would like to be able to take a large dendrogram resulting from a call to hclust, and split it up into smaller partitions to focus on specific parts of the sub-tree. The first step in that direction would be to split the tree in half and plot each sub-tree separately.

Based on some other helpful posts (e.g. [here](http://stackoverflow.com/questions/3033261/is-there-a-way-to-get-a-subtree-from-hclust-r) and [here](http://stackoverflow.com/questions/18789059/r-plot-smaller-clusters-from-hclust)), I can now split the main dendrogram into two sub-trees and plot those as dendrograms, e.g.:

   # full tree
​   hc = hclust(dist(iris[,-5]))

   plot(hc)

   # cast to dendro and get two primary sub-trees
   dendro = as.dendrogram(hc)

   left_branch  = dendro[[1]]
   right_branch = dendro[[2]]

   plot(left_branch)
   plot(right_branch)


The problem arises, however, when I try and pass these new sub-trees back to plotDendroAndColors:

For example:

    library(WGCNA)
    colors = rep('blue', nrow(iris))

    # plotting the full tree works fine
    plotDendroAndColors(hc, colors)

    # this does not work, however
    hc_left = as.hclust(left_branch)
    plotDendroAndColors(hc_left, colors[1:length(hc_left$order)])

The result of the above call is the error:

    Error in graphics:::plotHclust(n, merge, height, order(x$order), hang,  : 
      invalid dendrogram input
    Calls: plotDendroAndColors -> plot -> plot -> plot.hclust -> <Anonymous>

 

Anyone know of a way around this?

System info:

R version 3.1.1 (2014-07-10)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] WGCNA_1.41-1        flashClust_1.01-2   dynamicTreeCut_1.62 setwidth_1.0-3     
[5] colorout_1.0-3     

loaded via a namespace (and not attached):
 [1] acepack_1.3-3.3     cluster_1.15.2      codetools_0.2-8     doParallel_1.0.8   
 [5] foreach_1.4.2       foreign_0.8-61      Formula_1.1-2       grid_3.1.1         
 [9] Hmisc_3.14-5        impute_1.38.1       iterators_1.0.7     lattice_0.20-29    
[13] latticeExtra_0.6-26 matrixStats_0.10.0  nnet_7.3-8          parallel_3.1.1     
[17] plyr_1.8.1          RColorBrewer_1.0-5  Rcpp_0.11.2         reshape_0.8.5      
[21] R.methodsS3_1.6.1   rpart_4.1-8         splines_3.1.1       survival_2.37-7 

 

wgcna hclust plotdendroandcolors dendrogram • 2.7k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 13 hours ago
United States

This really isn't a Bioconductor question, and you should ask on R-help instead. The problem has nothing to do with WGCNA, and comes up in an internal function within plot.hclust() (graphics:::plotHclust, FWIW), which really doesn't like the re-formed hclust object you are feeding to it. I have to imagine that taking just a portion of a dendrogram and feeding that to as.hclust.dendrogram() is not something that was envisioned for that function, and the resulting hclust object is borked in some way.

When running your code on both Linux and Windows I get segfaults more often than not, and if I get an error, it is different from the one you report (I get an error about passing the wrong kind of CHARSXP to the underlying C code when I don't get a segfault).

ADD COMMENT

Login before adding your answer.

Traffic: 362 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6