-
Notifications
You must be signed in to change notification settings - Fork 532
[FIX] Define ANTSPATH for ants.BrainExtraction automatically #1986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ | |
import os | ||
from ...external.due import BibTeX | ||
from ...utils.filemanip import split_filename, copyfile | ||
from ..base import TraitedSpec, File, traits, InputMultiPath, OutputMultiPath, isdefined | ||
from ..base import (TraitedSpec, File, traits, InputMultiPath, OutputMultiPath, isdefined, | ||
_exists_in_path) | ||
from .base import ANTSCommand, ANTSCommandInputSpec | ||
|
||
|
||
|
@@ -692,6 +693,35 @@ class BrainExtraction(ANTSCommand): | |
output_spec = BrainExtractionOutputSpec | ||
_cmd = 'antsBrainExtraction.sh' | ||
|
||
def _run_interface(self, runtime, correct_return_codes=(0,)): | ||
# antsBrainExtraction.sh requires ANTSPATH to be defined | ||
out_environ = self._get_environ() | ||
if out_environ.get('ANTSPATH') is None: | ||
runtime.environ.update(out_environ) | ||
executable_name = self.cmd.split()[0] | ||
exist_val, cmd_path = _exists_in_path(executable_name, runtime.environ) | ||
if not exist_val: | ||
raise IOError("command '%s' could not be found on host %s" % | ||
(self.cmd.split()[0], runtime.hostname)) | ||
|
||
# Set the environment variable if found | ||
runtime.environ.update({'ANTSPATH': os.path.dirname(cmd_path)}) | ||
|
||
runtime = super(BrainExtraction, self)._run_interface(runtime) | ||
|
||
# Still, double-check if it didn't found N4 | ||
if 'we cant find the N4 program' in runtime.stdout: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the script can be in a different location than the N4 executable, can we not do this check before running in this particular case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I'm lost here. Which check would you remove? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i meant to put the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Judging from this: https://github.com/stnava/ANTs/blob/646459bf297a50cdf608ea7d39cb79b44906ad22/Scripts/antsBrainExtraction.sh#L5-L20, I think we just parse the output for "we cant find" and raise the message for the missing tool. For next release we can decouple or, as @blakedewey suggested, replicate antsBrainExtraction in pure nipype. |
||
errmsg = ('antsBrainExtraction.sh requires the environment variable ' | ||
'ANTSPATH to be defined') | ||
if runtime.stderr is None: | ||
runtime.stderr = errmsg | ||
else: | ||
runtime.stderr += '\n' + errmsg | ||
runtime.returncode = 1 | ||
self.raise_exception(runtime) | ||
|
||
return runtime | ||
|
||
def _list_outputs(self): | ||
outputs = self._outputs().get() | ||
outputs['BrainExtractionMask'] = os.path.join(os.getcwd(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe
ANTSPATH
requires a trailing/
. could you confirm this and make sure we adjust for it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the scripts don't need the trailing
/
. Particularly, theantsBrainExtraction.sh
doesn't need it.But I can add it anyways if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then not necessary.