Skip to content

Commit 65e44f5

Browse files
committed
change to ty.Union[bool, str] for cluster
1 parent 9cac101 commit 65e44f5

File tree

3 files changed

+36
-130
lines changed

3 files changed

+36
-130
lines changed

pydra/tasks/fsl/model/cluster.py

Lines changed: 34 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,14 @@
33
import typing as ty
44

55

6-
def Cluster_output(field, inputs):
6+
def Cluster_output(inputs):
77
import os, attr
88
from pydra.engine.helpers_file import split_filename
99

1010
in_file = inputs.in_file
11-
name = field.name
1211
pth, fname, ext = split_filename(in_file)
1312

14-
if name == "out_index_file":
15-
return os.path.join(pth, f"{fname}_index{ext}")
16-
elif name == "out_localmax_txt_file":
17-
return os.path.join(pth, f"{fname}_localmax.txt")
18-
elif name == "out_localmax_vol_file":
19-
return os.path.join(pth, f"{fname}_localmax{ext}")
20-
elif name == "out_max_file":
21-
return os.path.join(pth, f"{fname}_max{ext}")
22-
elif name == "out_mean_file":
23-
return os.path.join(pth, f"{fname}_mean{ext}")
24-
elif name == "out_pval_file":
25-
return os.path.join(pth, f"{fname}_pval{ext}")
26-
elif name == "out_size_file":
27-
return os.path.join(pth, f"{fname}_size{ext}")
28-
elif name == "out_threshold_file":
29-
return os.path.join(pth, f"{fname}_threshold{ext}")
30-
31-
else:
32-
raise Exception(
33-
f"this function should be run only for index_file, localmax_txt_file, localmax_vol_file, max_file, mean_file, pval_file, size_file, or threshold_file not {name}"
34-
)
13+
return os.path.join(pth, f"{fname}_localmax.txt")
3514

3615

3716
input_fields = [
@@ -51,66 +30,83 @@ def Cluster_output(field, inputs):
5130
),
5231
(
5332
"out_index_file",
54-
ty.Any,
33+
ty.Union[bool, str],
34+
False,
5535
{
5636
"help_string": "output of cluster index (in size order)",
5737
"argstr": "--oindex={out_index_file}",
38+
"output_file_template": "{in_file}_index",
5839
},
5940
),
6041
(
6142
"out_threshold_file",
62-
ty.Any,
43+
ty.Union[bool, str],
44+
False,
6345
{
6446
"help_string": "thresholded image",
6547
"argstr": "--othresh={out_threshold_file}",
48+
"output_file_template": "{in_file}_threshold",
6649
},
6750
),
6851
(
6952
"out_localmax_txt_file",
70-
ty.Any,
53+
ty.Union[bool, str],
54+
False,
7155
{
7256
"help_string": "local maxima text file",
7357
"argstr": "--olmax={out_localmax_txt_file}",
58+
"output_file_template": Cluster_output,
7459
},
7560
),
7661
(
7762
"out_localmax_vol_file",
78-
ty.Any,
63+
ty.Union[bool, str],
64+
False,
7965
{
8066
"help_string": "output of local maxima volume",
8167
"argstr": "--olmaxim={out_localmax_vol_file}",
68+
"output_file_template": "{in_file}_localmax",
69+
8270
},
8371
),
8472
(
8573
"out_size_file",
86-
ty.Any,
74+
ty.Union[bool, str],
75+
False,
8776
{
8877
"help_string": "filename for output of size image",
8978
"argstr": "--osize={out_size_file}",
79+
"output_file_template": "{in_file}_size"
9080
},
9181
),
9282
(
9383
"out_max_file",
94-
ty.Any,
84+
ty.Union[bool, str],
85+
False,
9586
{
9687
"help_string": "filename for output of max image",
9788
"argstr": "--omax={out_max_file}",
89+
"output_file_template": "{in_file}_max"
9890
},
9991
),
10092
(
10193
"out_mean_file",
102-
ty.Any,
94+
ty.Union[bool, str],
95+
False,
10396
{
10497
"help_string": "filename for output of mean image",
10598
"argstr": "--omean={out_mean_file}",
99+
"output_file_template": "{in_file}_mean"
106100
},
107101
),
108102
(
109103
"out_pval_file",
110-
ty.Any,
104+
ty.Union[bool, str],
105+
False,
111106
{
112107
"help_string": "filename for image output of log pvals",
113108
"argstr": "--opvals={out_pval_file}",
109+
"output_file_template": "{in_file}_pval"
114110
},
115111
),
116112
(
@@ -221,81 +217,12 @@ def Cluster_output(field, inputs):
221217
},
222218
),
223219
]
224-
Cluster_input_spec = specs.SpecInfo(name="Input", fields=input_fields, bases=(specs.ShellSpec,))
220+
Cluster_input_spec = specs.SpecInfo(
221+
name="Input", fields=input_fields, bases=(specs.ShellSpec,)
222+
)
225223

