Networkx basics, some code and materials adapted from Hiroki Sayama's awesome textbook. http://textbooks.opensuny.org/introduction-to-the-modeling-and-analysis-of-complex-systems/

In [2]:
from __future__ import division
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
plt.rcParams['figure.figsize'] = (20.0, 16.0)

Lots of stuff imported there, let's review: networkx is the tool we are going to use to analyze networks, matplolib.pyplot is for graphing stuff and graphical handling. numpy is math, matplotlib inline lets data show up in the notebook, and the next command makes our figures bigger so we can see them more easily.

First we need to talk about what a 'network' is. A network is any list of relationships between objects. It could be synaptic connections, friendships, facebook likes, interactions, roads, casual public intereactions. It can be directed (ie we know which object acts on the other), undirected (ie objects interact mutually), quantitative (we know how strongly objects interact in a quantitative sense), or binary (we jsut know that objects interact).

Lets start by making a hypothetical network g, and adding some nodes to it. A node is any object that interacts (or doesn't interact) in the network.

In [3]:
g=nx.Graph() #graph object
g.add_nodes_from (['hippocampus','piriform','entorhinal','perirhinal','frontal cortex'])

Now that we made some nodes, let's add some connections between those nodes, these will be called 'edges'

In [4]:
g.add_edges_from([('hippocampus','entorhinal'),('frontal cortex','hippocampus'),('piriform','entorhinal')])

Now that we've added some objects to our network let's print those details. Networkx gives us a few ways to do that.

In [5]:
print(g.nodes())
print(g.edges())
['piriform', 'entorhinal', 'perirhinal', 'hippocampus', 'frontal cortex']
[('piriform', 'entorhinal'), ('entorhinal', 'hippocampus'), ('hippocampus', 'frontal cortex')]

Today we won't be working with it, but in theory nodes and edges can have any number of traits. This is useful if you want to store lots of inforaation about the interaction, this comes in handy for filtering for analysis or visualization. Below I print all traits associated with each node, you'll notice it's empty.

In [6]:
g.node
Out[6]:
{'entorhinal': {},
 'frontal cortex': {},
 'hippocampus': {},
 'perirhinal': {},
 'piriform': {}}

Now we'll draw the network I made, don't worry about the syntax quite yet, but you'll notice it's pretty uninteresting

In [7]:
nx.draw(g,with_labels=True)

There is A LOT you can do with networks, today we'll focus on some basic visualization and quantiifcation of traits. In ther interest of space I'm going to grab one of the prebuilt graphs they have in NetworkX. In this case we'll be using the 'davis southern woman' network. They represent observed attendance at 14 social events by 18 Southern women. I'll declare this graph as G

In [8]:
G=nx.davis_southern_women_graph()

Let's draw it!

In [9]:
nx.draw(G)
print'basic'
basic

There are lots of ways to plot this data, the default is called a spring network, imagine the nodes are springs, lots of nodes with other nodes in their neighborhood are more closely pulled together, nodes with few connections dangle far away. Next we'll draw nodes with random positions.

In [10]:
nx.draw_random(G)
print 'random positions'
random positions

We can also place all the nodes on the outside and see their connections, this is called a circular graph.

In [11]:
nx.draw_circular(G)
print 'circular graph'
circular graph

The next class is called spectral format, it's complicated what it means

In [12]:
nx.draw_spectral(G)
print 'spectral graph'
spectral graph

net we are going to add the name of the nodes to the nodes, we do this with the tag with_labels=True, we are also defining the positions explicitly with the spring_layout command.

In [13]:
positions = nx.spring_layout(G)
nx.draw(G,positions, with_labels=True)

Next we will have each node be equivelent in size to the number connections it has, we'll discuss the degree command i ndepth soon, but for now, know that it means 'number of nodes that connect with this one'

In [14]:
node_sizes=[G.degree(i)*50 for i in G.nodes()]
nx.draw(G,positions,node_size=node_sizes)

That's a fun toy network but let's play with a REAL network, I've given you the allen brain atlas matrix, it's a list of all regions and their connective strengths in a mouse brain let's import it and get it plotted. We are going to import it with np.genfromtext, and we'll import it as a string so we can get the names associated with each row.

In [15]:
x = np.genfromtxt('ad_matrix.csv', delimiter=',', dtype='string'
              )

Now let's grab the bit with numbers and convert it to a matrix! it's just that easy, this is called an 'adjacency matrix' where columns and rows meet at connection points. We'll also grab a variable called names for later

In [16]:
values=x[1:,1:].astype('float')
new_g=nx.from_numpy_matrix(values)
names=x[0][1:]
idx_name_dict=dict(zip(new_g.nodes(),names))

let's plot it! with the same size trick as before

In [17]:
node_sizes=[new_g.degree(i)**1.2 for i in new_g.nodes()]
positions = nx.spring_layout(new_g)
nx.draw(new_g,positions,node_size=node_sizes)

Well that's a bit of a mess, in reality, netowrkx is actually not very good for this kind of plotting, gephi is better. though networkx can help us clean the graph up for gephi. for the moment we won't worry about that, we'll work here. Lets add names to our nodes, to do this we make a paired list: with a range the length of our nodes and the names file, we'll then make this a dictionary, don't get too bogged down with the specifics of this, jsut know that it works for this conversion. We'll then use relabel and make a new matrix cleanedup

In [18]:
renamer=dict(zip(range(len(new_g.node)),names))
cleanedup=nx.relabel_nodes(new_g,renamer)

Run .node to confirm it worked.

In [19]:
cleanedup.node
Out[19]:
{'AAA': {},
 'ACAd': {},
 'ACAv': {},
 'ACB': {},
 'AD': {},
 'AHN': {},
 'AId': {},
 'AIp': {},
 'AIv': {},
 'AMB': {},
 'AMd': {},
 'AMv': {},
 'AN': {},
 'AOB': {},
 'AON': {},
 'APN': {},
 'ARH': {},
 'AUDd': {},
 'AUDp': {},
 'AUDv': {},
 'AV': {},
 'BLA': {},
 'BMA': {},
 'BST': {},
 'CA1': {},
 'CA2': {},
 'CA3': {},
 'CEA': {},
 'CENT': {},
 'CL': {},
 'CLA': {},
 'CLI': {},
 'CM': {},
 'COAa': {},
 'COAp': {},
 'CP': {},
 'CS': {},
 'CUL': {},
 'CUN': {},
 'DCO': {},
 'DG': {},
 'DMH': {},
 'DN': {},
 'DP': {},
 'DR': {},
 'ECT': {},
 'ENTl': {},
 'ENTm': {},
 'EPd': {},
 'EPv': {},
 'FL': {},
 'FN': {},
 'FRP': {},
 'FS': {},
 'GPe': {},
 'GPi': {},
 'GRN': {},
 'GU': {},
 'IA': {},
 'ICc': {},
 'ICd': {},
 'ICe': {},
 'ILA': {},
 'IMD': {},
 'IO': {},
 'IP': {},
 'IPN': {},
 'IRN': {},
 'LA': {},
 'LAV': {},
 'LD': {},
 'LGd': {},
 'LGv': {},
 'LH': {},
 'LHA': {},
 'LP': {},
 'LPO': {},
 'LRN': {},
 'LSc': {},
 'LSr': {},
 'LSv': {},
 'MA': {},
 'MARN': {},
 'MD': {},
 'MDRNd': {},
 'MDRNv': {},
 'MEA': {},
 'MEPO': {},
 'MGd': {},
 'MGm': {},
 'MGv': {},
 'MH': {},
 'MM': {},
 'MOB': {},
 'MOp': {},
 'MOs': {},
 'MPN': {},
 'MPO': {},
 'MPT': {},
 'MRN': {},
 'MS': {},
 'MV': {},
 'NDB': {},
 'NI': {},
 'NLL': {},
 'NLOT': {},
 'NOD': {},
 'NOT': {},
 'NPC': {},
 'NTS': {},
 'ORBl': {},
 'ORBm': {},
 'ORBvl': {},
 'OT': {},
 'PA': {},
 'PAA': {},
 'PAG': {},
 'PAR': {},
 'PARN': {},
 'PB': {},
 'PCG': {},
 'PERI': {},
 'PF': {},
 'PFL': {},
 'PG': {},
 'PGRNd': {},
 'PGRNl': {},
 'PH': {},
 'PIR': {},
 'PL': {},
 'PMd': {},
 'PO': {},
 'POL': {},
 'POST': {},
 'PP': {},
 'PPN': {},
 'PRE': {},
 'PRM': {},
 'PRNc': {},
 'PRNr': {},
 'PRP': {},
 'PSV': {},
 'PT': {},
 'PTLp': {},
 'PVH': {},
 'PVT': {},
 'PVp': {},
 'PVpo': {},
 'PYR': {},
 'RCH': {},
 'RE': {},
 'RH': {},
 'RM': {},
 'RN': {},
 'RR': {},
 'RSPagl': {},
 'RSPd': {},
 'RSPv': {},
 'RT': {},
 'SBPV': {},
 'SCm': {},
 'SCs': {},
 'SF': {},
 'SI': {},
 'SIM': {},
 'SMT': {},
 'SNc': {},
 'SNr': {},
 'SOC': {},
 'SPA': {},
 'SPFm': {},
 'SPFp': {},
 'SPIV': {},
 'SPVC': {},
 'SPVI': {},
 'SPVO': {},
 'SSp-bfd': {},
 'SSp-ll': {},
 'SSp-m': {},
 'SSp-n': {},
 'SSp-tr': {},
 'SSp-ul': {},
 'SSs': {},
 'STN': {},
 'SUBd': {},
 'SUBv': {},
 'SUM': {},
 'SUT': {},
 'SUV': {},
 'TEa': {},
 'TR': {},
 'TRN': {},
 'TRS': {},
 'TT': {},
 'TU': {},
 'V': {},
 'VAL': {},
 'VCO': {},
 'VII': {},
 'VISC': {},
 'VISal': {},
 'VISam': {},
 'VISl': {},
 'VISp': {},
 'VISpl': {},
 'VISpm': {},
 'VM': {},
 'VMH': {},
 'VPL': {},
 'VPM': {},
 'VPMpc': {},
 'VTA': {},
 'XII': {}}

and replot it with names, let's try the shell layout this time!

In [20]:
node_sizes=[cleanedup.degree(i)**1.2 for i in cleanedup.nodes()]
positions = nx.shell_layout(cleanedup)
nx.draw(cleanedup,positions,node_size=node_sizes,with_labels=True)

Still a total mess, let's see why by checking number of nodes, number of edges, and density (% of total connections)

In [21]:
cleanedup.number_of_edges()
cleanedup.number_of_nodes()
nx.density(cleanedup)
Out[21]:
0.5928337319514572

And we find 60% of the possible connections occur, let's shave this down! Luckily this network is quantitative, so let's say we only care about the top 5% most powerful connections. First go back to our original numpy graph. find the 5% cut off value and replot! numpy has a nice command percentile. Then we'll filter by only connections stronger than that and redo all the stuff to make a new grarph: powerful connections. Then we'll plot it

In [22]:
values=x[1:,1:].astype('float')
p=np.percentile(values,95)
top_5_percent=(values>p)*1
top_5_g=nx.from_numpy_matrix(top_5_percent)
top_5_g_with_proper_names=nx.relabel_nodes(top_5_g,renamer)

#now plot

node_sizes=[top_5_g_with_proper_names.degree(i)**1.2 for i in top_5_g_with_proper_names.nodes()]
positions = nx.spring_layout(top_5_g_with_proper_names)
nx.draw(top_5_g_with_proper_names,positions,node_size=node_sizes,with_labels=True)

This is way more usable, for fun try other percentile values, here we'll try 1

In [23]:
values=x[1:,1:].astype('float')
p=np.percentile(values,99)
top_1_percent=(values>p)*1
top_1_g=nx.from_numpy_matrix(top_1_percent)
top_1_g_with_proper_names=nx.relabel_nodes(top_1_g,renamer)

#now plot

node_sizes=[top_1_g_with_proper_names.degree(i)**1.2 for i in top_1_g_with_proper_names.nodes()]
positions = nx.spring_layout(top_1_g_with_proper_names)
nx.draw(top_1_g_with_proper_names,positions,node_size=node_sizes,with_labels=True)

Now we are getting cool. Of course I'm cheating here and using this as an undirected graph, for the moment I'm going to cheat and keep using that. For further analysis I'm going to use the 5% graph it's nicely connected without being painfully over connected. Depenging on your personal mathematical sophistication, most of the commands I'm going to use next can be adpated to both quantitative and directed graphs. Next we are going to evaluate network 'topology'/

In [24]:
print('density')
print(nx.density(top_5_g_with_proper_names))
density
0.0927008592435

next we'll look at connected components, this is a realatively meaningless analysis in the brain as all regions should be connected, but lets see what is stongly connected

In [25]:
ccs=nx.connected_components(top_5_g_with_proper_names)
ccsl=[i for i in ccs]
print ccsl
[['PAR', 'AMB', 'PVp', 'PARN', 'PRNr', 'PPN', 'PAA', 'PFL', 'PAG', 'VISpm', 'VISpl', 'MDRNd', 'SIM', 'PRNc', 'PRE', 'DCO', 'RN', 'AOB', 'RR', 'EPv', 'AON', 'PERI', 'ENTm', 'ENTl', 'CENT', 'RE', 'SPVC', 'PRP', 'RM', 'EPd', 'RH', 'PG', 'GU', 'SNc', 'LHA', 'XII', 'SSp-ul', 'LPO', 'MRN', 'ORBm', 'ORBl', 'VPL', 'GPi', 'VCO', 'GPe', 'VII', 'AHN', 'NPC', 'NLL', 'APN', 'LAV', 'OT', 'NTS', 'SCm', 'SOC', 'LSc', 'DMH', 'IPN', 'SSp-tr', 'VISal', 'VISam', 'LSv', 'LSr', 'MPT', 'PCG', 'SCs', 'AMv', 'PGRNd', 'PP', 'BMA', 'VPMpc', 'PT', 'PGRNl', 'TRN', 'PB', 'PA', 'PF', 'SPA', 'PH', 'PO', 'PL', 'SSp-ll', 'MGd', 'MOs', 'MOp', 'SSs', 'MGm', 'GRN', 'TRS', 'AN', 'BLA', 'SUBv', 'MD', 'MA', 'MM', 'MPO', 'CUL', 'NLOT', 'MH', 'LRN', 'PRM', 'SUBd', 'MV', 'MS', 'NOT', 'MOB', 'PSV', 'MGv', 'ACB', 'FS', 'IO', 'ILA', 'TEa', 'SUM', 'SMT', 'LD', 'PMd', 'SUV', 'SUT', 'RT', 'FL', 'POST', 'FN', 'AUDv', 'NI', 'ACAd', 'PVT', 'AUDp', 'SBPV', 'BST', 'ACAv', 'AUDd', 'ECT', 'PVH', 'NOD', 'VTA', 'SPIV', 'CLI', 'CM', 'CL', 'NDB', 'CLA', 'AMd', 'FRP', 'V', 'CS', 'CUN', 'CP', 'PIR', 'SSp-bfd', 'MEA', 'VMH', 'MARN', 'MPN', 'ICc', 'SI', 'PTLp', 'SSp-m', 'SSp-n', 'DN', 'SPFp', 'AAA', 'DG', 'SPVI', 'SPVO', 'COAp', 'TU', 'VISC', 'RCH', 'MDRNv', 'DR', 'SPFm', 'IMD', 'VISp', 'VAL', 'LA', 'MEPO', 'TT', 'AIv', 'TR', 'AIp', 'LH', 'POL', 'DP', 'LP', 'VPM', 'AId', 'VISl', 'AD', 'ORBvl', 'IP', 'STN', 'VM', 'LGd', 'RSPv', 'IRN', 'AV', 'IA', 'COAa', 'LGv', 'RSPd', 'CEA', 'CA3', 'CA2', 'CA1', 'PVpo', 'ICe', 'ICd', 'RSPagl', 'ARH', 'SNr'], ['SF'], ['PYR']]

The two regions disconnected are subzones of the striatum (for the SF) and a subzone of the cerebellum. It's not surprising. Let's run an iterative shaving analysis:

In [26]:
for perc in range(95,100):
    values=x[1:,1:].astype('float')
    p=np.percentile(values,perc)
    shaved=(values>p)*1
    shaved=nx.from_numpy_matrix(shaved)
    shaved=nx.relabel_nodes(shaved,renamer)
    ccs=nx.connected_components(shaved)
    ccsl=[i for i in ccs]
    print(np.float(nx.density(shaved)))
    print(ccsl)
0.0927008592435
[['PAR', 'AMB', 'PVp', 'PARN', 'PRNr', 'PPN', 'PAA', 'PFL', 'PAG', 'VISpm', 'VISpl', 'MDRNd', 'SIM', 'PRNc', 'PRE', 'DCO', 'RN', 'AOB', 'RR', 'EPv', 'AON', 'PERI', 'ENTm', 'ENTl', 'CENT', 'RE', 'SPVC', 'PRP', 'RM', 'EPd', 'RH', 'PG', 'GU', 'SNc', 'LHA', 'XII', 'SSp-ul', 'LPO', 'MRN', 'ORBm', 'ORBl', 'VPL', 'GPi', 'VCO', 'GPe', 'VII', 'AHN', 'NPC', 'NLL', 'APN', 'LAV', 'OT', 'NTS', 'SCm', 'SOC', 'LSc', 'DMH', 'IPN', 'SSp-tr', 'VISal', 'VISam', 'LSv', 'LSr', 'MPT', 'PCG', 'SCs', 'AMv', 'PGRNd', 'PP', 'BMA', 'VPMpc', 'PT', 'PGRNl', 'TRN', 'PB', 'PA', 'PF', 'SPA', 'PH', 'PO', 'PL', 'SSp-ll', 'MGd', 'MOs', 'MOp', 'SSs', 'MGm', 'GRN', 'TRS', 'AN', 'BLA', 'SUBv', 'MD', 'MA', 'MM', 'MPO', 'CUL', 'NLOT', 'MH', 'LRN', 'PRM', 'SUBd', 'MV', 'MS', 'NOT', 'MOB', 'PSV', 'MGv', 'ACB', 'FS', 'IO', 'ILA', 'TEa', 'SUM', 'SMT', 'LD', 'PMd', 'SUV', 'SUT', 'RT', 'FL', 'POST', 'FN', 'AUDv', 'NI', 'ACAd', 'PVT', 'AUDp', 'SBPV', 'BST', 'ACAv', 'AUDd', 'ECT', 'PVH', 'NOD', 'VTA', 'SPIV', 'CLI', 'CM', 'CL', 'NDB', 'CLA', 'AMd', 'FRP', 'V', 'CS', 'CUN', 'CP', 'PIR', 'SSp-bfd', 'MEA', 'VMH', 'MARN', 'MPN', 'ICc', 'SI', 'PTLp', 'SSp-m', 'SSp-n', 'DN', 'SPFp', 'AAA', 'DG', 'SPVI', 'SPVO', 'COAp', 'TU', 'VISC', 'RCH', 'MDRNv', 'DR', 'SPFm', 'IMD', 'VISp', 'VAL', 'LA', 'MEPO', 'TT', 'AIv', 'TR', 'AIp', 'LH', 'POL', 'DP', 'LP', 'VPM', 'AId', 'VISl', 'AD', 'ORBvl', 'IP', 'STN', 'VM', 'LGd', 'RSPv', 'IRN', 'AV', 'IA', 'COAa', 'LGv', 'RSPd', 'CEA', 'CA3', 'CA2', 'CA1', 'PVpo', 'ICe', 'ICd', 'RSPagl', 'ARH', 'SNr'], ['SF'], ['PYR']]
0.0756488617238
[['PAR', 'TU', 'PVp', 'PARN', 'PRNr', 'PPN', 'PAA', 'PAG', 'VISpm', 'VISpl', 'MDRNd', 'SIM', 'PRNc', 'PRE', 'DCO', 'RN', 'AOB', 'RR', 'EPv', 'AON', 'PERI', 'ENTm', 'ENTl', 'CENT', 'RE', 'SPVC', 'PRP', 'RM', 'EPd', 'PG', 'GU', 'SNc', 'LHA', 'XII', 'SSp-ul', 'LPO', 'MRN', 'ORBm', 'ORBl', 'VPL', 'GPi', 'VCO', 'GPe', 'VII', 'AHN', 'NPC', 'NLL', 'APN', 'LAV', 'OT', 'NTS', 'SCm', 'LSc', 'DMH', 'IPN', 'SSp-tr', 'VISal', 'VISam', 'LSv', 'LSr', 'MPT', 'PCG', 'SCs', 'AMv', 'PGRNd', 'PP', 'BMA', 'VPMpc', 'PT', 'PGRNl', 'TRN', 'PB', 'PA', 'PF', 'SPA', 'PH', 'PO', 'PL', 'SSp-ll', 'ICc', 'MGd', 'MOs', 'MOp', 'SSs', 'MGm', 'GRN', 'POST', 'AN', 'BLA', 'SUBv', 'MD', 'MA', 'MM', 'MPO', 'CUL', 'NLOT', 'MH', 'LRN', 'PRM', 'SUBd', 'MV', 'MS', 'NOT', 'MOB', 'PSV', 'MGv', 'ACB', 'FS', 'IO', 'ILA', 'TEa', 'SUM', 'SMT', 'LD', 'PMd', 'SUV', 'SUT', 'RT', 'FL', 'TRS', 'FN', 'AUDv', 'NI', 'ACAd', 'PVT', 'AUDp', 'SBPV', 'BST', 'ACAv', 'AUDd', 'ECT', 'PVH', 'NOD', 'VTA', 'SPIV', 'IMD', 'CM', 'CL', 'NDB', 'CLA', 'AMd', 'FRP', 'V', 'CS', 'CUN', 'CP', 'PIR', 'SSp-bfd', 'MEA', 'VMH', 'AMB', 'MARN', 'MPN', 'SI', 'RCH', 'SSp-m', 'SSp-n', 'DN', 'SPFp', 'AAA', 'DG', 'SPVI', 'SPVO', 'COAp', 'PFL', 'VISC', 'PTLp', 'MDRNv', 'ICd', 'DR', 'SPFm', 'CLI', 'VISp', 'VAL', 'LA', 'MEPO', 'TT', 'AIv', 'TR', 'AIp', 'LH', 'POL', 'DP', 'LP', 'VPM', 'AId', 'VISl', 'AD', 'ORBvl', 'IP', 'STN', 'VM', 'LGd', 'RSPv', 'IRN', 'AV', 'IA', 'COAa', 'LGv', 'RSPd', 'CEA', 'CA3', 'CA2', 'CA1', 'PVpo', 'ICe', 'SOC', 'RSPagl', 'ARH', 'SNr'], ['SF'], ['RH'], ['PYR']]
0.057976791567
[['PAR', 'AIv', 'AN', 'PVp', 'PARN', 'V', 'PRNr', 'AIp', 'PAA', 'PAG', 'VISpm', 'VISpl', 'SIM', 'PRNc', 'PRE', 'DCO', 'RN', 'AOB', 'RR', 'EPv', 'AON', 'PERI', 'ENTm', 'ENTl', 'CENT', 'RE', 'SPVC', 'PRP', 'RM', 'PIR', 'GU', 'SNc', 'LHA', 'XII', 'SSp-ul', 'LPO', 'MRN', 'ORBm', 'ORBl', 'VPL', 'TRN', 'GPi', 'GPe', 'VII', 'AHN', 'NPC', 'PO', 'APN', 'SBPV', 'LAV', 'OT', 'NTS', 'SCm', 'SOC', 'LSc', 'DMH', 'IPN', 'SSp-tr', 'VISal', 'AMd', 'LSr', 'PCG', 'SCs', 'AMv', 'PGRNd', 'PP', 'BMA', 'VPMpc', 'PT', 'PGRNl', 'DR', 'AMB', 'PB', 'PA', 'PF', 'PG', 'PH', 'NLL', 'PL', 'SSp-ll', 'ICc', 'MGd', 'MOs', 'MOp', 'PPN', 'SSs', 'VM', 'MGm', 'GRN', 'POST', 'VCO', 'BLA', 'SUBv', 'MD', 'MA', 'MPN', 'MPO', 'CUL', 'MH', 'LRN', 'PRM', 'SUBd', 'MV', 'MS', 'NOT', 'MOB', 'PSV', 'MGv', 'ACB', 'FS', 'IO', 'ILA', 'TEa', 'SUM', 'SMT', 'PMd', 'SUV', 'SUT', 'RT', 'TRS', 'FN', 'AUDv', 'NI', 'ACAd', 'PVT', 'AUDp', 'NLOT', 'BST', 'ACAv', 'AUDd', 'ECT', 'PVH', 'NOD', 'VTA', 'SPIV', 'IMD', 'CM', 'CL', 'NDB', 'CLA', 'VISam', 'FRP', 'SPA', 'CS', 'CUN', 'CP', 'EPd', 'SSp-bfd', 'MEA', 'VMH', 'MARN', 'MM', 'SI', 'RCH', 'SSp-m', 'SSp-n', 'DN', 'SPFp', 'AAA', 'DG', 'SPVI', 'SPVO', 'COAp', 'PFL', 'VISC', 'PTLp', 'MDRNv', 'COAa', 'DP', 'CLI', 'LD', 'VAL', 'LA', 'MEPO', 'TT', 'TU', 'TR', 'MPT', 'LH', 'POL', 'SPFm', 'LP', 'VPM', 'AId', 'VISl', 'AD', 'ORBvl', 'IP', 'STN', 'VISp', 'LGd', 'RSPv', 'IRN', 'AV', 'IA', 'LGv', 'RSPd', 'CEA', 'CA3', 'CA2', 'CA1', 'PVpo', 'ICe', 'ICd', 'RSPagl', 'ARH', 'SNr'], ['LSv'], ['FL'], ['SF'], ['MDRNd'], ['RH'], ['PYR']]
0.0396403578705
[['PAR', 'TU', 'PVp', 'PARN', 'V', 'PRNr', 'PPN', 'PAA', 'PAG', 'VISpm', 'VISpl', 'SIM', 'PRNc', 'PRE', 'DCO', 'RN', 'AOB', 'RR', 'EPv', 'AON', 'PERI', 'ENTm', 'ENTl', 'CENT', 'RE', 'SPVC', 'SPA', 'PIR', 'PG', 'GU', 'SNc', 'LHA', 'XII', 'SSp-ul', 'LPO', 'MRN', 'ORBm', 'ORBl', 'VPL', 'GPi', 'VCO', 'GPe', 'VII', 'AHN', 'NPC', 'NLL', 'APN', 'SBPV', 'LAV', 'OT', 'NTS', 'SCm', 'SOC', 'LSc', 'DMH', 'IPN', 'SSp-tr', 'VISal', 'AMd', 'LSr', 'MPT', 'PCG', 'SCs', 'AMv', 'PGRNd', 'PP', 'BMA', 'VPMpc', 'PT', 'PGRNl', 'TRN', 'PB', 'PA', 'PF', 'ICc', 'PH', 'PO', 'PL', 'SSp-ll', 'MGd', 'MOs', 'MOp', 'SSs', 'VM', 'MGm', 'GRN', 'TRS', 'AN', 'BLA', 'SUBv', 'MD', 'MA', 'MM', 'MPO', 'MH', 'PRM', 'SUBd', 'MV', 'MS', 'NOT', 'MOB', 'PSV', 'MGv', 'ACB', 'FS', 'IRN', 'ILA', 'TEa', 'SUM', 'SMT', 'PMd', 'SUV', 'SUT', 'RT', 'POST', 'FN', 'AUDv', 'NI', 'ACAd', 'PVT', 'AUDp', 'NLOT', 'BST', 'ACAv', 'AUDd', 'ECT', 'PVH', 'NOD', 'VTA', 'CLI', 'CM', 'CL', 'NDB', 'CLA', 'VISam', 'FRP', 'RM', 'CS', 'CUN', 'CP', 'EPd', 'SSp-bfd', 'MEA', 'VMH', 'AMB', 'MARN', 'MPN', 'SI', 'RCH', 'SSp-m', 'SSp-n', 'DN', 'SPFp', 'AAA', 'DG', 'SPVI', 'SPVO', 'COAp', 'PFL', 'VISC', 'PTLp', 'MDRNv', 'COAa', 'DP', 'IMD', 'LD', 'VAL', 'LA', 'MEPO', 'TT', 'AIv', 'TR', 'AIp', 'LH', 'POL', 'SPFm', 'LP', 'VPM', 'AId', 'VISl', 'AD', 'ORBvl', 'IP', 'STN', 'VISp', 'LGd', 'RSPv', 'IO', 'AV', 'IA', 'LGv', 'RSPd', 'CEA', 'CA3', 'CA2', 'CA1', 'PVpo', 'ICe', 'ICd', 'RSPagl', 'ARH', 'SNr'], ['LSv'], ['FL'], ['SPIV'], ['SF'], ['MDRNd'], ['PRP'], ['RH'], ['PYR'], ['CUL', 'LRN'], ['DR']]
0.0200637788998
[['PAR', 'AIv', 'PARN', 'PRNr', 'PPN', 'PAA', 'PAG', 'VISpm', 'SIM', 'PRNc', 'PRE', 'AOB', 'RR', 'EPv', 'AON', 'PERI', 'ENTm', 'ENTl', 'RE', 'RM', 'PIR', 'GU', 'EPd', 'SNc', 'LHA', 'SSp-ul', 'LPO', 'MRN', 'ORBm', 'ORBl', 'VPL', 'GPi', 'GPe', 'VII', 'AHN', 'NPC', 'NLL', 'APN', 'OT', 'SCm', 'SOC', 'LSc', 'DMH', 'SSp-tr', 'VISal', 'AMd', 'LSr', 'MPT', 'PCG', 'SCs', 'AMv', 'PGRNd', 'PP', 'BMA', 'VPMpc', 'PT', 'AMB', 'PA', 'PF', 'PG', 'PO', 'PL', 'MGm', 'SSp-ll', 'MGd', 'MOs', 'MOp', 'SSs', 'MGv', 'GRN', 'TRS', 'AN', 'BLA', 'SUBv', 'MD', 'MA', 'MM', 'MPO', 'MH', 'SUBd', 'MS', 'NOT', 'MOB', 'ACB', 'ILA', 'TEa', 'SMT', 'PMd', 'SUV', 'RT', 'POST', 'AUDv', 'NI', 'ACAd', 'AUDp', 'BST', 'ACAv', 'AUDd', 'ECT', 'PVH', 'CLI', 'CM', 'CL', 'NDB', 'CLA', 'VISam', 'FRP', 'SPA', 'CS', 'CUN', 'CP', 'RN', 'SSp-bfd', 'MEA', 'VMH', 'NTS', 'SI', 'PTLp', 'SSp-m', 'SSp-n', 'VISp', 'DN', 'SPFp', 'AAA', 'DG', 'SPVO', 'COAp', 'RCH', 'MDRNv', 'COAa', 'DP', 'IMD', 'LD', 'VAL', 'LA', 'TT', 'TU', 'TR', 'AIp', 'POL', 'SPFm', 'LP', 'VPM', 'AId', 'VISl', 'AD', 'ORBvl', 'STN', 'VM', 'LGd', 'RSPv', 'IRN', 'AV', 'IA', 'LGv', 'RSPd', 'CEA', 'CA3', 'CA2', 'CA1', 'PFL', 'ICe', 'ICd', 'RSPagl', 'ARH', 'SNr'], ['VISpl'], ['DCO'], ['XII'], ['LAV'], ['LSv'], ['PB'], ['PH'], ['PRM'], ['MV'], ['SPVC', 'SPVI', 'PSV'], ['FS'], ['FL'], ['FN'], ['SBPV'], ['SPIV'], ['V'], ['MARN'], ['NOD'], ['SF'], ['LH'], ['IP'], ['IO'], ['PVpo'], ['MDRNd'], ['CENT'], ['PRP'], ['RH'], ['PYR'], ['IPN'], ['PGRNl'], ['TRN'], ['MPN'], ['NLOT'], ['LRN'], ['PVp'], ['SUM'], ['SUT'], ['PVT'], ['VTA'], ['CUL'], ['VISC'], ['DR'], ['MEPO'], ['VCO'], ['ICc']]

Now this is a crazy feature of the brain, we can cut 99% of the connections and get down to 2% connection density and still have only a few regions knocked off. This is a common feature of preferentially attached networks, these are networks where very few nodes draw in a lot of the connections. Next lets see the average length between any two paths, this shoudl be farmiliar to you if you've ever played 6 degrees of Kevin bacon, in essence it's the average 'bacon number' of any two nodes in our network. First I have to remove the disconnected nodes!

In [27]:
top_5_g_with_proper_names.remove_node('SF')
top_5_g_with_proper_names.remove_node('PYR')
nx.average_shortest_path_length(top_5_g_with_proper_names)
Out[27]:
2.3440306928458585

There are lots of other metrics covered in Sayama including eccentricity, diameter and radius, rather than reproducing them here, I'll just reccomend you check out page 379.

Two cool metrics are 'perphiery' which is points that are furthest from all others, and 'center' whcih are points closest to all others.

In [28]:
print(nx.periphery(top_5_g_with_proper_names))
print(nx.center(top_5_g_with_proper_names))
['MDRNd', 'AOB', 'XII', 'LSv', 'FL', 'FN', 'SPIV', 'NOD', 'SPVC', 'SPVI', 'VCO', 'MEPO']
['PPN', 'RR', 'PERI', 'RM', 'RN', 'GU', 'SNc', 'MRN', 'GPi', 'NPC', 'APN', 'SCm', 'DMH', 'PAG', 'PCG', 'PP', 'PB', 'PH', 'TRN', 'MOs', 'MOp', 'MM', 'MH', 'ILA', 'AUDv', 'NI', 'ACAd', 'BST', 'CLI', 'CL', 'CLA', 'SPFp', 'AAA', 'RCH', 'LHA', 'TU', 'AIp', 'LP', 'STN', 'LGd', 'LGv', 'CEA', 'ICe']

The peripheral structures are a bunch of striatal, cerebellar, and spinal nuclei (shocker) and the central is msotly thalamic, midbrain, and isocortex.

There are lots of measures you can use to capture this more purely, by looking at neighbors and neighbors of neighbors. This is all pretty subtle and complicated check out sayama and other referencs for more explanation, so I'm only gonna look at one here: pagerank. Pagerank is basically, how many of your neighbros are well connected (ie who is popular amongst the popular kids)

In [29]:
page_ranks=nx.pagerank(top_5_g_with_proper_names)
pr_values=[page_ranks[i] for i in page_ranks]
#the next two lines are super dirty, I don't fully understand them and you don't ahve to either,I just looked up 'sort dictionary
#by values in python and using what showed up in stack exchange, sometimes you gotta do that
import operator
sorted_x = sorted(page_ranks.items(), key=operator.itemgetter(1))
In [30]:
sorted_x
Out[30]:
[('RH', 0.0009258801661089493),
 ('MGm', 0.001263413740709441),
 ('LSv', 0.0014641728385281479),
 ('DR', 0.001474761696067397),
 ('XII', 0.001557011043038862),
 ('LSc', 0.0017450816243046053),
 ('VISpl', 0.0018580008447451593),
 ('PAR', 0.0018976293920119776),
 ('PRP', 0.0019055865266064),
 ('SUT', 0.0019486194942322692),
 ('AOB', 0.0019578945801456337),
 ('SBPV', 0.0019721321249454356),
 ('MEPO', 0.0019743992401499936),
 ('V', 0.0020090977401047076),
 ('ICd', 0.0020859180687721928),
 ('VCO', 0.002108051318793291),
 ('LH', 0.0021534050193558764),
 ('PGRNd', 0.002174113719649828),
 ('PRM', 0.0021859354547928483),
 ('MDRNd', 0.0022051821253917347),
 ('PFL', 0.0022162219684180714),
 ('MPN', 0.002236593366964545),
 ('FL', 0.0022571046376842663),
 ('SOC', 0.002308842203504311),
 ('CENT', 0.0023135323562128223),
 ('PRE', 0.002328205119740072),
 ('ICc', 0.0023298377939894883),
 ('MDRNv', 0.0023646050523229195),
 ('AD', 0.002369623949108165),
 ('NOD', 0.0024021473769587484),
 ('SSp-n', 0.0024239110538986784),
 ('MARN', 0.0024275348067128153),
 ('LAV', 0.0024457121443255537),
 ('VISpm', 0.0024939288163732163),
 ('MOB', 0.0025130523608308),
 ('IO', 0.0025338156392),
 ('PMd', 0.0025529837304776506),
 ('SPA', 0.0025770412305108036),
 ('AMB', 0.0026236561689818717),
 ('VPMpc', 0.002626730052923868),
 ('PVpo', 0.002690462531669643),
 ('NLL', 0.0027337259644131676),
 ('SUM', 0.002755158986120298),
 ('FN', 0.0027606006294086634),
 ('PF', 0.0027841022519362194),
 ('LRN', 0.002812507147109961),
 ('PVT', 0.0028267174316180792),
 ('CA2', 0.002830808055003878),
 ('CS', 0.0028367977410485735),
 ('SNr', 0.0028423162134542587),
 ('SIM', 0.0028448351411779656),
 ('CUN', 0.0028813256019351455),
 ('IA', 0.002946515576913243),
 ('MV', 0.002988071779235748),
 ('PVH', 0.0029923110493713123),
 ('RSPagl', 0.003034059689579028),
 ('CUL', 0.003053230892958297),
 ('SUV', 0.003094788658389704),
 ('AMd', 0.0031397941035360252),
 ('PVp', 0.0031510471081698864),
 ('MGv', 0.003170202627835842),
 ('AN', 0.003196571288105892),
 ('AMv', 0.0032190015131594134),
 ('VII', 0.0032433230896071895),
 ('NLOT', 0.0032557544341190433),
 ('CL', 0.0032728792356233743),
 ('IMD', 0.003292971830499007),
 ('AV', 0.0033048925301220173),
 ('IP', 0.0033146585966694784),
 ('IPN', 0.003340745762891316),
 ('NPC', 0.003353436608873991),
 ('AUDp', 0.0033799537849445406),
 ('NI', 0.003404390070286973),
 ('DN', 0.0034340543234297775),
 ('DP', 0.003434342037643132),
 ('PG', 0.003437179898523154),
 ('CM', 0.0034749517925539417),
 ('VMH', 0.0034989581952117165),
 ('TRS', 0.0035139053188911603),
 ('MS', 0.0035407134067666542),
 ('MPT', 0.0035509416111668022),
 ('VPM', 0.003607461958144241),
 ('SPIV', 0.003627515821619537),
 ('PCG', 0.003642681272336462),
 ('RN', 0.003668373157714521),
 ('AAA', 0.003722297296517627),
 ('VPL', 0.003734923638435185),
 ('SNc', 0.0037358796852887295),
 ('EPv', 0.003744796819039079),
 ('FS', 0.003753085804775109),
 ('VISal', 0.0037708561442916805),
 ('ARH', 0.0038209212102389848),
 ('POL', 0.003877643885597534),
 ('SSp-ll', 0.00388650355593137),
 ('PGRNl', 0.0038988821075882593),
 ('SSp-ul', 0.003926138701890336),
 ('SSp-m', 0.003938960908621534),
 ('ORBm', 0.003967634439775797),
 ('VISC', 0.004009895035732358),
 ('SMT', 0.004019408168151326),
 ('DG', 0.0041158479421234155),
 ('DMH', 0.0041622362535062634),
 ('MPO', 0.004167464414754677),
 ('VTA', 0.004187858439684255),
 ('ORBvl', 0.004199115284067371),
 ('MA', 0.004213738936209819),
 ('POST', 0.004230066608318349),
 ('VISp', 0.004282589904696883),
 ('COAp', 0.004285512480603961),
 ('SPVO', 0.0042866222369589676),
 ('VAL', 0.004296377999821688),
 ('SCs', 0.004344157013561659),
 ('SPVC', 0.004364368176946944),
 ('LD', 0.004373888065684841),
 ('SPFm', 0.004406359803135192),
 ('PB', 0.00445880734640492),
 ('ICe', 0.0045028202658488475),
 ('MEA', 0.004526923722226953),
 ('APN', 0.004537837588255344),
 ('AHN', 0.0045699078019170785),
 ('TR', 0.004608905770141867),
 ('SSp-bfd', 0.0046484431244781495),
 ('RSPd', 0.004669159962972614),
 ('RR', 0.004676271580854423),
 ('ACAv', 0.0046906863399454705),
 ('RE', 0.004726364551826473),
 ('DCO', 0.004741879602617338),
 ('SPVI', 0.004829729745862553),
 ('TRN', 0.004870932741690556),
 ('FRP', 0.004886212511805149),
 ('LGv', 0.004901846885318839),
 ('MGd', 0.004919313670692398),
 ('PL', 0.004945081500415072),
 ('ENTm', 0.004965867303847187),
 ('LA', 0.005012066076095685),
 ('RM', 0.0050562560099331475),
 ('ORBl', 0.005065818915445602),
 ('CA3', 0.005066184284261948),
 ('AON', 0.0052018585180419515),
 ('LSr', 0.005203223444056686),
 ('SSs', 0.005243969839488607),
 ('TU', 0.005261047331461653),
 ('AIp', 0.005310038038760125),
 ('MD', 0.005342626942985504),
 ('AUDd', 0.005352551614915495),
 ('VISl', 0.0053802558394929),
 ('EPd', 0.005391680971803905),
 ('LP', 0.005445745951789016),
 ('CA1', 0.005459950239849035),
 ('RCH', 0.00547223519693537),
 ('OT', 0.005580247780529449),
 ('SSp-tr', 0.005584241050119433),
 ('AId', 0.005599104266695677),
 ('PO', 0.005618362413150341),
 ('NOT', 0.005771049611814883),
 ('ECT', 0.005810597742611311),
 ('NTS', 0.005893790867476243),
 ('LGd', 0.005923505141827454),
 ('GPe', 0.005945759334694627),
 ('TT', 0.005948856041355017),
 ('BST', 0.0059547180519454925),
 ('GU', 0.0060127528568755546),
 ('RT', 0.006056423980662121),
 ('PSV', 0.006067686224030285),
 ('PARN', 0.006079297709859654),
 ('PH', 0.006150076474023979),
 ('VISam', 0.006206331472999933),
 ('RSPv', 0.006294380150695423),
 ('SPFp', 0.006357943657420981),
 ('BMA', 0.006470307623404366),
 ('VM', 0.006477654764928833),
 ('LPO', 0.006491965127677198),
 ('NDB', 0.006558499676115608),
 ('MH', 0.006576233934595504),
 ('SUBd', 0.006629856658697183),
 ('AIv', 0.006707428825281912),
 ('SUBv', 0.006743462246913685),
 ('TEa', 0.006829364793783001),
 ('COAa', 0.0068856232233377055),
 ('GRN', 0.006972367491902583),
 ('PPN', 0.007066240920800716),
 ('PRNc', 0.007213483036145371),
 ('IRN', 0.007269540476509168),
 ('PTLp', 0.0072792992188461525),
 ('CEA', 0.007291988626604824),
 ('PIR', 0.007362117990561366),
 ('MM', 0.0073924533897036125),
 ('ACAd', 0.007420596344156744),
 ('PT', 0.0074492372120352375),
 ('PA', 0.007516107335251525),
 ('PAA', 0.007518209112025047),
 ('ILA', 0.00783747709581099),
 ('ACB', 0.007888967859978557),
 ('AUDv', 0.008031635935086275),
 ('PRNr', 0.00807197176847069),
 ('MOp', 0.008189838338539255),
 ('MOs', 0.008483291486911288),
 ('ENTl', 0.008757583702753416),
 ('SI', 0.009078850707635257),
 ('BLA', 0.009436686194910369),
 ('CLI', 0.009968865083420075),
 ('STN', 0.010347200861554317),
 ('SCm', 0.010630040345483618),
 ('PERI', 0.011245594953760443),
 ('PP', 0.01151144720220493),
 ('CLA', 0.01230459089010794),
 ('GPi', 0.012716927516076742),
 ('CP', 0.01311471593385415),
 ('LHA', 0.013299024259923964),
 ('PAG', 0.013706125499232915),
 ('MRN', 0.014345066004451002)]

The answers are actually a bit surprising, networks are weird! reticular nucleus, caudate and periductal greay (probably an artifact, PERI is the first one I actually believe) remember these are thresholded and bicirectional, in a proper nonthresholded analysis this probably won't be true

Last metric for today, clustering: clustering is measuring neighborhoods, a high degree of clustering means a suepr connected neighborhood, low clustering means more spread out, basically it's measure of how connected your neighbors are to eachother.

In [31]:
print(nx.clustering(top_5_g_with_proper_names))
print(nx.average_clustering(top_5_g_with_proper_names))
{'PAR': 0.4, 'AIv': 0.4032258064516129, 'ACB': 0.26884779516358465, 'PARN': 0.29411764705882354, 'PRNr': 0.22379032258064516, 'PPN': 0.3032258064516129, 'PAA': 0.3697478991596639, 'SSp-tr': 0.4766666666666667, 'VISpm': 0.5714285714285714, 'VISpl': 0.5333333333333333, 'MDRNd': 1.0, 'SIM': 0.4, 'PRNc': 0.3046153846153846, 'PRE': 0.39285714285714285, 'DCO': 0.2878787878787879, 'CP': 0.1971153846153846, 'AOB': 0.5333333333333333, 'RR': 0.28421052631578947, 'EPv': 0.4, 'AON': 0.4155844155844156, 'PERI': 0.2902597402597403, 'ENTm': 0.34285714285714286, 'ENTl': 0.3146341463414634, 'CENT': 0.0, 'SBPV': 0.3333333333333333, 'PRP': 0.3333333333333333, 'RM': 0.3088235294117647, 'RN': 0.3904761904761905, 'RH': 0.0, 'GU': 0.41798941798941797, 'EPd': 0.4420289855072464, 'SNc': 0.5, 'VAL': 0.3742690058479532, 'XII': 0.6666666666666666, 'SSp-ul': 0.5916666666666667, 'LPO': 0.3275862068965517, 'MRN': 0.17509920634920634, 'ORBm': 0.5686274509803921, 'ORBl': 0.466403162055336, 'AId': 0.39, 'GPi': 0.1961038961038961, 'GPe': 0.2535612535612536, 'VII': 0.4722222222222222, 'IPN': 0.358974358974359, 'NPC': 0.4175824175824176, 'PO': 0.40923076923076923, 'APN': 0.3567251461988304, 'LAV': 0.5238095238095238, 'OT': 0.38153846153846155, 'NTS': 0.375, 'SCm': 0.22783687943262412, 'LSc': 0.3, 'SSp-ll': 0.49166666666666664, 'DMH': 0.27205882352941174, 'AHN': 0.39766081871345027, 'PAG': 0.18192090395480226, 'VISal': 0.55, 'AMd': 0.5256410256410257, 'LSv': 0.6666666666666666, 'LSr': 0.3438735177865613, 'MPT': 0.21978021978021978, 'PCG': 0.46153846153846156, 'SCs': 0.3088235294117647, 'AMv': 0.2948717948717949, 'PGRNd': 0.4666666666666667, 'PP': 0.18901960784313726, 'BMA': 0.37701149425287356, 'VPMpc': 0.5555555555555556, 'PT': 0.2235294117647059, 'PGRNl': 0.41025641025641024, 'AMB': 0.5238095238095238, 'PB': 0.35, 'PA': 0.26411290322580644, 'PF': 0.43636363636363634, 'PG': 0.25, 'PH': 0.27076923076923076, 'NLL': 0.5833333333333334, 'PL': 0.4268774703557312, 'RT': 0.30687830687830686, 'ICc': 0.5238095238095238, 'TRN': 0.375, 'MOs': 0.3402439024390244, 'SPA': 0.35555555555555557, 'MOp': 0.33873144399460187, 'MGm': 1.0, 'VM': 0.3471264367816092, 'SSs': 0.5059288537549407, 'GRN': 0.2714285714285714, 'POST': 0.2867647058823529, 'AN': 0.25, 'BLA': 0.30628019323671496, 'SUBv': 0.30295566502463056, 'MD': 0.2318840579710145, 'MA': 0.48366013071895425, 'MM': 0.22916666666666666, 'MPO': 0.35294117647058826, 'NLOT': 0.5384615384615384, 'MH': 0.15076923076923077, 'LRN': 0.09523809523809523, 'PRM': 0.4, 'SUBd': 0.2660098522167488, 'MV': 0.42857142857142855, 'MS': 0.37362637362637363, 'NOT': 0.3, 'MOB': 0.42857142857142855, 'PSV': 0.29411764705882354, 'MGv': 0.358974358974359, 'PVp': 0.4222222222222222, 'FS': 0.44166666666666665, 'IRN': 0.2766798418972332, 'ILA': 0.3108108108108108, 'TEa': 0.3326612903225806, 'SUM': 0.2222222222222222, 'SMT': 0.41830065359477125, 'LD': 0.3508771929824561, 'PMd': 0.3055555555555556, 'SUV': 0.4444444444444444, 'SUT': 0.7, 'FL': 0.3333333333333333, 'TRS': 0.3956043956043956, 'FN': 0.2, 'AUDv': 0.32063492063492066, 'NI': 0.23076923076923078, 'ACAd': 0.36134453781512604, 'PVT': 0.2, 'AUDp': 0.4945054945054945, 'RE': 0.28095238095238095, 'BST': 0.27, 'ACAv': 0.4, 'AUDd': 0.43478260869565216, 'ECT': 0.31054131054131057, 'PVH': 0.32727272727272727, 'VTA': 0.37254901960784315, 'SPIV': 0.4444444444444444, 'CLI': 0.18585858585858586, 'CM': 0.5142857142857142, 'CL': 0.38461538461538464, 'NDB': 0.32873563218390806, 'CLA': 0.2016364699006429, 'VISam': 0.4417989417989418, 'FRP': 0.49783549783549785, 'V': 0.4, 'CS': 0.19444444444444445, 'CUN': 0.35555555555555557, 'CUL': 0.06666666666666667, 'PIR': 0.32386363636363635, 'SSp-bfd': 0.5, 'DN': 0.3333333333333333, 'MEA': 0.36257309941520466, 'VMH': 0.3333333333333333, 'MARN': 0.6190476190476191, 'MPN': 0.6666666666666666, 'NOD': 0.16666666666666666, 'SI': 0.2646733111849391, 'PTLp': 0.3939393939393939, 'SSp-m': 0.5666666666666667, 'SSp-n': 0.6944444444444444, 'SPVC': 0.48484848484848486, 'SPFp': 0.3226600985221675, 'AAA': 0.5, 'DG': 0.4166666666666667, 'SPVI': 0.46153846153846156, 'SPVO': 0.4696969696969697, 'COAp': 0.5073529411764706, 'PFL': 0.5, 'VISC': 0.36764705882352944, 'RCH': 0.2536231884057971, 'MDRNv': 0.5333333333333333, 'DR': 0.8333333333333334, 'SPFm': 0.3368421052631579, 'IMD': 0.4175824175824176, 'SOC': 0.16666666666666666, 'LHA': 0.2083553675304072, 'LA': 0.4588744588744589, 'COAa': 0.42613636363636365, 'TT': 0.4444444444444444, 'TU': 0.2813852813852814, 'TR': 0.5476190476190477, 'AIp': 0.41, 'LH': 0.5238095238095238, 'POL': 0.375, 'DP': 0.4857142857142857, 'LP': 0.36333333333333334, 'VPM': 0.4380952380952381, 'VPL': 0.525, 'VISl': 0.39855072463768115, 'AD': 0.35714285714285715, 'ORBvl': 0.42105263157894735, 'IP': 0.3888888888888889, 'STN': 0.22664199814986125, 'VISp': 0.477124183006536, 'LGd': 0.2966666666666667, 'VCO': 0.16666666666666666, 'IO': 0.42857142857142855, 'AV': 0.5274725274725275, 'IA': 0.3333333333333333, 'LGv': 0.3380952380952381, 'RSPd': 0.4631578947368421, 'MGd': 0.33766233766233766, 'CEA': 0.2721774193548387, 'RSPv': 0.3492063492063492, 'CA3': 0.36257309941520466, 'CA2': 0.5555555555555556, 'CA1': 0.34782608695652173, 'PVpo': 0.2857142857142857, 'ICe': 0.39705882352941174, 'ICd': 0.7333333333333333, 'RSPagl': 0.5454545454545454, 'MEPO': 0.3333333333333333, 'ARH': 0.4065934065934066, 'SNr': 0.45454545454545453}
0.382530309303

Plotting degree distribution

In [32]:
plt.plot(np.histogram(top_5_g_with_proper_names.degree().values(),bins=20)[1][1:]
         ,np.histogram(top_5_g_with_proper_names.degree().values(),bins=20)[0])
Out[32]:
[<matplotlib.lines.Line2D at 0x1a776a90>]

There is lots of other things and if you are going to write a real paper, I'd reccomend looking up assorativity and modularity cause it's cool, but we don't really have the time to discuss it here. Now go and do this with Swanson's network!

In [33]:
node_colors=[page_ranks[i] for i in top_5_g_with_proper_names.nodes()]
clust=nx.clustering(top_5_g_with_proper_names)
pos=nx.spring_layout(top_5_g_with_proper_names,iterations=500)
nx.draw(top_5_g_with_proper_names,pos,node_color=node_colors,cmap=plt.cm.Blues)