-
Notifications
You must be signed in to change notification settings - Fork 0
/
05_visualize.py
188 lines (161 loc) · 8.32 KB
/
05_visualize.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# LEiDA(Cabral 2017. Sci Rep.)-PART5: Visualization of result
# author: zhangjiaqi(Smile.Z), CASIA, Brainnetome
import numpy as np
from scipy.signal import hilbert
from scipy.spatial.distance import cosine
import math
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score
from sklearn.metrics import davies_bouldin_score
import pandas as pd
from sklearn.decomposition import PCA
import os
from validclust import ValidClust
from mpl_toolkits.mplot3d import Axes3D
import itertools
from scipy import stats
from scipy.stats import ttest_ind
sns.set()
def Func_Network(K):
yeo7 = ['Visual', 'Somatomotor', 'Dorsal', 'Ventral', 'Limbic', 'Frontoparietal', 'Default']
yeo17 = ['Visual_A', 'Visual_B', 'Somatomotor_A', 'Somatomotor_B', 'Temporal Parietal',
'Frontoparietal', 'Dorsal Attention_B', 'Salience+Ventral Attention_A', 'Salience+Ventral Attention_B',
'Control_A', 'Control_B', 'Control_C', 'Default_A', 'Default_B', 'Default_C',
'Limbic_A', 'Limbic_B']
corr7 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/cluster/'+str(K)+'/yeo7corr.txt')
corr17 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/cluster/'+str(K)+'/yeo17corr.txt')
p7 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/cluster/'+str(K)+'/yeo7pvalue.txt')
p17 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/cluster/'+str(K)+'/yeo17pvalue.txt')
x = list(range(1, K+1, 1))
xx = list(range(0, K+1, 1))
plt.figure(figsize=(25, 18))
plt.xticks(np.arange(len(xx)), xx)
plt.axhline(y=0)
wid = 1.0/8
for i in range(7):
plt.bar(x, corr7[:, i], width=wid, label=yeo7[i])
for j in range(K):
if p7[:, i][j]<0.001 and corr7[:, i][j]>0:
plt.text(x[j], corr7[:, i][j], "*", horizontalalignment='center', verticalalignment= 'bottom')
if p7[:, i][j]<0.001 and corr7[:, i][j]<0:
plt.text(x[j], corr7[:, i][j], "*", horizontalalignment='center', verticalalignment= 'top')
x = [a+wid for a in x]
plt.xlabel('Brain States obtained with LEiDA for k='+str(K))
plt.ylabel("Pearson's correlation with Yeo7")
plt.legend(bbox_to_anchor=(1.02, 1), borderaxespad=0., fontsize=8)
plt.savefig('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/func_network/'+str(K)+'/yeo7_cluster.png')
plt.clf()
x = list(range(1, K+1, 1))
plt.figure(figsize=(25, 5))
plt.xticks(np.arange(len(xx)), xx)
plt.axhline(y=0)
wid = 1.0/18
for i in range(17):
plt.bar(x, corr17[:, i], width=wid, label=yeo17[i])
for j in range(K):
if p17[:, i][j]<0.001 and corr17[:, i][j]>0:
plt.text(x[j], corr17[:, i][j], "*", horizontalalignment='center', verticalalignment= 'bottom')
if p17[:, i][j]<0.001 and corr17[:, i][j]<0:
plt.text(x[j], corr17[:, i][j], "*", horizontalalignment='center', verticalalignment= 'top')
x = [a+wid for a in x]
plt.xlabel('Brain States obtained with LEiDA for k='+str(K))
plt.ylabel("Pearson's correlation with Yeo17")
plt.legend(bbox_to_anchor=(1.02, 1), borderaxespad=0., fontsize=8)
plt.savefig('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/func_network/'+str(K)+'/yeo17_cluster.png')
plt.clf()
def DT(K, g1, g2):
x = list(range(1, K+1, 1))
xx = list(range(0, K+1, 1))
plt.figure(figsize=(25, 5))
plt.xticks(np.arange(len(xx)), xx)
plt.axhline(y=0)
wid = 1.0/3
pvalue = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step4_permutaion_test/'+g1+'_VS_'+g2+'/DT/'+str(K)+'/Dwell_Time_Test.txt')
y1 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/'+g1+'/'+str(K)+'/DT.txt')
y2 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/'+g2+'/'+str(K)+'/DT.txt')
y1 = list(y1)
y2 = list(y2)
plt.bar(x, y1, width=wid, label=g1)
x1 = [a+wid for a in x]
plt.bar(x1, y2, width=wid, label=g2)
for i in range(K):
if pvalue[i]<0.05:
plt.text((x[i]+x1[i])/2, max(y1[i], y2[i]), "*", horizontalalignment='center', verticalalignment= 'bottom')
plt.xlabel('Brain States obtained with LEiDA for k='+str(K))
plt.ylabel("Dwell Time(s)")
plt.legend(bbox_to_anchor=(1.02, 1), borderaxespad=0., fontsize=8)
plt.savefig('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/DT/'+str(K)+'/'+g1+'_VS_'+g2+'_DT.png')
plt.clf()
def FO(K, g1, g2):
x = list(range(1, K+1, 1))
xx = list(range(0, K+1, 1))
plt.figure(figsize=(25, 5))
plt.xticks(np.arange(len(xx)), xx)
plt.axhline(y=0)
wid = 1.0/3
pvalue = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step4_permutaion_test/'+g1+'_VS_'+g2+'/FO/'+str(K)+'/Fractional_Occupancy_Test.txt')
y1 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/'+g1+'/'+str(K)+'/FO.txt')
y2 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/'+g2+'/'+str(K)+'/FO.txt')
y1 = list(y1)
y2 = list(y2)
plt.bar(x, y1, width=wid, label=g1)
x1 = [a+wid for a in x]
plt.bar(x1, y2, width=wid, label=g2)
for i in range(K):
if pvalue[i]<0.05:
plt.text((x[i]+x1[i])/2, max(y1[i], y2[i]), "*", horizontalalignment='center', verticalalignment= 'bottom')
plt.xlabel('Brain States obtained with LEiDA for k='+str(K))
plt.ylabel("Fractional Occupancy")
plt.legend(bbox_to_anchor=(1.02, 1), borderaxespad=0., fontsize=8)
plt.savefig('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/FO/'+str(K)+'/'+g1+'_VS_'+g2+'_FO.png')
plt.clf()
def Markov(K, g1, g2):
pvalue = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step4_permutaion_test/'+g1+'_VS_'+g2+'/Markov/'+str(K)+'/Transition_Probability_Test.txt')
m1 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/'+g1+'/'+str(K)+'/Markov_Matrix.txt')
m2 = np.loadtxt('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step3_index/'+g2+'/'+str(K)+'/Markov_Matrix.txt')
annot1 = []
annot2 = []
for i in range(K):
annot11 = []
annot22 = []
for j in range(K):
if pvalue[i][j]<0.05:
annot11.append(str(np.round(m1[i][j], 3))+'*')
annot22.append(str(np.round(m2[i][j], 3))+'*')
else:
annot11.append(np.round(m1[i][j], 3))
annot22.append(np.round(m2[i][j], 3))
annot1.append(annot11)
annot2.append(annot22)
m1 = list(m1)
m2 = list(m2)
x_axis_labels = list(range(1, K+1, 1))
y_axis_labels = list(range(1, K+1, 1))
if K<7:
plt.figure(figsize=(10, 10))
else:
plt.figure(figsize=(20, 20))
sns.heatmap(m1, annot=annot1, vmax=1, vmin=0, fmt='', square=True, xticklabels=x_axis_labels, yticklabels=y_axis_labels)
plt.savefig('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/Markov/'+str(K)+'/'+g1+'_VS_'+g2+'_Markov_'+g1+'_.png')
plt.clf()
sns.heatmap(m2, annot=annot2, vmax=1, vmin=0, fmt='', square=True, xticklabels=x_axis_labels, yticklabels=y_axis_labels)
plt.savefig('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/Markov/'+str(K)+'/'+g1+'_VS_'+g2+'_Markov_'+g2+'_.png')
plt.clf()
if __name__ == '__main__':
for K in range(2, 21):
os.makedirs('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/func_network/'+str(K))
Func_Network(K)
os.makedirs('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/DT/'+str(K))
DT(K, 'MDD1','MDD2')
DT(K, 'MDD1', 'HC')
DT(K, 'MDD2', 'HC')
os.makedirs('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/FO/'+str(K))
FO(K, 'MDD1','MDD2')
FO(K, 'MDD1', 'HC')
FO(K, 'MDD2', 'HC')
os.makedirs('/share/home/zhangjiaqi/2022Project/HOPF/02_LEiDA_Empircal/step5_visualize/Markov/'+str(K))
Markov(K, 'MDD1', 'MDD2')
Markov(K, 'MDD1', 'HC')
Markov(K, 'MDD2', 'HC')