1414import os
1515import os .path as op
1616import warnings
17+ import glob
1718
1819import numpy as np
1920
@@ -1475,52 +1476,59 @@ def _gen_filename(self, name):
14751476
14761477
14771478class FIRSTInputSpec (FSLCommandInputSpec ):
1478- in_file = File (exists = True , mandatory = True , position = - 2 , copyfile = False ,
1479- argstr = '-i %s' ,
1480- desc = 'input data file' )
1481- out_file = File ('segmented' , usedefault = True , mandatory = True , position = - 1 ,
1482- argstr = '-o %s' ,
1483- desc = 'output data file' , hash_files = False )
1479+ in_file = File (
1480+ exists = True , mandatory = True , position = - 2 , copyfile = False ,
1481+ argstr = '-i %s' , desc = 'input data file' )
1482+ out_file = File (
1483+ 'segmented' , usedefault = True , mandatory = True , position = - 1 ,
1484+ argstr = '-o %s' , desc = 'output data file' , hash_files = False )
14841485 verbose = traits .Bool (argstr = '-v' , position = 1 ,
1485- desc = "Use verbose logging." )
1486- brain_extracted = traits .Bool (argstr = '-b' , position = 2 ,
1486+ desc = "Use verbose logging." )
1487+ brain_extracted = traits .Bool (
1488+ argstr = '-b' , position = 2 ,
14871489 desc = "Input structural image is already brain-extracted" )
1488- no_cleanup = traits .Bool (argstr = '-d' , position = 3 ,
1490+ no_cleanup = traits .Bool (
1491+ argstr = '-d' , position = 3 ,
14891492 desc = "Input structural image is already brain-extracted" )
1490- method = traits .Enum ('auto' , 'fast' , 'none' ,
1491- xor = ['method_as_numerical_threshold' ],
1492- argstr = '-m' , position = 4 ,
1493+ method = traits .Enum (
1494+ 'auto' , 'fast' , 'none' , xor = ['method_as_numerical_threshold' ],
1495+ argstr = '-m %s ' , position = 4 , usedefault = True ,
14931496 desc = ("Method must be one of auto, fast, none, or it can be entered "
14941497 "using the 'method_as_numerical_threshold' input" ))
1495- method_as_numerical_threshold = traits .Float (argstr = '-m' , position = 4 ,
1498+ method_as_numerical_threshold = traits .Float (
1499+ argstr = '-m %.4f' , position = 4 ,
14961500 desc = ("Specify a numerical threshold value or use the 'method' input "
14971501 "to choose auto, fast, or none" ))
1498- list_of_specific_structures = traits .List (traits . Str , argstr = '-s %s' ,
1499- sep = ',' , position = 5 , minlen = 1 ,
1502+ list_of_specific_structures = traits .List (
1503+ traits . Str , argstr = '-s %s' , sep = ',' , position = 5 , minlen = 1 ,
15001504 desc = 'Runs only on the specified structures (e.g. L_Hipp, R_Hipp'
1501- 'L_Accu, R_Accu, L_Amyg, R_Amyg'
1502- 'L_Caud, R_Caud, L_Pall, R_Pall'
1503- 'L_Puta, R_Puta, L_Thal, R_Thal, BrStem' )
1504- affine_file = File (exists = True , position = 6 ,
1505- argstr = '-a %s' ,
1506- desc = ('Affine matrix to use (e.g. img2std.mat) (does not '
1507- 're-run registration)' ))
1505+ 'L_Accu, R_Accu, L_Amyg, R_Amyg'
1506+ 'L_Caud, R_Caud, L_Pall, R_Pall'
1507+ 'L_Puta, R_Puta, L_Thal, R_Thal, BrStem' )
1508+ affine_file = File (
1509+ exists = True , position = 6 , argstr = '-a %s' ,
1510+ desc = ('Affine matrix to use (e.g. img2std.mat) (does not '
1511+ 're-run registration)' ))
15081512
15091513
15101514class FIRSTOutputSpec (TraitedSpec ):
1511- vtk_surfaces = OutputMultiPath (File (exists = True ),
1512- desc = 'VTK format meshes for each subcortical region' )
1513- bvars = OutputMultiPath (File (exists = True ),
1514- desc = 'bvars for each subcortical region' )
1515- original_segmentations = File (exists = True ,
1516- desc = ('3D image file containing the segmented regions as integer '
1517- 'values. Uses CMA labelling' ))
1518- segmentation_file = File (exists = True ,
1519- desc = '4D image file containing a single volume per segmented region' )
1515+ vtk_surfaces = OutputMultiPath (
1516+ File (exists = True ),
1517+ desc = 'VTK format meshes for each subcortical region' )
1518+ bvars = OutputMultiPath (
1519+ File (exists = True ),
1520+ desc = 'bvars for each subcortical region' )
1521+ original_segmentations = File (
1522+ exists = True , desc = ('3D image file containing the segmented regions '
1523+ 'as integer values. Uses CMA labelling' ))
1524+ segmentation_file = File (
1525+ exists = True , desc = ('4D image file containing a single volume per '
1526+ 'segmented region' ))
15201527
15211528
15221529class FIRST (FSLCommand ):
1523- """Use FSL's run_first_all command to segment subcortical volumes
1530+ """
1531+ Use FSL's run_first_all command to segment subcortical volumes
15241532
15251533 http://www.fmrib.ox.ac.uk/fsl/first/index.html
15261534
@@ -1554,7 +1562,7 @@ def _list_outputs(self):
15541562 'L_Thal' , 'R_Thal' ,
15551563 'BrStem' ]
15561564 outputs ['original_segmentations' ] = \
1557- self ._gen_fname ('original_segmentations' )
1565+ self ._gen_fname ('original_segmentations' )
15581566 outputs ['segmentation_file' ] = self ._gen_fname ('segmentation_file' )
15591567 outputs ['vtk_surfaces' ] = self ._gen_mesh_names ('vtk_surfaces' ,
15601568 structures )
@@ -1563,10 +1571,20 @@ def _list_outputs(self):
15631571
15641572 def _gen_fname (self , name ):
15651573 path , outname , ext = split_filename (self .inputs .out_file )
1574+
1575+ method = 'none'
1576+ if isdefined (self .inputs .method ) and self .inputs .method == 'fast' :
1577+ method = 'fast'
1578+
1579+ if isdefined (self .inputs .method_as_numerical_threshold ):
1580+ thres = '%.4f' % self .inputs .method_as_numerical_threshold
1581+ method = thres .replace ('.' , '' )
1582+
15661583 if name == 'original_segmentations' :
1567- return op .abspath (outname + '_all_fast_origsegs .nii.gz' )
1584+ return op .abspath ('%s_all_%s_origsegs .nii.gz' % ( outname , method ) )
15681585 if name == 'segmentation_file' :
1569- return op .abspath (outname + '_all_fast_firstseg.nii.gz' )
1586+ return op .abspath ('%s_all_%s_firstseg.nii.gz' % (outname , method ))
1587+
15701588 return None
15711589
15721590 def _gen_mesh_names (self , name , structures ):
@@ -1583,4 +1601,4 @@ def _gen_mesh_names(self, name, structures):
15831601 bvar = prefix + '-' + struct + '_first.bvars'
15841602 bvars .append (op .abspath (bvar ))
15851603 return bvars
1586- return None
1604+ return None
0 commit comments