-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
executable file
·83 lines (72 loc) · 2.98 KB
/
analysis.py
File metadata and controls
executable file
·83 lines (72 loc) · 2.98 KB
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
#!/usr/bin/python
'''
Analysis main script to build Virtual Resection application pipeline.
'''
import sys
import glob
import json
import time
from util import *
from util_connectivity import *
from util_virtual_resection import *
from util_plot import *
if __name__ == '__main__':
# Get arguments
try:
patient_id = sys.argv[1]
except TypeError:
print 'Please enter an appropriate PATIENT_ID.'
raise
try:
epoch_length = int(sys.argv[2]) # seconds
except IndexError:
epoch_length = 1
try:
force_flag = int(sys.argv[3])
except IndexError:
force_flag = 0
# Check if connectivity already exists
count_conn = 0
for k,v in data["PATIENTS"][patient_id]['Events']['Ictal'].items():
try:
if(v["STATUS"] == 'ALL_DROPOUT'):
continue
else:
count_conn += 1
except Exception:
count_conn += 1
# Check if all connectivity adjacency matrices have been computed
if(len(glob.glob('%s/%s/aim3/*multiband*'%(os.path.expanduser(data['COMP_DIR']),patient_id))) != count_conn) or force_flag:
# Compute multi band connectivity and store adjacency matricies
# blah
# pass
compute_multiband_connectivity(patient_id, epoch_length)
# Check if all node-level virtual resections have been computed
if(len(glob.glob('%s/%s/aim3/*noderes*'%(os.path.expanduser(data['COMP_DIR']),patient_id))) != count_conn) or force_flag:
# Compute node-level virtual resection
nodal_virtual_resection(patient_id, data=data)
# Keep dilating and eroding resection zone to capture percentage of network nodes
# for dilate_radius in [0, -5, 5, 10, -10, 15, -15, 20, -20]:
for dilate_radius in [0]:
# Check if already exists
unique_idx = []
for fn in glob.glob(os.path.expanduser('%s/%s/aim3/*pipedef*'%(data['COMP_DIR'],patient_id))):
pipedef = json.load(open(fn,'r'))
try:
if(pipedef['fconn'] == 'multiband+broadband' and pipedef['dilate_radius'] == dilate_radius):
uid = fn.split('.')[-3]
event_type = fn.split('.')[1]
event_id = fn.split('.')[2]
unique_idx.append((uid,event_type,event_id))
except KeyError:
continue
if(len(unique_idx) == 0) or force_flag or len(glob.glob('%s/%s/aim3/*cres*1000*'%(os.path.expanduser(data['COMP_DIR']),patient_id))) == 0:
# if dilate_radius < 0:
print dilate_radius
# Compute virtual resection to get c_{res}(t)
unique_idx = virtual_resection(patient_id, dilate_radius, data)
# Compute control centrality of SOZ
# Check if already exists
if not len(glob.glob(os.path.expanduser('%s/%s/aim3/*sozres*'%(data['COMP_DIR'],patient_id)))) or force_flag:
# Compute virtual resection to get c_{res}(t)
unique_idx = soz_virtual_resection(patient_id, data)