Skip to content

Commit 5b4e9bb

Browse files
committed
add afni nwarpadjust
1 parent 04b440a commit 5b4e9bb

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

nipype/interfaces/afni/utils.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,92 @@ def _list_outputs(self):
15111511
return outputs
15121512

15131513

1514+
class NwarpAdjustInputSpec(CommandLineInputSpec):
1515+
warps = InputMultiPath(
1516+
File(exists=True),
1517+
minlen=5,
1518+
mandatory=True,
1519+
argstr='-nwarp %s',
1520+
desc='List of input 3D warp datasets')
1521+
in_files = InputMultiPath(
1522+
File(exists=True),
1523+
minlen=5,
1524+
mandatory=False,
1525+
argstr='-source %s',
1526+
desc='List of input 3D datasets to be warped by the adjusted warp '
1527+
'datasets. There must be exactly as many of these datasets as '
1528+
'there are input warps.')
1529+
out_file = File(
1530+
desc='Output mean dataset, only needed if in_files are also given. '
1531+
'The output dataset will be on the common grid shared by the '
1532+
'source datasets.',
1533+
argstr='-prefix %s',
1534+
mandatory=False,
1535+
name_source='in_files',
1536+
name_template='%s_NwarpAdjust',
1537+
keep_extension=True,
1538+
xand=['in_files'])
1539+
1540+
1541+
class NwarpAdjust(AFNICommandBase):
1542+
"""This program takes as input a bunch of 3D warps, averages them,
1543+
and computes the inverse of this average warp. It then composes
1544+
each input warp with this inverse average to 'adjust' the set of
1545+
warps. Optionally, it can also read in a set of 1-brick datasets
1546+
corresponding to the input warps, and warp each of them, and average
1547+
those.
1548+
1549+
For complete details, see the `3dNwarpAdjust Documentation.
1550+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNwarpAdjust.html>`_
1551+
1552+
Examples
1553+
========
1554+
1555+
>>> from nipype.interfaces import afni
1556+
>>> adjust = afni.NwarpAdjust()
1557+
>>> adjust.inputs.warps = [Fred_WARP+tlrc, Fred.Xaff12.1D, Fred.Xaff12.1D, Fred.Xaff12.1D, Fred.Xaff12.1D]
1558+
>>> adjust.cmdline
1559+
"NwarpAdjust -nwarp Fred_WARP+tlrc Fred.Xaff12.1D Fred.Xaff12.1D Fred.Xaff12.1D Fred.Xaff12.1D"
1560+
>>> res = adjust.run() # doctest: +SKIP
1561+
1562+
"""
1563+
_cmd = '3dNwarpAdjust'
1564+
input_spec = NwarpAdjustInputSpec
1565+
output_spec = AFNICommandOutputSpec
1566+
1567+
def _parse_inputs(self, skip=None):
1568+
if not self.inputs.in_files:
1569+
if skip is None:
1570+
skip = []
1571+
skip += ['out_file']
1572+
return super(NwarpAdjust, self)._parse_inputs(skip=skip)
1573+
1574+
def _gen_filename(self, name):
1575+
if name == 'out_file':
1576+
return self._list_outputs()[name]
1577+
return None
1578+
1579+
def _list_outputs(self):
1580+
outputs = self.output_spec().get()
1581+
1582+
if self.inputs.out_file:
1583+
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
1584+
1585+
if self.inputs.in_files:
1586+
if self.inputs.out_file:
1587+
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
1588+
else:
1589+
basename = os.path.basename(self.inputs.in_files[0])
1590+
basename_noext, ext = op.splitext(basename)
1591+
if '.gz' in ext:
1592+
basename_noext, ext2 = op.splitext(basename_noext)
1593+
ext = ext2 + ext
1594+
outputs['out_file'] = os.path.abspath(
1595+
basename_noext + '_NwarpAdjust' + ext)
1596+
1597+
return outputs
1598+
1599+
15141600
class NwarpApplyInputSpec(CommandLineInputSpec):
15151601
in_file = traits.Either(
15161602
File(exists=True),

0 commit comments

Comments
 (0)