226224
output_fields = [
227-
(
228-
"out_index_file",
229-
specs.File,
230-
{
231-
"help_string": "output of cluster index (in size order)",
232-
"requires": ["in_file", "out_index_file"],
233-
"callable": Cluster_output,
234-
},
235-
),
236-
(
237-
"out_threshold_file",
238-
specs.File,
239-
{
240-
"help_string": "thresholded image",
241-
"requires": ["in_file", "out_threshold_file"],
242-
"callable": Cluster_output,
243-
},
244-
),
245-
(
246-
"out_localmax_txt_file",
247-
specs.File,
248-
{
249-
"help_string": "local maxima text file",
250-
"requires": ["in_file", "out_localmax_txt_file"],
251-
"callable": Cluster_output,
252-
},
253-
),
254-
(
255-
"out_localmax_vol_file",
256-
specs.File,
257-
{
258-
"help_string": "output of local maxima volume",
259-
"requires": ["in_file", "out_localmax_vol_file"],
260-
"callable": Cluster_output,
261-
},
262-
),
263-
(
264-
"out_size_file",
265-
specs.File,
266-
{
267-
"help_string": "filename for output of size image",
268-
"requires": ["in_file", "out_size_file"],
269-
"callable": Cluster_output,
270-
},
271-
),
272-
(
273-
"out_max_file",
274-
specs.File,
275-
{
276-
"help_string": "filename for output of max image",
277-
"requires": ["in_file", "out_max_file"],
278-
"callable": Cluster_output,
279-
},
280-
),
281-
(
282-
"out_mean_file",
283-
specs.File,
284-
{
285-
"help_string": "filename for output of mean image",
286-
"requires": ["in_file", "out_mean_file"],
287-
"callable": Cluster_output,
288-
},
289-
),
290-
(
291-
"out_pval_file",
292-
specs.File,
293-
{
294-
"help_string": "filename for image output of log pvals",
295-
"requires": ["in_file", "out_pval_file"],
296-
"callable": Cluster_output,
297-
},
298-
),
225+
299226
]
300227
Cluster_output_spec = specs.SpecInfo(
301228
name="Output", fields=output_fields, bases=(specs.ShellOutSpec,)
@@ -308,20 +235,13 @@ class Cluster(ShellCommandTask):
308235
-------
309236
>>> task = Cluster()
310237
>>> task.inputs.in_file = "zstat1.nii.gz"
238+
>>> task.inputs.out_localmax_txt_file = True
311239
>>> task.inputs.threshold = 2.3
312240
>>> task.inputs.use_mm = True
313-
>>> task.inputs.out_index_file = "zstat1_index.nii.gz"
314-
>>> task.inputs.out_threshold_file = "zstat1_threshold.nii.gz"
315-
>>> task.inputs.out_localmax_txt_file = "zstat1_localmax.txt"
316-
>>> task.inputs.out_localmax_vol_file = "zstat1_localmax.nii.gz"
317-
>>> task.inputs.out_size_file = "zstat1_size.nii.gz"
318-
>>> task.inputs.out_max_file = "zstat1_max.nii.gz"
319-
>>> task.inputs.out_mean_file = "zstat1_mean.nii.gz"
320-
>>> task.inputs.out_pval_file = "zstat1_pval.nii.gz"
321241
>>> task.cmdline
322-
'cluster --in=zstat1.nii.gz --thresh=2.3000000000 --oindex=zstat1_index.nii.gz --othresh=zstat1_threshold.nii.gz --olmax=zstat1_localmax.txt --olmaxim=zstat1_localmax.nii.gz --osize=zstat1_size.nii.gz --omax=zstat1_max.nii.gz --omean=zstat1_mean.nii.gz --opvals=zstat1_pval.nii.gz --mm'
242+
'cluster --in=zstat1.nii.gz --olmax=zstat1_localmax.txt --thresh=2.3000000000 --mm'
323243
"""
324244

325245
input_spec = Cluster_input_spec
326246
output_spec = Cluster_output_spec
327-
executable = "cluster"
247+
executable = "cluster"

pydra/tasks/fsl/model/tests/test_run_cluster.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@
1212
"in_file": "zstat1.nii.gz",
1313
"threshold": 2.3,
1414
"use_mm": True,
15-
"out_index_file": "zstat1_index.nii.gz",
16-
"out_threshold_file": "zstat1_threshold.nii.gz",
17-
"out_localmax_txt_file": "zstat1_localmax.txt",
18-
"out_localmax_vol_file": "zstat1_localmax.nii.gz",
19-
"out_size_file": "zstat1_size.nii.gz",
20-
"out_max_file": "zstat1_max.nii.gz",
21-
"out_mean_file": "zstat1_mean.nii.gz",
22-
"out_pval_file": "zstat1_pval.nii.gz",
15+
"out_index_file": True,
2316
},
2417
[
2518
"out_index_file",

pydra/tasks/fsl/model/tests/test_spec_cluster.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@
1111
"in_file": "zstat1.nii.gz",
1212
"threshold": 2.3,
1313
"use_mm": True,
14-
"out_index_file": "zstat1_index.nii.gz",
15-
"out_threshold_file": "zstat1_threshold.nii.gz",
16-
"out_localmax_txt_file": "zstat1_localmax.txt",
17-
"out_localmax_vol_file": "zstat1_localmax.nii.gz",
18-
"out_size_file": "zstat1_size.nii.gz",
19-
"out_max_file": "zstat1_max.nii.gz",
20-
"out_mean_file": "zstat1_mean.nii.gz",
21-
"out_pval_file": "zstat1_pval.nii.gz",
14+
"out_index_file": True
2215
},
2316
[
2417
"out_index_file",

0 commit comments

Comments
 (0)