Skip to content

Commit cc22499

Browse files
author
Oscar Esteban
committed
fix ACF output of FWHMx, add env variable to all afni interfaces for OSX
1 parent 667ed2f commit cc22499

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

nipype/interfaces/afni/base.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Provide interface to AFNI commands."""
44

5-
from builtins import object
6-
7-
85
import os
6+
from sys import platform
7+
from builtins import object
98

109
from ... import logging
1110
from ...utils.filemanip import split_filename
1211
from ..base import (
1312
CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec)
1413

1514
# Use nipype's logging system
16-
iflogger = logging.getLogger('interface')
15+
IFLOGGER = logging.getLogger('interface')
1716

1817

1918
class Info(object):
@@ -46,14 +45,14 @@ def version():
4645
currv = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip()
4746
except IOError:
4847
# If afni_vcheck is not present, return None
49-
iflogger.warn('afni_vcheck executable not found.')
48+
IFLOGGER.warn('afni_vcheck executable not found.')
5049
return None
5150
except RuntimeError as e:
5251
# If AFNI is outdated, afni_vcheck throws error.
5352
# Show new version, but parse current anyways.
5453
currv = str(e).split('\n')[4].split('=', 1)[1].strip()
5554
nextv = str(e).split('\n')[6].split('=', 1)[1].strip()
56-
iflogger.warn(
55+
IFLOGGER.warn(
5756
'AFNI is outdated, detected version %s and %s is available.' % (currv, nextv))
5857

5958
if currv.startswith('AFNI_'):
@@ -117,6 +116,17 @@ def standard_image(img_name):
117116
return os.path.join(basedir, img_name)
118117

119118

119+
class AFNICommandBase(CommandLine):
120+
"""
121+
A base class to fix a linking problem in OSX and afni.
122+
See http://afni.nimh.nih.gov/afni/community/board/read.php?1,145346,145347#msg-145347
123+
"""
124+
def _run_interface(self, runtime):
125+
if platform == 'darwin':
126+
runtime.environ['DYLD_FALLBACK_LIBRARY_PATH'] = '/usr/local/afni/'
127+
return super(AFNICommandBase, self)._run_interface(runtime)
128+
129+
120130
class AFNICommandInputSpec(CommandLineInputSpec):
121131
outputtype = traits.Enum('AFNI', list(Info.ftypes.keys()),
122132
desc='AFNI output filetype')
@@ -130,8 +140,8 @@ class AFNICommandOutputSpec(TraitedSpec):
130140
exists=True)
131141

132142

133-
class AFNICommand(CommandLine):
134-
143+
class AFNICommand(AFNICommandBase):
144+
"""Shared options for several AFNI commands """
135145
input_spec = AFNICommandInputSpec
136146
_outputtype = None
137147

nipype/interfaces/afni/preprocess.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
"""
1111

1212
import os
13-
from sys import platform
1413
import os.path as op
1514
import re
1615
import numpy as np
1716

18-
from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec, Info, no_afni
19-
from ..base import CommandLineInputSpec, CommandLine
17+
from .base import (AFNICommandBase, AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec,
18+
Info, no_afni)
19+
from ..base import CommandLineInputSpec
2020
from ..base import (Directory, TraitedSpec,
2121
traits, isdefined, File, InputMultiPath, Undefined)
2222
from ...external.six import string_types
@@ -182,7 +182,7 @@ class RefitInputSpec(CommandLineInputSpec):
182182
' template type, e.g. TLRC, MNI, ORIG')
183183

184184

