3
3
import typing as ty
4
4
5
5
6
- def Cluster_output (field , inputs ):
6
+ def Cluster_output (inputs ):
7
7
import os , attr
8
8
from pydra .engine .helpers_file import split_filename
9
9
10
10
in_file = inputs .in_file
11
- name = field .name
12
11
pth , fname , ext = split_filename (in_file )
13
12
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" )
35
14
36
15
37
16
input_fields = [
@@ -51,66 +30,83 @@ def Cluster_output(field, inputs):
51
30
),
52
31
(
53
32
"out_index_file" ,
54
- ty .Any ,
33
+ ty .Union [bool , str ],
34
+ False ,
55
35
{
56
36
"help_string" : "output of cluster index (in size order)" ,
57
37
"argstr" : "--oindex={out_index_file}" ,
38
+ "output_file_template" : "{in_file}_index" ,
58
39
},
59
40
),
60
41
(
61
42
"out_threshold_file" ,
62
- ty .Any ,
43
+ ty .Union [bool , str ],
44
+ False ,
63
45
{
64
46
"help_string" : "thresholded image" ,
65
47
"argstr" : "--othresh={out_threshold_file}" ,
48
+ "output_file_template" : "{in_file}_threshold" ,
66
49
},
67
50
),
68
51
(
69
52
"out_localmax_txt_file" ,
70
- ty .Any ,
53
+ ty .Union [bool , str ],
54
+ False ,
71
55
{
72
56
"help_string" : "local maxima text file" ,
73
57
"argstr" : "--olmax={out_localmax_txt_file}" ,
58
+ "output_file_template" : Cluster_output ,
74
59
},
75
60
),
76
61
(
77
62
"out_localmax_vol_file" ,
78
- ty .Any ,
63
+ ty .Union [bool , str ],
64
+ False ,
79
65
{
80
66
"help_string" : "output of local maxima volume" ,
81
67
"argstr" : "--olmaxim={out_localmax_vol_file}" ,
68
+ "output_file_template" : "{in_file}_localmax" ,
69
+
82
70
},
83
71
),
84
72
(
85
73
"out_size_file" ,
86
- ty .Any ,
74
+ ty .Union [bool , str ],
75
+ False ,
87
76
{
88
77
"help_string" : "filename for output of size image" ,
89
78
"argstr" : "--osize={out_size_file}" ,
79
+ "output_file_template" : "{in_file}_size"
90
80
},
91
81
),
92
82
(
93
83
"out_max_file" ,
94
- ty .Any ,
84
+ ty .Union [bool , str ],
85
+ False ,
95
86
{
96
87
"help_string" : "filename for output of max image" ,
97
88
"argstr" : "--omax={out_max_file}" ,
89
+ "output_file_template" : "{in_file}_max"
98
90
},
99
91
),
100
92
(
101
93
"out_mean_file" ,
102
- ty .Any ,
94
+ ty .Union [bool , str ],
95
+ False ,
103
96
{
104
97
"help_string" : "filename for output of mean image" ,
105
98
"argstr" : "--omean={out_mean_file}" ,
99
+ "output_file_template" : "{in_file}_mean"
106
100
},
107
101
),
108
102
(
109
103
"out_pval_file" ,
110
- ty .Any ,
104
+ ty .Union [bool , str ],
105
+ False ,
111
106
{
112
107
"help_string" : "filename for image output of log pvals" ,
113
108
"argstr" : "--opvals={out_pval_file}" ,
109
+ "output_file_template" : "{in_file}_pval"
114
110
},
115
111
),
116
112
(
@@ -221,81 +217,12 @@ def Cluster_output(field, inputs):
221
217
},
222
218
),
223
219
]
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
+ )
225
223
226
224
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
+
299
226
]
300
227
Cluster_output_spec = specs .SpecInfo (
301
228
name = "Output" , fields = output_fields , bases = (specs .ShellOutSpec ,)
@@ -308,20 +235,13 @@ class Cluster(ShellCommandTask):
308
235
-------
309
236
>>> task = Cluster()
310
237
>>> task.inputs.in_file = "zstat1.nii.gz"
238
+ >>> task.inputs.out_localmax_txt_file = True
311
239
>>> task.inputs.threshold = 2.3
312
240
>>> 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"
321
241
>>> 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'
323
243
"""
324
244
325
245
input_spec = Cluster_input_spec
326
246
output_spec = Cluster_output_spec
327
- executable = "cluster"
247
+ executable = "cluster"
0 commit comments