-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcollect_areas.py
More file actions
107 lines (89 loc) · 4.43 KB
/
collect_areas.py
File metadata and controls
107 lines (89 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import pdb
"""
Created on Wed Aug 27 23:17:01 2014
@author: rkp
Analyze properties of specific brain areas with extreme ranks according to
specific criteria.
"""
import numpy as np
import networkx as nx
import print_net
import network_compute
# Network generation parameters
p_th = .01 # P-value threshold
w_th = 0 # Weight-value threshold
# Analysis parameters
top_out_in = 10
bot_out_in = 10
top_node_btwn = 10
top_edge_btwn = top_node_btwn*(top_node_btwn-1)/2
top_degree = 6
top_ccoeff = 10
def collect_and_sort(G,W_net,labels,print_out=True):
"""Collect lists of nodes & edges sorted by certain attributes.
Returns dictionary of node & edge labels sorted according to specific
criteria, which are available alongside the sorted labels."""
# Collect nodes ranked according to degree distribution
degree_dict = G.degree()
degree_labels, degree_vals = network_compute.get_ranked(degree_dict)
# Collect nodes ranked according to output/input ratio
out_dict,in_dict,out_in_dict = network_compute.out_in(W_net, labels=labels,binarized=False)
out_labels, out_vals = network_compute.get_ranked(out_dict)
in_labels, in_vals = network_compute.get_ranked(in_dict)
out_in_labels, out_in_vals = network_compute.get_ranked(out_in_dict)
# Collect nodes ranked according to clustering coefficient
ccoeff_dict = nx.clustering(G)
ccoeff_labels, ccoeff_vals = network_compute.get_ranked(ccoeff_dict)
# Collect nodes ranked according to node-betweenness
node_btwn_dict = nx.betweenness_centrality(G)
node_btwn_labels, node_btwn_vals = network_compute.get_ranked(node_btwn_dict)
# Collect edges ranked by edge-betweenness
edge_btwn_dict = nx.edge_betweenness_centrality(G)
edge_btwn_labels, edge_btwn_vals = network_compute.get_ranked(edge_btwn_dict)
if print_out:
print 'By degree:'
print_net.print_node_list(degree_labels,degree_vals,top_degree)
print 'By output/input (top):'
print_net.print_node_list(out_in_labels,out_in_vals,top_out_in)
print 'By output/input (bottom):'
print_net.print_node_list(out_in_labels,out_in_vals,-bot_out_in)
print 'By clustering coefficient:'
print_net.print_node_list(ccoeff_labels,ccoeff_vals,top_ccoeff)
print 'By node-betweenness:'
print_net.print_node_list(node_btwn_labels,node_btwn_vals,top_node_btwn)
print 'By edge-betweenness:'
print_net.print_edge_list(edge_btwn_labels,edge_btwn_vals,top_edge_btwn)
# Print out what percent of the top edge-betweenness edges touch the top
# node-betweenness nodes & what percent of them connect two top node-
# betweenness nodes
edges_touching, edges_connecting = \
network_compute.node_edge_overlap(node_btwn_labels[:top_node_btwn],
edge_btwn_labels[:top_edge_btwn])
print 'Top edges touching top nodes (by node-betweenness):'
print '%d/%d'%(len(edges_touching),top_edge_btwn)
print 'Top edges connecting top nodes (by node-betweenness):'
print '%d/%d'%(len(edges_connecting),top_edge_btwn)
# Print out what percent of the top edge-betweenness edges touch the top
# degree nodes & what percent of them connect two top degree nodes
edges_touching, edges_connecting = \
network_compute.node_edge_overlap(degree_labels[:top_degree],
edge_btwn_labels[:top_edge_btwn])
print 'Top edges touching top nodes (by degree):'
print '%d/%d'%(len(edges_touching),top_edge_btwn)
print 'Top edges connecting top nodes (by degree):'
print '%d/%d'%(len(edges_connecting),top_edge_btwn)
sorted_dict = {'degree_labels':degree_labels,
'degree_vals':degree_vals,
'out_labels':out_labels,
'out_vals':out_vals,
'in_labels':in_labels,
'in_vals':in_vals,
'out_in_labels':out_in_labels,
'out_in_vals':out_in_vals,
'ccoeff_labels':ccoeff_labels,
'ccoeff_vals':ccoeff_vals,
'node_btwn_labels':node_btwn_labels,
'node_btwn_vals':node_btwn_vals,
'edge_btwn_labels':edge_btwn_labels,
'edge_btwn_vals':edge_btwn_vals}
return sorted_dict