juanbot / CoExpNets

Co-expression network management based on WGCNA + k-means
Apache License 2.0
16 stars 8 forks source link

How to transform the RDS object into something that can be read by visualization tools such as gephi #24

Closed madzafv closed 2 years ago

madzafv commented 2 years ago

Hi, I have generated my network, which I believe it is contained in the rds obj, but I'm having a hard time finding a way of converting into something that can be read by gephi. Does CoExpNets has a function to do that? Thank you!

madzafv commented 2 years ago

What I worked out was this

netLast = getDownstreamNetwork(
  tissue = "AreaXLast",
  n.iterations = 50,
  min.exchanged.genes = 20,
  t(normalized_counts),
  beta = -1,
  job.path = "/u/project/gxxiao3/madzayas/BFRNASeq/BFaligned",
  min.cluster.size = 30,
  net.type = "signed",
  debug = F,
  blockTOM = F,
  save.tom = T,
  save.plots = T,
  excludeGrey = TRUE,
  fullAnnotation = T,
  silent = T
)

net <- readRDS("/u/project/gxxiao3/madzayas/BFRNASeq/BFaligned/netAreaXLast.5.it.50.rds")
TOM <- readRDS("/u/project/gxxiao3/madzayas/BFRNASeq/BFaligned/netAreaXLast.5.it.50.rds.tom.rds")

# Select modules
modules = c("cyan") 

# Select module genes
probes = names(net$adjacency)
inModule = is.finite(match(net$moduleColors, modules));
modGenes = probes[inModule];
# Select the corresponding Topological Overlap
dimnames(TOM2) = list(names(net$adjacency),names(net$adjacency))
modTOM = TOM2[inModule, inModule];

# Export the network into edge and node list files Cytoscape can read
cyt = exportNetworkToCytoscape(modTOM,
                               edgeFile = paste("CytoscapeInput-edges-", ".tsv", sep=""),
                               nodeFile = paste("CytoscapeInput-nodes-", ".tsv", sep=""),
                               weighted = TRUE,
                               threshold = 0.1,
                               nodeNames = modGenes,
                               nodeAttr = net$moduleColors[inModule]);

edges <- read.table(file = 'CytoscapeInput-edges-.tsv', sep = '\t', header = TRUE)
nodes <- read.table(file = 'CytoscapeInput-nodes-.tsv', sep = '\t', header = TRUE)

write.csv(x=edges, file="CytoscapeInput-edges.csv")
write.csv(x=nodes, file="CytoscapeInput-nodes.csv")