Skip to content

Commit 8136172

Browse files
ShotgunosineDylan
authored andcommitted
[ENH] Add options to Allineate and Means
1 parent 1c845f6 commit 8136172

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

nipype/interfaces/afni/preprocess.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ class AllineateInputSpec(AFNICommandInputSpec):
213213
in_file = File(
214214
desc='input file to 3dAllineate',
215215
argstr='-source %s',
216-
position=-1,
217216
mandatory=True,
218217
exists=True,
219218
copyfile=False)
@@ -225,9 +224,10 @@ class AllineateInputSpec(AFNICommandInputSpec):
225224
out_file = File(
226225
desc='output file from 3dAllineate',
227226
argstr='-prefix %s',
228-
position=-2,
229-
name_source='%s_allineate',
230-
genfile=True)
227+
name_source='in_file',
228+
name_template='%s_allineate',
229+
genfile=True,
230+
xors=['allcostx'])
231231
out_param_file = File(
232232
argstr='-1Dparam_save %s',
233233
desc='Save the warp parameters in ASCII (.1D) format.')
@@ -241,8 +241,14 @@ class AllineateInputSpec(AFNICommandInputSpec):
241241
desc='Save the transformation matrix for each volume.')
242242
in_matrix = File(
243243
desc='matrix to align input file',
244-
argstr='-1Dmatrix_apply %s',
245-
position=-3)
244+
argstr='-1Dmatrix_apply %s')
245+
# TODO: implement sensible xors for allcostx and suppres prefix in command when allcosx is used
246+
allcostx= File(
247+
desc='Compute and print ALL available cost functionals for the un-warped inputs'
248+
'AND THEN QUIT. If you use this option none of the other expected outputs will be produced',
249+
argstr='-allcostx |& tee %s',
250+
position=-1,
251+
xors=['out_file'])
246252

247253
_cost_funcs = [
248254
'leastsq', 'ls',
@@ -414,6 +420,7 @@ class AllineateInputSpec(AFNICommandInputSpec):
414420
class AllineateOutputSpec(TraitedSpec):
415421
out_file = File(desc='output image file name')
416422
matrix = File(desc='matrix to align input file')
423+
allcostx = File(desc='Compute and print ALL available cost functionals for the un-warped inputs')
417424

418425

419426
class Allineate(AFNICommand):
@@ -431,9 +438,17 @@ class Allineate(AFNICommand):
431438
>>> allineate.inputs.out_file = 'functional_allineate.nii'
432439
>>> allineate.inputs.in_matrix = 'cmatrix.mat'
433440
>>> allineate.cmdline # doctest: +ALLOW_UNICODE
434-
'3dAllineate -1Dmatrix_apply cmatrix.mat -prefix functional_allineate.nii -source functional.nii'
441+
'3dAllineate -source functional.nii -1Dmatrix_apply cmatrix.mat -prefix functional_allineate.nii'
435442
>>> res = allineate.run() # doctest: +SKIP
436443
444+
>>> from nipype.interfaces import afni
445+
>>> allineate = afni.Allineate()
446+
>>> allineate.inputs.in_file = 'functional.nii'
447+
>>> allineate.inputs.reference = 'structural.nii'
448+
>>> allineate.inputs.allcostx = 'out.allcostX.txt'
449+
>>> allineate.cmdline # doctest: +ALLOW_UNICODE
450+
'3dAllineate -source functional.nii -prefix functional_allineate -base structural.nii -allcostx |& tee out.allcostX.txt'
451+
>>> res = allineate.run() # doctest: +SKIP
437452
"""
438453

439454
_cmd = '3dAllineate'
@@ -457,6 +472,10 @@ def _list_outputs(self):
457472
if isdefined(self.inputs.out_matrix):
458473
outputs['matrix'] = os.path.abspath(os.path.join(os.getcwd(),\
459474
self.inputs.out_matrix +'.aff12.1D'))
475+
476+
if isdefined(self.inputs.allcostX):
477+
outputs['allcostX'] = os.path.abspath(os.path.join(os.getcwd(),\
478+
self.inputs.allcostx))
460479
return outputs
461480

462481
def _gen_filename(self, name):
@@ -1520,14 +1539,17 @@ class MeansInputSpec(AFNICommandInputSpec):
15201539
in_file_a = File(
15211540
desc='input file to 3dMean',
15221541
argstr='%s',
1523-
position=0,
1542+
position=-2,
15241543
mandatory=True,
15251544
exists=True)
15261545
in_file_b = File(
15271546
desc='another input file to 3dMean',
15281547
argstr='%s',
1529-
position=1,
1548+
position=-1,
15301549
exists=True)
1550+
datum = traits.Str(
1551+
desc='Sets the data type of the output dataset',
1552+
argstr='-datum %s')
15311553
out_file = File(
15321554
name_template='%s_mean',
15331555
desc='output image file name',
@@ -1574,7 +1596,16 @@ class Means(AFNICommand):
15741596
>>> means.inputs.in_file_b = 'im2.nii'
15751597
>>> means.inputs.out_file = 'output.nii'
15761598
>>> means.cmdline # doctest: +ALLOW_UNICODE
1577-
'3dMean im1.nii im2.nii -prefix output.nii'
1599+
'3dMean -prefix output.nii im1.nii im2.nii'
1600+
>>> res = means.run() # doctest: +SKIP
1601+
1602+
>>> from nipype.interfaces import afni
1603+
>>> means = afni.Means()
1604+
>>> means.inputs.in_file_a = 'im1.nii'
1605+
>>> means.inputs.out_file = 'output.nii'
1606+
>>> means.inputs.datum = 'short'
1607+
>>> means.cmdline # doctest: +ALLOW_UNICODE
1608+
'3dMean -datum short -prefix output.nii im1.nii'
15781609
>>> res = means.run() # doctest: +SKIP
15791610
15801611
"""

0 commit comments

Comments
 (0)