-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
70 lines (57 loc) · 1.92 KB
/
utils.py
File metadata and controls
70 lines (57 loc) · 1.92 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
def create_design_files(age):
import os
mat = age
mat_str = [
'/NumWaves 1',
'/NumPoints %s' % str(mat.shape[0]),
'/Matrix'
]
n_cons = 2
cons_str = [
'/ContrastName1 pos_age',
'/ContrastName2 neg_age',
'/NumWaves 1',
'/NumContrasts %s' % str(n_cons),
'',
'/Matrix',
'1',
'-1',
]
mat_file = os.path.join(os.getcwd(), 'design.mat')
con_file = os.path.join(os.getcwd(), 'design.con')
with open(con_file, 'w') as out_file:
for line in cons_str:
out_file.write('%s\n' % line)
with open(mat_file, 'w') as out_file:
for line in mat_str:
out_file.write('%s\n' % line)
for line in mat:
out_file.write('%s\n' % line)
return (con_file, mat_file)
def run_randomise_fct(data_file, mat_file, con_file, mask_file):
import os
out_dir = os.path.join(os.getcwd(), 'glm')
os.mkdir(out_dir)
cmd_str = 'randomise -i %s -o glm/glm -d %s -t %s -m %s -n 500 -D -T' % (data_file, mat_file, con_file, mask_file)
file = open('command.txt', 'w')
file.write(cmd_str)
file.close()
os.system(cmd_str)
return out_dir
def create_renders_fct(randomise_dir, n_cons, background_img):
import os
thresh = .95
out_files_list = []
corr_list = ['glm_tfce_corrp_tstat']
for corr in corr_list:
for con in range(1, n_cons + 1):
output_root = corr + str(con)
in_file = os.path.join(randomise_dir, output_root + '.nii.gz')
out_file = os.path.join(os.getcwd(), 'rendered_' + output_root + '.png')
out_files_list.append(out_file)
cmd_str = 'easythresh %s %s %s %s' % (in_file, str(thresh), background_img, output_root)
file = open('command.txt', 'w')
file.write(cmd_str)
file.close()
os.system(cmd_str)
return out_files_list