Skip to content

Commit a28c7a2

Browse files
committed
[FIX] Define ANTSPATH for ants.BrainExtraction automatically
When it is not already defined. Also check if the interface failed for that reason nonetheless. Fixes #1901
1 parent d82a18f commit a28c7a2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

nipype/interfaces/ants/segmentation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,33 @@ class BrainExtraction(ANTSCommand):
692692
output_spec = BrainExtractionOutputSpec
693693
_cmd = 'antsBrainExtraction.sh'
694694

695+
def _run_interface(self, runtime, correct_return_codes=(0,)):
696+
out_environ = self._get_environ()
697+
if out_environ.get('ANTSPATH') is None:
698+
runtime.environ.update(out_environ)
699+
executable_name = self.cmd.split()[0]
700+
exist_val, cmd_path = _exists_in_path(executable_name,
701+
runtime.environ)
702+
if not exist_val:
703+
raise IOError("command '%s' could not be found on host %s" %
704+
(self.cmd.split()[0], runtime.hostname))
705+
706+
runtime.environ.update({'ANTSPATH': cmd_path})
707+
708+
runtime = super(BrainExtraction, self)._run_interface(runtime)
709+
710+
if 'we cant find the N4 program' in runtime.stdout:
711+
errmsg = ('antsBrainExtraction.sh requires the environment variable '
712+
'ANTSPATH to be defined')
713+
if runtime.stderr is None:
714+
runtime.stderr = errmsg
715+
else:
716+
runtime.stderr += '\n' + errmsg
717+
runtime.returncode = 1
718+
self.raise_exception(runtime)
719+
720+
return runtime
721+
695722
def _list_outputs(self):
696723
outputs = self._outputs().get()
697724
outputs['BrainExtractionMask'] = os.path.join(os.getcwd(),

0 commit comments

Comments
 (0)