Skip to content

Commit 2f7ac22

Browse files
committed
Merge pull request #1328 from oesteban/fix/AfniVirtualDisplay
[ENH] Check AFNI version in SkullStrip to avoid xvfb
2 parents a9e2b51 + 43e8c20 commit 2f7ac22

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ before_install:
2323
- if $INSTALL_DEB_DEPENDECIES; then travis_retry sudo apt-get install -qq fsl-atlases;
2424
fi
2525
- if $INSTALL_DEB_DEPENDECIES; then source /etc/fsl/fsl.sh; fi
26+
- if $INSTALL_DEB_DEPENDECIES; then source /etc/afni/afni.sh; fi
2627
install:
2728
- conda update --yes conda
2829
- conda create -n testenv --yes pip python=$TRAVIS_PYTHON_VERSION

nipype/interfaces/afni/base.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,30 @@ def version():
3737
Version number as string or None if AFNI not found
3838
3939
"""
40-
clout = CommandLine(command='afni_vcheck',
41-
terminal_output='allatonce').run()
42-
out = clout.runtime.stdout
43-
return out.split('\n')[1]
40+
try:
41+
clout = CommandLine(command='afni_vcheck',
42+
terminal_output='allatonce').run()
43+
except IOError:
44+
# If afni_vcheck is not present, return None
45+
warn('afni_vcheck executable not found.')
46+
return None
47+
except RuntimeError as e:
48+
# If AFNI is outdated, afni_vcheck throws error
49+
warn('AFNI is outdated')
50+
return str(e).split('\n')[4].split('=', 1)[1].strip()
51+
52+
# Try to parse the version number
53+
out = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip()
54+
55+
if out.startswith('AFNI_'):
56+
out = out[5:]
57+
58+
v = out.split('.')
59+
try:
60+
v = [int(n) for n in v]
61+
except ValueError:
62+
return out
63+
return tuple(v)
4464

4565
@classmethod
4666
def outputtype_to_ext(cls, outputtype):
@@ -160,3 +180,10 @@ def _list_outputs(self):
160180
if ext == "":
161181
outputs[name] = outputs[name] + "+orig.BRIK"
162182
return outputs
183+
184+
185+
def no_afni():
186+
""" Checks if AFNI is available """
187+
if Info.version() is None:
188+
return True
189+
return False

nipype/interfaces/afni/preprocess.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,17 @@ class SkullStrip(AFNICommand):
12351235
input_spec = SkullStripInputSpec
12361236
output_spec = AFNICommandOutputSpec
12371237

1238+
def __init__(self, **inputs):
1239+
from .base import Info, no_afni
1240+
super(SkullStrip, self).__init__(**inputs)
1241+
1242+
if not no_afni():
1243+
v = Info.version()
1244+
1245+
# As of AFNI 16.0.00, redirect_x is not needed
1246+
if isinstance(v[0], int) and v[0] > 15:
1247+
self._redirect_x = False
1248+
12381249

12391250
class TCatInputSpec(AFNICommandInputSpec):
12401251
in_files = InputMultiPath(

0 commit comments

Comments
 (0)