The Python workflow of Anne


In this jupyter-notebook, I'll show you the Python workflow of Anne as the sample.

You can understand the basic workflow by reading this, but the py2cytoscape's documentation is really useful and you can know much more about this.

The documentation : coming soon

Setup


To execute this, please sutisfy following items.

  • Java SE 8
  • Cytoscape version 3.3+
  • CyREST
  • Use docker file to do this. The docker file provide you the environment below.
    • py2cytoscape
    • igraph
    • ...

Start a new session


Let's start a new session with py2cytoscape.


In [3]:
from py2cytoscape.data.cynetwork import CyNetwork
from py2cytoscape.data.cyrest_client import CyRestClient
from py2cytoscape.data.style import StyleUtil
import py2cytoscape.util.cytoscapejs as cyjs
import py2cytoscape.cytoscapejs as renderer

import networkx as nx
import pandas as pd
import json



In [4]:
# !!!!!!!!!!!!!!!!! Step 0: Start Cytoscape 3 with cyREST App !!!!!!!!!!!!!!!!!!!!!!!!!!

# Step 1: Create py2cytoscape client
cy = CyRestClient()

# Reset
cy.session.delete()

Load a network data from file/URL



In [7]:
# Load network from somewhere
net_from_local1 = cy.network.create_from('sample_yeast_network.xgmml', collection='My Collection')

# 
cy.layout.apply(name='degree-circle', network=net_from_local1)


---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-7-1744fe7f75a0> in <module>()
      1 # Load network from somewhere
----> 2 net_from_local1 = cy.network.create_from('sample_yeast_network.xgmml', collection='My Collection')
      3 
      4 #
      5 cy.layout.apply(name='degree-circle', network=net_from_local1)

/Users/St_Hakky/.pyenv/versions/anaconda3-2.5.0/lib/python3.5/site-packages/py2cytoscape/data/network_client.py in create_from(self, locations, collection)
     55         res = self.session.post(self.__url, data=json.dumps(location_list),
     56                                 params=parameters, headers=HEADERS)
---> 57         check_response(res)
     58         res = res.json()
     59 

/Users/St_Hakky/.pyenv/versions/anaconda3-2.5.0/lib/python3.5/site-packages/py2cytoscape/data/cynetwork.py in check_response(res)
    372                                        % list(err_info.keys()))
    373         exc.args += (err_msg,)
--> 374         raise exc

/Users/St_Hakky/.pyenv/versions/anaconda3-2.5.0/lib/python3.5/site-packages/py2cytoscape/data/cynetwork.py in check_response(res)
    360     """ Check HTTP response and raise exception if response is not OK. """
    361     try:
--> 362         res.raise_for_status() # ALternative is res.ok
    363     except Exception as exc:
    364         # Bad response code, e.g. if adding an edge with nodes that doesn't exist

/Users/St_Hakky/.pyenv/versions/anaconda3-2.5.0/lib/python3.5/site-packages/requests/models.py in raise_for_status(self)
    842 
    843         if http_error_msg:
--> 844             raise HTTPError(http_error_msg, response=self)
    845 
    846     def close(self):

HTTPError: ('500 Server Error: Internal Server Error for url: http://localhost:1234/v1/networks?source=url&collection=My+Collection', 'Could not load networks from given locations.')

In [ ]:

Upload a network table, an edge attribute table and a node attribute table.


Now, we use only network data. However, you also want to use an edge attribute and a node attribute table. So, first we will import attribution data, then merge it to network data.

The following document will show you some example.

Import edge attribute table and merge it.


In [ ]:

Import node attribute table and merge it.


In [ ]:

Select edges based on some edge attributes



In [ ]:
#TODO

Hide these edges



In [ ]:

Select nodes based on some node attributes



In [ ]:

Hide these nodes



In [ ]:

Apply a layout the the network that is not hidden


Get list of available layout algorithms

First, let's get the list of available layout algorithms. Then, you can apply any layout algorithms that you want.


In [ ]:

Apply layout


In [ ]:

Apply a visual style to this network


Get all Visual Style Names


In [ ]:

Apply a Visual Style to a network view


In [ ]:


In [ ]: