softPower = 6 adjacency = adjacency(datExpr0, power = softPower) ##### Turn adjacency into topological overlap TOM = TOMsimilarity(adjacency); dissTOM = 1-TOM # Call the hierarchical clustering function geneTree = hclust(as.dist(dissTOM), method = "average"); # Plot the resulting clustering tree (dendrogram) sizeGrWindow(12,9) plot(geneTree, xlab="", sub="", main = "ES_Gene clustering on TOM-based dissimilarity", labels = FALSE, hang = 0.04) # We like large modules, so we set the minimum module size relatively high: minModuleSize = 30 # Module identification using dynamic tree cut: dynamicMods = cutreeDynamic(dendro = geneTree, distM = dissTOM, deepSplit = 2, pamRespectsDendro = FALSE, minClusterSize = minModuleSize); table(dynamicMods) # Convert numeric lables into colors dynamicColors = labels2colors(dynamicMods) table(dynamicColors) # Plot the dendrogram and colors underneath sizeGrWindow(8,6) plotDendroAndColors(geneTree, dynamicColors, "Dynamic Tree Cut", dendroLabels = FALSE, hang = 0.03, addGuide = TRUE, guideHang = 0.05, main = "ES_Gene dendrogram and module colors") dev.new() MEList = moduleEigengenes(datExpr0, colors = dynamicColors) MEs = MEList$eigengenes # Calculate dissimilarity of module eigengenes MEDiss = 1-cor(MEs); # Cluster module eigengenes METree = hclust(as.dist(MEDiss), method = "average") # Plot the result sizeGrWindow(7, 6) plot(METree, main = "ES_Clustering of module eigengenes", xlab = "", sub = "") MEDissThres = 0.25 # Plot the cut line into the dendrogram abline(h=MEDissThres, col = "red") # Call an automatic merging function merge = mergeCloseModules(datExpr0, dynamicColors, cutHeight = MEDissThres, verbose = 3) # The merged module colors mergedColors = merge$colors # Eigengenes of the new merged modules: mergedMEs = merge$newMEs table(mergedColors) sizeGrWindow(12, 9) plotDendroAndColors(geneTree, mergedColors, "Merged dynamic", dendroLabels = FALSE, hang = 0.03, addGuide = TRUE, guideHang = 0.05, main = "ES_Gene dendrogram and module colors") # Rename to moduleColors moduleColors = mergedColors # Construct numerical labels corresponding to the colors colorOrder = c("grey", standardColors(50)) moduleLabels = match(moduleColors, colorOrder)-1 MEs = mergedMEs write.table(paste(colnames(datExpr0),moduleColors,sep="\t"),file="ES_abotus_netcolorgene.xls",row.names=FALSE,quote=FALSE) # Save module colors and labels for use in subsequent parts save(adjacency,MEs, TOM, dissTOM, moduleLabels, moduleColors, geneTree, sft, file = "ES-networkConstruction-stepByStep.RData")