3535
3636
3737def copy2subjdir (cls , in_file , folder = None , basename = None , subject_id = None ):
38+ """Method to copy an input to the subjects directory"""
39+ # check that the input is defined
40+ if not isdefined (in_file ):
41+ return in_file
42+ # check that subjects_dir is defined
3843 if isdefined (cls .inputs .subjects_dir ):
3944 subjects_dir = cls .inputs .subjects_dir
4045 else :
41- subjects_dir = os .getcwd ()
46+ subjects_dir = os .getcwd () #if not use cwd
47+ # check for subject_id
4248 if not subject_id :
4349 if isdefined (cls .inputs .subject_id ):
4450 subject_id = cls .inputs .subject_id
4551 else :
46- subject_id = 'subject_id'
52+ subject_id = 'subject_id' #default
53+ # check for basename
4754 if basename == None :
4855 basename = os .path .basename (in_file )
56+ # check which folder to put the file in
4957 if folder != None :
5058 out_dir = os .path .join (subjects_dir , subject_id , folder )
5159 else :
5260 out_dir = os .path .join (subjects_dir , subject_id )
61+ # make the output folder if it does not exist
5362 if not os .path .isdir (out_dir ):
5463 os .makedirs (out_dir )
5564 out_file = os .path .join (out_dir , basename )
@@ -58,7 +67,7 @@ def copy2subjdir(cls, in_file, folder=None, basename=None, subject_id=None):
5867 return out_file
5968
6069def createoutputdirs (outputs ):
61- """create an output directories. If not created, some freesurfer interfaces fail"""
70+ """create all output directories. If not created, some freesurfer interfaces fail"""
6271 for output in outputs .itervalues ():
6372 dirname = os .path .dirname (output )
6473 if not os .path .isdir (dirname ):
@@ -1867,6 +1876,7 @@ class MakeSurfacesInputSpec(FSTraitedSpec):
18671876 in_filled = File (exists = True , mandatory = True ,
18681877 desc = "Implicit input file filled.mgz" )
18691878 # optional
1879+ in_white = File (exists = True , desc = "Implicit input that is sometimes used" )
18701880 in_label = File (exists = True , mandatory = False , xor = ['noaparc' ],
18711881 desc = "Implicit input label/<hemisphere>.aparc.annot" )
18721882 orig_white = File (argstr = "-orig_white %s" , exists = True , mandatory = False ,
@@ -1893,6 +1903,8 @@ class MakeSurfacesInputSpec(FSTraitedSpec):
18931903 argstr = "-max %.1f" , desc = "No documentation (used for longitudinal processing)" )
18941904 longitudinal = traits .Bool (
18951905 argstr = "-long" , desc = "No documentation (used for longitudinal processing)" )
1906+ white = traits .String (argstr = "-white %s" ,
1907+ desc = "White surface name" )
18961908 copy_inputs = traits .Bool (mandatory = False ,
18971909 desc = "If running as a node, set this to True." +
18981910 "This will copy the input files to the node " +
@@ -1947,15 +1959,15 @@ def run(self, **inputs):
19471959 folder = 'mri' , basename = 'wm.mgz' )
19481960 copy2subjdir (self , self .inputs .in_filled ,
19491961 folder = 'mri' , basename = 'filled.mgz' )
1962+ copy2subjdir (self , self .inputs .in_white ,
1963+ 'surf' , '{0}.white' .format (self .inputs .hemisphere ))
19501964 for originalfile in [self .inputs .in_aseg ,
19511965 self .inputs .in_T1 ]:
1952- if isdefined (originalfile ):
1953- copy2subjdir (self , originalfile , folder = 'mri' )
1966+ copy2subjdir (self , originalfile , folder = 'mri' )
19541967 for originalfile in [self .inputs .orig_white ,
19551968 self .inputs .orig_pial ,
19561969 self .inputs .in_orig ]:
1957- if isdefined (originalfile ):
1958- copy2subjdir (self , originalfile , folder = 'surf' )
1970+ copy2subjdir (self , originalfile , folder = 'surf' )
19591971 if isdefined (self .inputs .in_label ):
19601972 copy2subjdir (self , self .inputs .in_label , 'label' ,
19611973 '{0}.aparc.annot' .format (self .inputs .hemisphere ))
@@ -1972,9 +1984,11 @@ def _format_arg(self, name, spec, value):
19721984 basename = os .path .basename (value )
19731985 # whent the -mgz flag is specified, it assumes the mgz extension
19741986 if self .inputs .mgz :
1975- prefix = basename . rstrip ( '.mgz' )
1987+ prefix = os . path . splitext ( basename )[ 0 ]
19761988 else :
19771989 prefix = basename
1990+ if prefix == 'aseg' :
1991+ return # aseg is already the default
19781992 return spec .argstr % prefix
19791993 elif name in ['orig_white' , 'orig_pial' ]:
19801994 # these inputs do take full file paths or even basenames
@@ -2011,8 +2025,8 @@ def _list_outputs(self):
20112025 dest_dir , str (self .inputs .hemisphere ) + '.area' )
20122026 # Something determines when a pial surface and thickness file is generated
20132027 # but documentation doesn't say what.
2014- # The orig_pial flag is just a guess
2015- if isdefined (self .inputs .orig_pial ):
2028+ # The orig_pial input is just a guess
2029+ if isdefined (self .inputs .orig_pial ) or self . inputs . white == 'NOWRITE' :
20162030 outputs ["out_curv" ] = outputs ["out_curv" ] + ".pial"
20172031 outputs ["out_area" ] = outputs ["out_area" ] + ".pial"
20182032 outputs ["out_pial" ] = os .path .join (
@@ -2029,7 +2043,7 @@ def _list_outputs(self):
20292043
20302044class CurvatureInputSpec (FSTraitedSpec ):
20312045 in_file = File (argstr = "%s" , position = - 2 , mandatory = True , exists = True ,
2032- desc = "Input file for Curvature" )
2046+ copyfile = True , desc = "Input file for Curvature" )
20332047 # optional
20342048 threshold = traits .Float (
20352049 argstr = "-thresh %.3f" , mandatory = False , desc = "Undocumented input threshold" )
@@ -2073,7 +2087,6 @@ def _format_arg(self, name, spec, value):
20732087 if self .inputs .copy_input :
20742088 if name == 'in_file' :
20752089 basename = os .path .basename (value )
2076- shutil .copy (value , basename )
20772090 return spec .argstr % basename
20782091 return super (Curvature , self )._format_arg (name , spec , value )
20792092
@@ -2301,11 +2314,16 @@ class VolumeMaskInputSpec(FSTraitedSpec):
23012314 desc = "Implicit input left white matter surface" )
23022315 rh_white = File (mandatory = True , exists = True ,
23032316 desc = "Implicit input right white matter surface" )
2317+ aseg = File (exists = True ,
2318+ xor = ['in_aseg' ],
2319+ desc = "Implicit aseg.mgz segmentation. " +
2320+ "Specify a different aseg by using the 'in_aseg' input." )
23042321 subject_id = traits .String ('subject_id' , usedefault = True ,
23052322 position = - 1 , argstr = "%s" , mandatory = True ,
23062323 desc = "Subject being processed" )
23072324 # optional
2308- in_aseg = File (argstr = "--aseg_name %s" , mandatory = False , exists = True ,
2325+ in_aseg = File (argstr = "--aseg_name %s" , mandatory = False ,
2326+ exists = True , xor = ['aseg' ],
23092327 desc = "Input aseg file for VolumeMask" )
23102328 save_ribbon = traits .Bool (argstr = "--save_ribbon" , mandatory = False ,
23112329 desc = "option to save just the ribbon for the " +
@@ -2364,6 +2382,8 @@ def run(self, **inputs):
23642382 copy2subjdir (self , self .inputs .lh_white , 'surf' , 'lh.white' )
23652383 copy2subjdir (self , self .inputs .rh_white , 'surf' , 'rh.white' )
23662384 copy2subjdir (self , self .inputs .in_aseg , 'mri' )
2385+ copy2subjdir (self , self .inputs .aseg , 'mri' , 'aseg.mgz' )
2386+
23672387 return super (VolumeMask , self ).run (** inputs )
23682388
23692389 def _format_arg (self , name , spec , value ):
@@ -2726,6 +2746,8 @@ class Aparc2AsegInputSpec(FSTraitedSpec):
27262746 rh_annotation = File (mandatory = True , exists = True ,
27272747 desc = "Input file must be <subject_id>/label/rh.aparc.annot" )
27282748 # optional
2749+ filled = File (exists = True ,
2750+ desc = "Implicit input filled file. Only required with FS v5.3." )
27292751 aseg = File (argstr = "--aseg %s" , mandatory = False , exists = True ,
27302752 desc = "Input aseg file" )
27312753 volmask = traits .Bool (argstr = "--volmask" , mandatory = False ,
@@ -2808,6 +2830,7 @@ def run(self, **inputs):
28082830 copy2subjdir (self , self .inputs .rh_ribbon , 'mri' , 'rh.ribbon.mgz' )
28092831 copy2subjdir (self , self .inputs .ribbon , 'mri' , 'ribbon.mgz' )
28102832 copy2subjdir (self , self .inputs .aseg , 'mri' )
2833+ copy2subjdir (self , self .inputs .filled , 'mri' , 'filled.mgz' )
28112834 copy2subjdir (self , self .inputs .lh_annotation , 'label' )
28122835 copy2subjdir (self , self .inputs .rh_annotation , 'label' )
28132836
@@ -2816,7 +2839,8 @@ def run(self, **inputs):
28162839 def _format_arg (self , name , spec , value ):
28172840 if name == 'aseg' :
28182841 # aseg does not take a full filename
2819- return spec .argstr % os .path .basename (value ).replace ('.mgz' , '' )
2842+ basename = os .path .basename (value ).replace ('.mgz' , '' )
2843+ return spec .argstr % basename
28202844 elif name == 'out_file' :
28212845 return spec .argstr % os .path .abspath (value )
28222846
0 commit comments