/
analyzeNeuromorpho.py
266 lines (248 loc) · 14.1 KB
/
analyzeNeuromorpho.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from numpy.core.numeric import True_
import requests
import numpy as np
from matplotlib import pyplot as plt
plt.ion()
brainstem_rxvs = ['Williams_Wilson', 'Mena-Segovia', 'Cameron', 'Irintchev']
neo_pyramidal_rxvs = ['BICCN-MOp-miniatlas-anatomy', 'Dendritica', 'Suter_Shepherd', 'Groh', 'Buchs', 'DeKock', 'Kawaguchi', 'Jacobs', 'Meyer']
neo_int_rxvs = ['Yuste', 'Sun', 'Bikson']
hipp_pyr_rxvs = ['Arnold_Johnston', 'Soltesz']
granule_rxvs = ['Beining', 'Bausch']
hipp_int_rxvs = ['Anstoetz', 'Gulyas', 'Hajos', 'Turner']
out = {}
base_url = 'http://neuromorpho.org/api/neuron/select?q=archive:'
all_rxvs = brainstem_rxvs + neo_pyramidal_rxvs + neo_int_rxvs + hipp_pyr_rxvs + granule_rxvs + hipp_int_rxvs
for rxv in all_rxvs:
full_url = base_url + rxv
r = requests.get(full_url)
data = r.json()
out[rxv] = {}
for cell in data['_embedded']['neuronResources']:
if (cell['attributes'] == 'Diameter, 3D, Angles') and (cell['domain'].startswith('Dendrites')):
if 'neocortex' in cell['brain_region'] and (('principal cell' in cell['cell_type']) or ('pyramidal' in cell['cell_type'])):
if 'neo_pyr' not in list(out[rxv].keys()):
out[rxv]['neo_pyr'] = {'sv' : [float(cell['surface']) / float(cell['volume'])],
'min_age' : [cell['min_age']],
'max_age' : [cell['max_age']],
'reference' : cell['reference_doi'],
'avg_sv' : None,
'std_sv' : None,
'brain_region' : cell['brain_region'],
'species' : cell['species'],
'cell_type' : cell['cell_type'],
'n' : None}
else:
out[rxv]['neo_pyr']['sv'].append(float(cell['surface']) / float(cell['volume']))
out[rxv]['neo_pyr']['min_age'].append(cell['min_age'])
out[rxv]['neo_pyr']['max_age'].append(cell['max_age'])
out[rxv]['neo_pyr']['avg_sv'] = np.mean(out[rxv]['neo_pyr']['sv'])
out[rxv]['neo_pyr']['std_sv'] = np.std(out[rxv]['neo_pyr']['sv'])
out[rxv]['neo_pyr']['n'] = len(out[rxv]['neo_pyr']['sv'])
if ('neocortex' in cell['brain_region']) and ('interneuron' in cell['cell_type']):
if 'neo_int' not in list(out[rxv].keys()):
out[rxv]['neo_int'] = {'sv' : [float(cell['surface']) / float(cell['volume'])],
'min_age' : [cell['min_age']],
'max_age' : [cell['max_age']],
'reference' : cell['reference_doi'],
'avg_sv' : None,
'std_sv' : None,
'brain_region' : cell['brain_region'],
'species' : cell['species'],
'cell_type' : cell['cell_type'],
'n' : None}
else:
out[rxv]['neo_int']['sv'].append(float(cell['surface']) / float(cell['volume']))
out[rxv]['neo_int']['min_age'].append(cell['min_age'])
out[rxv]['neo_int']['max_age'].append(cell['max_age'])
out[rxv]['neo_int']['avg_sv'] = np.mean(out[rxv]['neo_int']['sv'])
out[rxv]['neo_int']['std_sv'] = np.std(out[rxv]['neo_int']['sv'])
out[rxv]['neo_int']['n'] = len(out[rxv]['neo_int']['sv'])
if ('brainstem' in cell['brain_region']):
if 'brainstem' not in list(out[rxv].keys()):
out[rxv]['brainstem'] = {'sv' : [float(cell['surface']) / float(cell['volume'])],
'min_age' : [cell['min_age']],
'max_age' : [cell['max_age']],
'reference' : cell['reference_doi'],
'avg_sv' : None,
'std_sv' : None,
'brain_region' : cell['brain_region'],
'species' : cell['species'],
'cell_type' : [cell['cell_type']],
'n' : None}
else:
out[rxv]['brainstem']['sv'].append(float(cell['surface']) / float(cell['volume']))
out[rxv]['brainstem']['min_age'].append(cell['min_age'])
out[rxv]['brainstem']['max_age'].append(cell['max_age'])
out[rxv]['brainstem']['avg_sv'] = np.mean(out[rxv]['brainstem']['sv'])
out[rxv]['brainstem']['std_sv'] = np.std(out[rxv]['brainstem']['sv'])
out[rxv]['brainstem']['n'] = len(out[rxv]['brainstem']['sv'])
out[rxv]['brainstem']['cell_type'].append(cell['cell_type'])
if ('hippocampus' in cell['brain_region']) and ('Control' in cell['experiment_condition']) and (('pyramidal' in cell['cell_type']) or ('pyramidal cell' in cell['cell_type'])):
if 'hipp_pyr' not in list(out[rxv].keys()):
out[rxv]['hipp_pyr'] = {'sv' : [float(cell['surface']) / float(cell['volume'])],
'min_age' : [cell['min_age']],
'max_age' : [cell['max_age']],
'reference' : cell['reference_doi'],
'avg_sv' : None,
'std_sv' : None,
'brain_region' : cell['brain_region'],
'species' : cell['species'],
'cell_type' : cell['cell_type'],
'n' : None}
else:
out[rxv]['hipp_pyr']['sv'].append(float(cell['surface']) / float(cell['volume']))
out[rxv]['hipp_pyr']['min_age'].append(cell['min_age'])
out[rxv]['hipp_pyr']['max_age'].append(cell['max_age'])
out[rxv]['hipp_pyr']['avg_sv'] = np.mean(out[rxv]['hipp_pyr']['sv'])
out[rxv]['hipp_pyr']['std_sv'] = np.std(out[rxv]['hipp_pyr']['sv'])
out[rxv]['hipp_pyr']['n'] = len(out[rxv]['hipp_pyr']['sv'])
if ('hippocampus' in cell['brain_region']) and ('Control' in cell['experiment_condition']) and ('granule' in cell['cell_type']):
if 'hipp_gran' not in list(out[rxv].keys()):
out[rxv]['hipp_gran'] = {'sv' : [float(cell['surface']) / float(cell['volume'])],
'min_age' : [cell['min_age']],
'max_age' : [cell['max_age']],
'reference' : cell['reference_doi'],
'avg_sv' : None,
'std_sv' : None,
'brain_region' : cell['brain_region'],
'species' : cell['species'],
'cell_type' : cell['cell_type'],
'n' : None}
else:
out[rxv]['hipp_gran']['sv'].append(float(cell['surface']) / float(cell['volume']))
out[rxv]['hipp_gran']['min_age'].append(cell['min_age'])
out[rxv]['hipp_gran']['max_age'].append(cell['max_age'])
out[rxv]['hipp_gran']['avg_sv'] = np.mean(out[rxv]['hipp_gran']['sv'])
out[rxv]['hipp_gran']['std_sv'] = np.std(out[rxv]['hipp_gran']['sv'])
out[rxv]['hipp_gran']['n'] = len(out[rxv]['hipp_gran']['sv'])
if ('hippocampus' in cell['brain_region']) and ('Control' in cell['experiment_condition']) and ('interneuron' in cell['cell_type']):
if 'hipp_inter' not in list(out[rxv].keys()):
out[rxv]['hipp_inter'] = {'sv' : [float(cell['surface']) / float(cell['volume'])],
'min_age' : [cell['min_age']],
'max_age' : [cell['max_age']],
'reference' : cell['reference_doi'],
'avg_sv' : None,
'std_sv' : None,
'brain_region' : cell['brain_region'],
'species' : cell['species'],
'cell_type' : cell['cell_type'],
'n' : None}
else:
out[rxv]['hipp_inter']['sv'].append(float(cell['surface']) / float(cell['volume']))
out[rxv]['hipp_inter']['min_age'].append(cell['min_age'])
out[rxv]['hipp_inter']['max_age'].append(cell['max_age'])
out[rxv]['hipp_inter']['avg_sv'] = np.mean(out[rxv]['hipp_inter']['sv'])
out[rxv]['hipp_inter']['std_sv'] = np.std(out[rxv]['hipp_inter']['sv'])
out[rxv]['hipp_inter']['n'] = len(out[rxv]['hipp_inter']['sv'])
# plt.plot(sv, '*')
# plt.scatter(age, sv)
for archive in out.keys():
print(archive)
for cell_type in out[archive].keys():
print(cell_type)
print('s:v ' + str(out[archive][cell_type]['avg_sv']))
print('std ' + str(out[archive][cell_type]['std_sv']))
print('species ' + out[archive][cell_type]['species'])
print('cell type' + str(out[archive][cell_type]['cell_type']))
print('n ' + str(out[archive][cell_type]['n']))
print('\n')
bstem = []
adlt_bstem = []
bstem_refs = []
for rxv in brainstem_rxvs:
adlt = []
for sv, age in zip(out[rxv]['brainstem']['sv'], out[rxv]['brainstem']['min_age']):
if age != 'Not Reported' and age != '4.5':
if float(age) > 14:
adlt.append(sv)
else:
adlt.append(sv)
# adlt = [sv for sv, age in zip(out[rxv]['brainstem']['sv'], out[rxv]['brainstem']['min_age']) if (age is not 'Not Reported') and float(age) > 14]
adlt_bstem = adlt_bstem + adlt
bstem = bstem + out[rxv]['brainstem']['sv']
bstem_refs.append(out[rxv]['brainstem']['reference'])
rat_neopyr = []
rat_neopyr_rxvs = []
rat_neopyr_refs = []
for rxv in all_rxvs:
if 'neo_pyr' in (out[rxv].keys()):
if out[rxv]['neo_pyr']['species'] == 'rat':
rat_neopyr_rxvs.append(rxv)
rat_neopyr = rat_neopyr + out[rxv]['neo_pyr']['sv']
rat_neopyr_refs.append(out[rxv]['neo_pyr']['reference'])
mouse_neopyr_rxvs = []
mouse_neopyr_refs = []
for rxv in all_rxvs:
if 'neo_pyr' in (out[rxv].keys()):
if out[rxv]['neo_pyr']['species'] == 'mouse':
mouse_neopyr_rxvs.append(rxv)
mouse_neopyr = rat_neopyr + out[rxv]['neo_pyr']['sv']
mouse_neopyr_refs.append(out[rxv]['neo_pyr']['reference'])
rat_neoint = []
rat_neoint_rxvs = []
rat_neoint_refs = []
for rxv in all_rxvs:
if 'neo_int' in (out[rxv].keys()):
if out[rxv]['neo_int']['species'] == 'rat':
rat_neoint_rxvs.append(rxv)
rat_neoint = rat_neopyr + out[rxv]['neo_int']['sv']
rat_neoint_refs.append(out[rxv]['neo_int']['reference'])
mouse_neoint = []
mouse_neoint_rxvs = []
mouse_neoint_refs = []
for rxv in all_rxvs:
if 'neo_int' in (out[rxv].keys()):
if out[rxv]['neo_int']['species'] == 'mouse':
mouse_neoint_rxvs.append(rxv)
mouse_neoint = rat_neopyr + out[rxv]['neo_int']['sv']
mouse_neoint_refs.append(out[rxv]['neo_int']['reference'])
print('Brainstem: ' + str(round(np.mean(bstem),2)) + ' +/- ' +
str(round(np.std(bstem),2)) + ' (n=' + str(len(bstem)) + ')\n')
print('Mature Brainstem: ' + str(round(np.mean(adlt_bstem),2)) + ' +/- ' +
str(round(np.std(adlt_bstem),2)) + ' (n=' + str(len(adlt_bstem)) + ')\n')
refstr = ''
for ref in bstem_refs:
if ref:
refstr = refstr + ref[0] + ', '
else:
refstr = refstr + 'None, '
refstr = refstr[:-2] + '\n'
print(refstr)
print('Rat Nctx PYR: ' + str(round(np.mean(rat_neopyr),2)) + ' +/- ' +
str(round(np.std(rat_neopyr),2)) + ' (n=' + str(len(rat_neopyr)) + ')\n')
refstr = ''
for ref, rxv in zip(rat_neopyr_refs, rat_neopyr_rxvs):
if ref:
refstr = refstr + ref[0] + ', '
else:
refstr = refstr + rxv + ', '
refstr = refstr[:-2] + '\n'
print(refstr)
print('Rat Nctx INT: ' + str(round(np.mean(rat_neoint),2)) + ' +/- ' +
str(round(np.std(rat_neoint),2)) + ' (n=' + str(len(rat_neoint)) + ')\n')
for ref, rxv in zip(rat_neoint_refs, rat_neoint_rxvs):
if ref:
refstr = refstr + ref[0] + ', '
else:
refstr = refstr + rxv + ', '
refstr = refstr[:-2] + '\n'
print(refstr)
print('Mouse Nctx PYR: ' + str(round(np.mean(mouse_neopyr),2)) + ' +/- ' +
str(round(np.std(mouse_neopyr),2)) + ' (n=' + str(len(mouse_neopyr)) + ')\n')
for ref, rxv in zip(mouse_neopyr_refs, mouse_neopyr_rxvs):
if ref:
refstr = refstr + ref[0] + ', '
else:
refstr = refstr + rxv + ', '
refstr = refstr[:-2] + '\n'
print(refstr)
print('Mouse Nctx INT: ' + str(round(np.mean(mouse_neoint),2)) + ' +/- ' +
str(round(np.std(mouse_neoint),2)) + ' (n=' + str(len(mouse_neoint)) + ')\n')
for ref, rxv in zip(mouse_neoint_refs, mouse_neoint_rxvs):
if ref:
refstr = refstr + ref[0] + ', '
else:
refstr = refstr + rxv + ', '
refstr = refstr[:-2] + '\n'
print(refstr)
# v1.0 - analysis of S:V for cells from NeuroMorpho with largely complete 3D dendritic reconstructions