185-
class Refit(CommandLine):
185+
class Refit(AFNICommandBase):
186186
"""Changes some of the information inside a 3D dataset's header
187187
188188
For complete details, see the `3drefit Documentation.
@@ -1546,7 +1546,7 @@ class ROIStatsOutputSpec(TraitedSpec):
15461546
stats = File(desc='output tab separated values file', exists=True)
15471547

15481548

1549-
class ROIStats(CommandLine):
1549+
class ROIStats(AFNICommandBase):
15501550
"""Display statistics over masked regions
15511551
15521552
For complete details, see the `3dROIstats Documentation.
@@ -2115,7 +2115,7 @@ class HistOutputSpec(TraitedSpec):
21152115
out_show = File(desc='output visual histogram')
21162116

21172117

2118-
class Hist(CommandLine):
2118+
class Hist(AFNICommandBase):
21192119
"""Computes average of all voxels in the input dataset
21202120
which satisfy the criterion in the options list
21212121
@@ -2197,8 +2197,8 @@ class FWHMxInputSpec(CommandLineInputSpec):
21972197
combine = traits.Bool(argstr='-combine', desc='combine the final measurements along each axis')
21982198
compat = traits.Bool(argstr='-compat', desc='be compatible with the older 3dFWHM')
21992199
acf = traits.Either(
2200-
traits.Bool(), File(exists=True), traits.Tuple(File(exists=True), traits.Float()),
2201-
argstr='-acf', desc='computes the spatial autocorrelation')
2200+
traits.Bool(), File(), traits.Tuple(File(exists=True), traits.Float()),
2201+
default=False, usedefault=True, argstr='-acf', desc='computes the spatial autocorrelation')
22022202

22032203

22042204
class FWHMxOutputSpec(TraitedSpec):
@@ -2209,9 +2209,14 @@ class FWHMxOutputSpec(TraitedSpec):
22092209
traits.Tuple(traits.Float(), traits.Float(), traits.Float()),
22102210
traits.Tuple(traits.Float(), traits.Float(), traits.Float(), traits.Float()),
22112211
desc='FWHM along each axis')
2212+
acf_param = traits.Either(
2213+
traits.Tuple(traits.Float(), traits.Float(), traits.Float()),
2214+
traits.Tuple(traits.Float(), traits.Float(), traits.Float(), traits.Float()),
2215+
desc='fitted ACF model parameters')
2216+
out_acf = File(exists=True, desc='output acf file')
22122217

22132218

2214-
class FWHMx(CommandLine):
2219+
class FWHMx(AFNICommandBase):
22152220
"""
22162221
Unlike the older 3dFWHM, this program computes FWHMs for all sub-bricks
22172222
in the input dataset, each one separately. The output for each one is
@@ -2312,6 +2317,7 @@ class FWHMx(CommandLine):
23122317
_cmd = '3dFWHMx'
23132318
input_spec = FWHMxInputSpec
23142319
output_spec = FWHMxOutputSpec
2320+
_acf = True
23152321

23162322
def _parse_inputs(self, skip=None):
23172323
if not self.inputs.detrend:
@@ -2331,20 +2337,18 @@ def _format_arg(self, name, trait_spec, value):
23312337
return trait_spec.argstr + ' %d' % value
23322338

23332339
if name == 'acf':
2334-
if isinstance(value, tuple):
2340+
if isinstance(value, bool):
2341+
if value:
2342+
return trait_spec.argstr
2343+
else:
2344+
self._acf = False
2345+
return None
2346+
elif isinstance(value, tuple):
23352347
return trait_spec.argstr + ' %s %f' % value
23362348
elif isinstance(value, string_types):
23372349
return trait_spec.argstr + ' ' + value
23382350
return super(FWHMx, self)._format_arg(name, trait_spec, value)
23392351

2340-
def _run_interface(self, runtime):
2341-
if platform == 'darwin':
2342-
# http://afni.nimh.nih.gov/afni/community/board/read.php?1,145346,145347#msg-145347
2343-
runtime.environ['DYLD_FALLBACK_LIBRARY_PATH'] = '/usr/local/afni/'
2344-
2345-
return super(FWHMx, self)._run_interface(runtime)
2346-
2347-
23482352
def _list_outputs(self):
23492353
outputs = super(FWHMx, self)._list_outputs()
23502354

@@ -2357,5 +2361,14 @@ def _list_outputs(self):
23572361
else:
23582362
outputs['out_detrend'] = Undefined
23592363

2360-
outputs['fwhm'] = tuple(np.loadtxt(outputs['out_file'])) #pylint: disable=E1101
2364+
sout = np.loadtxt(outputs['out_file']) #pylint: disable=E1101
2365+
if self._acf:
2366+
outputs['acf_param'] = tuple(sout[1])
2367+
sout = tuple(sout[0])
2368+
2369+
outputs['out_acf'] = op.abspath('3dFWHMx.1D')
2370+
if isinstance(self.inputs.acf, string_types):
2371+
outputs['out_acf'] = op.abspath(self.inputs.acf)
2372+
2373+
outputs['fwhm'] = tuple(sout)
23612374
return outputs

0 commit comments

Comments
 (0)