From dd55523eec74cbbf22af5740abf5841f47165903 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Sat, 23 Jan 2016 09:18:46 -0800 Subject: [PATCH 1/7] added version checking in afni.SkullStrip to avoid use of virtual display with AFNI >= 16 --- nipype/interfaces/afni/base.py | 17 +++++++++++++++-- nipype/interfaces/afni/preprocess.py | 9 +++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index da77dc7728..cfa6b53972 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -37,10 +37,23 @@ def version(): Version number as string or None if AFNI not found """ + import re clout = CommandLine(command='afni_vcheck', terminal_output='allatonce').run() - out = clout.runtime.stdout - return out.split('\n')[1] + out = clout.runtime.stdout.split('\n')[1] + + # Try to parse the version number + m = re.search(r'[\.\d]*$', out) + # is the format kept through versions before 16.x? + if m is None or not m.group(0): + return out + + v = m.group(0).split('.') + try: + v = [int(n) for n in v] + except ValueError: + return out + return tuple(v) @classmethod def outputtype_to_ext(cls, outputtype): diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 96bbaaccae..163785c0a4 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -1235,6 +1235,15 @@ class SkullStrip(AFNICommand): input_spec = SkullStripInputSpec output_spec = AFNICommandOutputSpec + def __init__(self, **inputs): + from .base import Info + super(SkullStrip, self).__init__(**inputs) + 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( From b400aa94cf66a340e923ba24ce14da86dacc9d79 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Sat, 23 Jan 2016 09:46:14 -0800 Subject: [PATCH 2/7] added a travis command to let tests pass --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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 From 47d05b2bc7dbd491aae6048b8322007f0fab03cd Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Sat, 23 Jan 2016 10:34:26 -0800 Subject: [PATCH 3/7] fixed tests without AFNI installation --- nipype/interfaces/afni/base.py | 16 ++++++++++++++-- nipype/interfaces/afni/preprocess.py | 14 +++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index cfa6b53972..33f03a6429 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -38,8 +38,13 @@ def version(): """ import re - clout = CommandLine(command='afni_vcheck', - terminal_output='allatonce').run() + try: + clout = CommandLine(command='afni_vcheck', + terminal_output='allatonce').run() + except IOError: + # If afni_vcheck is not present, return None + return None + out = clout.runtime.stdout.split('\n')[1] # Try to parse the version number @@ -173,3 +178,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 163785c0a4..c65dc4f6c4 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -1236,13 +1236,17 @@ class SkullStrip(AFNICommand): output_spec = AFNICommandOutputSpec def __init__(self, **inputs): - from .base import Info + from .base import Info, no_afni super(SkullStrip, self).__init__(**inputs) - 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 + 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 + else: + raise RuntimeWarning('afni_vcheck executable not found.') class TCatInputSpec(AFNICommandInputSpec): From 31f5ecde914c45d1dc413edf9751680b42c7ed6a Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Sat, 23 Jan 2016 10:43:21 -0800 Subject: [PATCH 4/7] replaced RuntimeWarning by nipype warning --- nipype/interfaces/afni/base.py | 1 + nipype/interfaces/afni/preprocess.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index 33f03a6429..4ccfd5e350 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -43,6 +43,7 @@ def version(): terminal_output='allatonce').run() except IOError: # If afni_vcheck is not present, return None + warn('afni_vcheck executable not found.') return None out = clout.runtime.stdout.split('\n')[1] diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index c65dc4f6c4..058a99a1af 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -1245,8 +1245,6 @@ def __init__(self, **inputs): # As of AFNI 16.0.00, redirect_x is not needed if isinstance(v[0], int) and v[0] > 15: self._redirect_x = False - else: - raise RuntimeWarning('afni_vcheck executable not found.') class TCatInputSpec(AFNICommandInputSpec): From 3777370a0bbba3a64cce2fac693670ba7ccd4673 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Sat, 23 Jan 2016 10:49:31 -0800 Subject: [PATCH 5/7] improved msg when AFNI is outdated --- nipype/interfaces/afni/base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index 4ccfd5e350..4e3c0256b8 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -41,12 +41,15 @@ def version(): try: clout = CommandLine(command='afni_vcheck', terminal_output='allatonce').run() + out = clout.runtime.stdout.split('\n')[1] except IOError: # If afni_vcheck is not present, return None warn('afni_vcheck executable not found.') return None - - out = clout.runtime.stdout.split('\n')[1] + except RuntimeError: + # If AFNI is outdated, afni_vcheck throws error + warn('AFNI is outdated') + out = clout.runtime.stderr.split('\n')[1] # Try to parse the version number m = re.search(r'[\.\d]*$', out) From 22a9477df48383d93f4b1b9a9ed01a6294ee3a8e Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Sat, 23 Jan 2016 11:19:06 -0800 Subject: [PATCH 6/7] fixed behavior with outdated versions of afni --- nipype/interfaces/afni/base.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index 4e3c0256b8..064f2958fc 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -41,23 +41,22 @@ def version(): try: clout = CommandLine(command='afni_vcheck', terminal_output='allatonce').run() - out = clout.runtime.stdout.split('\n')[1] except IOError: # If afni_vcheck is not present, return None warn('afni_vcheck executable not found.') return None - except RuntimeError: + except RuntimeError as e: # If AFNI is outdated, afni_vcheck throws error warn('AFNI is outdated') - out = clout.runtime.stderr.split('\n')[1] + return str(e).split('\n')[4].split('=', 1)[1].strip() # Try to parse the version number - m = re.search(r'[\.\d]*$', out) - # is the format kept through versions before 16.x? - if m is None or not m.group(0): - return out + out = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip() + + if out.startswith('AFNI_'): + out = out[5:] - v = m.group(0).split('.') + v = out.split('.') try: v = [int(n) for n in v] except ValueError: From 43e8c20f0b6a9e540eadf4fbf8d06d31d4bf0aef Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Mon, 25 Jan 2016 09:50:17 -0800 Subject: [PATCH 7/7] removed unnecessary import --- nipype/interfaces/afni/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index 064f2958fc..22870d5d19 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -37,7 +37,6 @@ def version(): Version number as string or None if AFNI not found """ - import re try: clout = CommandLine(command='afni_vcheck', terminal_output='allatonce').run()