The gene clusters from the WGCNA dendrogram output are not in order
0
0
Entering edit mode
@df10c8f5
Last seen 9 months ago
United States

I am running WGCNA and trying to visualize the gene network as TOM plot. Rather than using the native function in the package, I am looking for plotting it out by ggplot or other packages. The main reason is I would like to also annotate the TOM plot by placing rectangles on each module found by the WGCNA.

However, I found a very hard time reproducing the plot of the native function, one of the main issues is when I trying to look for the order of genes by using the net$dendrograms[[1]]$order and also the module labels by net$color, I find that the color (or module) are not clustered together. Rather they are very scattered. Therefore, I am not sure if I can place a rectangle to bracket the modules. However, when I look at the dendrograms with module labels plotted by the native WGCNA function, the module (at least at the color level) seems clustered together. I did not use the pam options and the tree deep is set to 2, which I believe is quite conservative in defining modules.

I am confused and not sure whether I have missed something. I have also tried to reach out to the Biostars community before but the problem is not fully solved. I am here to reproduce the problem using the tutorial dataset.

library(WGCNA)
library(tidyverse)

lnames = load(file = "FemaleLiver-01-dataInput.RData"); # followed everything mentioned in the first tutorial
net = blockwiseModules(datExpr, 
                       power = 6, 
                       TOMType = "signed", 
                       minModuleSize = 30, 
                       reassignThreshold = 0, 
                       mergeCutHeight = 0.25, 
                       deepSplit = 2, 
                       pamStage = FALSE, 
                       numericLabels = TRUE, 
                       pamRespectsDendro = FALSE, 
                       saveTOMs = TRUE, 
                       saveTOMFileBase = "femaleMouseTOM", 
                       verbose = 3)

moduleLabels = net$colors # this line is not necessary for reproducing the error, but I ran it in my Rstduio
moduleColors = labels2colors(net$colors) # this line is not necessary for reproducing the error, but I ran it in my Rstduio
MEs = net$MEs; # this line is not necessary for reproducing the error, but I ran it in my Rstduio
geneTree = net$dendrograms[[1]]; # this line is not necessary for reproducing the error, but I ran it in my Rstduio

### look at the clustering of each gene/ probe
annotation_dataset <- as_tibble(net$color, rownames = "generow") %>% 
  dplyr::rename(cluster = value) %>% 
  mutate(geneorder = !!(net$dendrograms[[1]]$order)) %>% 
  arrange(geneorder)

sessionInfo( )

The output is like this

generow cluster geneorder
MMT00005210 14  1       
MMT00051382 1   2       
MMT00049262 1   3       
MMT00004428 0   4       
MMT00011541 1   5       
MMT00055921 9   6       
MMT00029144 10  7       
MMT00069114 14  8       
MMT00021297 5   9       
MMT00039882 0   10  

Here is the session information:

R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

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

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

other attached packages:
 [1] forcats_0.5.1         stringr_1.4.0         dplyr_1.0.7          
 [4] purrr_0.3.4           readr_2.1.1           tidyr_1.1.4          
 [7] tibble_3.1.6          ggplot2_3.3.5         tidyverse_1.3.0      
[10] WGCNA_1.70-3          fastcluster_1.2.3     dynamicTreeCut_1.63-1
[13] xml2_1.3.3           

loaded via a namespace (and not attached):
 [1] fs_1.5.2              matrixStats_0.61.0    lubridate_1.7.10     
 [4] bit64_4.0.5           doParallel_1.0.16     RColorBrewer_1.1-2   
 [7] httr_1.4.2            tools_4.1.2           backports_1.4.1      
[10] utf8_1.2.2            R6_2.5.1              rpart_4.1-15         
[13] Hmisc_4.6-0           DBI_1.1.2             BiocGenerics_0.34.0  
[16] colorspace_2.0-2      nnet_7.3-16           withr_2.4.3          
[19] tidyselect_1.1.1      gridExtra_2.3         bit_4.0.4            
[22] compiler_4.1.2        preprocessCore_1.50.0 cli_3.0.1            
[25] rvest_1.0.2           Biobase_2.48.0        htmlTable_2.3.0      
[28] scales_1.1.1          checkmate_2.0.0       digest_0.6.29        
[31] foreign_0.8-81        base64enc_0.1-3       jpeg_0.1-9           
[34] pkgconfig_2.0.3       htmltools_0.5.2       dbplyr_2.1.1         
[37] fastmap_1.1.0         htmlwidgets_1.5.4     rlang_0.4.12         
[40] readxl_1.3.1          rstudioapi_0.13       RSQLite_2.2.7        
[43] impute_1.62.0         generics_0.1.1        jsonlite_1.7.2       
[46] magrittr_2.0.1        GO.db_3.11.4          Formula_1.2-4        
[49] Matrix_1.3-4          Rcpp_1.0.7            munsell_0.5.0        
[52] S4Vectors_0.26.1      fansi_0.5.0           lifecycle_1.0.1      
[55] stringi_1.7.6         grid_4.1.2            blob_1.2.2           
[58] parallel_4.1.2        crayon_1.4.1          lattice_0.20-45      
[61] haven_2.4.3           splines_4.1.2         hms_1.1.1            
[64] knitr_1.37            pillar_1.6.4          codetools_0.2-18     
[67] stats4_4.1.2          reprex_2.0.1          glue_1.6.0           
[70] latticeExtra_0.6-29   data.table_1.14.2     modelr_0.1.8         
[73] png_0.1-7             vctrs_0.3.8           tzdb_0.2.0           
[76] foreach_1.5.1         cellranger_1.1.0      gtable_0.3.0         
[79] assertthat_0.2.1      cachem_1.0.6          xfun_0.29            
[82] broom_0.7.10          survival_3.2-13       iterators_1.0.13     
[85] AnnotationDbi_1.50.3  memoise_2.0.1         IRanges_2.22.2       
[88] cluster_2.1.2         ellipsis_0.3.2
Clustering WGCNA • 928 views
ADD COMMENT

Login before adding your answer.

Traffic: 668 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