dendogram in R
0
0
Entering edit mode
4.7 years ago
parinv ▴ 80

I am following the WGCNA tutorial by Peter Langfelder and Steve Horvath. In Step-by-step network construction and module detection (2b), I am getting an error in the Merging of modules whose expression profiles are similar.

     # Calculate eigengenes
MEList = moduleEigengenes(datExpr, 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 = "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(datExpr, dynamicColors, cutHeight = MEDissThres, verbose = 3)
# The merged module colors
mergedColors = merge$colors;
# Eigengenes of the new merged modules:
mergedMEs = merge$newMEs;
sizeGrWindow(12, 9)

#pdf(file = "Plots/geneDendro-3.pdf", wi = 9, he = 6)

    plotDendroAndColors(geneTree, cbind(dynamicColors, mergedColors),
    c("Dynamic Tree Cut", "Merged dynamic"),
    dendroLabels = FALSE, hang = 0.03,
    addGuide = TRUE, guideHang = 0.05)

In the final step for dendrogram, I'm facing an error:

Error in plotOrderedColors(dendro$order, colors = colors, rowLabels = rowLabels, : ERROR: length of colors vector not compatible with number of objects in 'order'.

Can anyone help with this error? Thank you.

R • 1.9k views
ADD COMMENT
1
Entering edit mode

According to the error, you have different number of factor levels in dendro$order and in the color vector. This is, that you are either supplying too few or too many colors. Check that the length of both vectors is the same.

Hope you are able to fix it!

Jordi

ADD REPLY
0
Entering edit mode

Did it work for you? Have you been able to solve the error? If you have, then bookmark the answer and close the question.

ADD REPLY
0
Entering edit mode

Closing the question is not the correct way to do this. If @parinv confirms that your advice solved their problem then one of the mods can move your comment to answer. It can then be accepted by @parinv to provide closure to this thread.

ADD REPLY
0
Entering edit mode

That's what I meant with "If you have..." part

ADD REPLY
0
Entering edit mode

Thank you for your reply,

  • Length of both the vectors are not same. What should i do to make it same?

  • Also I found problem in the other command:

    dynamicMods = cutreeDynamic(dendro = geneTree, distM = NULL, method = "hybrid", deepSplit = 2, pamRespectsDendro = FALSE, minClusterSize = minModuleSize,) it gives warning:

Warning message: In cutreeDynamic(dendro = geneTree, distM = NULL, method = "hybrid", : cutreeDynamic: method "hybrid" requires a valid dissimilarity matrix "distM". Defaulting to method "tree"

can you suggest what can help here?

ADD REPLY
1
Entering edit mode

Length of both the vectors are not same. What should i do to make it same?

Please trace back through your code, line by line, in order to understand what might be happening to result in the discrepancy in length between these objects.

Also I found problem in the other command:

Can you confirm that you are following the WGCNA tutorial, please?

ADD REPLY

Login before adding your answer.

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