When you vizualize your network, you also want to analize the network. In this section, you can learn basic analysis methods to network. The methods used in this section are prepared in the Python's libraries, igraph, networkx and so on. So, we will also use them to analyze network and if you want to get more detail about this examples or find more information, please look at these documentations.
Global Network Analysis
Node Analysis
Edge Analysis
In [52]:
# import data from url
from py2cytoscape.data.cyrest_client import CyRestClient
from IPython.display import Image
# Create REST client for Cytoscape
cy = CyRestClient()
# Reset current session for fresh start
cy.session.delete()
# Load a sample network
network = cy.network.create_from('http://chianti.ucsd.edu/~kono/data/galFiltered.sif')
# Apply layout to the cytoscape network object
cy.layout.apply(network = network)
# Show it!!
network_png = network.get_png()
Image(network_png)
Out[52]:
In this example, we will use "igraph" to analyze global network propety. "igraph" are the very popular and useful package and you can analyze your own network by this.
And py2cytoscape can convert their own network to igraph object. So, first, we have to convert cytoscape network object to igraph object.
In [55]:
# covert cytoscape network object to igraph object
import igraph as ig
import py2cytoscape.util.util_igraph as util_ig
# convert cytoscape object to igraph object
g = util_ig.to_igraph(network.to_json())
Calculates the density of the graph.
Further information : http://igraph.org/python/doc/igraph.GraphBase-class.html#density
In [57]:
density = g.density()
print(density)
There are three methods to calculate the transitivity in igraph. In the following methods, we will use "transitivity_undirected" method.
Calculates the average of the vertex transitivities of the graph.
http://igraph.org/python/doc/igraph.GraphBase-class.html#transitivity_avglocal_undirected
Calculates the local transitivity (clustering coefficient) of the given vertices in the graph.
http://igraph.org/python/doc/igraph.GraphBase-class.html#transitivity_local_undirected
Calculates the global transitivity (clustering coefficient) of the graph.
http://igraph.org/python/doc/igraph.GraphBase-class.html#transitivity_undirected
In [58]:
transitivity = g.transitivity_undirected()
print(transitivity)
Finds the community structure of the graph according to the algorithm of Clauset et al based on the greedy optimization of modularity. http://igraph.org/python/doc/igraph.GraphBase-class.html#community_fastgreedy
In [72]:
# If you want to use this method, you have to use the non-multiple-edges graph object.
#community_fastgreedy = g.community_fastgreedy()
#print(community_fastgreedy)
Calculates the closeness centralities of given vertices in a graph.
http://igraph.org/python/doc/igraph.GraphBase-class.html#closeness
In [75]:
closeness = g.closeness()
# Show 10 results of node closeness
print(closeness[0:9])
In [74]:
indegree = g.indegree()
outdegree = g.outdegree()
# Show 10 results of node degree
print(indegree[0:9])
print(outdegree[0:9])
Calculates the Google PageRank values of a graph. http://igraph.org/python/doc/igraph.Graph-class.html#pagerank
In [73]:
pagerank = g.pagerank()
# Show 10 results of node degree
print(pagerank[0:9])
Finds the community structure of the graph according to the algorithm of Clauset et al based on the greedy optimization of modularity. http://igraph.org/python/doc/igraph.GraphBase-class.html#community_fastgreedy
In [ ]:
# If you want to use this method, you have to use the non-multiple-edges graph object.
#community_fastgreedy = g.community_fastgreedy()
#print(community_fastgreedy)
Calculates or estimates the edge betweennesses in a graph. http://igraph.org/python/doc/igraph.GraphBase-class.html#edge_betweenness
In [68]:
edge_betweenness = g.edge_betweenness()
print(edge_betweenness[0:9])
Community structure detection based on the betweenness of the edges in the network. http://igraph.org/python/doc/igraph.GraphBase-class.html#community_edge_betweenness
In [70]:
community_edge_betweenness_detection = g.community_edge_betweenness()
print(community_edge_betweenness_detection)