Subset WGCNA results for export to Cytoscape
1
3
Entering edit mode
@charlesfoster-17652
Last seen 20 days ago
Australia

Hi all,

I am trying to export my results from WGCNA for network visualisation with visANT or Cytoscape. This step requires the topological overlap matrix (TOM) to be subset. Tutorial 6 on the WGCNA page deals with this: https://horvath.genetics.ucla.edu/html/CoexpressionNetwork/Rpackages/WGCNA/Tutorials/FemaleLiver-06-ExportNetwork.pdf. I should note here that I used the blockwiseModules function to create the TOM because of the size of my RNAseq data set.

The steps in R are as follows:

# choose module
module = "green"
# get list of genes
probes = names(datExpr)
inModule = (moduleColors==module)
modProbes = probes[inModule]
# Select the corresponding Topological Overlap
modTOM = TOM[inModule, inModule]

I get the following error:

Error in TOM[inModule, inModule] : incorrect number of dimensions

Previously it was suggested that this error might be related to loading the TOM from file, in which case it is not saved as a proper similarity matrix (https://support.bioconductor.org/p/69715/). However, following the advice in that bioconductor thread leads to another error:

TOM.mat = as.matrix(TOM)
modTOM = TOM.mat[inModule, inModule]

Error in TOM.mat[inModule, inModule] : (subscript) logical subscript too long

I've also run the analysis from scratch to avoid loading the TOM, and I get the same error.

Extra info:

length(inModule)
[1] 41047
dim(TOM.mat)
[1] 12664 12664

Any thoughts on how to get around this error?

Thanks

wgcna • 5.7k views
ADD COMMENT
0
Entering edit mode

Hi Charles,

I have encountered this problem before. Can you give me the the results of dim(datExpr) and dim(TOM)?

ADD REPLY
0
Entering edit mode

Hi Andres,

Thanks for the reply. The results are:

> class(TOM)
[1] "dist"
> dim(TOM)
NULL
> length(TOM)
[1] 80182116
> dim(datExpr)
[1]    12 41047

The original command to generate the TOM was:

net = blockwiseModules(datExpr, maxBlockSize = 20000, power = 18, networkType="signed", TOMType = "signed", minModuleSize = 30,reassignThreshold = 0, mergeCutHeight = 0.25,numericLabels = TRUE, pamRespectsDendro = FALSE,saveTOMs = TRUE,saveTOMFileBase = "blockwiseTOM",verbose = 3)

This command results in three blocks being used. I THINK the as.matrix function is only working on the third block:

> length(net$blockGenes[[3]])
[1] 12664
> dim(TOM.mat)
[1] 12664 12664
ADD REPLY
1
Entering edit mode

I wasn't able to replicate your error, but I might have an alternitive solution:

module = "green"
datexpr_green = datExpr[moduleColors == module,moduleColors == module]
TOM_green = TOMsimilarityFromExpr(datexpr_green, power = 18, networkType = "signed", TOMType="signed");
probes = names(datexpr_green)
dimnames(TOM_green) = list(probes, probes)
cyt = exportNetworkToCytoscape(TOM_green,
                               edgeFile = paste("CytoscapeInput-edges-", paste(module, collapse="-"), ".txt", sep=""),
                               nodeFile = paste("CytoscapeInput-nodes-", paste(module, collapse="-"), ".txt", sep=""),
                               weighted = TRUE,
                               threshold = 0.02,
                               nodeNames = probes,
                               altNodeNames = probes);

let me know if it works

ADD REPLY
0
Entering edit mode

Hi again Andres,

Thanks for the suggestion. I ran your code and it appeared to work, but the edges etc all had 'NA'. I think the subsetting of datExpr was wrong. I changed it to:

datexpr_green = datExpr[,moduleColors == module]

so that only the columns (not rows) were subset based on the genes in the green module. The rest of the code then worked fine, and I have the necessary files for Cytoscape. Thanks!

ADD REPLY
4
Entering edit mode
@peter-langfelder-4469
Last seen 8 weeks ago
United States

The simplest solution is to calculate TOM only for the module genes, as Andres suggested. A slight drawback is that the TOM within the module may be slightly different from TOM calculated from all data (or at least data from the relevant block). An alternative is to use the function vectorTOM which is computationally more involved but will precisely recapitulate TOM calculated from the full data set.

If your green module lies entirely within one block, you can load TOM for the relevant block, turn it into a matrix, then use something like

inModule = moduleColors[ bwmods$blockGenes[[ block ]] ]=="green"

to select just the green module from the genes of the relevant block (whose index is contained in the variable 'block').

As a santiy check, verify that the the dimensions of the TOM matrix for the relevant block agree with the length of bwmods$blockGenes[[block]].

HTH,

Peter

ADD COMMENT
0
Entering edit mode

Hi Peter,

Thanks for the reply. The green module lay between two different blocks, so I couldn't just load one block as suggested. I'll keep that in mind for future, though.

I calculated the TOM just for the module genes, as Andres suggested. This was successful, and I have the necessary files for Cytoscape now - hooray! Out of interest, I'm also trying out vectorTOM, although I'm not sure if it will end up taking too long:

res <- vectorTOM(datExpr, vect=datexpr_green, subtract1=T,blockSize=4039, corFnc="cor",corOptions = "use = 'p'",networkType = "signed",power=18,verbose = 1, indent = 0)

Thanks again to you and Andres for the advice.

ADD REPLY

Login before adding your answer.

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