Hi,
I am getting this error while running TOMplot.
TOMplot(plotTOM, geneTree, moduleColors, main = "Network heatmap plot, all genes") Error in .heatmap(as.matrix(dissim), Rowv = as.dendrogram(dendro, hang = 0.1), : row dendrogram ordering gave index of wrong length
geneTree and plotTOM were made exactly the way as described in the manual https://labs.genetics.ucla.edu/horvath/CoexpressionNetwork/Rpackages/WGCNA/Tutorials/index.html
Here is the complete code: library(WGCNA) femData = read.csv("lg2FPKM.csv"); dim(femData); names(femData); datExpr0 = as.data.frame(t(femData[, -1])) names(datExpr0) = femData$substanceBXH; rownames(datExpr0) = names(femData)[-1]; gsg = goodSamplesGenes(datExpr0, verbose = 3); gsg$allOK sampleTree = hclust(dist(datExpr0), method = "average"); # Plot the sample tree: Open a graphic output window of size 12 by 9 inches # The user should change the dimensions if the window is too large or too small. sizeGrWindow(12,9) #pdf(file = "Plots/sampleClustering.pdf", width = 12, height = 9); par(cex = 0.6); par(mar = c(0,4,2,0)) plot(sampleTree, main = "Sample clustering to detect outliers", sub="", xlab="", cex.lab = 1.5, cex.axis = 1.5, cex.main = 2) Plot a line to show the cut abline(h = 15, col = "red"); # Determine cluster under the line clust = cutreeStatic(sampleTree, cutHeight = 15, minSize = 10) table(clust) # clust 1 contains the samples we want to keep. keepSamples = (clust==0) datExpr = datExpr0[keepSamples, ] nGenes = ncol(datExpr) nSamples = nrow(datExpr) traitData = read.csv("ClinicalTraits.csv"); dim(traitData) names(traitData) #allTraits = traitData[, -c(31, 16)]; allTraits = traitData[, c(2, 3,4) ]; dim(allTraits) names(allTraits) femaleSamples = rownames(datExpr); traitRows = match(femaleSamples, allTraits$Pig); datTraits = allTraits[traitRows, -1]; rownames(datTraits) = allTraits[traitRows, 1]; collectGarbage() # Re-cluster samples sampleTree2 = hclust(dist(datExpr), method = "average") # Convert traits to a color representation: white means low, red means high, grey means missing entry traitColors = numbers2colors(datTraits, signed = FALSE); # Plot the sample dendrogram and the colors underneath. plotDendroAndColors(sampleTree2, traitColors, groupLabels = names(datTraits), main = "Sample dendrogram and trait heatmap") lnames = load(file = "FemaleLiver-01-dataInput.RData"); lnames powers = c(c(1:10), seq(from = 12, to=20, by=2)) # Call the network topology analysis function sft = pickSoftThreshold(datExpr, powerVector = powers, verbose = 5) # Plot the results: sizeGrWindow(9, 5) par(mfrow = c(1,2)); cex1 = 0.9; # Scale-free topology fit index as a function of the soft-thresholding power plot(sft$fitIndices[,1], -sign(sft$fitIndices[,3])*sft$fitIndices[,2], xlab="Soft Threshold (power)",ylab="Scale Free Topology Model Fit,signed R^2",type="n", main = paste("Scale independence")); text(sft$fitIndices[,1], -sign(sft$fitIndices[,3])*sft$fitIndices[,2], labels=powers,cex=cex1,col="red"); # this line corresponds to using an R^2 cut-off of h abline(h=0.90,col="red") # Mean connectivity as a function of the soft-thresholding power plot(sft$fitIndices[,1], sft$fitIndices[,5], xlab="Soft Threshold (power)",ylab="Mean Connectivity", type="n", main = paste("Mean connectivity")) text(sft$fitIndices[,1], sft$fitIndices[,5], labels=powers, cex=cex1,col="red") net = blockwiseModules(datExpr, power = 6, TOMType = "unsigned", minModuleSize = 30, reassignThreshold = 0, mergeCutHeight = 0.25, numericLabels = TRUE, pamRespectsDendro = FALSE, saveTOMs = TRUE, saveTOMFileBase = "femaleMouseTOM", verbose = 3) # open a graphics window sizeGrWindow(12, 9) # Convert labels to colors for plotting mergedColors = labels2colors(net$colors) # Plot the dendrogram and the module colors underneath plotDendroAndColors(net$dendrograms[[1]], mergedColors[net$blockGenes[[1]]], "Module colors", dendroLabels = FALSE, hang = 0.03, addGuide = TRUE, guideHang = 0.05) moduleLabels = net$colors moduleColors = labels2colors(net$colors) MEs = net$MEs; geneTree = net$dendrograms[[1]]; save(MEs, moduleLabels, moduleColors, geneTree, file = "FemaleLiver-02-networkConstruction-auto.RData") lnames = load(file = "FemaleLiver-01-dataInput.RData"); #The variable lnames contains the names of loaded variables. lnames # Load network data saved in the second part. lnames = load(file = "FemaleLiver-02-networkConstruction-auto.RData"); lnames enableWGCNAThreads() nGenes = ncol(datExpr) nSamples = nrow(datExpr) # Calculate topological overlap anew: this could be done more efficiently by saving the TOM # calculated during module detection, but let us do it again here. dissTOM = 1-TOMsimilarityFromExpr(datExpr, power = 6); # Transform dissTOM with a power to make moderately strong connections more visible in the heatmap plotTOM = dissTOM^7; # Set diagonal to NA for a nicer plot diag(plotTOM) = NA; # Call the plot function sizeGrWindow(9,9) TOMplot(plotTOM, geneTree, moduleColors, main = "Network heatmap plot, all genes")
Could please help me in fixing this error.
I tried looking through Search engines but it was not helpful.
Thank you
How do you build the dendrogram? How do you create the plotTOM and the geneTree?
Hi,
Please have a look at the updated question.
Have you checked the dimension of the data? I mean you seem to mix files from the tutorial and yours.
Yes, the function is certainly using my files and I did not mixed it up with the tutorial files. However, the names are same.