Skip to content

Commit 76cbf0f

Browse files
committed
automatically set ANTSPATH when possible
1 parent a28c7a2 commit 76cbf0f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

nipype/interfaces/ants/segmentation.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import os
1515
from ...external.due import BibTeX
1616
from ...utils.filemanip import split_filename, copyfile
17-
from ..base import TraitedSpec, File, traits, InputMultiPath, OutputMultiPath, isdefined
17+
from ..base import (TraitedSpec, File, traits, InputMultiPath, OutputMultiPath, isdefined,
18+
_exists_in_path)
1819
from .base import ANTSCommand, ANTSCommandInputSpec
1920

2021

@@ -693,20 +694,22 @@ class BrainExtraction(ANTSCommand):
693694
_cmd = 'antsBrainExtraction.sh'
694695

695696
def _run_interface(self, runtime, correct_return_codes=(0,)):
697+
# antsBrainExtraction.sh requires ANTSPATH to be defined
696698
out_environ = self._get_environ()
697699
if out_environ.get('ANTSPATH') is None:
698700
runtime.environ.update(out_environ)
699701
executable_name = self.cmd.split()[0]
700-
exist_val, cmd_path = _exists_in_path(executable_name,
701-
runtime.environ)
702+
exist_val, cmd_path = _exists_in_path(executable_name, runtime.environ)
702703
if not exist_val:
703704
raise IOError("command '%s' could not be found on host %s" %
704705
(self.cmd.split()[0], runtime.hostname))
705706

706-
runtime.environ.update({'ANTSPATH': cmd_path})
707+
# Set the environment variable if found
708+
runtime.environ.update({'ANTSPATH': os.path.dirname(cmd_path)})
707709

708710
runtime = super(BrainExtraction, self)._run_interface(runtime)
709711

712+
# Still, double-check if it didn't found N4
710713
if 'we cant find the N4 program' in runtime.stdout:
711714
errmsg = ('antsBrainExtraction.sh requires the environment variable '
712715
'ANTSPATH to be defined')

0 commit comments

Comments
 (0)