@@ -720,17 +720,19 @@ class BrainExtraction(ANTSCommand):
720
720
def _run_interface (self , runtime , correct_return_codes = (0 ,)):
721
721
# antsBrainExtraction.sh requires ANTSPATH to be defined
722
722
out_environ = self ._get_environ ()
723
- if out_environ .get ('ANTSPATH' ) is None :
724
- runtime .environ .update (out_environ )
725
- executable_name = self .cmd .split ()[0 ]
726
- exist_val , cmd_path = _exists_in_path (executable_name , runtime .environ )
727
- if not exist_val :
728
- raise IOError ("command '%s' could not be found on host %s" %
729
- (self .cmd .split ()[0 ], runtime .hostname ))
730
-
731
- # Set the environment variable if found
732
- runtime .environ .update ({'ANTSPATH' : os .path .dirname (cmd_path )})
733
-
723
+ ants_path = out_environ .get ('ANTSPATH' , None ) or os .getenv ('ANTSPATH' , None )
724
+ if ants_path is None :
725
+ # Check for antsRegistration, which is under bin/ (the $ANTSPATH) instead of
726
+ # checking for antsBrainExtraction.sh which is under script/
727
+ _ , cmd_path = _exists_in_path ('antsRegistration' , runtime .environ )
728
+ if not cmd_path :
729
+ raise RuntimeError (
730
+ 'The environment variable $ANTSPATH is not defined in host "%s", '
731
+ 'and Nipype could not determine it automatically.' % runtime .hostname )
732
+ ants_path = os .path .dirname (cmd_path )
733
+
734
+ self .inputs .environ .update ({'ANTSPATH' : ants_path })
735
+ runtime .environ .update ({'ANTSPATH' : ants_path })
734
736
runtime = super (BrainExtraction , self )._run_interface (runtime )
735
737
736
738
# Still, double-check if it didn't found N4
@@ -740,8 +742,8 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
740
742
tool = line .strip ().replace ('we cant find the' , '' ).split (' ' )[0 ]
741
743
break
742
744
743
- errmsg = ('antsBrainExtraction.sh requires %s the environment variable '
744
- 'ANTSPATH to be defined' % tool )
745
+ errmsg = ('antsBrainExtraction.sh requires "%s" to be found in $ANTSPATH '
746
+ '($ ANTSPATH="%s").' ) % ( tool , ants_path )
745
747
if runtime .stderr is None :
746
748
runtime .stderr = errmsg
747
749
else :
0 commit comments