-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSFig2H_hiarachical_clustering.py
54 lines (39 loc) · 1.71 KB
/
SFig2H_hiarachical_clustering.py
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
ana = ana_all_rd
conn_data = ana.conn_data['glom_kc_in_claw_unit']
ob_conn, glom_prob, glom_idx_ids = get_conn_prob_idx(conn_data)
num_exp = 10000
stat = [get_raw_inputs(shuffle_glom_kc_w_prob(ob_conn, glom_prob)) for i in range(num_exp)]
stat = np.array(stat)
sd = np.nanstd(stat, axis=0)
avg = np.nanmean(stat, axis=0)
ob_ci = get_raw_inputs(ob_conn)
comm_zscore = np.divide(np.subtract(ob_ci, avg), sd)
cm_zs = PairMatrix('', comm_zscore, glom_idx_ids)
from sklearn.cluster import AgglomerativeClustering
x = comm_zscore.copy()
clustering = AgglomerativeClustering(n_clusters=None).fit(x)
clustering
clustering.labels_
reorder_idx = np.argsort(clustering.labels_)
t1_zs = cm_zs.reorder(reorder_idx, return_new=True)
# plotting z score matrix
fig, ax1 = plt.subplots()
t1 = t1_zs;
gloms = df_lookup('glom_id',t1.col_ids,'short_glom_name',glom_btn_table)
sns.heatmap(t1.conn, xticklabels=gloms, yticklabels=gloms, ax=ax1, vmin=-8.53, vmax=8.53, cmap="RdBu_r")
ax1.tick_params(bottom=False,labeltop=True, top=True, labelbottom=False)
ax1.tick_params(axis='x',labelrotation=90)
# run and get tbl in 191029-bouton-KC-representations_per_PN.py
col_list = t1.col_ids
col_colors = df_lookup('short_glom_name', gloms, 'color', tbl)
for x in [ax1.get_xticklabels(), ax1.get_yticklabels()]:
for idx, tick in enumerate(x):
tick.set_color(col_colors[idx])
if col_list[idx] in comm_ids:
tick.set_weight("extra bold")
# tick.set_bbox(dict(ec='green', fc=None, alpha=0.05))
ax1.set_aspect("equal")
fig.set_size_inches(16,12)
plt.show()
# save_path = "/Users/zhengz11/myscripts/data_results/191212-clusterings/"
# fig.savefig(save_path + "191212-allKCs_Hiarachical_clustering.png", bbox_inches='tight')