WGCNA Concise Guide | 3. Network Visualization with WGCNA

WGCNA Concise Guide | 3. Network Visualization with WGCNA

WGCNA series

  1. WGCNA Concise Guide | 1. Gene Coexpression Network Construction and Module Identification

  2. WGCNA Concise Guide | 2. Module-Trait Association Analysis and Identification of Important Genes


The basic tutorial of WGCNA has come to an end here, and will be explained in practice with examples in published articles. Friends who need all the code and sample data of the basic tutorial can do 点赞+在看,并转发朋友圈集赞10个it 赞赏10元.

  • WGCNA series

  • reference

  • data preparation

  • Visualizing Networks in R

    • Visualizing gene networks

    • eigengenes network visualization

  • Export network data to network visualization software

    • Export to Cytoscape

  • Past

reference

This article mainly refers to the official guide Tutorials for WGCNA R package (ucla.edu). For details, please refer to the official documentation.

Other information:

  1. WGCNA - Anthology - Jianshu (jianshu.com)

  2. WGCNA analysis, the latest simple and comprehensive tutorial - short book (jianshu.com)

  3. WGCNA: (weighted co-expression network analysis) - bioprogrammer - CSDN blog

  4. How does WGCNA mine key genes from modules - Programmer Sought

data preparation

  1. WGCNA Concise Guide | 1. Gene Coexpression Network Construction and Module Identification

  2. WGCNA Concise Guide | 2. Module-Trait Association Analysis and Identification of Important Genes

Visualizing Networks in R

Visualizing gene networks

# 模块检测时的计算,重新算一次
dissTOM = 1-TOMsimilarityFromExpr(datExpr, power = 6);
# 对dissTOM进行power转换,使中等强度的连接在热图中更加明显
plotTOM = dissTOM^7;
# 设置对角线为NA以得到更好的图
diag(plotTOM) = NA;
# 绘图
sizeGrWindow(9,9)
TOMplot(plotTOM, geneTree, moduleColors, main = "Network heatmap plot, all genes")
9131d31d9fc57a445ad7b944ee6a7658.png
Figure 1: Displaying gene networks using heatmaps. The heatmap depicts the topological overlap matrix (TOM) of all genes in the analysis. Light colors represent low overlap, and progressively darker reds represent high overlap. The dark blocks along the diagonal are the modules. The gene dendrogram and module assignments are also shown on the left and at the top.

Partial gene visualization TOM matrix

Generating a heatmap for all genes can take a significant amount of time. The number of genes can be limited to speed up the plot. However, a gene dendrogram for a subset of genes often looks different from a gene dendrogram for all genes. In the example below, the number of genes plotted is limited to 400.

nSelect = 400
# 为了可重复,设置随机数种子
set.seed(10);
select = sample(nGenes, size = nSelect);
selectTOM = dissTOM[select, select];
# 没有简单的方法将聚类树限制在基因的一个子集,所以我们必须重新聚类
selectTree = hclust(as.dist(selectTOM), method = "average")
selectColors = moduleColors[select];
# 绘制
sizeGrWindow(9,9)
plotDiss = selectTOM^7;
diag(plotDiss) = NA;
TOMplot(plotDiss, selectTree, selectColors, main = "Network heatmap plot, selected genes")
706aa4c3e77d801b600569469b694d53.png
Figure 2: Partial gene visualization TOM matrix

eigengenes network visualization

# 重新计算模块 eigengenes
MEs = moduleEigengenes(datExpr, moduleColors)$eigengenes
# 提取临床特征weight
weight = as.data.frame(datTraits$weight_g);
names(weight) = "weight"
# 在eigengenes模块中加入临床特征weight
MET = orderMEs(cbind(MEs, weight))
# 绘制eigengenes和临床特征weight之间的关系图
sizeGrWindow(5,7.5);
par(cex = 0.9)
plotEigengeneNetworks(MET, "", 
                      marDendro = c(0,4,1,2), 
                      marHeatmap = c(3,4,1,2), 
                      cex.lab = 0.8, xLabelsAngle= 90)
# 分别绘制                      
# 绘制树状图
sizeGrWindow(6,6);
par(cex = 1.0)
plotEigengeneNetworks(MET, "Eigengene dendrogram", marDendro = c(0,4,2,0),
                      plotHeatmaps = FALSE)
# 绘制热图
par(cex = 1.0)
plotEigengeneNetworks(MET, "Eigengene adjacency heatmap", marHeatmap = c(3,4,2,2),
                      plotDendrograms = FALSE, xLabelsAngle = 90)
5d9493b8cecab4e31a5ebb58d29e9e0b.png
Hierarchical clustering dendrogram of eigengenes eigengenes. The dendrogram shows that the red, brown and blue modules are highly correlated, and their correlation is stronger than their correlation with weight.
61b2acc091a47c3bd431ed7e8e456516.png
Correlation heatmap.

Export network data to network visualization software

Export to Cytoscape

# Recalculate topological overlap if needed
TOM = TOMsimilarityFromExpr(datExpr, power = 6);
# Read in the annotation file
annot = read.csv(file = "GeneAnnotation.csv");
# 以红色和棕色模块为例
modules = c("brown", "red");
# Select module probes
probes = names(datExpr)
inModule = is.finite(match(moduleColors, modules));
modProbes = probes[inModule];
modGenes = annot$gene_symbol[match(modProbes, annot$substanceBXH)];
# Select the corresponding Topological Overlap
modTOM = TOM[inModule, inModule];
dimnames(modTOM) = list(modProbes, modProbes)
# Export the network into edge and node list files Cytoscape can read
cyt = exportNetworkToCytoscape(modTOM,
                               edgeFile = paste("CytoscapeInput-edges-", paste(modules, collapse="-"), ".txt", sep=""),
                               nodeFile = paste("CytoscapeInput-nodes-", paste(modules, collapse="-"), ".txt", sep=""),
                               weighted = TRUE,
                               threshold = 0.02,
                               nodeNames = modProbes,
                               altNodeNames = modGenes,
                               nodeAttr = moduleColors[inModule]);

cytThere are edgesum nodedata, which can be imported cytoscapefor visualization.

Past

  1. Mapping with Nature | Paired Dumbbell Plot + Grouped Fitting Curve + Categorical Variable Heat Map

  2. (Free Tutorial + Code Collection)|Follow Cell to Learn Drawing Series Collection

  3. Follow Nat Commun to learn to draw | 1. Batch boxplot + scatter + difference analysis

  4. Follow Nat Commun to learn to draw | 2. Timeline graph

  5. Follow Nat Commun to learn to map | 3. Species abundance stacking histogram

  6. Follow Nat Commun to learn to draw | 4. Paired boxplot + difference analysis


Guess you like

Origin blog.csdn.net/weixin_45822007/article/details/122206982