Skip to content

Commit d0aebbb

Browse files
committed
Merge pull request #465 from chrisfilo/fix/afni_calc_escape
Escape the expr parameter in 3dcalc.
2 parents 12abb6a + 9a71507 commit d0aebbb

File tree

1 file changed

+46
-68
lines changed

1 file changed

+46
-68
lines changed

nipype/interfaces/afni/preprocess.py

Lines changed: 46 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Change directory to provide relative paths for doctests
66
>>> import os
77
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
8-
>>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
8+
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
99
>>> os.chdir(datadir)
1010
"""
1111
import warnings
@@ -148,9 +148,8 @@ class TShift(AFNICommand):
148148
========
149149
150150
>>> from nipype.interfaces import afni as afni
151-
>>> from nipype.testing import example_data
152151
>>> tshift = afni.TShift()
153-
>>> tshift.inputs.in_file = example_data('functional.nii')
152+
>>> tshift.inputs.in_file = 'functional.nii'
154153
>>> tshift.inputs.out_file = 'functional_tshift.nii'
155154
>>> tshift.inputs.tpattern = 'alt+z'
156155
>>> tshift.inputs.tzero = 0.0
@@ -201,7 +200,7 @@ class RefitInputSpec(AFNITraitedSpec):
201200

202201

203202
class RefitOutputSpec(TraitedSpec):
204-
out_file = File(desc='Same file as original infile with modified matrix',
203+
out_file = File(desc='Same file as original in_file with modified matrix',
205204
exists=True)
206205

207206

@@ -215,9 +214,8 @@ class Refit(AFNICommand):
215214
========
216215
217216
>>> from nipype.interfaces import afni as afni
218-
>>> from nipype.testing import example_data
219217
>>> refit = afni.Refit()
220-
>>> refit.inputs.in_file = example_data('structural.nii')
218+
>>> refit.inputs.in_file = 'structural.nii'
221219
>>> refit.inputs.deoblique=True
222220
>>> res = refit.run() # doctest: +SKIP
223221
@@ -294,9 +292,8 @@ class Warp(AFNICommand):
294292
========
295293
296294
>>> from nipype.interfaces import afni as afni
297-
>>> from nipype.testing import example_data
298295
>>> warp = afni.Warp()
299-
>>> warp.inputs.in_file = example_data('structural.nii')
296+
>>> warp.inputs.in_file = 'structural.nii'
300297
>>> warp.inputs.deoblique = True
301298
>>> res = warp.run() # doctest: +SKIP
302299
@@ -356,9 +353,8 @@ class Resample(AFNICommand):
356353
========
357354
358355
>>> from nipype.interfaces import afni as afni
359-
>>> from nipype.testing import example_data
360356
>>> resample = afni.Resample()
361-
>>> resample.inputs.in_file = example_data('functional.nii')
357+
>>> resample.inputs.in_file = 'functional.nii'
362358
>>> resample.inputs.orientation= 'RPI'
363359
>>> res = resample.run() # doctest: +SKIP
364360
@@ -414,9 +410,8 @@ class TStat(AFNICommand):
414410
========
415411
416412
>>> from nipype.interfaces import afni as afni
417-
>>> from nipype.testing import example_data
418413
>>> tstat = afni.TStat()
419-
>>> tstat.inputs.in_file = example_data('functional.nii')
414+
>>> tstat.inputs.in_file = 'functional.nii'
420415
>>> tstat.inputs.args= '-mean'
421416
>>> res = tstat.run() # doctest: +SKIP
422417
@@ -471,9 +466,8 @@ class Detrend(AFNICommand):
471466
========
472467
473468
>>> from nipype.interfaces import afni as afni
474-
>>> from nipype.testing import example_data
475469
>>> detrend = afni.Detrend()
476-
>>> detrend.inputs.in_file = example_data('functional.nii')
470+
>>> detrend.inputs.in_file = 'functional.nii'
477471
>>> detrend.inputs.args = '-polort 2'
478472
>>> res = detrend.run() # doctest: +SKIP
479473
@@ -529,9 +523,8 @@ class Despike(AFNICommand):
529523
========
530524
531525
>>> from nipype.interfaces import afni as afni
532-
>>> from nipype.testing import example_data
533526
>>> despike = afni.Despike()
534-
>>> despike.inputs.in_file = example_data('functional.nii')
527+
>>> despike.inputs.in_file = 'functional.nii'
535528
>>> res = despike.run() # doctest: +SKIP
536529
537530
"""
@@ -605,9 +598,8 @@ class Automask(AFNICommand):
605598
========
606599
607600
>>> from nipype.interfaces import afni as afni
608-
>>> from nipype.testing import example_data
609601
>>> automask = afni.Automask()
610-
>>> automask.inputs.in_file = example_data('functional.nii')
602+
>>> automask.inputs.in_file = 'functional.nii'
611603
>>> automask.inputs.dilate = 1
612604
>>> res = automask.run() # doctest: +SKIP
613605
@@ -691,11 +683,10 @@ class Volreg(AFNICommand):
691683
========
692684
693685
>>> from nipype.interfaces import afni as afni
694-
>>> from nipype.testing import example_data
695686
>>> volreg = afni.Volreg()
696-
>>> volreg.inputs.in_file = example_data('functional.nii')
697-
>>> volreg.inputs.other = '-Fourier -twopass'
698-
>>> volreg.inputs.zpad = '4'
687+
>>> volreg.inputs.in_file = 'functional.nii'
688+
>>> volreg.inputs.args = '-Fourier -twopass'
689+
>>> volreg.inputs.zpad = 4
699690
>>> res = volreg.run() # doctest: +SKIP
700691
701692
"""
@@ -759,12 +750,11 @@ class Merge(AFNICommand):
759750
========
760751
761752
>>> from nipype.interfaces import afni as afni
762-
>>> from nipype.testing import example_data
763753
>>> merge = afni.Merge()
764-
>>> merge.inputs.infile = example_data('functional.nii')
765-
>>> merge.inputs.blurfwhm = 4.0
754+
>>> merge.inputs.in_files = ['functional.nii', 'functional2.nii']
755+
>>> merge.inputs.blurfwhm = 4
766756
>>> merge.inputs.doall = True
767-
>>> merge.inputs.outfile = 'e7.nii'
757+
>>> merge.inputs.out_file = 'e7.nii'
768758
>>> res = merge.run() # doctest: +SKIP
769759
770760
"""
@@ -816,9 +806,8 @@ class Copy(AFNICommand):
816806
========
817807
818808
>>> from nipype.interfaces import afni as afni
819-
>>> from nipype.testing import example_data
820809
>>> copy = afni.Copy()
821-
>>> copy.inputs.in_file = example_data('functional.nii')
810+
>>> copy.inputs.in_file = 'functional.nii'
822811
>>> copy.inputs.out_file = 'new_func.nii'
823812
>>> res = copy.run() # doctest: +SKIP
824813
@@ -879,9 +868,8 @@ class Fourier(AFNICommand):
879868
========
880869
881870
>>> from nipype.interfaces import afni as afni
882-
>>> from nipype.testing import example_data
883871
>>> fourier = afni.Fourier()
884-
>>> fourier.inputs.in_file = example_data('functional.nii')
872+
>>> fourier.inputs.in_file = 'functional.nii'
885873
>>> fourier.inputs.args = '-retrend'
886874
>>> fourier.inputs.highpass = 0.005
887875
>>> fourier.inputs.lowpass = 0.1
@@ -937,10 +925,9 @@ class ZCutUp(AFNICommand):
937925
========
938926
939927
>>> from nipype.interfaces import afni as afni
940-
>>> from nipype.testing import example_data
941-
>>> zcutup = afni.Zcutup()
942-
>>> zcutup.inputs.infile = example_data('functional.nii')
943-
>>> zcutup.inputs.outfile= 'functional_zcutup.nii'
928+
>>> zcutup = afni.ZCutUp()
929+
>>> zcutup.inputs.in_file = 'functional.nii'
930+
>>> zcutup.inputs.out_file = 'functional_zcutup.nii'
944931
>>> zcutup.inputs.keep= '0 10'
945932
>>> res = zcutup.run() # doctest: +SKIP
946933
@@ -996,11 +983,10 @@ class Allineate(AFNICommand):
996983
========
997984
998985
>>> from nipype.interfaces import afni as afni
999-
>>> from nipype.testing import example_data
1000986
>>> allineate = afni.Allineate()
1001-
>>> allineate.inputs.infile = example_data('functional.nii')
1002-
>>> allineate.inputs.outfile= 'functional_allineate.nii'
1003-
>>> allineate.inputs.matrix= example_data('cmatrix.mat')
987+
>>> allineate.inputs.in_file = 'functional.nii'
988+
>>> allineate.inputs.out_file= 'functional_allineate.nii'
989+
>>> allineate.inputs.matrix= 'cmatrix.mat'
1004990
>>> res = allineate.run() # doctest: +SKIP
1005991
1006992
"""
@@ -1061,10 +1047,9 @@ class Maskave(AFNICommand):
10611047
========
10621048
10631049
>>> from nipype.interfaces import afni as afni
1064-
>>> from nipype.testing import example_data
10651050
>>> maskave = afni.Maskave()
1066-
>>> maskave.inputs.in_file = example_data('functional.nii')
1067-
>>> maskave.inputs.mask= example_data('seed_mask.nii')
1051+
>>> maskave.inputs.in_file = 'functional.nii'
1052+
>>> maskave.inputs.mask= 'seed_mask.nii'
10681053
>>> maskave.inputs.quiet= True
10691054
>>> maskave.inputs.out_file= 'maskave.1D'
10701055
>>> res = maskave.run() # doctest: +SKIP
@@ -1119,9 +1104,8 @@ class SkullStrip(AFNICommand):
11191104
========
11201105
11211106
>>> from nipype.interfaces import afni as afni
1122-
>>> from nipype.testing import example_data
1123-
>>> skullstrip = afni.Skullstrip()
1124-
>>> skullstrip.inputs.in_file = example_data('functional.nii')
1107+
>>> skullstrip = afni.SkullStrip()
1108+
>>> skullstrip.inputs.in_file = 'functional.nii'
11251109
>>> skullstrip.inputs.args = '-o_ply'
11261110
>>> res = skullstrip.run() # doctest: +SKIP
11271111
@@ -1177,9 +1161,8 @@ class TCat(AFNICommand):
11771161
========
11781162
11791163
>>> from nipype.interfaces import afni as afni
1180-
>>> from nipype.testing import example_data
11811164
>>> tcat = afni.TCat()
1182-
>>> tcat.inputs.in_file = example_data('functional.nii')
1165+
>>> tcat.inputs.in_files = ['functional.nii', 'functional2.nii']
11831166
>>> tcat.inputs.out_file= 'functional_tcat.nii'
11841167
>>> tcat.inputs.rlt = '+'
11851168
>>> res = tcat.run() # doctest: +SKIP
@@ -1243,10 +1226,9 @@ class Fim(AFNICommand):
12431226
========
12441227
12451228
>>> from nipype.interfaces import afni as afni
1246-
>>> from nipype.testing import example_data
12471229
>>> fim = afni.Fim()
1248-
>>> fim.inputs.in_file = example_data('functional.nii')
1249-
>>> fim.inputs.ideal_file= example_data('seed.1D')
1230+
>>> fim.inputs.in_file = 'functional.nii'
1231+
>>> fim.inputs.ideal_file= 'seed.1D'
12501232
>>> fim.inputs.out_file = 'functional_corr.nii'
12511233
>>> fim.inputs.out = 'Correlation'
12521234
>>> fim.inputs.fim_thr = 0.0009
@@ -1313,11 +1295,9 @@ class TCorrelate(AFNICommand):
13131295
========
13141296
13151297
>>> from nipype.interfaces import afni as afni
1316-
>>> from nipype.testing import example_data
13171298
>>> tcorrelate = afni.TCorrelate()
1318-
>>> tcorrelate.inputs.in_file = example_data('functional.nii')
1319-
>>> tcorrelate.inputs.xset= example_data('u_rc1s1_Template.nii')
1320-
>>> tcorrelate.inputs.yset = example_data('u_rc1s2_Template.nii')
1299+
>>> tcorrelate.inputs.xset= 'u_rc1s1_Template.nii'
1300+
>>> tcorrelate.inputs.yset = 'u_rc1s2_Template.nii'
13211301
>>> tcorrelate.inputs.out_file = 'functional_tcorrelate.nii.gz'
13221302
>>> tcorrelate.inputs.polort = -1
13231303
>>> tcorrelate.inputs.pearson = True
@@ -1375,10 +1355,9 @@ class BrickStat(AFNICommand):
13751355
========
13761356
13771357
>>> from nipype.interfaces import afni as afni
1378-
>>> from nipype.testing import example_data
13791358
>>> brickstat = afni.BrickStat()
1380-
>>> brickstat.inputs.in_file = example_data('functional.nii')
1381-
>>> brickstat.inputs.mask = example_data('skeleton_mask.nii.gz')
1359+
>>> brickstat.inputs.in_file = 'functional.nii'
1360+
>>> brickstat.inputs.mask = 'skeleton_mask.nii.gz'
13821361
>>> brickstat.inputs.min = True
13831362
>>> res = brickstat.run() # doctest: +SKIP
13841363
@@ -1453,10 +1432,9 @@ class ROIStats(AFNICommand):
14531432
========
14541433
14551434
>>> from nipype.interfaces import afni as afni
1456-
>>> from nipype.testing import example_data
14571435
>>> roistats = afni.ROIStats()
1458-
>>> roistats.inputs.in_file = example_data('functional.nii')
1459-
>>> roistats.inputs.mask = example_data('skeleton_mask.nii.gz')
1436+
>>> roistats.inputs.in_file = 'functional.nii'
1437+
>>> roistats.inputs.mask = 'skeleton_mask.nii.gz'
14601438
>>> roistats.inputs.quiet=True
14611439
>>> res = roistats.run() # doctest: +SKIP
14621440
@@ -1514,15 +1492,15 @@ class CalcInputSpec(AFNITraitedSpec):
15141492
argstr='-a %s', position=0, mandatory=True, exists=True)
15151493
in_file_b = File(desc='operand file to 3dcalc',
15161494
argstr=' -b %s', position=1, exists=True)
1517-
expr = traits.Str(desc='expr', argstr='-expr %s', position=2,
1495+
expr = traits.Str(desc='expr', argstr='-expr "%s"', position=2,
15181496
mandatory=True)
15191497
out_file = File(desc='output file from 3dFourier', argstr='-prefix %s',
15201498
position=-1, genfile=True)
1521-
start_idx = traits.Int(desc='start index for infile_a',
1499+
start_idx = traits.Int(desc='start index for in_file_a',
15221500
requires=['stop_idx'])
1523-
stop_idx = traits.Int(desc='stop index for infile_a',
1501+
stop_idx = traits.Int(desc='stop index for in_file_a',
15241502
requires=['start_idx'])
1525-
single_idx = traits.Int(desc='volume index for infile_a')
1503+
single_idx = traits.Int(desc='volume index for in_file_a')
15261504
suffix = traits.Str('_calc', desc="out_file suffix", usedefault=True)
15271505

15281506

@@ -1540,13 +1518,13 @@ class Calc(AFNICommand):
15401518
========
15411519
15421520
>>> from nipype.interfaces import afni as afni
1543-
>>> from nipype.testing import example_data
15441521
>>> calc = afni.Calc()
1545-
>>> calc.inputs.infile_a = example_data('functional.nii')
1546-
>>> calc.inputs.Infile_b = example_data('functional2.nii.gz')
1522+
>>> calc.inputs.in_file_a = 'functional.nii'
1523+
>>> calc.inputs.in_file_b = 'functional2.nii'
15471524
>>> calc.inputs.expr='a*b'
15481525
>>> calc.inputs.out_file = 'functional_calc.nii.gz'
1549-
>>> res = calc.run() # doctest: +SKIP
1526+
>>> calc.cmdline
1527+
'3dcalc -a functional.nii -b functional2.nii -expr "a*b" -prefix functional_calc.nii.gz'
15501528
15511529
"""
15521530

@@ -1568,7 +1546,7 @@ def _gen_filename(self, name):
15681546
return self._list_outputs()[name]
15691547

15701548
def _format_arg(self, name, trait_spec, value):
1571-
if name == 'infile_a':
1549+
if name == 'in_file_a':
15721550
arg = trait_spec.argstr % value
15731551
if isdefined(self.inputs.start_idx):
15741552
arg += '[%d..%d]' % (self.inputs.start_idx,

0 commit comments

Comments
 (0)