In WGCNA, how to perform block-wise network construction but show the results using only 1 graph (1 dendrogram)?
1
1
Entering edit mode
5.9 years ago

Hi there! is it possible to construct Block-wise networks in WGCNA and then show a continuous dendrogram for all genes?

Cheers!

wgcna blockwise network construction • 3.5k views
ADD COMMENT
1
Entering edit mode
5.9 years ago

Please show the code that you have used so far, and provide any figure output? Do you have an example of a 'continuous dendrogram'?

ADD COMMENT
1
Entering edit mode

Thank you for your response. I enclose a reproducible code below:

library(WGCNA)
options(stringsAsFactors = FALSE)
n.genes = 200
n.samples=50
set.seed(0)
 set.seed(0)
expr= matrix(rnorm (n.samples*n.genes), n.samples)
expr [,20:30]= expr[,30]
expr [,120:130]= expr[,120]
colnames(expr)= paste0('gene', 1:n.genes)
rownames (expr)=  paste0('sample', 1:n.samples)
powers = c(c(1:10), seq(from = 12, to=30, by=4))
sft = pickSoftThreshold(expr, powerVector = powers, verbose = 5)
pwr= min( sft$fitIndices[,1][-sign(sft$fitIndices[,3])*sft$fitIndices[,2]>0.4])
net=blockwiseModules(expr, power = pwr,  TOMType = "unsigned", minModuleSize = 5, #for testing reasons of this simulation
                       reassignThreshold = 0,mergeCutHeight = 0.25,numericLabels = TRUE,
              maxBlockSize= 80,# for this simulation we'll have around 3 nets.
              pamRespectsDendro = FALSE,saveTOMs = TRUE,saveTOMFileBase = "PETOM",verbose = 3)
moduleLabels = net$colors 
moduleColors = labels2colors(net$colors) 
MEs = net$MEs 
geneTree = net$dendrograms[[1]] 

plotDendroAndColors(net$dendrograms[[1]], moduleColors[net$blockGenes[[1]]],
            "Module colors", 
                    dendroLabels = F, hang = 0.03,

                    addGuide = TRUE, guideHang = 0.05)
dev.new()
plotDendroAndColors(net$dendrograms[[2]], moduleColors[net$blockGenes[[2]]],
            "Module colors", #
                    dendroLabels = F, hang = 0.03,
                    addGuide = TRUE, guideHang = 0.05)
dev.new()
plotDendroAndColors(net$dendrograms[[3]], moduleColors[net$blockGenes[[3]]],
            "Module colors", 
                    dendroLabels = F, hang = 0.03,
                    addGuide = TRUE, guideHang = 0.05)

I want to put the last 3 plot in one and i used

plotDendroAndColors (hclust (dist(t(expr))), moduleColors)

which seems correct to me but I still doubt I have coded correctly. perhaps somewhere I should use

 match (hclust (dist(t(expr)))$order, net$dendrograms[[1]]$order)

or something like that.

Cheers!

ADD REPLY
1
Entering edit mode

You edited the post since I last looked. You mentioned there being only 1 module? If there was only 1 module, then your data may be quite 'flat'. How does it look on a histogram?

Is the issue that you just want to plot the dendrograms in the same plot window?

ADD REPLY
0
Entering edit mode

You are right. There are 3 modules in my simulated data. My issue is that visualizing block-wise networks sing plotDendroAndColors should be done for networks separately and one does not obtain a one-glance image of data.

ADD REPLY
1
Entering edit mode

Does passing mfrow to par() not work for the purpose of plotting these? It usually works for hclust / dendrogram objects.

For example:

par(mfrow=c(1,3))

plot(d1)
plot(d2)
plot(d3)
ADD REPLY
0
Entering edit mode

Thank you for your time and comments. I cant get par(mfrow=c(1,3)) working: (after appending this code to the code above):

par(mfrow= c(1,length(net$blockGenes)))
for (i in 1:length (net$blockGenes)) {

plotDendroAndColors(net$dendrograms[[i]], moduleColors[net$blockGenes[[i]]],
            "Module colors", 
                    dendroLabels = F, hang = 0.03,
                    addGuide = TRUE, guideHang = 0.05)

}
ADD REPLY
1
Entering edit mode

Yeh, the problem is that the plotDendroAndColors() is a WGCNA function that manipulates the usage of par(), overriding your own usage of par() and mfrow.

If you just type plotDendroAndColors at the command prompt, you can see the code for this function. You can either edit this code and override the function or plot the dendrograms with just:

plot(net$dendrograms[[i]])

You do not obtain the colour bars that way, though.

Another way: Just output them on separate pages as a PDF and then merge them together into a single page using a PDF printer.

ADD REPLY
0
Entering edit mode

Thank you indeed very much. Very helpful comment.

ADD REPLY

Login before adding your answer.

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