The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
This wrapper function spits out some basic graph properties of a NetworkX graph object. We can use it to conveniently explore the different graphs on which to compute hierarchy scores.
graph_properties (G)
Return the properties of a NetworkX graph.
Type | Details | |
---|---|---|
G | NetworkX graph | |
Returns | str | Concatenated string with number of edges and of nodes, the average degree and the graph’s density |
Let’s test it on a simple directed graph.
First we wil define the graph and visualise it using Graphviz
And now we can print the output of graph_properties
print(graph_properties(G1))
assert graph_properties(G1)=="Edges:7, Nodes:6, Avg Degree:2.3333333333333335, Density:0.23333333333333334"
Edges:7, Nodes:6, Avg Degree:2.3333333333333335, Density:0.23333333333333334
We can also check out some other hand-defined directed graphs, a digraph built from the OmniPath database or a NetworkX built-in graph.
# Directed Graph from OmniPath
#using the following link: https://omnipathdb.org/interactions?genesymbols=yes&fields=type&license=academic&directed=0
#Gets us all interactions, no matter type nor undirected/vs directed
omnidata = pd.read_csv("https://omnipathdb.org/interactions?genesymbols=yes&fields=type&license=academic&directed=1", sep="\t")
G4 = nx.from_pandas_edgelist(omnidata, source="source_genesymbol", target="target_genesymbol",edge_attr="type", create_using=nx.DiGraph)
print(graph_properties(G1))
print(graph_properties(G2))
print(graph_properties(G3))
print(graph_properties(G4))
print(graph_properties(G5))
Edges:7, Nodes:6, Avg Degree:2.3333333333333335, Density:0.23333333333333334
Edges:6, Nodes:6, Avg Degree:2.0, Density:0.2
Edges:2, Nodes:4, Avg Degree:1.0, Density:0.16666666666666666
Edges:91888, Nodes:9248, Avg Degree:19.8719723183391, Density:0.0010745091553119445
Edges:18, Nodes:10, Avg Degree:3.6, Density:0.4