|
| 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" |
0 commit comments