Skip to content

Commit 908e326

Browse files
committed
ENH: add interface for AFNI 3dTproject
1 parent 79d30b4 commit 908e326

File tree

3 files changed

+239
-1
lines changed

3 files changed

+239
-1
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
BlurInMask, BlurToFWHM, ClipLevel, DegreeCentrality, Despike, Detrend, ECM,
1414
Fim, Fourier, Hist, LFCD, Maskave, Means, OutlierCount, QualityIndex,
1515
ROIStats, Retroicor, Seg, SkullStrip, TCorr1D, TCorrMap, TCorrelate, TNorm,
16-
TShift, Volreg, Warp, QwarpPlusMinus, Qwarp)
16+
TProject, TShift, Volreg, Warp, QwarpPlusMinus, Qwarp)
1717
from .svm import (SVMTest, SVMTrain)
1818
from .utils import (
1919
ABoverlap, AFNItoNIFTI, Autobox, Axialize, BrickStat, Bucket, Calc, Cat,

nipype/interfaces/afni/preprocess.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,170 @@ class TNorm(AFNICommand):
24062406
output_spec = AFNICommandOutputSpec
24072407

24082408

2409+
class TProjectInputSpec(AFNICommandInputSpec):
2410+
in_file = File(
2411+
desc='input file to 3dTproject',
2412+
argstr='%s',
2413+
position=1,
2414+
mandatory=True,
2415+
exists=True,
2416+
copyfile=False)
2417+
out_file = File(
2418+
name_template='%s_tproject',
2419+
desc='output image file name',
2420+
position=-1,
2421+
argstr='-prefix %s',
2422+
name_source='in_file')
2423+
censor = File(
2424+
desc="""filename of censor .1D time series
2425+
* This is a file of 1s and 0s, indicating which
2426+
time points are to be included (1) and which are
2427+
to be excluded (0).""",
2428+
argstr="-censor %s")
2429+
censortr = traits.List(
2430+
traits.Str(),
2431+
desc="""list of strings that specify time indexes
2432+
to be removed from the analysis. Each string is
2433+
of one of the following forms:
2434+
37 => remove global time index #37
2435+
2:37 => remove time index #37 in run #2
2436+
37..47 => remove global time indexes #37-47
2437+
37-47 => same as above
2438+
2:37..47 => remove time indexes #37-47 in run #2
2439+
*:0-2 => remove time indexes #0-2 in all runs
2440+
+Time indexes within each run start at 0.
2441+
+Run indexes start at 1 (just be to confusing).
2442+
+N.B.: 2:37,47 means index #37 in run #2 and
2443+
global time index 47; it does NOT mean
2444+
index #37 in run #2 AND index #47 in run #2.""",
2445+
argstr="-CENSORTR %s")
2446+
cenmode = traits.Enum(
2447+
'KILL', 'ZERO', 'NTRP',
2448+
desc="""specifies how censored time points are treated in
2449+
the output dataset:
2450+
+ mode = ZERO ==> put zero values in their place
2451+
==> output datset is same length as input
2452+
+ mode = KILL ==> remove those time points
2453+
==> output dataset is shorter than input
2454+
+ mode = NTRP ==> censored values are replaced by interpolated
2455+
neighboring (in time) non-censored values,
2456+
BEFORE any projections, and then the
2457+
analysis proceeds without actual removal
2458+
of any time points -- this feature is to
2459+
keep the Spanish Inquisition happy.
2460+
* The default mode is KILL !!!""",
2461+
argstr='-cenmode %s')
2462+
concat = File(
2463+
desc="""The catenation file, as in 3dDeconvolve, containing the
2464+
TR indexes of the start points for each contiguous run
2465+
within the input dataset (the first entry should be 0).
2466+
++ Also as in 3dDeconvolve, if the input dataset is
2467+
automatically catenated from a collection of datasets,
2468+
then the run start indexes are determined directly,
2469+
and '-concat' is not needed (and will be ignored).
2470+
++ Each run must have at least 9 time points AFTER
2471+
censoring, or the program will not work!
2472+
++ The only use made of this input is in setting up
2473+
the bandpass/stopband regressors.
2474+
++ '-ort' and '-dsort' regressors run through all time
2475+
points, as read in. If you want separate projections
2476+
in each run, then you must either break these ort files
2477+
into appropriate components, OR you must run 3dTproject
2478+
for each run separately, using the appropriate pieces
2479+
from the ort files via the '{...}' selector for the
2480+
1D files and the '[...]' selector for the datasets.""",
2481+
exists=True,
2482+
argstr='-concat %s')
2483+
noblock = traits.Bool(
2484+
desc="""Also as in 3dDeconvolve, if you want the program to treat
2485+
an auto-catenated dataset as one long run, use this option.
2486+
++ However, '-noblock' will not affect catenation if you use
2487+
the '-concat' option.""",
2488+
argstr='-noblock')
2489+
ort = File(
2490+
desc="""Remove each column in file
2491+
++ Each column will have its mean removed.""",
2492+
exist=True,
2493+
argstr="-ort %s")
2494+
polort = traits.Int(
2495+
desc="""Remove polynomials up to and including degree pp.
2496+
++ Default value is 2.
2497+
++ It makes no sense to use a value of pp greater than
2498+
2, if you are bandpassing out the lower frequencies!
2499+
++ For catenated datasets, each run gets a separate set
2500+
set of pp+1 Legendre polynomial regressors.
2501+
++ Use of -polort -1 is not advised (if data mean != 0),
2502+
even if -ort contains constant terms, as all means are
2503+
removed.""",
2504+
argstr="-polort %d")
2505+
bandpass = traits.Tuple(
2506+
traits.Float, traits.Float,
2507+
desc="""Remove all frequencies EXCEPT those in the range""",
2508+
argstr='-bandpass %f %f')
2509+
stopband = traits.Tuple(
2510+
traits.Float, traits.Float,
2511+
desc="""Remove all frequencies in the range""",
2512+
argstr='-stopband %f %f')
2513+
TR = traits.Float(
2514+
desc="""Use time step dd for the frequency calculations,
2515+
rather than the value stored in the dataset header.""",
2516+
argstr='-TR %f')
2517+
mask = File(
2518+
exist=True,
2519+
desc="""Only operate on voxels nonzero in the mset dataset.
2520+
++ Voxels outside the mask will be filled with zeros.
2521+
++ If no masking option is given, then all voxels
2522+
will be processed.""",
2523+
argstr='-mask %s')
2524+
automask = traits.Bool(
2525+
desc="""Generate a mask automatically""",
2526+
xor=['mask'],
2527+
argstr='-automask')
2528+
blur = traits.Float(
2529+
desc="""Blur (inside the mask only) with a filter that has
2530+
width (FWHM) of fff millimeters.
2531+
++ Spatial blurring (if done) is after the time
2532+
series filtering.""",
2533+
argstr='-blur %f')
2534+
norm = traits.Bool(
2535+
desc="""Normalize each output time series to have sum of
2536+
squares = 1. This is the LAST operation.""",
2537+
argstr='-norm')
2538+
2539+
2540+
class TProject(AFNICommand):
2541+
"""
2542+
This program projects (detrends) out various 'nuisance' time series from
2543+
each voxel in the input dataset. Note that all the projections are done
2544+
via linear regression, including the frequency-based options such
2545+
as '-passband'. In this way, you can bandpass time-censored data, and at
2546+
the same time, remove other time series of no interest
2547+
(e.g., physiological estimates, motion parameters).
2548+
Shifts voxel time series from input so that seperate slices are aligned to
2549+
the same temporal origin.
2550+
2551+
For complete details, see the `3dTproject Documentation.
2552+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTproject.html>`_
2553+
2554+
Examples
2555+
========
2556+
2557+
>>> from nipype.interfaces import afni
2558+
>>> tproject = afni.TProject()
2559+
>>> tproject.inputs.in_file = 'functional.nii'
2560+
>>> tproject.inputs.bandpass = (0.00667, 99999)
2561+
>>> tproject.inputs.polort = 3
2562+
>>> tproject.inputs.automask = True
2563+
>>> tproject.inputs.out_file = 'projected.nii.gz'
2564+
>>> tproject.cmdline
2565+
'3dTproject functional.nii -automask -bandpass 0.006670 99999.000000 -polort 3 -prefix projected.nii.gz'
2566+
>>> res = tproject.run() # doctest: +SKIP
2567+
2568+
"""
2569+
_cmd = '3dTproject'
2570+
input_spec = TProjectInputSpec
2571+
output_spec = AFNICommandOutputSpec
2572+
24092573
class TShiftInputSpec(AFNICommandInputSpec):
24102574
in_file = File(
24112575
desc='input file to 3dTShift',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..preprocess import TProject
4+
5+
6+
def test_TProject_inputs():
7+
input_map = dict(
8+
TR=dict(argstr='-TR %f', ),
9+
args=dict(argstr='%s', ),
10+
automask=dict(
11+
argstr='-automask',
12+
xor=['mask'],
13+
),
14+
bandpass=dict(argstr='-bandpass %f %f', ),
15+
blur=dict(argstr='-blur %f', ),
16+
cenmode=dict(argstr='-cenmode %s', ),
17+
censor=dict(argstr='-censor %s', ),
18+
censortr=dict(argstr='-CENSORTR %s', ),
19+
concat=dict(argstr='-concat %s', ),
20+
environ=dict(
21+
nohash=True,
22+
usedefault=True,
23+
),
24+
ignore_exception=dict(
25+
deprecated='1.0.0',
26+
nohash=True,
27+
usedefault=True,
28+
),
29+
in_file=dict(
30+
argstr='%s',
31+
copyfile=False,
32+
mandatory=True,
33+
position=1,
34+
),
35+
mask=dict(
36+
argstr='-mask %s',
37+
exist=True,
38+
),
39+
noblock=dict(argstr='-noblock', ),
40+
norm=dict(argstr='-norm', ),
41+
num_threads=dict(
42+
nohash=True,
43+
usedefault=True,
44+
),
45+
ort=dict(
46+
argstr='-ort %s',
47+
exist=True,
48+
),
49+
out_file=dict(
50+
argstr='-prefix %s',
51+
name_source='in_file',
52+
name_template='%s_tproject',
53+
position=-1,
54+
),
55+
outputtype=dict(),
56+
polort=dict(argstr='-polort %d', ),
57+
stopband=dict(argstr='-stopband %f %f', ),
58+
terminal_output=dict(
59+
deprecated='1.0.0',
60+
nohash=True,
61+
),
62+
)
63+
inputs = TProject.input_spec()
64+
65+
for key, metadata in list(input_map.items()):
66+
for metakey, value in list(metadata.items()):
67+
assert getattr(inputs.traits()[key], metakey) == value
68+
def test_TProject_outputs():
69+
output_map = dict(out_file=dict(), )
70+
outputs = TProject.output_spec()
71+
72+
for key, metadata in list(output_map.items()):
73+
for metakey, value in list(metadata.items()):
74+
assert getattr(outputs.traits()[key], metakey) == value

0 commit comments

Comments
 (0)