@@ -2912,33 +2912,37 @@ class MRIsExpandInputSpec(FSTraitedSpec):
2912
2912
# Input spec derived from
2913
2913
# https://github.com/freesurfer/freesurfer/blob/102e053/mris_expand/mris_expand.c
2914
2914
in_file = File (
2915
- exists = True , mandatory = True , argstr = '%s' , position = - 3 ,
2915
+ exists = True , mandatory = True , argstr = '%s' , position = - 3 , copyfile = False ,
2916
2916
desc = 'Surface to expand' )
2917
2917
distance = traits .Float (
2918
2918
mandatory = True , argstr = '%g' , position = - 2 ,
2919
2919
desc = 'Distance in mm or fraction of cortical thickness' )
2920
2920
out_name = traits .Str (
2921
2921
'expanded' , argstr = '%s' , position = - 1 , usedefault = True ,
2922
2922
desc = ('Output surface file\n '
2923
- 'If missing "lh." or "rh.", derive from `in_file`' ))
2923
+ 'If no path, uses directory of `in_file`\n '
2924
+ 'If no path AND missing "lh." or "rh.", derive from `in_file`' ))
2924
2925
thickness = traits .Bool (
2925
2926
argstr = '-thickness' ,
2926
2927
desc = 'Expand by fraction of cortical thickness, not mm' )
2927
2928
thickness_name = traits .Str (
2928
- argstr = "-thickness_name %s" ,
2929
+ argstr = "-thickness_name %s" , copyfile = False ,
2929
2930
desc = ('Name of thickness file (implicit: "thickness")\n '
2930
2931
'If no path, uses directory of `in_file`\n '
2931
- 'If missing "lh." or "rh.", derive from `in_file`' ))
2932
+ 'If no path AND missing "lh." or "rh.", derive from `in_file`' ))
2932
2933
navgs = traits .Tuple (
2933
2934
traits .Int , traits .Int ,
2934
2935
argstr = '-navgs %d %d' ,
2935
2936
desc = ('Tuple of (n_averages, min_averages) parameters '
2936
2937
'(implicit: (16, 0))' ))
2937
2938
pial = traits .Str (
2938
- argstr = '-pial %s' ,
2939
+ argstr = '-pial %s' , copyfile = False ,
2939
2940
desc = ('Name of pial file (implicit: "pial")\n '
2940
2941
'If no path, uses directory of `in_file`\n '
2941
- 'If missing "lh." or "rh.", derive from `in_file`' ))
2942
+ 'If no path AND missing "lh." or "rh.", derive from `in_file`' ))
2943
+ sphere = traits .Str (
2944
+ 'sphere' , copyfile = False , usedefault = True ,
2945
+ desc = 'WARNING: Do not change this trait' )
2942
2946
spring = traits .Float (argstr = '-S %g' , desc = "Spring term (implicit: 0.05)" )
2943
2947
dt = traits .Float (argstr = '-T %g' , desc = 'dt (implicit: 0.25)' )
2944
2948
write_iterations = traits .Int (
@@ -2972,30 +2976,52 @@ class MRIsExpand(FSCommand):
2972
2976
>>> from nipype.interfaces.freesurfer import MRIsExpand
2973
2977
>>> mris_expand = MRIsExpand(thickness=True, distance=0.5)
2974
2978
>>> mris_expand.inputs.in_file = 'lh.white'
2975
- >>> mris_expand.cmdline # doctest: +ALLOW_UNICODE, +ELLIPSIS
2976
- 'mris_expand -thickness lh.white 0.5 .../lh. expanded'
2979
+ >>> mris_expand.cmdline # doctest: +ALLOW_UNICODE
2980
+ 'mris_expand -thickness lh.white 0.5 expanded'
2977
2981
>>> mris_expand.inputs.out_name = 'graymid'
2978
- >>> mris_expand.cmdline # doctest: +ALLOW_UNICODE, +ELLIPSIS
2979
- 'mris_expand -thickness lh.white 0.5 .../lh. graymid'
2982
+ >>> mris_expand.cmdline # doctest: +ALLOW_UNICODE
2983
+ 'mris_expand -thickness lh.white 0.5 graymid'
2980
2984
"""
2981
2985
_cmd = 'mris_expand'
2982
2986
input_spec = MRIsExpandInputSpec
2983
2987
output_spec = MRIsExpandOutputSpec
2984
2988
2985
- def _format_arg (self , name , spec , value ):
2986
- if name == 'out_name' :
2987
- value = self ._list_outputs ()['out_file' ]
2988
- return super (MRIsExpand , self )._format_arg (name , spec , value )
2989
-
2990
2989
def _list_outputs (self ):
2991
2990
outputs = self ._outputs ().get ()
2992
- # Mimic FreeSurfer output filename derivation, but in local directory
2993
- # if no path specified
2994
- out_file = self .inputs .out_name
2995
- path , base = os .path .split (out_file )
2996
- if path == '' and base [:3 ] not in ('lh.' , 'rh.' ):
2997
- in_file = os .path .basename (self .inputs .in_file )
2998
- if in_file [:3 ] in ('lh.' , 'rh.' ):
2999
- out_file = os .path .basename (self .inputs .in_file )[:3 ] + base
3000
- outputs ["out_file" ] = os .path .abspath (out_file )
2991
+ outputs ['out_file' ] = self ._associated_file (self .inputs .in_file ,
2992
+ self .inputs .out_name )
3001
2993
return outputs
2994
+
2995
+ def _get_filecopy_info (self ):
2996
+ in_file = self .inputs .in_file
2997
+
2998
+ pial = self .inputs .pial
2999
+ if not isdefined (pial ):
3000
+ pial = 'pial'
3001
+ self .inputs .pial = self ._associated_file (in_file , pial )
3002
+
3003
+ if isdefined (self .inputs .thickness ) and self .inputs .thickness :
3004
+ thickness_name = self .inputs .thickness_name
3005
+ if not isdefined (thickness_name ):
3006
+ thickness_name = 'thickness'
3007
+ self .inputs .thickness_name = self ._associated_file (in_file ,
3008
+ thickness_name )
3009
+
3010
+ self .inputs .sphere = self ._associated_file (in_file , self .inputs .sphere )
3011
+
3012
+ return super (MRIsExpand , self )._get_filecopy_info ()
3013
+
3014
+ @staticmethod
3015
+ def _associated_file (in_file , out_name ):
3016
+ """Based on MRIsBuildFileName in freesurfer/utils/mrisurf.c
3017
+
3018
+ Use file prefix to indicate hemisphere, rather than inspecting the
3019
+ surface data structure
3020
+ """
3021
+ path , base = os .path .split (out_name )
3022
+ if path == '' :
3023
+ path , in_file = os .path .split (in_file )
3024
+ hemis = ('lh.' , 'rh.' )
3025
+ if in_file [:3 ] in hemis and base [:3 ] not in hemis :
3026
+ base = in_file [:3 ] + base
3027
+ return os .path .join (path , base )
0 commit comments