Skip to content

Commit 60a107d

Browse files
committed
[FIX]: AFNI Allineate
Errors in OutputSpec mapping for Allineate, where out_file name was not successfully generated or mapped. Added xor options for some input options that are mutually exclusive. Included new "overwrite" feature to overwrite output if it already exists.
1 parent d3010a2 commit 60a107d

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

nipype/interfaces/afni/preprocess.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,29 @@ class AllineateInputSpec(AFNICommandInputSpec):
6464
desc='output file from 3dAllineate',
6565
argstr='-prefix %s',
6666
position=-2,
67-
name_source='%s_allineate',
6867
genfile=True)
6968
out_param_file = File(
7069
argstr='-1Dparam_save %s',
71-
desc='Save the warp parameters in ASCII (.1D) format.')
70+
desc='Save the warp parameters in ASCII (.1D) format.',
71+
xor=['in_param_file'])
7272
in_param_file = File(
7373
exists=True,
7474
argstr='-1Dparam_apply %s',
7575
desc='Read warp parameters from file and apply them to '
76-
'the source dataset, and produce a new dataset')
76+
'the source dataset, and produce a new dataset',
77+
xor=['out_param_file'])
7778
out_matrix = File(
7879
argstr='-1Dmatrix_save %s',
79-
desc='Save the transformation matrix for each volume.')
80+
desc='Save the transformation matrix for each volume.',
81+
xor=['in_matrix'])
8082
in_matrix = File(
8183
desc='matrix to align input file',
8284
argstr='-1Dmatrix_apply %s',
83-
position=-3)
84-
85+
position=-3,
86+
xor=['out_matrix'])
87+
overwrite = traits.Bool(
88+
desc='overwrite output file if it already exists',
89+
argstr='-overwrite')
8590
_cost_funcs = [
8691
'leastsq', 'ls',
8792
'mutualinfo', 'mi',
@@ -250,8 +255,10 @@ class AllineateInputSpec(AFNICommandInputSpec):
250255

251256

252257
class AllineateOutputSpec(TraitedSpec):
253-
out_file = File(desc='output image file name')
254-
matrix = File(desc='matrix to align input file')
258+
out_file = File(exists=True, desc='output image file name')
259+
out_matrix = File(exists=True, desc='matrix to align input file')
260+
out_param_file = File(exists=True, desc='warp parameters')
261+
out_weight_file = File(exists=True, desc='weight volume')
255262

256263

257264
class Allineate(AFNICommand):
@@ -271,7 +278,6 @@ class Allineate(AFNICommand):
271278
>>> allineate.cmdline # doctest: +ALLOW_UNICODE
272279
'3dAllineate -1Dmatrix_apply cmatrix.mat -prefix functional_allineate.nii -source functional.nii'
273280
>>> res = allineate.run() # doctest: +SKIP
274-
275281
"""
276282

277283
_cmd = '3dAllineate'
@@ -285,21 +291,23 @@ def _format_arg(self, name, trait_spec, value):
285291
return super(Allineate, self)._format_arg(name, trait_spec, value)
286292

287293
def _list_outputs(self):
288-
outputs = self.output_spec().get()
294+
outputs = self._outputs().get()
289295
if not isdefined(self.inputs.out_file):
290-
outputs['out_file'] = self._gen_filename(self.inputs.in_file,
291-
suffix=self.inputs.suffix)
296+
outputs['out_file'] = self._gen_fname(self.inputs.in_file,
297+
suffix='_allineate.nii')
292298
else:
293299
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
294300

295301
if isdefined(self.inputs.out_matrix):
296-
outputs['matrix'] = os.path.abspath(os.path.join(os.getcwd(),\
297-
self.inputs.out_matrix +'.aff12.1D'))
302+
outputs['out_matrix'] = os.path.abspath(os.path.join(os.getcwd(),
303+
self.inputs.out_matrix +
304+
'.aff12.1D'))
298305
return outputs
299306

300307
def _gen_filename(self, name):
301308
if name == 'out_file':
302309
return self._list_outputs()[name]
310+
return None
303311

304312

305313
class AutoTcorrelateInputSpec(AFNICommandInputSpec):
@@ -358,6 +366,7 @@ class AutoTcorrelate(AFNICommand):
358366
'3dAutoTcorrelate -eta2 -mask mask.nii -mask_only_targets -prefix functional_similarity_matrix.1D -polort -1 functional.nii'
359367
>>> res = corr.run() # doctest: +SKIP
360368
"""
369+
361370
input_spec = AutoTcorrelateInputSpec
362371
output_spec = AFNICommandOutputSpec
363372
_cmd = '3dAutoTcorrelate'

nipype/interfaces/afni/tests/test_auto_Allineate.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ def test_Allineate_inputs():
3939
),
4040
in_matrix=dict(argstr='-1Dmatrix_apply %s',
4141
position=-3,
42+
xor=['out_matrix'],
4243
),
4344
in_param_file=dict(argstr='-1Dparam_apply %s',
45+
xor=['out_param_file'],
4446
),
4547
interpolation=dict(argstr='-interp %s',
4648
),
@@ -64,16 +66,19 @@ def test_Allineate_inputs():
6466
),
6567
out_file=dict(argstr='-prefix %s',
6668
genfile=True,
67-
name_source='%s_allineate',
6869
position=-2,
6970
),
7071
out_matrix=dict(argstr='-1Dmatrix_save %s',
72+
xor=['in_matrix'],
7173
),
7274
out_param_file=dict(argstr='-1Dparam_save %s',
75+
xor=['in_param_file'],
7376
),
7477
out_weight_file=dict(argstr='-wtprefix %s',
7578
),
7679
outputtype=dict(),
80+
overwrite=dict(argstr='-overwrite',
81+
),
7782
reference=dict(argstr='-base %s',
7883
),
7984
replacebase=dict(argstr='-replacebase',
@@ -113,8 +118,10 @@ def test_Allineate_inputs():
113118

114119

115120
def test_Allineate_outputs():
116-
output_map = dict(matrix=dict(),
117-
out_file=dict(),
121+
output_map = dict(out_file=dict(),
122+
out_matrix=dict(),
123+
out_param_file=dict(),
124+
out_weight_file=dict(),
118125
)
119126
outputs = Allineate.output_spec()
120127

0 commit comments

Comments
 (0)