14
14
import os
15
15
import os .path as op
16
16
import warnings
17
+ import glob
17
18
18
19
import numpy as np
19
20
@@ -1475,52 +1476,59 @@ def _gen_filename(self, name):
1475
1476
1476
1477
1477
1478
class 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 )
1484
1485
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 ,
1487
1489
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 ,
1489
1492
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 ,
1493
1496
desc = ("Method must be one of auto, fast, none, or it can be entered "
1494
1497
"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 ,
1496
1500
desc = ("Specify a numerical threshold value or use the 'method' input "
1497
1501
"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 ,
1500
1504
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)' ))
1508
1512
1509
1513
1510
1514
class 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' ))
1520
1527
1521
1528
1522
1529
class 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
1524
1532
1525
1533
http://www.fmrib.ox.ac.uk/fsl/first/index.html
1526
1534
@@ -1554,7 +1562,7 @@ def _list_outputs(self):
1554
1562
'L_Thal' , 'R_Thal' ,
1555
1563
'BrStem' ]
1556
1564
outputs ['original_segmentations' ] = \
1557
- self ._gen_fname ('original_segmentations' )
1565
+ self ._gen_fname ('original_segmentations' )
1558
1566
outputs ['segmentation_file' ] = self ._gen_fname ('segmentation_file' )
1559
1567
outputs ['vtk_surfaces' ] = self ._gen_mesh_names ('vtk_surfaces' ,
1560
1568
structures )
@@ -1563,10 +1571,20 @@ def _list_outputs(self):
1563
1571
1564
1572
def _gen_fname (self , name ):
1565
1573
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
+
1566
1583
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 ) )
1568
1585
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
+
1570
1588
return None
1571
1589
1572
1590
def _gen_mesh_names (self , name , structures ):
@@ -1583,4 +1601,4 @@ def _gen_mesh_names(self, name, structures):
1583
1601
bvar = prefix + '-' + struct + '_first.bvars'
1584
1602
bvars .append (op .abspath (bvar ))
1585
1603
return bvars
1586
- return None
1604
+ return None
0 commit comments