-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlagged_fnc.py
149 lines (115 loc) · 6.5 KB
/
lagged_fnc.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
import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
#plt.ioff()
import utils as u
import core as c
from nilearn import plotting
import os
import numpy as np
import plotGallery as pg
import csv
TR = 2.46
lag = 3
new_tr = 0.5
namesNodes_node_to_node = ['Auditory', 'Cerebellum', 'DMN', 'ECL', 'ECR', 'Salience', 'SensoriMotor', 'Vis_Lateral',
'Vis_Medial', 'Vis_Occipital']
crs_r_hc = '/home/jrudascas/Desktop/Test/crs_r_hc.csv'
crs_r_mcs = '/home/jrudascas/Desktop/Test/crs_r_mcs.csv'
crs_r_uws = '/home/jrudascas/Desktop/Test/crs_r_uws.csv'
crs_r = '/home/jrudascas/Desktop/Test/crs_r.csv'
crs_r_hc_values = []
crs_r_mcs_values = []
crs_r_uws_values = []
with open(crs_r_hc) as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar=',', quoting=csv.QUOTE_MINIMAL)
for row in reader:
crs_r_hc_values.append(int(row[1]))
with open(crs_r_mcs) as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar=',', quoting=csv.QUOTE_MINIMAL)
for row in reader:
crs_r_mcs_values.append(int(row[1]))
with open(crs_r_uws) as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar=',', quoting=csv.QUOTE_MINIMAL)
for row in reader:
crs_r_uws_values.append(int(row[1]))
#path_general = '/home/runlab/data/COMA/'
#path_general_atlas = '/home/runlab/data/Atlas/RSN/'
path_general = '/home/jrudascas/Desktop/Test/'
#path_general = '/home/jrudascas/Desktop/Oa/'
path_general_atlas = '/home/jrudascas/Desktop/DWITest/Additionals/Atlas/RSN/'
list_path_atlas = [path_general_atlas + 'frAuditory_corr.nii.gz',
path_general_atlas + 'frCerebellum_corr.nii.gz',
path_general_atlas + 'frDMN_corr.nii.gz',
path_general_atlas + 'frECN_L_corr.nii.gz',
path_general_atlas + 'frECN_R_corr.nii.gz',
path_general_atlas + 'frSalience_corr.nii.gz',
path_general_atlas + 'frSensorimotor_corr.nii.gz',
path_general_atlas + 'frVisual_lateral_corr.nii.gz',
path_general_atlas + 'frVisual_medial_corr.nii.gz',
path_general_atlas + 'frVisual_occipital_corr.nii.gz']
core = c.Core()
name_file = 'data/functional/fmriGLM.nii.gz'
list_connectivity_matrixs_group = []
list_td_matrixs_group = []
for group in sorted(os.listdir(path_general)):
path_group = os.path.join(path_general, group)
if os.path.isdir(path_group):
list_connectivity_matrixs = []
list_td_matrixs = []
for dir in sorted(os.listdir(path_group)):
path_subject = os.path.join(os.path.join(path_general, group), dir)
if os.path.isdir(path_subject):
print(dir)
path_full_file = os.path.join(path_subject, name_file)
print(1)
#if os.path.join(path_subject, 'time_series.txt'):
time_series_rsn = u.to_extract_time_series(path_full_file, list_path_altas=list_path_atlas)
print(2)
connectivity_matrix, td_matrix, awtd_matrix, tr = core.run2(time_series_rsn, tr=TR, lag=lag, new_tr=new_tr)
print(3)
list_connectivity_matrixs.append(connectivity_matrix)
list_td_matrixs.append(td_matrix*tr)
fig, ax = plt.subplots()
plotting.plot_matrix(np.mean(np.array(list_connectivity_matrixs), axis=0), labels=namesNodes_node_to_node,
vmax=1, vmin=-1, figure=fig)
fig.savefig(path_group + group + '_mean.png', dpi=600)
list_connectivity_matrixs_group.append(list_connectivity_matrixs)
list_td_matrixs_group.append(list_td_matrixs)
td_hc = np.array(list_td_matrixs_group[0])[:,np.triu_indices(10, k=1)[0], np.triu_indices(10, k=1)[1]]
td_mcs = np.array(list_td_matrixs_group[1])[:,np.triu_indices(10, k=1)[0], np.triu_indices(10, k=1)[1]]
td_uws = np.array(list_td_matrixs_group[2])[:,np.triu_indices(10, k=1)[0], np.triu_indices(10, k=1)[1]]
pg.fivethirtyeightPlot(td_mcs, td_uws, group3=td_hc, lag=lag, save='ThreadsLagPC.png')
print("Test Graph MCS UWS\n")
pList1 = u.to_find_statistical_differences(u.buildFeaturesVector(np.array(list_connectivity_matrixs_group[1])),
u.buildFeaturesVector(np.array(list_connectivity_matrixs_group[2])),
to_correct=True)
print("Test Graph HC MCS\n")
pList1 = u.to_find_statistical_differences(u.buildFeaturesVector(np.array(list_connectivity_matrixs_group[0])),
u.buildFeaturesVector(np.array(list_connectivity_matrixs_group[1])),
to_correct=True)
print("Test Graph HC UWS\n")
pList1 = u.to_find_statistical_differences(u.buildFeaturesVector(np.array(list_connectivity_matrixs_group[0])),
u.buildFeaturesVector(np.array(list_connectivity_matrixs_group[2])),
to_correct=True)
print("\nLaggeds HC MCS")
pList1 = u.to_find_statistical_differences(np.mean(np.array(list_td_matrixs_group[0]), axis=-1),
np.mean(np.array(list_td_matrixs_group[1]), axis=-1))
print("\nLaggeds HC UWS")
pList1 = u.to_find_statistical_differences(np.mean(np.array(list_td_matrixs_group[0]), axis=-1),
np.mean(np.array(list_td_matrixs_group[2]), axis=-1))
print("\nLaggeds MCS UWS")
pList1 = u.to_find_statistical_differences(np.mean(np.array(list_td_matrixs_group[1]), axis=-1),
np.mean(np.array(list_td_matrixs_group[2]), axis=-1))
print(np.mean(np.array(list_td_matrixs_group[2]), axis=-1).shape)
for index in range(np.mean(np.array(list_td_matrixs_group[2]), axis=-1).shape[-1]):
u.plot_linear_regression((crs_r_hc_values, crs_r_mcs_values, crs_r_uws_values),
(np.mean(np.array(list_td_matrixs_group[0]), axis=-1)[:,index],
np.mean(np.array(list_td_matrixs_group[1]), axis=-1)[:,index],
np.mean(np.array(list_td_matrixs_group[2]), axis=-1)[:,index]), str(index))
np.savetxt(path_general + 'mean_td_hc.txt', np.mean(np.array(list_td_matrixs_group[0]), axis=-1), delimiter=' ',
fmt='%s')
np.savetxt(path_general + 'mean_td_mcs.txt', np.mean(np.array(list_td_matrixs_group[1]), axis=-1), delimiter=' ',
fmt='%s')
np.savetxt(path_general + 'mean_td_uws.txt', np.mean(np.array(list_td_matrixs_group[2]), axis=-1), delimiter=' ',
fmt='%s')