Skip to content

Commit cee5db9

Browse files
authored
Merge pull request #2210 from emdupre/master
[ENH] Add 3dSynthesize, `-cbucket` flag for 3dDeconvolve
2 parents 3ce081a + 8fe85ab commit cee5db9

File tree

4 files changed

+142
-2
lines changed

4 files changed

+142
-2
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
Refit, Resample, TCat, TCatSubBrick, TStat, To3D, Unifize,
2727
Undump, ZCutUp, GCOR,
2828
Zcat, Zeropad)
29-
from .model import (Deconvolve, Remlfit)
29+
from .model import (Deconvolve, Remlfit, Synthesize)

nipype/interfaces/afni/model.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ class DeconvolveInputSpec(AFNICommandInputSpec):
154154
x1D_stop = traits.Bool(
155155
desc='stop running after writing .xmat.1D file',
156156
argstr='-x1D_stop')
157+
cbucket = traits.Str(
158+
desc='Name for dataset in which to save the regression '
159+
'coefficients (no statistics). This dataset '
160+
'will be used in a -xrestore run [not yet implemented] '
161+
'instead of the bucket dataset, if possible.',
162+
argstr='-cbucket %s')
157163
out_file = File(
158164
desc='output statistics file',
159165
argstr='-bucket %s')
@@ -231,6 +237,8 @@ class DeconvolveOutputSpec(TraitedSpec):
231237
desc='automatical generated script to run 3dREMLfit', exists=True)
232238
x1D = File(
233239
desc='save out X matrix', exists=True)
240+
cbucket = File(
241+
desc='output regression coefficients file (if generated)')
234242

235243

236244
class Deconvolve(AFNICommand):
@@ -588,3 +596,75 @@ def _list_outputs(self):
588596
outputs[key] = os.path.abspath(self.inputs.get()[key])
589597

590598
return outputs
599+
600+
601+
class SynthesizeInputSpec(AFNICommandInputSpec):
602+
cbucket = File(
603+
desc='Read the dataset output from '
604+
'3dDeconvolve via the \'-cbucket\' option.',
605+
argstr='-cbucket %s',
606+
copyfile=False,
607+
mandatory=True)
608+
matrix = File(
609+
desc='Read the matrix output from '
610+
'3dDeconvolve via the \'-x1D\' option.',
611+
argstr='-matrix %s',
612+
copyfile=False,
613+
mandatory=True)
614+
select = traits.List(
615+
Str(desc='selected columns to synthesize'),
616+
argstr='-select %s',
617+
desc='A list of selected columns from the matrix (and the '
618+
'corresponding coefficient sub-bricks from the '
619+
'cbucket). Valid types include \'baseline\', '
620+
' \'polort\', \'allfunc\', \'allstim\', \'all\', '
621+
'Can also provide \'something\' where something matches '
622+
'a stim_label from 3dDeconvolve, and \'digits\' where digits '
623+
'are the numbers of the select matrix columns by '
624+
'numbers (starting at 0), or number ranges of the form '
625+
'\'3..7\' and \'3-7\'.',
626+
mandatory=True)
627+
out_file = File(
628+
name_template='syn',
629+
desc='output dataset prefix name (default \'syn\')',
630+
argstr='-prefix %s')
631+
dry_run = traits.Bool(
632+
desc='Don\'t compute the output, just '
633+
'check the inputs.',
634+
argstr='-dry')
635+
TR = traits.Float(
636+
desc='TR to set in the output. The default value of '
637+
'TR is read from the header of the matrix file.',
638+
argstr='-TR %f')
639+
cenfill = traits.Enum(
640+
'zero','nbhr','none',
641+
argstr='-cenfill %s',
642+
desc='Determines how censored time points from the '
643+
'3dDeconvolve run will be filled. Valid types '
644+
'are \'zero\', \'nbhr\' and \'none\'.')
645+
646+
647+
class Synthesize(AFNICommand):
648+
"""Reads a '-cbucket' dataset and a '.xmat.1D' matrix from 3dDeconvolve,
649+
and synthesizes a fit dataset using user-selected sub-bricks and
650+
matrix columns.
651+
652+
For complete details, see the `3dSynthesize Documentation.
653+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dSynthesize.html>`_
654+
655+
Examples
656+
========
657+
658+
>>> from nipype.interfaces import afni
659+
>>> synthesize = afni.Synthesize()
660+
>>> synthesize.inputs.cbucket = 'functional.nii'
661+
>>> synthesize.inputs.matrix = 'output.1D'
662+
>>> synthesize.inputs.select = ['baseline']
663+
>>> synthesize.cmdline # doctest: +ALLOW_UNICODE
664+
'3dSynthesize -cbucket functional.nii -matrix output.1D -select baseline'
665+
>>> syn = synthesize.run() # doctest: +SKIP
666+
"""
667+
668+
_cmd = '3dSynthesize'
669+
input_spec = SynthesizeInputSpec
670+
output_spec = AFNICommandOutputSpec

nipype/interfaces/afni/tests/test_auto_Deconvolve.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def test_Deconvolve_inputs():
1414
),
1515
automask=dict(argstr='-automask',
1616
),
17+
cbucket=dict(argstr='-cbucket %s',
18+
),
1719
censor=dict(argstr='-censor %s',
1820
),
1921
dmbase=dict(argstr='-dmbase',
@@ -127,7 +129,8 @@ def test_Deconvolve_inputs():
127129

128130

129131
def test_Deconvolve_outputs():
130-
output_map = dict(out_file=dict(),
132+
output_map = dict(cbucket=dict(),
133+
out_file=dict(),
131134
reml_script=dict(),
132135
x1D=dict(),
133136
)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..model import Synthesize
4+
5+
6+
def test_Synthesize_inputs():
7+
input_map = dict(TR=dict(argstr='-TR %f',
8+
),
9+
args=dict(argstr='%s',
10+
),
11+
cbucket=dict(argstr='-cbucket %s',
12+
copyfile=False,
13+
mandatory=True,
14+
),
15+
cenfill=dict(argstr='-cenfill %s',
16+
),
17+
dry_run=dict(argstr='-dry',
18+
),
19+
environ=dict(nohash=True,
20+
usedefault=True,
21+
),
22+
ignore_exception=dict(nohash=True,
23+
usedefault=True,
24+
),
25+
matrix=dict(argstr='-matrix %s',
26+
copyfile=False,
27+
mandatory=True,
28+
),
29+
num_threads=dict(nohash=True,
30+
usedefault=True,
31+
),
32+
out_file=dict(argstr='-prefix %s',
33+
name_template='syn',
34+
),
35+
outputtype=dict(),
36+
select=dict(argstr='-select %s',
37+
mandatory=True,
38+
),
39+
terminal_output=dict(deprecated='1.0.0',
40+
nohash=True,
41+
),
42+
)
43+
inputs = Synthesize.input_spec()
44+
45+
for key, metadata in list(input_map.items()):
46+
for metakey, value in list(metadata.items()):
47+
assert getattr(inputs.traits()[key], metakey) == value
48+
49+
50+
def test_Synthesize_outputs():
51+
output_map = dict(out_file=dict(),
52+
)
53+
outputs = Synthesize.output_spec()
54+
55+
for key, metadata in list(output_map.items()):
56+
for metakey, value in list(metadata.items()):
57+
assert getattr(outputs.traits()[key], metakey) == value

0 commit comments

Comments
 (0)