CFeregrino / scWGCNA

scWGCNA
GNU General Public License v3.0
52 stars 10 forks source link

How to export network to Cytoscape #10

Open tiramisutes opened 2 years ago

tiramisutes commented 2 years ago

Hi, How to export the network data to Cytoscape when I run scWGCNA.networks?

MmLimbE155.scWGCNA = scWGCNA.networks(scWGCNA.data = MmLimbE155.scWGCNA)

Or how can I select/filter some gene to plot when run scW.p.network(MmLimbE155.scWGCNA, module=1)?

Thanks.

CFeregrino commented 2 years ago

Hello! This is something I am still planning to implement in the package, and it might take me a couple of days. But this code would produce the data.frames you can then export as tables for cytoscape:

geneModuleMembership = as.data.frame(WGCNA::signedKME(scWGCNA.data[["expression"]], scWGCNA.data[["MEs"]])) my.cols = levels(as.factor(scWGCNA.data[["dynamicCols"]]))

my.cyto = lapply(as.list(my.cols), function(col){
    mod=is.finite(match(scWGCNA.data[["dynamicCols"]], col))
    mynetwork = suppressWarnings(reshape::melt(scWGCNA.data[["TOM"]][mod,mod]))
    mynetwork = mynetwork[!mynetwork$X1 == mynetwork$X2,]
    colnames(mynetwork) = c("fromNode", "toNode", "weight")
    mynetwork$fromNode = as.character(mynetwork$fromNode)
    mynetwork$toNode = as.character(mynetwork$toNode)
    mynodes = geneModuleMembership[levels(as.factor(mynetwork$fromNode)),which(my.cols == col), drop=F]
    return(list(mynetwork,mynodes))})

This will create a list of lists. Each of the internal lists correspond to each module (ordered as levels(as.factor(scWGCNA.data[["dynamicCols"]])) ). The first dataframe on each list is your vertex table, and the second one is the node table for cytoscape. I will modify the function in the package to add the option of exporting the cytoscape tables. Let me know if this helps!

tiramisutes commented 2 years ago

Thank you very much for your quick reply. That's what I need.