diff --git a/.travis.yml b/.travis.yml index fe9bf96a93..fe17fe3398 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ before_install: - if $INSTALL_DEB_DEPENDECIES; then travis_retry sudo apt-get install -qq fsl-atlases; fi - if $INSTALL_DEB_DEPENDECIES; then source /etc/fsl/fsl.sh; fi +- if $INSTALL_DEB_DEPENDECIES; then source /etc/afni/afni.sh; fi install: - conda update --yes conda - conda create -n testenv --yes pip python=$TRAVIS_PYTHON_VERSION diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index da77dc7728..22870d5d19 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -37,10 +37,30 @@ def version(): Version number as string or None if AFNI not found """ - clout = CommandLine(command='afni_vcheck', - terminal_output='allatonce').run() - out = clout.runtime.stdout - return out.split('\n')[1] + try: + clout = CommandLine(command='afni_vcheck', + terminal_output='allatonce').run() + except IOError: + # If afni_vcheck is not present, return None + warn('afni_vcheck executable not found.') + return None + except RuntimeError as e: + # If AFNI is outdated, afni_vcheck throws error + warn('AFNI is outdated') + return str(e).split('\n')[4].split('=', 1)[1].strip() + + # Try to parse the version number + out = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip() + + if out.startswith('AFNI_'): + out = out[5:] + + v = out.split('.') + try: + v = [int(n) for n in v] + except ValueError: + return out + return tuple(v) @classmethod def outputtype_to_ext(cls, outputtype): @@ -160,3 +180,10 @@ def _list_outputs(self): if ext == "": outputs[name] = outputs[name] + "+orig.BRIK" return outputs + + +def no_afni(): + """ Checks if AFNI is available """ + if Info.version() is None: + return True + return False diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 96bbaaccae..058a99a1af 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -1235,6 +1235,17 @@ class SkullStrip(AFNICommand): input_spec = SkullStripInputSpec output_spec = AFNICommandOutputSpec + def __init__(self, **inputs): + from .base import Info, no_afni + super(SkullStrip, self).__init__(**inputs) + + if not no_afni(): + v = Info.version() + + # As of AFNI 16.0.00, redirect_x is not needed + if isinstance(v[0], int) and v[0] > 15: + self._redirect_x = False + class TCatInputSpec(AFNICommandInputSpec): in_files = InputMultiPath(