35
35
36
36
37
37
def 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
38
43
if isdefined (cls .inputs .subjects_dir ):
39
44
subjects_dir = cls .inputs .subjects_dir
40
45
else :
41
- subjects_dir = os .getcwd ()
46
+ subjects_dir = os .getcwd () #if not use cwd
47
+ # check for subject_id
42
48
if not subject_id :
43
49
if isdefined (cls .inputs .subject_id ):
44
50
subject_id = cls .inputs .subject_id
45
51
else :
46
- subject_id = 'subject_id'
52
+ subject_id = 'subject_id' #default
53
+ # check for basename
47
54
if basename == None :
48
55
basename = os .path .basename (in_file )
56
+ # check which folder to put the file in
49
57
if folder != None :
50
58
out_dir = os .path .join (subjects_dir , subject_id , folder )
51
59
else :
52
60
out_dir = os .path .join (subjects_dir , subject_id )
61
+ # make the output folder if it does not exist
53
62
if not os .path .isdir (out_dir ):
54
63
os .makedirs (out_dir )
55
64
out_file = os .path .join (out_dir , basename )
@@ -58,7 +67,7 @@ def copy2subjdir(cls, in_file, folder=None, basename=None, subject_id=None):
58
67
return out_file
59
68
60
69
def 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"""
62
71
for output in outputs .itervalues ():
63
72
dirname = os .path .dirname (output )
64
73
if not os .path .isdir (dirname ):
@@ -1867,6 +1876,7 @@ class MakeSurfacesInputSpec(FSTraitedSpec):
1867
1876
in_filled = File (exists = True , mandatory = True ,
1868
1877
desc = "Implicit input file filled.mgz" )
1869
1878
# optional
1879
+ in_white = File (exists = True , desc = "Implicit input that is sometimes used" )
1870
1880
in_label = File (exists = True , mandatory = False , xor = ['noaparc' ],
1871
1881
desc = "Implicit input label/<hemisphere>.aparc.annot" )
1872
1882
orig_white = File (argstr = "-orig_white %s" , exists = True , mandatory = False ,
@@ -1893,6 +1903,8 @@ class MakeSurfacesInputSpec(FSTraitedSpec):
1893
1903
argstr = "-max %.1f" , desc = "No documentation (used for longitudinal processing)" )
1894
1904
longitudinal = traits .Bool (
1895
1905
argstr = "-long" , desc = "No documentation (used for longitudinal processing)" )
1906
+ white = traits .String (argstr = "-white %s" ,
1907
+ desc = "White surface name" )
1896
1908
copy_inputs = traits .Bool (mandatory = False ,
1897
1909
desc = "If running as a node, set this to True." +
1898
1910
"This will copy the input files to the node " +
@@ -1947,15 +1959,15 @@ def run(self, **inputs):
1947
1959
folder = 'mri' , basename = 'wm.mgz' )
1948
1960
copy2subjdir (self , self .inputs .in_filled ,
1949
1961
folder = 'mri' , basename = 'filled.mgz' )
1962
+ copy2subjdir (self , self .inputs .in_white ,
1963
+ 'surf' , '{0}.white' .format (self .inputs .hemisphere ))
1950
1964
for originalfile in [self .inputs .in_aseg ,
1951
1965
self .inputs .in_T1 ]:
1952
- if isdefined (originalfile ):
1953
- copy2subjdir (self , originalfile , folder = 'mri' )
1966
+ copy2subjdir (self , originalfile , folder = 'mri' )
1954
1967
for originalfile in [self .inputs .orig_white ,
1955
1968
self .inputs .orig_pial ,
1956
1969
self .inputs .in_orig ]:
1957
- if isdefined (originalfile ):
1958
- copy2subjdir (self , originalfile , folder = 'surf' )
1970
+ copy2subjdir (self , originalfile , folder = 'surf' )
1959
1971
if isdefined (self .inputs .in_label ):
1960
1972
copy2subjdir (self , self .inputs .in_label , 'label' ,
1961
1973
'{0}.aparc.annot' .format (self .inputs .hemisphere ))
@@ -1972,9 +1984,11 @@ def _format_arg(self, name, spec, value):
1972
1984
basename = os .path .basename (value )
1973
1985
# whent the -mgz flag is specified, it assumes the mgz extension
1974
1986
if self .inputs .mgz :
1975
- prefix = basename . rstrip ( '.mgz' )
1987
+ prefix = os . path . splitext ( basename )[ 0 ]
1976
1988
else :
1977
1989
prefix = basename
1990
+ if prefix == 'aseg' :
1991
+ return # aseg is already the default
1978
1992
return spec .argstr % prefix
1979
1993
elif name in ['orig_white' , 'orig_pial' ]:
1980
1994
# these inputs do take full file paths or even basenames
@@ -2011,8 +2025,8 @@ def _list_outputs(self):
2011
2025
dest_dir , str (self .inputs .hemisphere ) + '.area' )
2012
2026
# Something determines when a pial surface and thickness file is generated
2013
2027
# 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' :
2016
2030
outputs ["out_curv" ] = outputs ["out_curv" ] + ".pial"
2017
2031
outputs ["out_area" ] = outputs ["out_area" ] + ".pial"
2018
2032
outputs ["out_pial" ] = os .path .join (
@@ -2029,7 +2043,7 @@ def _list_outputs(self):
2029
2043
2030
2044
class CurvatureInputSpec (FSTraitedSpec ):
2031
2045
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" )
2033
2047
# optional
2034
2048
threshold = traits .Float (
2035
2049
argstr = "-thresh %.3f" , mandatory = False , desc = "Undocumented input threshold" )
@@ -2073,7 +2087,6 @@ def _format_arg(self, name, spec, value):
2073
2087
if self .inputs .copy_input :
2074
2088
if name == 'in_file' :
2075
2089
basename = os .path .basename (value )
2076
- shutil .copy (value , basename )
2077
2090
return spec .argstr % basename
2078
2091
return super (Curvature , self )._format_arg (name , spec , value )
2079
2092
@@ -2301,11 +2314,16 @@ class VolumeMaskInputSpec(FSTraitedSpec):
2301
2314
desc = "Implicit input left white matter surface" )
2302
2315
rh_white = File (mandatory = True , exists = True ,
2303
2316
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." )
2304
2321
subject_id = traits .String ('subject_id' , usedefault = True ,
2305
2322
position = - 1 , argstr = "%s" , mandatory = True ,
2306
2323
desc = "Subject being processed" )
2307
2324
# 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' ],
2309
2327
desc = "Input aseg file for VolumeMask" )
2310
2328
save_ribbon = traits .Bool (argstr = "--save_ribbon" , mandatory = False ,
2311
2329
desc = "option to save just the ribbon for the " +
@@ -2364,6 +2382,8 @@ def run(self, **inputs):
2364
2382
copy2subjdir (self , self .inputs .lh_white , 'surf' , 'lh.white' )
2365
2383
copy2subjdir (self , self .inputs .rh_white , 'surf' , 'rh.white' )
2366
2384
copy2subjdir (self , self .inputs .in_aseg , 'mri' )
2385
+ copy2subjdir (self , self .inputs .aseg , 'mri' , 'aseg.mgz' )
2386
+
2367
2387
return super (VolumeMask , self ).run (** inputs )
2368
2388
2369
2389
def _format_arg (self , name , spec , value ):
@@ -2726,6 +2746,8 @@ class Aparc2AsegInputSpec(FSTraitedSpec):
2726
2746
rh_annotation = File (mandatory = True , exists = True ,
2727
2747
desc = "Input file must be <subject_id>/label/rh.aparc.annot" )
2728
2748
# optional
2749
+ filled = File (exists = True ,
2750
+ desc = "Implicit input filled file. Only required with FS v5.3." )
2729
2751
aseg = File (argstr = "--aseg %s" , mandatory = False , exists = True ,
2730
2752
desc = "Input aseg file" )
2731
2753
volmask = traits .Bool (argstr = "--volmask" , mandatory = False ,
@@ -2808,6 +2830,7 @@ def run(self, **inputs):
2808
2830
copy2subjdir (self , self .inputs .rh_ribbon , 'mri' , 'rh.ribbon.mgz' )
2809
2831
copy2subjdir (self , self .inputs .ribbon , 'mri' , 'ribbon.mgz' )
2810
2832
copy2subjdir (self , self .inputs .aseg , 'mri' )
2833
+ copy2subjdir (self , self .inputs .filled , 'mri' , 'filled.mgz' )
2811
2834
copy2subjdir (self , self .inputs .lh_annotation , 'label' )
2812
2835
copy2subjdir (self , self .inputs .rh_annotation , 'label' )
2813
2836
@@ -2816,7 +2839,8 @@ def run(self, **inputs):
2816
2839
def _format_arg (self , name , spec , value ):
2817
2840
if name == 'aseg' :
2818
2841
# 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
2820
2844
elif name == 'out_file' :
2821
2845
return spec .argstr % os .path .abspath (value )
2822
2846
0 commit comments