cytoscape / RCy3

New version of RCy3, redesigned and collaboratively maintained by Cytoscape developer community
MIT License
48 stars 20 forks source link

Function to load the cytoscape-formatted json to RCy3? #206

Closed gmhhope closed 1 year ago

gmhhope commented 1 year ago

Dear developers,

I am trying to import a networkx-exported cytoscape-style JSON file (basically a JSON file that is ready to load in cytoscape desktop) into the RCy3 for further configuring the style. Is there anyway I can do that? Trying the functions importNetworkFromFile. But it doesn't look like working.

graph.json.filename = "./graph.json" # nx.json_graph.cytoscape_data(neworkx_graph)
graphAsJSON <- importNetworkFromFile(graph.json.filename) 

Hope you can help!

Thanks, Minghao Gong

AlexanderPico commented 1 year ago

Hi. RCy3 is a set of wrapper functions for CyREST. It provides R functions to help you work with a running instance of Cytoscape via its CyREST API.

So, importNetworkFromFile allows you to import a file into Cytoscape as a network. It does not support reading files into your R environment.

Perhaps https://github.com/frankkramer-lab/ndexr has what you are looking for...

gmhhope commented 1 year ago

Hi Alex,

I have thought that importNetworkFromFile might not work.

I just would like to see if I can work around this as I have been using networkx to manipulate the network. But I have used RCy3 for configuring the shape of the network before (Now I know maybe I can use py4cytoscape). Thus, to allow putting together between these two broken pieces across Python and R, I am trying to be able to convert the networkx graph in some sorts of format and import it into RCy3 for doing the layout stuffs. However, I faced some difficulties to doing so. I was thinking that the Cytoscape-formatted JSON file would be directly imported but it doesn't look like there is a way to do it?

I think ndexr mostly handles public network if I understand correctly. Do you have any clues?

Any suggestions will be welcome!

gmhhope commented 1 year ago

Okay I found out the py4cytoscape can create graph from networkx object. Now the question is that if there are ways I can export it and let RCy3 handle the rest?


import networkx as nx
import py4cytoscape as p4c
import cyjupyter

graph = nx.Graph()
graph.add_nodes_from([1, 2, 3])
graph.add_edges_from([(1, 2), (2, 3)])

cy_network = p4c.create_network_from_networkx(graph)