Using networkx to calculate statistics and send to cytoscape.

619 views
Skip to first unread message

re...@channing.harvard.edu

unread,
Nov 6, 2015, 8:46:32 AM11/6/15
to cytoscape-discuss
This is a follow up question to:

"Hi.

Sorry for slow response.

Unfortunately, Network Analyzer is designed to be used from GUI, not from external scripts and it is a bit tricky if I implement to call its function from cyREST/ py2cytoscape.  For now, the best way to do the same analysis with Cytoscape and Python is using Cytoscape as visualizer for the output of Python-based graph analysis tool such as NetworkX or igraph.

In this sample notebook, you can find how to convert NetworkX / igraph objects into Cytoscape:


Cell #14 is the sample code analyzing graph with networkX and send it to Cytoscape for visualization.  These graph analysis tools have all of the functions Network Analyzer has, and you can create similar visualizations by calling them from your Python code.
  

Please let me know if you have further questions.

Thanks,
Kei"



So I have a network in cytoscape, and I've used it to cut down the number of nodes to those within 3 "neighbors" away from a center node.

I create the networkx:


res = requests.get(BASE + 'networks/' + network_id + "/views/first")
# Convert to Python object
existing_network = res.json()
nx_network = cy.to_networkx(existing_network)

I then calculate some statistics(not shown) and add it to the networkx, (This might be uneccessary) for example:

nx.set_node_attributes(nx_network, 'average shortest path', translated_path_dict)

I get the network view:

view_id_list = network.get_views()
view = network.get_view(view_id_list[0], format='view')
 


I attempt to set visual properties:
view.update_node_views(visual_property='NODE_SIZE', values = translated_path_dict)
view.update_node_views(visual_property='NODE_FILL_COLOR', values = translated_color_dict)

The color is updated but the node size is not.


When I get the values from the view, the new values are present, but the cytoscape window only reflect the color change:

node_views_dict = view.get_node_views_as_dict()
nv_df = pd.DataFrame.from_dict(node_views_dict, orient='index' )


Am I going about this wrong?



Kei

unread,
Nov 12, 2015, 12:33:10 PM11/12/15
to cytoscape-discuss
Hi.

Cytoscape has both "SIZE" and combination of "WIDTH" and "HEIGHT."  I think the problem is you are trying to set SIZE while W/H properties are used.  The trick is using "Visual Property dependencies" API:

And if you call this API:


You can see list of dependencies (In Cytoscape GUI, it's called "lock")

[ {
  "visualPropertyDependency" : "arrowColorMatchesEdge",
  "enabled" : false
}, {
  "visualPropertyDependency" : "nodeCustomGraphicsSizeSync",
  "enabled" : true
}, {
  "visualPropertyDependency" : "nodeSizeLocked",
  "enabled" : false 
} ] 


In your case, if you set "nodeSizeLocked" to true, you can use SIZE property.  Setting "nodeSizeLocked" true means use SIZE instead of combination of W/H.

Please let me know if you have further questions.

Thanks,
Kei




2015年11月6日金曜日 5時46分32秒 UTC-8 re...@channing.harvard.edu:
Reply all
Reply to author
Forward
0 new messages