|
| 1 | +from nipype.interfaces.base import TraitedSpec, CommandLineInputSpec, \ |
| 2 | + traits, isdefined |
| 3 | +from nipype.utils.filemanip import fname_presuffix |
| 4 | +import os |
| 5 | +from base import CommandLineDtitk |
| 6 | + |
| 7 | + |
| 8 | +class RigidInputSpec(CommandLineInputSpec): |
| 9 | + fixed_file = traits.Str(desc="fixed diffusion tensor image", |
| 10 | + exists=True, mandatory=True, |
| 11 | + position=0, argstr="%s") |
| 12 | + moving_file = traits.Str(desc="diffusion tensor image path", exists=True, |
| 13 | + mandatory=True, position=1, argstr="%s") |
| 14 | + similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', exists=True, |
| 15 | + mandatory=True, position=2, argstr="%s", |
| 16 | + desc="similarity metric") |
| 17 | + |
| 18 | + |
| 19 | +class RigidOutputSpec(TraitedSpec): |
| 20 | + out_file = traits.File(exists=True) |
| 21 | + out_file_xfm = traits.File(exists=True) |
| 22 | + |
| 23 | + |
| 24 | +class RigidTask(CommandLineDtitk): |
| 25 | + """ |
| 26 | + Performs rigid registration between two tensor volumes |
| 27 | +
|
| 28 | + Example |
| 29 | + ------- |
| 30 | +
|
| 31 | + >>> import nipype.interfaces.dtitk as dtitk |
| 32 | + >>> node = dtitk.RigidTask() |
| 33 | + >>> node.inputs.fixed_file = 'diffusion.nii' |
| 34 | + >>> node.inputs.moving_file = 'diffusion.nii' |
| 35 | + >>> node.inputs.similarity_metric = 'EDS' |
| 36 | + >>> node.run() |
| 37 | + """ |
| 38 | + input_spec = RigidInputSpec |
| 39 | + output_spec = RigidOutputSpec |
| 40 | + _cmd = 'dti_rigid_sn' |
| 41 | + |
| 42 | + def _list_outputs(self): |
| 43 | + outputs = self.output_spec().get() |
| 44 | + outputs['out_file_xfm'] = self.inputs.in_file.replace('.nii.gz', '.aff') |
| 45 | + outputs['out_file'] = self.inputs.in_file.replace('.nii.gz', |
| 46 | + '_aff.nii.gz') |
| 47 | + return outputs |
| 48 | + |
| 49 | + |
| 50 | +class AffineInputSpec(CommandLineInputSpec): |
| 51 | + in_fixed_tensor = traits.Str(desc="fixed diffusion tensor image", |
| 52 | + exists=True, mandatory=False, position=0, |
| 53 | + argstr="%s") |
| 54 | + in_moving_txt = traits.Str( |
| 55 | + desc="moving list of diffusion tensor image paths", exists=True, |
| 56 | + mandatory=False, position=1, argstr="%s") |
| 57 | + in_similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', exists=True, |
| 58 | + mandatory=False, position=3, argstr="%s", |
| 59 | + desc = "similarity metric") |
| 60 | + in_usetrans_flag = traits.Enum('--useTrans', '', exists=True, |
| 61 | + mandatory=False, position=4, argstr="%s", |
| 62 | + desc="initialize using rigid transform??") |
| 63 | + |
| 64 | + |
| 65 | +class AffineOutputSpec(TraitedSpec): |
| 66 | + out_file = traits.File(exists=True) |
| 67 | + out_file_xfm = traits.File(exists=True) |
| 68 | + |
| 69 | + |
| 70 | +class AffineTask(CommandLineDtitk): |
| 71 | + """ |
| 72 | + Performs affine registration between two tensor volumes |
| 73 | +
|
| 74 | + Example |
| 75 | + ------- |
| 76 | +
|
| 77 | + >>> import nipype.interfaces.dtitk as dtitk |
| 78 | + >>> node = dtitk.AffineTask() |
| 79 | + >>> node.inputs.in_fixed_tensor = 'diffusion.nii' |
| 80 | + >>> node.inputs.in_moving_txt = 'dirs.txt' |
| 81 | + >>> node.inputs.in_similarity_metric = 'EDS' |
| 82 | + >>> node.run() |
| 83 | + """ |
| 84 | + |
| 85 | + input_spec = AffineInputSpec |
| 86 | + output_spec = AffineOutputSpec |
| 87 | + _cmd = 'dti_affine_sn' |
| 88 | + |
| 89 | + def _list_outputs(self): |
| 90 | + outputs = self.output_spec().get() |
| 91 | + outputs['out_file_xfm'] = self.inputs.in_fixed_tensor.replace('.nii.gz', |
| 92 | + '.aff') |
| 93 | + outputs['out_file'] = self.inputs.in_fixed_tensor.replace('.nii.gz', |
| 94 | + '_aff.nii.gz') |
| 95 | + return outputs |
| 96 | + |
| 97 | + |
| 98 | +class DiffeoInputSpec(CommandLineInputSpec): |
| 99 | + in_fixed_tensor = traits.Str(desc="fixed diffusion tensor image", |
| 100 | + exists=True, mandatory=False, position=0, |
| 101 | + argstr="%s") |
| 102 | + in_moving_txt = traits.Str(desc="moving list of diffusion tensor image " |
| 103 | + "paths", exists=True, mandatory=False, |
| 104 | + position=1, argstr="%s") |
| 105 | + in_mask = traits.Str(desc="mask", exists=True, mandatory=False, position=2, |
| 106 | + argstr="%s") |
| 107 | + in_numbers = traits.Str(desc='#iters ftol', exists=True, mandatory=False, |
| 108 | + position=3, argstr="%s") |
| 109 | + |
| 110 | + |
| 111 | +class DiffeoOutputSpec(TraitedSpec): |
| 112 | + out_file = traits.File(exists=True) |
| 113 | + out_file_xfm = traits.File(exists=True) |
| 114 | + |
| 115 | + |
| 116 | +class DiffeoTask(CommandLineDtitk): |
| 117 | + """ |
| 118 | + Performs diffeomorphic registration between two tensor volumes |
| 119 | +
|
| 120 | + Example |
| 121 | + ------- |
| 122 | +
|
| 123 | + >>> import nipype.interfaces.dtitk as dtitk |
| 124 | + >>> node = dtitk.DiffeoTask() |
| 125 | + >>> node.inputs.in_fixed_tensor = 'diffusion.nii' |
| 126 | + >>> node.inputs.in_moving_txt = 'dirs.txt' |
| 127 | + >>> node.inputs.in_mask = 'mask.nii' |
| 128 | + >>> node.inputs.in_numbers = '6 0.002' |
| 129 | + >>> node.run() |
| 130 | + """ |
| 131 | + input_spec = DiffeoInputSpec |
| 132 | + output_spec = DiffeoOutputSpec |
| 133 | + _cmd = 'dti_diffeomorphic_sn' |
| 134 | + |
| 135 | + def _list_outputs(self): |
| 136 | + outputs = self.output_spec().get() |
| 137 | + outputs['out_file_xfm'] = self.inputs.in_fixed_tensor.replace( |
| 138 | + '.nii.gz','_aff_diffeo.df.nii.gz') |
| 139 | + outputs['out_file'] = self.inputs.in_fixed_tensor.replace( |
| 140 | + '.nii.gz', '_aff_diffeo.nii.gz') |
| 141 | + return outputs |
| 142 | + |
| 143 | + |
| 144 | +class ComposeXfmInputSpec(CommandLineInputSpec): |
| 145 | + in_df = traits.Str(desc='diffeomorphic file.df.nii.gz', exists=True, |
| 146 | + mandatory=False, position=1, argstr="-df %s") |
| 147 | + in_aff = traits.Str(desc='affine file.aff', exists=True, mandatory=False, |
| 148 | + position=0, argstr="-aff %s") |
| 149 | + out_path = traits.Str(desc='output_path', exists=True, mandatory=False, |
| 150 | + position=2, argstr="-out %s", name_source="in_df", |
| 151 | + name_template="%s_comboaff.nii.gz") |
| 152 | + |
| 153 | + |
| 154 | +class ComposeXfmOutputSpec(TraitedSpec): |
| 155 | + out_file = traits.File(desc='cheese', exists=True) |
| 156 | + |
| 157 | + |
| 158 | +class ComposeXfmTask(CommandLineDtitk): |
| 159 | + """ |
| 160 | + Combines diffeomorphic and affine transforms |
| 161 | +
|
| 162 | + Example |
| 163 | + ------- |
| 164 | +
|
| 165 | + >>> import nipype.interfaces.dtitk as dtitk |
| 166 | + >>> node = dtitk.ComposeXfmTask() |
| 167 | + >>> node.inputs.in_df = 'ants_Warp.nii.gz' |
| 168 | + >>> node.inputs.in_aff= 'ants_Affine.txt' |
| 169 | + >>> node.run() |
| 170 | + """ |
| 171 | + input_spec = ComposeXfmInputSpec |
| 172 | + output_spec = ComposeXfmOutputSpec |
| 173 | + _cmd = 'dfRightComposeAffine' |
| 174 | + |
| 175 | + def _list_outputs(self): |
| 176 | + outputs = self.output_spec().get() |
| 177 | + outputs['out_file'] = self.inputs.in_df.replace('.df.nii.gz', |
| 178 | + '_combo.df.nii.gz') |
| 179 | + return outputs |
| 180 | + |
| 181 | + |
| 182 | +class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): |
| 183 | + in_tensor = traits.Str(desc='moving tensor', exists=True, mandatory=False, |
| 184 | + position=0, argstr="-in %s") |
| 185 | + in_xfm = traits.Str(desc='transform to apply', exists=True, mandatory=False, |
| 186 | + position=1, argstr="-trans %s") |
| 187 | + in_target = traits.Str(desc='', exists=True, mandatory=False, position=2, |
| 188 | + argstr="-target %s") |
| 189 | + out_path = traits.Str(desc='', exists=True, mandatory=False, position=3, |
| 190 | + argstr="-out %s", name_source="in_tensor", |
| 191 | + name_template="%s_diffeoxfmd.nii.gz") |
| 192 | + |
| 193 | + |
| 194 | +class diffeoSymTensor3DVolOutputSpec(TraitedSpec): |
| 195 | + out_file = traits.File(desc='cheese', exists=True) |
| 196 | + |
| 197 | + |
| 198 | +class diffeoSymTensor3DVolTask(CommandLineDtitk): |
| 199 | + """ |
| 200 | + Applies diffeomorphic transform to a tensor volume |
| 201 | +
|
| 202 | + Example |
| 203 | + ------- |
| 204 | +
|
| 205 | + >>> import nipype.interfaces.dtitk as dtitk |
| 206 | + >>> node = dtitk.diffeoSymTensor3DVolTask() |
| 207 | + >>> node.inputs.in_tensor = 'diffusion.nii' |
| 208 | + >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' |
| 209 | + >>> node.run() |
| 210 | + """ |
| 211 | + |
| 212 | + input_spec = diffeoSymTensor3DVolInputSpec |
| 213 | + output_spec = diffeoSymTensor3DVolOutputSpec |
| 214 | + _cmd = 'deformationSymTensor3DVolume' |
| 215 | + |
| 216 | + def _list_outputs(self): |
| 217 | + outputs = self.output_spec().get() |
| 218 | + outputs['out_file'] = self.inputs.out_path |
| 219 | + return outputs |
| 220 | + |
| 221 | + |
| 222 | +class affSymTensor3DVolInputSpec(CommandLineInputSpec): |
| 223 | + in_tensor = traits.Str(desc='moving tensor', exists=True, mandatory=False, |
| 224 | + position=0, argstr="-in %s") |
| 225 | + in_xfm = traits.Str(desc='transform to apply', exists=True, mandatory=False, |
| 226 | + position=1, argstr="-trans %s") |
| 227 | + in_target = traits.Str(desc='', exists=True, mandatory=False, position=2, |
| 228 | + argstr="-target %s") |
| 229 | + out_path = traits.Str(desc='', exists=True, mandatory=False, position=3, |
| 230 | + argstr="-out %s", name_source="in_tensor", |
| 231 | + name_template="%s_affxfmd.nii.gz") |
| 232 | + |
| 233 | + |
| 234 | +class affSymTensor3DVolOutputSpec(TraitedSpec): |
| 235 | + out_file = traits.File(desc='cheese', exists=True) |
| 236 | + |
| 237 | + |
| 238 | +class affSymTensor3DVolTask(CommandLineDtitk): |
| 239 | + """ |
| 240 | + Applies affine transform to a tensor volume |
| 241 | +
|
| 242 | + Example |
| 243 | + ------- |
| 244 | +
|
| 245 | + >>> import nipype.interfaces.dtitk as dtitk |
| 246 | + >>> node = dtitk.affSymTensor3DVolTask() |
| 247 | + >>> node.inputs.in_tensor = 'diffusion.nii' |
| 248 | + >>> node.inputs.in_xfm = 'ants_Affine.txt' |
| 249 | + >>> node.run() |
| 250 | + """ |
| 251 | + input_spec = affSymTensor3DVolInputSpec |
| 252 | + output_spec = affSymTensor3DVolOutputSpec |
| 253 | + _cmd = 'affineSymTensor3DVolume' |
| 254 | + |
| 255 | + def _list_outputs(self): |
| 256 | + outputs = self.output_spec().get() |
| 257 | + outputs['out_file'] = os.path.abspath(self.inputs.out_path) |
| 258 | + return outputs |
| 259 | + |
| 260 | + |
| 261 | +class affScalarVolInputSpec(CommandLineInputSpec): |
| 262 | + in_volume = traits.Str(desc='moving volume', exists=True, mandatory=False, |
| 263 | + position=0, argstr="-in %s") |
| 264 | + in_xfm = traits.Str(desc='transform to apply', exists=True, mandatory=False, |
| 265 | + position=1, argstr="-trans %s") |
| 266 | + in_target = traits.Str(desc='', position=2, argstr="-target %s") |
| 267 | + out_path = traits.Str(desc='', mandatory=False, position=3, |
| 268 | + argstr="-out %s", name_source="in_volume", |
| 269 | + name_template="%s_affxfmd.nii.gz") |
| 270 | + |
| 271 | + |
| 272 | +class affScalarVolOutputSpec(TraitedSpec): |
| 273 | + out_file = traits.File(desc='moved volume', exists=True) |
| 274 | + |
| 275 | + |
| 276 | +class affScalarVolTask(CommandLineDtitk): |
| 277 | + """ |
| 278 | + Applies affine transform to a scalar volume |
| 279 | +
|
| 280 | + Example |
| 281 | + ------- |
| 282 | +
|
| 283 | + >>> import nipype.interfaces.dtitk as dtitk |
| 284 | + >>> node = dtitk.affScalarVolTask() |
| 285 | + >>> node.inputs.in_volume = 'fa.nii.gz' |
| 286 | + >>> node.inputs.in_xfm = 'ants_Affine.txt' |
| 287 | + >>> node.run() |
| 288 | + """ |
| 289 | + input_spec = affScalarVolInputSpec |
| 290 | + output_spec = affScalarVolOutputSpec |
| 291 | + _cmd = 'affineScalarVolume' |
| 292 | + |
| 293 | + def _list_outputs(self): |
| 294 | + outputs = self.output_spec().get() |
| 295 | + outputs['out_file'] = os.path.abspath(self.inputs.out_path) |
| 296 | + return outputs |
| 297 | + |
| 298 | + |
| 299 | +class diffeoScalarVolInputSpec(CommandLineInputSpec): |
| 300 | + in_volume = traits.Str(desc='moving volume', exists=True, mandatory=False, |
| 301 | + position=0, argstr="-in %s") |
| 302 | + in_xfm = traits.Str(desc='transform to apply', exists=True, mandatory=False, |
| 303 | + position=2, argstr="-trans %s") |
| 304 | + in_target = traits.Str(desc='', exists=True, mandatory=False, position=3, |
| 305 | + argstr="-target %s") |
| 306 | + out_path = traits.Str(desc='', position=1, argstr="-out %s", |
| 307 | + name_source="in_volume", |
| 308 | + name_template="%s_diffeoxfmd.nii.gz") |
| 309 | + in_vsize = traits.Str(desc='', exists=True, mandatory=False, position=4, |
| 310 | + argstr="-vsize %s") |
| 311 | + in_flip = traits.Str(desc='', exists=True, mandatory=False, position=5, |
| 312 | + argstr="-flip %s") |
| 313 | + in_type = traits.Str(desc='', exists=True, mandatory=False, position=6, |
| 314 | + argstr="-type %s") |
| 315 | + in_interp = traits.Str(desc='0 trilin, 1 NN', exists=True, mandatory=False, |
| 316 | + position=7, argstr="-interp %s") |
| 317 | + |
| 318 | + |
| 319 | +class diffeoScalarVolOutputSpec(TraitedSpec): |
| 320 | + out_file = traits.File(desc='moved volume', exists=True) |
| 321 | + |
| 322 | + |
| 323 | +class diffeoScalarVolTask(CommandLineDtitk): |
| 324 | + """ |
| 325 | + Applies diffeomorphic transform to a scalar volume |
| 326 | +
|
| 327 | + Example |
| 328 | + ------- |
| 329 | +
|
| 330 | + >>> import nipype.interfaces.dtitk as dtitk |
| 331 | + >>> node = dtitk.diffeoScalarVolTask() |
| 332 | + >>> node.inputs.in_tensor = 'fa.nii.gz' |
| 333 | + >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' |
| 334 | + >>> node.run() |
| 335 | + """ |
| 336 | + |
| 337 | + input_spec = diffeoScalarVolInputSpec |
| 338 | + output_spec = diffeoScalarVolOutputSpec |
| 339 | + _cmd = 'deformationScalarVolume' |
| 340 | + |
| 341 | + def _list_outputs(self): |
| 342 | + outputs = self.output_spec().get() |
| 343 | + if not isdefined(self.inputs.out_path): |
| 344 | + self.inputs.out_path = fname_presuffix(self.inputs.in_volume, |
| 345 | + suffix="_diffeoxfmd", |
| 346 | + newpath=os.path.abspath(".")) |
| 347 | + outputs['out_file'] = os.path.abspath(self.inputs.out_path) |
| 348 | + return outputs |
0 commit comments