-
Notifications
You must be signed in to change notification settings - Fork 6
/
readElecLocalCSVFile.py
147 lines (121 loc) · 5.18 KB
/
readElecLocalCSVFile.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
#
# From Electrodes localisation, read CSV file coming from INTRANAT
#
import csv, sys, os, re
from datetime import date
import pdb
def readElecLocalCSVFile(infile = None):
data = csv.reader(open(infile), delimiter = '\t')
contents = []
for row in data:
contents.append(row)
saveSpaceL = 0
#find the string 'contact' to identify the starting line
for i1 in range(len(contents[1])):
for i2 in range(10):
try:
if contents[i2][i1] == 'contact':
savec = i1
savel = i2
if contents[i2][i1] == 'Use of MNI Template':
saveSpaceL = i2
except:
continue
props = {}
if saveSpaceL == 0:
props['MarsAtlas'] = 'specific'
props['Freesurfer'] = 'empty'
props['HippoSubfieldFreesurfer'] = 'empty'
else:
if contents[saveSpaceL][contents[saveSpaceL].index('MarsAtlas')+1] == 'True':
props['MarsAtlas'] = 'MNI'
else:
props['MarsAtlas'] = 'specific'
if contents[saveSpaceL][contents[saveSpaceL].index('Freesurfer')+1] =='True':
props['Freesurfer'] = 'MNI'
else:
props['Freesurfer'] = 'specific'
if contents[saveSpaceL][contents[saveSpaceL].index('HippoSubfieldFreesurfer')+1] == 'True':
props['HippoSubfieldFreesurfer'] = 'MNI'
else:
props['HippoSubfieldFreesurfer'] = 'specific'
startl = savel + 1
#extract monopolar and bipolar contacts, assuming each list is separated by a two-lines blank
stimpolarity = ['monopolar', 'bipolar']
ContactsInfos = {'monopolar':{},'bipolar':{}}
i = -2
for pol in stimpolarity:
i = i + 2
while contents[startl+i]:
# standard name : 'Ap12' (not A'12, Ap21, a'1a'2...)
nametmp = contents[startl+i][savec]
testpol = re.search(" - ",nametmp)
if testpol is not None:
polarity = 'bipolar'
else:
polarity = 'monopolar'
resection = []
if contents[startl+i][contents[savel].index('Resection')] == 'not in resection':
resection = False
elif not contents[startl+i][contents[savel].index('Resection')] == 'resection not calculated':
resection = True
#if not Contact.objects.filter(CRF = crf, name = name, polarity = polarity):
if nametmp not in list(ContactsInfos.keys()):
ContactsInfos[polarity].update({nametmp:{}})
#newcontact = Contact(CRF = crf, name = name, polarity = polarity, resection = resection, segmentation = greywhite)
for index_column in contents[savel]:
if index_column != 'contact':
ContactsInfos[polarity][nametmp].update({index_column:contents[startl+i][contents[savel].index(index_column)]})
i += 1
ResectionInfos={}
i=i+2
try:
while contents[startl+i]:
if contents[startl+i]==['Resection Information']:
actualAtlas = ''
elif contents[startl+i]==['mars_atlas']:
actualAtlas = 'mars_atlas'
ResectionInfos.update({'mars_atlas':{}})
elif contents[startl+i]==['Freesurfer']:
actualAtlas = 'Freesurfer'
ResectionInfos.update({'Freesurfer':{}})
elif contents[startl+i][0] == 'Volume resection (mm3):' :
ResectionInfos.update({'Volume resection (mm3):':contents[startl+i][1]})
else:
ResectionInfos[actualAtlas].update({contents[startl+i][0]:contents[startl+i][1]})
i += 1
except:
pass
return (props,ContactsInfos,ResectionInfos)
#try:
#ContactsInfos[nametmp].update({'MarsAtlas':contents[startl+i][contents[savel].index('MarsAtlas')]})
#except:
#pass
#try:
#ContactsInfos[nametmp].update({'Freesurfer':contents[startl+i][contents[savel].index('Freesurfer')]})
#except:
#pass
#try:
#ContactsInfos[nametmp].update({'HippoSubfieldFreeSurfer':contents[startl+i][contents[savel].index('HippoSubfieldFreeSurfer')]})
#except:
#pass
#try:
#ContactsInfos[nametmp].update({'MNI':contents[startl+i][contents[savel].index('MNI')]})
#except:
#pass
#try:
#ContactsInfos[nametmp].update({'AAL':contents[startl+i][contents[savel].index('AAL')]})
#except:
#pass
#try:
#ContactsInfos[nametmp].update({'AALDilate':contents[startl+i][contents[savel].index('AALDilate')]})
#except:
#pass
#try:
#ContactsInfos[nametmp].update({'Broadmann':contents[startl+i][contents[savel].index('Broadmann')]})
#except:
#pass
#try:
#ContactsInfos[nametmp].update({'Hammers':contents[startl+i][contents[savel].index('Hammers')]})
#except:
#pass