Skip to content

Commit 6957eb6

Browse files
authored
Merge pull request #33 from yibeichan/wip-yc-convert
convert convertxfm.py
2 parents 58a272c + cca0b1f commit 6957eb6

File tree

83 files changed

+17153
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+17153
-489
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
pydra/tasks/fsl/_version.py export-subst
2+
*.nii.gz filter=lfs diff=lfs merge=lfs -text
3+
*.nii* filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
.DS_Store
2+
*/.DS_Store
3+
*/*/.DS_Store
4+
*/*/*/.DS_Store
5+
*/.DS_Store
6+
*/*/*/*/.DS_Store
7+
*/*/*/*/*/.DS_Store
8+
19
# Byte-compiled / optimized / DLL files
210
__pycache__/
311
*.py[cod]

pydra/tasks/fsl/model/__init__.py

Whitespace-only changes.

pydra/tasks/fsl/model/cluster.py

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
from pydra.engine import specs
2+
from pydra import ShellCommandTask
3+
import typing as ty
4+
5+
6+
def Cluster_output(inputs):
7+
import os, attr
8+
from pydra.engine.helpers_file import split_filename
9+
10+
in_file = inputs.in_file
11+
pth, fname, ext = split_filename(in_file)
12+
13+
return os.path.join(pth, f"{fname}_localmax.txt")
14+
15+
16+
input_fields = [
17+
(
18+
"in_file",
19+
specs.File,
20+
{"help_string": "input volume", "argstr": "--in={in_file}", "mandatory": True},
21+
),
22+
(
23+
"threshold",
24+
float,
25+
{
26+
"help_string": "threshold for input volume",
27+
"argstr": "--thresh={threshold:.10f}",
28+
"mandatory": True,
29+
},
30+
),
31+
(
32+
"out_index_file",
33+
ty.Union[bool, str],
34+
False,
35+
{
36+
"help_string": "output of cluster index (in size order)",
37+
"argstr": "--oindex={out_index_file}",
38+
"output_file_template": "{in_file}_index",
39+
},
40+
),
41+
(
42+
"out_threshold_file",
43+
ty.Union[bool, str],
44+
False,
45+
{
46+
"help_string": "thresholded image",
47+
"argstr": "--othresh={out_threshold_file}",
48+
"output_file_template": "{in_file}_threshold",
49+
},
50+
),
51+
(
52+
"out_localmax_txt_file",
53+
ty.Union[bool, str],
54+
False,
55+
{
56+
"help_string": "local maxima text file",
57+
"argstr": "--olmax={out_localmax_txt_file}",
58+
"output_file_template": Cluster_output,
59+
},
60+
),
61+
(
62+
"out_localmax_vol_file",
63+
ty.Union[bool, str],
64+
False,
65+
{
66+
"help_string": "output of local maxima volume",
67+
"argstr": "--olmaxim={out_localmax_vol_file}",
68+
"output_file_template": "{in_file}_localmax",
69+
},
70+
),
71+
(
72+
"out_size_file",
73+
ty.Union[bool, str],
74+
False,
75+
{
76+
"help_string": "filename for output of size image",
77+
"argstr": "--osize={out_size_file}",
78+
"output_file_template": "{in_file}_size",
79+
},
80+
),
81+
(
82+
"out_max_file",
83+
ty.Union[bool, str],
84+
False,
85+
{
86+
"help_string": "filename for output of max image",
87+
"argstr": "--omax={out_max_file}",
88+
"output_file_template": "{in_file}_max",
89+
},
90+
),
91+
(
92+
"out_mean_file",
93+
ty.Union[bool, str],
94+
False,
95+
{
96+
"help_string": "filename for output of mean image",
97+
"argstr": "--omean={out_mean_file}",
98+
"output_file_template": "{in_file}_mean",
99+
},
100+
),
101+
(
102+
"out_pval_file",
103+
ty.Union[bool, str],
104+
False,
105+
{
106+
"help_string": "filename for image output of log pvals",
107+
"argstr": "--opvals={out_pval_file}",
108+
"output_file_template": "{in_file}_pval",
109+
},
110+
),
111+
(
112+
"pthreshold",
113+
float,
114+
{
115+
"help_string": "p-threshold for clusters",
116+
"argstr": "--pthresh={pthreshold:.10f}",
117+
"requires": ["dlh", "volume"],
118+
},
119+
),
120+
(
121+
"peak_distance",
122+
float,
123+
{
124+
"help_string": "minimum distance between local maxima/minima, in mm (default 0)",
125+
"argstr": "--peakdist={peak_distance:.10f}",
126+
},
127+
),
128+
("cope_file", str, {"help_string": "cope volume", "argstr": "--cope={cope_file}"}),
129+
(
130+
"volume",
131+
int,
132+
{"help_string": "number of voxels in the mask", "argstr": "--volume={volume}"},
133+
),
134+
(
135+
"dlh",
136+
float,
137+
{
138+
"help_string": "smoothness estimate = sqrt(det(Lambda))",
139+
"argstr": "--dlh={dlh:.10f}",
140+
},
141+
),
142+
(
143+
"fractional",
144+
bool,
145+
False,
146+
{
147+
"help_string": "interprets the threshold as a fraction of the robust range",
148+
"argstr": "--fractional",
149+
},
150+
),
151+
(
152+
"connectivity",
153+
int,
154+
{
155+
"help_string": "the connectivity of voxels (default 26)",
156+
"argstr": "--connectivity={connectivity}",
157+
},
158+
),
159+
(
160+
"use_mm",
161+
bool,
162+
False,
163+
{"help_string": "use mm, not voxel, coordinates", "argstr": "--mm"},
164+
),
165+
(
166+
"find_min",
167+
bool,
168+
False,
169+
{"help_string": "find minima instead of maxima", "argstr": "--min"},
170+
),
171+
(
172+
"no_table",
173+
bool,
174+
False,
175+
{
176+
"help_string": "suppresses printing of the table info",
177+
"argstr": "--no_table",
178+
},
179+
),
180+
(
181+
"minclustersize",
182+
bool,
183+
False,
184+
{
185+
"help_string": "prints out minimum significant cluster size",
186+
"argstr": "--minclustersize",
187+
},
188+
),
189+
(
190+
"xfm_file",
191+
str,
192+
{
193+
"help_string": "filename for Linear: input->standard-space transform. Non-linear: input->highres transform",
194+
"argstr": "--xfm={xfm_file}",
195+
},
196+
),
197+
(
198+
"std_space_file",
199+
str,
200+
{
201+
"help_string": "filename for standard-space volume",
202+
"argstr": "--stdvol={std_space_file}",
203+
},
204+
),
205+
(
206+
"num_maxima",
207+
int,
208+
{"help_string": "no of local maxima to report", "argstr": "--num={num_maxima}"},
209+
),
210+
(
211+
"warpfield_file",
212+
str,
213+
{
214+
"help_string": "file contining warpfield",
215+
"argstr": "--warpvol={warpfield_file}",
216+
},
217+
),
218+
]
219+
Cluster_input_spec = specs.SpecInfo(name="Input", fields=input_fields, bases=(specs.ShellSpec,))
220+
221+
output_fields = []
222+
Cluster_output_spec = specs.SpecInfo(
223+
name="Output", fields=output_fields, bases=(specs.ShellOutSpec,)
224+
)
225+
226+
227+
class Cluster(ShellCommandTask):
228+
"""
229+
Example
230+
-------
231+
>>> task = Cluster()
232+
>>> task.inputs.in_file = "zstat1.nii.gz"
233+
>>> task.inputs.out_localmax_txt_file = True
234+
>>> task.inputs.threshold = 2.3
235+
>>> task.inputs.use_mm = True
236+
>>> task.cmdline
237+
'cluster --in=zstat1.nii.gz --olmax=zstat1_localmax.txt --thresh=2.3000000000 --mm'
238+
"""
239+
240+
input_spec = Cluster_input_spec
241+
output_spec = Cluster_output_spec
242+
executable = "cluster"

pydra/tasks/fsl/model/feat.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from pydra.engine import specs
2+
from pydra import ShellCommandTask
3+
import typing as ty
4+
5+
6+
def FEAT_output(fsf_file):
7+
is_ica = False
8+
with open(fsf_file, "rt") as fp:
9+
text = fp.read()
10+
if "set fmri(inmelodic) 1" in text:
11+
is_ica = True
12+
for line in text.split("\n"):
13+
if line.find("set fmri(outputdir)") > -1:
14+
try:
15+
outputdir_spec = line.split('"')[-2]
16+
if os.path.exists(outputdir_spec):
17+
outputs = outputdir_spec
18+
except:
19+
pass
20+
21+
if not outputs:
22+
if is_ica:
23+
outputs = glob(os.path.join(os.getcwd(), "*ica"))[0]
24+
else:
25+
outputs = glob(os.path.join(os.getcwd(), "*feat"))[0]
26+
print("Outputs from FEATmodel:", outputs)
27+
return outputs
28+
29+
30+
input_fields = [
31+
(
32+
"fsf_file",
33+
specs.File,
34+
{
35+
"help_string": "File specifying the feat design spec file",
36+
"argstr": "{fsf_file}",
37+
"mandatory": True,
38+
"position": 0,
39+
},
40+
)
41+
]
42+
FEAT_input_spec = specs.SpecInfo(name="Input", fields=input_fields, bases=(specs.ShellSpec,))
43+
44+
output_fields = [
45+
("feat_dir", specs.Directory, {"requires": ["fsf_file"], "callable": FEAT_output})
46+
]
47+
FEAT_output_spec = specs.SpecInfo(name="Output", fields=output_fields, bases=(specs.ShellOutSpec,))
48+
49+
50+
class FEAT(ShellCommandTask):
51+
"""
52+
Example
53+
-------
54+
>>> task = FEAT()
55+
>>> task.inputs.fsf_file = "test.fsf"
56+
>>> task.cmdline
57+
'feat test.fsf'
58+
"""
59+
60+
input_spec = FEAT_input_spec
61+
output_spec = FEAT_output_spec
62+
executable = "feat"

0 commit comments

Comments
 (0)