|
14 | 14 | import os
|
15 | 15 | from ...external.due import BibTeX
|
16 | 16 | 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) |
18 | 19 | from .base import ANTSCommand, ANTSCommandInputSpec
|
19 | 20 |
|
20 | 21 |
|
@@ -692,6 +693,40 @@ class BrainExtraction(ANTSCommand):
|
692 | 693 | output_spec = BrainExtractionOutputSpec
|
693 | 694 | _cmd = 'antsBrainExtraction.sh'
|
694 | 695 |
|
| 696 | + def _run_interface(self, runtime, correct_return_codes=(0,)): |
| 697 | + # antsBrainExtraction.sh requires ANTSPATH to be defined |
| 698 | + out_environ = self._get_environ() |
| 699 | + if out_environ.get('ANTSPATH') is None: |
| 700 | + runtime.environ.update(out_environ) |
| 701 | + executable_name = self.cmd.split()[0] |
| 702 | + exist_val, cmd_path = _exists_in_path(executable_name, runtime.environ) |
| 703 | + if not exist_val: |
| 704 | + raise IOError("command '%s' could not be found on host %s" % |
| 705 | + (self.cmd.split()[0], runtime.hostname)) |
| 706 | + |
| 707 | + # Set the environment variable if found |
| 708 | + runtime.environ.update({'ANTSPATH': os.path.dirname(cmd_path)}) |
| 709 | + |
| 710 | + runtime = super(BrainExtraction, self)._run_interface(runtime) |
| 711 | + |
| 712 | + # Still, double-check if it didn't found N4 |
| 713 | + if 'we cant find' in runtime.stdout: |
| 714 | + for line in runtime.stdout.split('\n'): |
| 715 | + if line.strip().startswith('we cant find'): |
| 716 | + tool = line.strip().replace('we cant find the', '').split(' ')[0] |
| 717 | + break |
| 718 | + |
| 719 | + errmsg = ('antsBrainExtraction.sh requires %s the environment variable ' |
| 720 | + 'ANTSPATH to be defined' % tool) |
| 721 | + if runtime.stderr is None: |
| 722 | + runtime.stderr = errmsg |
| 723 | + else: |
| 724 | + runtime.stderr += '\n' + errmsg |
| 725 | + runtime.returncode = 1 |
| 726 | + self.raise_exception(runtime) |
| 727 | + |
| 728 | + return runtime |
| 729 | + |
695 | 730 | def _list_outputs(self):
|
696 | 731 | outputs = self._outputs().get()
|
697 | 732 | outputs['BrainExtractionMask'] = os.path.join(os.getcwd(),
|
|
0 commit comments