-
Notifications
You must be signed in to change notification settings - Fork 1
/
hcp_dti.py
207 lines (169 loc) · 5.22 KB
/
hcp_dti.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
from scipy.io import loadmat
class HcpDesikanKilliany():
"""
Connectivity from the HCP in the Desikan Killiany atlas.
Provided by Alex Goulas and Claus Hilgetag.
Returns
-------
data : Panel
All available data
names : list
Names of Desikan Killiany atlas
"""
def __init__(self, file_path):
self.file_path = file_path
# Read in data
self.data = loadmat(self.file_path)
# Preprocess names: Convert to 1d list & strip leading 'ctx-lh-'
self.names = self.data['DK_Names']
self.names = np.concatenate(self.names.flatten()).tolist()
self.names = [s.split('-')[-1] for s in self.names]
self.dist = pd.DataFrame(
self.data['Dist'],
columns=self.names,
index=self.names,
dtype=np.float64
)
self.RightHem = pd.DataFrame(
self.data['LowResDK_EstimatedDist_RHem'],
columns=self.names,
index=self.names,
dtype=np.float64
)
self.LeftHem = pd.DataFrame(
self.data['LowResDK_EstimatedDist_LHem'],
columns=self.names,
index=self.names,
dtype=np.float64
)
self.ConnectivityRight = pd.DataFrame(
self.data['C_R'],
columns=self.names,
index=self.names,
dtype=np.float64
)
self.ConnectivityLeft = pd.DataFrame(
self.data['C_L'],
columns=self.names,
index=self.names,
dtype=np.float64
)
def __repr__(self):
return ('HCP connectivity data\n'
'File: {0}\nRegions (major & minor axis):\n{1}\n'
'Items:\n{2}\n'
.format(self.file_path,
np.array(self.names),
self.data.items.values)
)
def getDesikanKillianyNames(self):
"""
Returns the names of the different Desikan Killiany areasself.
Returns
-------
names : list
"""
return self.names
def getDist(self):
"""
Returns the euclidean distances in mm of the different Desikan Killiany
areas.
Returns
-------
euclidean_distance : DataFrame
"""
return self.dist
def getFiberLengthRight(self):
"""
Returns the fiber lengthes in mm of the right hemisphere of the different
Desikan Killiany areas.
Returns
-------
fiber_length_right : DataFrame
"""
return self.RightHem
def getFiberLengthLeft(self):
"""
Returns the fiber lengthes in mm of the left hemisphere of the different
Desikan Killiany areas.
Returns
-------
fiber_length_left : DataFrame
"""
return self.LeftHem
def getConnectivityRight(self):
"""
Returns the connectivity of the right hemisphere of the different
Desikan Killiany areas.
Returns
-------
connectivity_right : DataFrame
"""
return self.ConnectivityRight
def getConnectivityLeft(self):
"""
Returns the connectivity of the left hemisphere of the different
Desikan Killiany areas
Returns
-------
connectivity_left : DataFrame
"""
return self.ConnectivityLeft
def dump(self, file_path):
"""
Save all data as a hdf file
"""
# TODO keep as hdf?
self.data.to_hdf(file_path, key='HCP', mode='w')
class VolumesDK():
"""
Loads area volumes in Desikan Killiany parcellation. Provided
by Alex Goulas.
Parameters
----------
file_path : string
Path to data file
"""
def __init__(self, file_path):
self.file_path = file_path
# Read in data
self.data = loadmat(self.file_path)
# Preprocess names: Convert to 1d list & strip leading 'ctx-lh-'
self.names = self.data['HumanDKNames']
self.names = np.concatenate(self.names.flatten()).tolist()
self.data = pd.Series(
data=self.data['Volume'].flatten(),
index=self.names,
dtype=np.float64
)
def getVolume(self):
"""
Returns the volume of all areas in the Desikan Killiany
parcellation. The volume is cubic mm.
Returns
-------
volume : Series
Volume of the areas
"""
return self.data
if __name__ == "__main__":
dk_path = 'experimental_data/hcp_dti/Connectivity_Distances_HCP_DesikanKilliany.mat'
dk = HcpDesikanKilliany(dk_path)
print(dk)
# dk.dump('dk_tmp.hdf')
print(dk.data['Connectivity (right) [NOS]', 'middletemporal'])
# import seaborn as sns
# import matplotlib.pyplot as plt
# fig, ax = plt.subplots(figsize=(10, 10))
# sns.heatmap(
# dk.data['Connectivity (right) [NOS]'],
# ax=ax,
# xticklabels=1,
# yticklabels=1,
# cmap='Blues'
# )
# plt.tight_layout()
# plt.show()