-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskfslmodel.py
executable file
·113 lines (103 loc) · 4.56 KB
/
taskfslmodel.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#AZEEZ ADEBIMPE PENN BBL
from argparse import (ArgumentParser, RawTextHelpFormatter)
import json
import numpy as np
import pandas as pd
from scipy.stats import gamma
def get_parser():
parser = ArgumentParser(
formatter_class=RawTextHelpFormatter,
description=' generate design.fsf and hrfconvolved matrix')
parser.add_argument(
'-f', '--taskfiledir', action='store', required=True,
help='event file')
parser.add_argument(
'-t', '--template', action='store', required=True,
help=' FSL design template')
return parser
opts = get_parser().parse_args()
filedir=opts.taskfiledir
taskfile=filedir +'/task.json'
with open(taskfile, 'r') as contrastfile:
data_contrast=contrastfile.read()
objcon=json.loads(data_contrast)
eventname=objcon['eventname']
contrast=objcon['contrast']
if contrast:
tasklist=list(contrast.keys())
weight=list(contrast.values())
template1=opts.template
filex = open(template1,"a") #append mode
tevenr="set "+"fmri(evs_real)" + " " + str(len(eventname)) + "\n"
teveno="set "+"fmri(evs_orig)" + " " + str(len(eventname)) + "\n"
evvox="set "+"fmri(evs_vox)" + " " + str(0) + "\n"
nco="set "+"fmri(ncon_orig)" + " " + str(len(tasklist)) + "\n"
ncr="set "+"fmri(ncon_real)" + " " + str(len(tasklist)) + "\n"
filex.write(tevenr)
filex.write(teveno)
filex.write(evvox)
filex.write(nco)
filex.write(ncr)
for i in np.arange(0,len(eventname)):
c=i+1
eventfile=filedir+'/'+eventname[i]+'.txt'
eventt="set "+"fmri(evtitle"+str(c)+")" + " " + '"' + eventname[i] + '"' + "\n"
eventshape="set "+"fmri(shape"+str(c)+")" + " " + str(3) + "\n"
eventtemp="set "+"fmri(tempfilt_yn"+str(c)+")" + " " + str(1) + "\n"
eventcustom="set "+"fmri(custom"+str(c)+")" + " " + '"' + eventfile + '"' + "\n"
eventconv="set "+"fmri(convolve"+str(c)+")" + " " + str(3) + "\n"
orhtho="set "+"fmri(ortho"+str(c)+"."+str(0)+")" + " " + str(0) + "\n"
conphase="set "+"fmri(convolve_phase"+str(c)+")" + " " + str(0) + "\n"
derivey="set "+"fmri(deriv_yn"+str(c)+")" + " " + str(0) + "\n"
filex.write(eventt)
filex.write(eventshape)
filex.write(eventtemp)
filex.write(eventcustom)
filex.write(eventconv)
filex.write(orhtho)
filex.write(derivey)
filex.write(conphase)
for k in np.arange(0,len(eventname)):
h=k+1
orhtho1="set "+"fmri(ortho"+str(c)+"."+str(h)+")" + " " + str(0) + "\n"
filex.write(orhtho1)
for i in np.arange(0,len(tasklist)):
c=i+1
ctdisplay="set " +"fmri(conpic_real."+str(c)+")" + " " + str(1) + " \n"
ctname="set " +"fmri(conname_real."+str(c)+")" + " " + '"' + tasklist[i]+ '"'+ "\n"
ctpdisplay="set " +"fmri(conpic_orig."+str(c)+")" + " " + str(1) + "\n"
conpic="set " +"fmri(conname_orig."+str(c)+")" + " " + '"' + tasklist[i]+ '"'+ "\n"
filex.write(ctdisplay)
filex.write(ctname)
filex.write(ctpdisplay)
filex.write(conpic)
if len(weight[0]) == 1:
ctreal="set " +"fmri(con_real"+str(1)+"."+str(1)+")"+ " " + str(1)+"\n"
ctorig="set " +"fmri(con_orig"+str(1)+"."+str(1)+")"+ " " + str(1)+"\n"
nftr="set " +"fmri(nftests_orig) " + str(0)+"\n"
nftg="set " +"fmri(nftests_real) " + str(0)+"\n"
filex.write(ctreal)
filex.write(nftr)
filex.write(nftg)
else:
for j in np.arange(0,len(weight[1])):
p=j+1
ctreal="set " +"fmri(con_real"+str(c)+"."+str(p)+")"+ " " + str(weight[i][j])+"\n"
ctorig="set " +"fmri(con_orig"+str(c)+"."+str(p)+")"+ " " + str(weight[i][j])+"\n"
filex.write(ctreal)
filex.write(ctorig)
if sum(weight[i]) == 1:
ftestr="set " +"fmri(ftest_real"+str(1)+"."+str(c)+")"+ " " + str(1) + "\n"
ftesto="set " +"fmri(ftest_orig"+str(1)+"."+str(c)+")"+ " " + str(1) + "\n"
filex.write(ftestr)
filex.write(ftesto)
else:
ftestr="set " +"fmri(ftest_real"+str(1)+"."+str(c)+")"+ " " + str(0) + "\n"
ftesto="set " +"fmri(ftest_orig"+str(1)+"."+str(c)+")"+ " " + str(0) + "\n"
filex.write(ftestr)
filex.write(ftesto)
filex.close()