Skip to content

Commit 298f4a2

Browse files
ShotgunosineDylan
authored andcommitted
[ENH] Add interface for 1d_tool.py
1 parent 37335d9 commit 298f4a2

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .utils import (ABoverlap, AFNItoNIFTI, Autobox, Axialize, BrickStat, Bucket,
2222
Calc, Cat, CatMatvec, Copy, Dot,
2323
Edge3, Eval, FWHMx, MaskTool, Merge, Notes, NwarpApply,
24+
OneDToolPy,
2425
Refit, Resample, TCat, TStat, To3D, Unifize, ZCutUp, GCOR,
2526
Zcat, Zeropad)
2627
from .model import (Deconvolve, Remlfit)

nipype/interfaces/afni/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class AllineateInputSpec(AFNICommandInputSpec):
227227
name_source='in_file',
228228
name_template='%s_allineate',
229229
genfile=True,
230-
xors=['allcostx'])
230+
xor=['allcostx'])
231231
out_param_file = File(
232232
argstr='-1Dparam_save %s',
233233
desc='Save the warp parameters in ASCII (.1D) format.')
@@ -248,7 +248,7 @@ class AllineateInputSpec(AFNICommandInputSpec):
248248
'AND THEN QUIT. If you use this option none of the other expected outputs will be produced',
249249
argstr='-allcostx |& tee %s',
250250
position=-1,
251-
xors=['out_file'])
251+
xor=['out_file'])
252252

253253
_cost_funcs = [
254254
'leastsq', 'ls',

nipype/interfaces/afni/utils.py

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
CommandLineInputSpec, CommandLine, Directory, TraitedSpec,
2626
traits, isdefined, File, InputMultiPath, Undefined, Str)
2727
from ...external.due import BibTeX
28-
28+
from distutils import spawn
2929
from .base import (
3030
AFNICommandBase, AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec)
3131

@@ -1494,6 +1494,94 @@ class NwarpApply(AFNICommandBase):
14941494
input_spec = NwarpApplyInputSpec
14951495
output_spec = AFNICommandOutputSpec
14961496

1497+
class OneDToolPyInputSpec(AFNICommandInputSpec):
1498+
in_file = File(
1499+
desc='input file to OneDTool',
1500+
argstr='-infile %s',
1501+
mandatory=True,
1502+
exists=True)
1503+
py27_path = File(
1504+
desc='Path to Python 2.7 executable for running afni python scripts',
1505+
argstr='%s '+spawn.find_executable('1d_tool.py'),
1506+
exists=True,
1507+
default='/opt/miniconda/envs/py27/bin/python',
1508+
usedefault=True,
1509+
position=0
1510+
)
1511+
set_nruns = traits.Int(
1512+
desc='treat the input data as if it has nruns',
1513+
argstr='-set_nruns %d')
1514+
derivative = traits.Bool(
1515+
desc='take the temporal derivative of each vector (done as first backward difference)',
1516+
argstr='-derivative')
1517+
demean = traits.Bool(
1518+
desc='demean each run (new mean of each run = 0.0)',
1519+
argstr='-demean')
1520+
out_file = File(
1521+
desc='write the current 1D data to FILE',
1522+
argstr='-write %s',
1523+
xor=['show_cormat_warnings'])
1524+
show_censor_count = traits.Bool(
1525+
desc='display the total number of censored TRs Note : if input is a valid xmat.1D dataset,'
1526+
'then the count will come from the header. Otherwise the input is assumed to be a binary censor'
1527+
'file, and zeros are simply counted.',
1528+
argstr="-show_censor_count")
1529+
censor_motion = traits.Tuple(
1530+
(traits.Float(),File()),
1531+
desc='Tuple of motion limit and outfile prefix. need to also set set_nruns -r set_run_lengths',
1532+
argstr="-censor_motion %f %s")
1533+
censor_prev_TR = traits.Bool(
1534+
desc='for each censored TR, also censor previous',
1535+
argstr='-censor_prev_TR')
1536+
show_trs_uncensored = traits.Enum('comma','space','encoded','verbose',
1537+
desc='display a list of TRs which were not censored in the specified style',
1538+
argstr='-show_trs_uncensored %s')
1539+
show_cormat_warnings = traits.File(
1540+
desc='Write cormat warnings to a file',
1541+
argstr="-show_cormat_warnings |& tee %s",
1542+
default="out.cormat_warn.txt",
1543+
usedefault=False,
1544+
position=-1,
1545+
xor=['out_file'])
1546+
show_indices_interest = traits.Bool(
1547+
desc="display column indices for regs of interest",
1548+
argstr="-show_indices_interest")
1549+
show_trs_run = traits.Int(
1550+
desc="restrict -show_trs_[un]censored to the given 1-based run",
1551+
argstr="-show_trs_run %d")
1552+
1553+
class OneDToolPyOutputSpec(AFNICommandOutputSpec):
1554+
out_file = File(desc='output of 1D_tool.py')
1555+
1556+
class OneDToolPy(AFNICommandBase):
1557+
"""This program is meant to read/manipulate/write/diagnose 1D datasets.
1558+
Input can be specified using AFNI sub-brick[]/time{} selectors.
1559+
1560+
>>> from nipype.interfaces import afni
1561+
>>> odt = afni.OneDToolPy()
1562+
>>> odt.inputs.in_file = 'f1.1D'
1563+
>>> odt.inputs.py27_path = "/opt/miniconda/envs/py27/bin/python"
1564+
>>> odt.inputs.set_nruns = 3
1565+
>>> odt.inputs.demean = True
1566+
>>> odt.inputs.out_file = 'motion_dmean.1D'
1567+
>>> odt.cmdline # doctest: +ALLOW_UNICODE
1568+
'echo "" && /opt/miniconda/envs/py27/bin/python /root/abin/1d_tool.py -demean -infile f1.1D -write motion_dmean.1D -set_nruns 3'
1569+
>>> res = odt.run() # doctest: +SKIP
1570+
"""
1571+
1572+
_cmd = 'echo "" && '
1573+
1574+
input_spec = OneDToolPyInputSpec
1575+
output_spec = OneDToolPyOutputSpec
1576+
1577+
def _list_outputs(self):
1578+
outputs = self.output_spec().get()
1579+
1580+
if isdefined(self.inputs.out_file):
1581+
outputs['out_file']=os.path.join(os.getcwd(), self.inputs.out_file)
1582+
if isdefined(self.inputs.show_cormat_warnings):
1583+
outputs['out_file']=os.path.join(os.getcwd(), self.inputs.show_cormat_warnings)
1584+
return outputs
14971585

14981586
class RefitInputSpec(CommandLineInputSpec):
14991587
in_file = File(

0 commit comments

Comments
 (0)