cytoscape / py4cytoscape

Python library for calling Cytoscape Automation via CyREST
https://Py4Cytoscape.readthedocs.io
Other
72 stars 14 forks source link

create_network_from_networkx only takes in a MultiDiGraph #49

Closed Jiafi closed 3 years ago

Jiafi commented 3 years ago

I have a standard networkx graph that I want to display in cytoscape. I have to first make it into a MultiDiGraph and then send it through the API. It should just take a graph and construct it from there.

bdemchak commented 3 years ago

Thanks for the feedback. That code was written a while ago, and I'm working to understand how and why it was created this way.

We don't have much experience with NetworkX ... I see that the py4cytoscape documentation says that create_network_from_networkx() accepts a MultiDiGraph.

From what I can tell, the use of .out_edges() in create_network_from_network() pretty much limits the graph to at least a DiGraph or MultiDiGraph (but not Graph or MultiGraph). Would that be right?

This seems appropriate for a DiGraph or MultiDiGraph, but for undirected graphs, the function should be .edges(). Correct? Also, according to networkx.org (https://networkx.org/documentation/networkx-1.9/reference/generated/networkx.Graph.edges.html#networkx.Graph.edges), using just .edges() on a directed graph should give the same result as out_edges() if used on a directed graph. Is that the way you see it, too?

So, we might be able to generalize this function to suit your purpose by using .edges() instead.

I'd like to try this on a simple graph that embodies your use case. Would you be able to provide a graph I can test with??

While we're on the topic, I'd note that create_networkx_from_network() assumes that a Cytoscape network maps to a MultiDiGraph. As a NetworkX user, can you advise on this? In fact, Cytoscape networks can have a mixture of directed and undirected edges, or only directed, or only undirected edges. Given this, what would a NetworkX user expect create_networkx_from_network() to return?

Thanks for your reply ... we'd like very much to produce something you find useful.

bdemchak commented 3 years ago

Changed create_network_from_networkx() to accept Graph, DiGraph, MultiGraph and MultiDiGraph.

For now, this is in branch 0.0.9, but will be promoted to master in next release.

Would you mind trying it out?

Thanks!