26
26
from nipype .utils .filemanip import (
27
27
list_to_filename , filename_to_list , fname_presuffix )
28
28
from nibabel import load
29
+ from nipype .utils .misc import human_order_sorted
29
30
30
31
warn = warnings .warn
31
32
warnings .filterwarnings ('always' , category = UserWarning )
@@ -678,6 +679,9 @@ class FLAMEOOutputSpec(TraitedSpec):
678
679
exists = True , desc = "Variance estimates for each contrast" )
679
680
zstats = OutputMultiPath (exists = True , desc = "z-stat file for each contrast" )
680
681
tstats = OutputMultiPath (exists = True , desc = "t-stat file for each contrast" )
682
+ zfstats = OutputMultiPath (
683
+ exists = True , desc = "z stat file for each f contrast" )
684
+ fstats = OutputMultiPath (exists = True , desc = "f-stat file for each contrast" )
681
685
mrefvars = OutputMultiPath (
682
686
exists = True , desc = "mean random effect variances for each contrast" )
683
687
tdof = OutputMultiPath (
@@ -732,41 +736,57 @@ def _list_outputs(self):
732
736
outputs = self ._outputs ().get ()
733
737
pth = os .path .join (os .getcwd (), self .inputs .log_dir )
734
738
735
- pes = glob (os .path .join (pth , 'pe[0-9]*.*' ))
739
+ pes = human_order_sorted ( glob (os .path .join (pth , 'pe[0-9]*.*' ) ))
736
740
assert len (pes ) >= 1 , 'No pe volumes generated by FSL Estimate'
737
741
outputs ['pes' ] = pes
738
742
739
- res4d = glob (os .path .join (pth , 'res4d.*' ))
743
+ res4d = human_order_sorted ( glob (os .path .join (pth , 'res4d.*' ) ))
740
744
assert len (res4d ) == 1 , 'No residual volume generated by FSL Estimate'
741
745
outputs ['res4d' ] = res4d [0 ]
742
746
743
- copes = glob (os .path .join (pth , 'cope[0-9]*.*' ))
747
+ copes = human_order_sorted ( glob (os .path .join (pth , 'cope[0-9]*.*' ) ))
744
748
assert len (copes ) >= 1 , 'No cope volumes generated by FSL CEstimate'
745
749
outputs ['copes' ] = copes
746
750
747
- var_copes = glob (os .path .join (pth , 'varcope[0-9]*.*' ))
751
+ var_copes = human_order_sorted (
752
+ glob (os .path .join (pth , 'varcope[0-9]*.*' )))
748
753
assert len (
749
754
var_copes ) >= 1 , 'No varcope volumes generated by FSL CEstimate'
750
755
outputs ['var_copes' ] = var_copes
751
756
752
- zstats = glob (os .path .join (pth , 'zstat[0-9]*.*' ))
757
+ zstats = human_order_sorted ( glob (os .path .join (pth , 'zstat[0-9]*.*' ) ))
753
758
assert len (zstats ) >= 1 , 'No zstat volumes generated by FSL CEstimate'
754
759
outputs ['zstats' ] = zstats
755
760
756
- tstats = glob (os .path .join (pth , 'tstat[0-9]*.*' ))
761
+ if isdefined (self .inputs .f_con_file ):
762
+ zfstats = human_order_sorted (
763
+ glob (os .path .join (pth , 'zfstat[0-9]*.*' )))
764
+ assert len (
765
+ zfstats ) >= 1 , 'No zfstat volumes generated by FSL CEstimate'
766
+ outputs ['zfstats' ] = zfstats
767
+
768
+ fstats = human_order_sorted (
769
+ glob (os .path .join (pth , 'fstat[0-9]*.*' )))
770
+ assert len (
771
+ fstats ) >= 1 , 'No fstat volumes generated by FSL CEstimate'
772
+ outputs ['fstats' ] = fstats
773
+
774
+ tstats = human_order_sorted (glob (os .path .join (pth , 'tstat[0-9]*.*' )))
757
775
assert len (tstats ) >= 1 , 'No tstat volumes generated by FSL CEstimate'
758
776
outputs ['tstats' ] = tstats
759
777
760
- mrefs = glob (os .path .join (pth , 'mean_random_effects_var[0-9]*.*' ))
778
+ mrefs = human_order_sorted (
779
+ glob (os .path .join (pth , 'mean_random_effects_var[0-9]*.*' )))
761
780
assert len (
762
781
mrefs ) >= 1 , 'No mean random effects volumes generated by FLAMEO'
763
782
outputs ['mrefvars' ] = mrefs
764
783
765
- tdof = glob (os .path .join (pth , 'tdof_t[0-9]*.*' ))
784
+ tdof = human_order_sorted ( glob (os .path .join (pth , 'tdof_t[0-9]*.*' ) ))
766
785
assert len (tdof ) >= 1 , 'No T dof volumes generated by FLAMEO'
767
786
outputs ['tdof' ] = tdof
768
787
769
- weights = glob (os .path .join (pth , 'weights[0-9]*.*' ))
788
+ weights = human_order_sorted (
789
+ glob (os .path .join (pth , 'weights[0-9]*.*' )))
770
790
assert len (weights ) >= 1 , 'No weight volumes generated by FLAMEO'
771
791
outputs ['weights' ] = weights
772
792
@@ -784,7 +804,7 @@ class ContrastMgrInputSpec(FSLCommandInputSpec):
784
804
param_estimates = InputMultiPath (File (exists = True ),
785
805
argstr = '' , copyfile = False ,
786
806
mandatory = True ,
787
- desc = 'Parameter estimates for each column of the design matrix' )
807
+ desc = 'Parameter estimates for each column of the design matrix' )
788
808
corrections = File (exists = True , copyfile = False , mandatory = True ,
789
809
desc = 'statistical corrections used within FILM modelling' )
790
810
dof_file = File (exists = True , argstr = '' , copyfile = False , mandatory = True ,
@@ -793,26 +813,26 @@ class ContrastMgrInputSpec(FSLCommandInputSpec):
793
813
copyfile = False , mandatory = True ,
794
814
desc = 'summary of residuals, See Woolrich, et. al., 2001' )
795
815
contrast_num = traits .Int (min = 1 , argstr = '-cope' ,
796
- desc = 'contrast number to start labeling copes from' )
816
+ desc = 'contrast number to start labeling copes from' )
797
817
suffix = traits .Str (argstr = '-suffix %s' ,
798
818
desc = 'suffix to put on the end of the cope filename before the contrast number, default is nothing' )
799
819
800
820
801
821
class ContrastMgrOutputSpec (TraitedSpec ):
802
822
copes = OutputMultiPath (File (exists = True ),
803
- desc = 'Contrast estimates for each contrast' )
823
+ desc = 'Contrast estimates for each contrast' )
804
824
varcopes = OutputMultiPath (File (exists = True ),
805
- desc = 'Variance estimates for each contrast' )
825
+ desc = 'Variance estimates for each contrast' )
806
826
zstats = OutputMultiPath (File (exists = True ),
807
- desc = 'z-stat file for each contrast' )
827
+ desc = 'z-stat file for each contrast' )
808
828
tstats = OutputMultiPath (File (exists = True ),
809
- desc = 't-stat file for each contrast' )
829
+ desc = 't-stat file for each contrast' )
810
830
fstats = OutputMultiPath (File (exists = True ),
811
- desc = 'f-stat file for each contrast' )
831
+ desc = 'f-stat file for each contrast' )
812
832
zfstats = OutputMultiPath (File (exists = True ),
813
833
desc = 'z-stat file for each F contrast' )
814
834
neffs = OutputMultiPath (File (exists = True ),
815
- desc = 'neff file ?? for each contrast' )
835
+ desc = 'neff file ?? for each contrast' )
816
836
817
837
818
838
class ContrastMgr (FSLCommand ):
@@ -881,16 +901,16 @@ def _list_outputs(self):
881
901
neffs = []
882
902
for i in range (numtcons ):
883
903
copes .append (self ._gen_fname ('cope%d.nii' % (base_contrast + i ),
884
- cwd = pth ))
904
+ cwd = pth ))
885
905
varcopes .append (
886
906
self ._gen_fname ('varcope%d.nii' % (base_contrast + i ),
887
- cwd = pth ))
907
+ cwd = pth ))
888
908
zstats .append (self ._gen_fname ('zstat%d.nii' % (base_contrast + i ),
889
- cwd = pth ))
909
+ cwd = pth ))
890
910
tstats .append (self ._gen_fname ('tstat%d.nii' % (base_contrast + i ),
891
- cwd = pth ))
911
+ cwd = pth ))
892
912
neffs .append (self ._gen_fname ('neff%d.nii' % (base_contrast + i ),
893
- cwd = pth ))
913
+ cwd = pth ))
894
914
if copes :
895
915
outputs ['copes' ] = copes
896
916
outputs ['varcopes' ] = varcopes
@@ -901,10 +921,10 @@ def _list_outputs(self):
901
921
zfstats = []
902
922
for i in range (numfcons ):
903
923
fstats .append (self ._gen_fname ('fstat%d.nii' % (base_contrast + i ),
904
- cwd = pth ))
924
+ cwd = pth ))
905
925
zfstats .append (
906
926
self ._gen_fname ('zfstat%d.nii' % (base_contrast + i ),
907
- cwd = pth ))
927
+ cwd = pth ))
908
928
if fstats :
909
929
outputs ['fstats' ] = fstats
910
930
outputs ['zfstats' ] = zfstats
@@ -913,7 +933,7 @@ def _list_outputs(self):
913
933
914
934
class L2ModelInputSpec (BaseInterfaceInputSpec ):
915
935
num_copes = traits .Int (min = 1 , mandatory = True ,
916
- desc = 'number of copes to be combined' )
936
+ desc = 'number of copes to be combined' )
917
937
918
938
919
939
class L2ModelOutputSpec (TraitedSpec ):
@@ -1011,7 +1031,7 @@ class MultipleRegressDesignInputSpec(BaseInterfaceInputSpec):
1011
1031
mandatory = True ,
1012
1032
desc = 'dictionary containing named lists of regressors' )
1013
1033
groups = traits .List (traits .Int ,
1014
- desc = 'list of group identifiers (defaults to single group)' )
1034
+ desc = 'list of group identifiers (defaults to single group)' )
1015
1035
1016
1036
1017
1037
class MultipleRegressDesignOutputSpec (TraitedSpec ):
@@ -1091,7 +1111,7 @@ def _run_interface(self, runtime):
1091
1111
convals = np .zeros ((nwaves , 1 ))
1092
1112
for regidx , reg in enumerate (self .inputs .contrasts [idx ][2 ]):
1093
1113
convals [regs .index (reg )
1094
- ] = self .inputs .contrasts [idx ][3 ][regidx ]
1114
+ ] = self .inputs .contrasts [idx ][3 ][regidx ]
1095
1115
con_txt .append (' ' .join (['%e' % val for val in convals ]))
1096
1116
con_txt = '\n ' .join (con_txt )
1097
1117
# write f-con file
@@ -1150,11 +1170,11 @@ def _list_outputs(self):
1150
1170
class SMMInputSpec (FSLCommandInputSpec ):
1151
1171
spatial_data_file = File (
1152
1172
exists = True , position = 0 , argstr = '--sdf="%s"' , mandatory = True ,
1153
- desc = "statistics spatial map" , copyfile = False )
1173
+ desc = "statistics spatial map" , copyfile = False )
1154
1174
mask = File (exist = True , position = 1 , argstr = '--mask="%s"' , mandatory = True ,
1155
1175
desc = "mask file" , copyfile = False )
1156
1176
no_deactivation_class = traits .Bool (position = 2 , argstr = "--zfstatmode" ,
1157
- desc = "enforces no deactivation class" )
1177
+ desc = "enforces no deactivation class" )
1158
1178
1159
1179
1160
1180
class SMMOutputSpec (TraitedSpec ):
@@ -1189,7 +1209,7 @@ def _list_outputs(self):
1189
1209
class MELODICInputSpec (FSLCommandInputSpec ):
1190
1210
in_files = InputMultiPath (
1191
1211
File (exists = True ), argstr = "-i %s" , mandatory = True , position = 0 ,
1192
- desc = "input file names (either single file name or a list)" )
1212
+ desc = "input file names (either single file name or a list)" )
1193
1213
out_dir = Directory (
1194
1214
argstr = "-o %s" , desc = "output directory name" , genfile = True )
1195
1215
mask = File (exists = True , argstr = "-m %s" ,
@@ -1474,7 +1494,7 @@ def _list_outputs(self):
1474
1494
suffix = '_' + suffix ,
1475
1495
change_ext = change_ext )
1476
1496
else :
1477
- outputs [outkey ] = os .pardir .abspath (inval )
1497
+ outputs [outkey ] = os .path .abspath (inval )
1478
1498
return outputs
1479
1499
1480
1500
def _format_arg (self , name , spec , value ):
@@ -1492,7 +1512,7 @@ class RandomiseInputSpec(FSLCommandInputSpec):
1492
1512
position = 0 , mandatory = True )
1493
1513
base_name = traits .Str (
1494
1514
'tbss_' , desc = 'the rootname that all generated files will have' ,
1495
- argstr = '-o "%s"' , position = 1 , usedefault = True )
1515
+ argstr = '-o "%s"' , position = 1 , usedefault = True )
1496
1516
design_mat = File (
1497
1517
exists = True , desc = 'design matrix file' , argstr = '-d %s' , position = 2 )
1498
1518
tcon = File (
@@ -1505,27 +1525,27 @@ class RandomiseInputSpec(FSLCommandInputSpec):
1505
1525
desc = 'demean data temporally before model fitting' , argstr = '-D' )
1506
1526
one_sample_group_mean = traits .Bool (
1507
1527
desc = 'perform 1-sample group-mean test instead of generic permutation test' ,
1508
- argstr = '-1' )
1528
+ argstr = '-1' )
1509
1529
show_total_perms = traits .Bool (
1510
1530
desc = 'print out how many unique permutations would be generated and exit' ,
1511
- argstr = '-q' )
1531
+ argstr = '-q' )
1512
1532
show_info_parallel_mode = traits .Bool (
1513
1533
desc = 'print out information required for parallel mode and exit' ,
1514
- argstr = '-Q' )
1534
+ argstr = '-Q' )
1515
1535
vox_p_values = traits .Bool (
1516
1536
desc = 'output voxelwise (corrected and uncorrected) p-value images' ,
1517
- argstr = '-x' )
1537
+ argstr = '-x' )
1518
1538
tfce = traits .Bool (
1519
1539
desc = 'carry out Threshold-Free Cluster Enhancement' , argstr = '-T' )
1520
1540
tfce2D = traits .Bool (
1521
1541
desc = 'carry out Threshold-Free Cluster Enhancement with 2D optimisation' ,
1522
- argstr = '--T2' )
1542
+ argstr = '--T2' )
1523
1543
f_only = traits .Bool (desc = 'calculate f-statistics only' , argstr = '--f_only' )
1524
1544
raw_stats_imgs = traits .Bool (
1525
1545
desc = 'output raw ( unpermuted ) statistic images' , argstr = '-R' )
1526
1546
p_vec_n_dist_files = traits .Bool (
1527
1547
desc = 'output permutation vector and null distribution text files' ,
1528
- argstr = '-P' )
1548
+ argstr = '-P' )
1529
1549
num_perm = traits .Int (
1530
1550
argstr = '-n %d' , desc = 'number of permutations (default 5000, set to 0 for exhaustive)' )
1531
1551
seed = traits .Int (
@@ -1596,9 +1616,9 @@ class Randomise(FSLCommand):
1596
1616
def _list_outputs (self ):
1597
1617
outputs = self .output_spec ().get ()
1598
1618
outputs ['tstat_files' ] = glob (self ._gen_fname (
1599
- '%s_tstat*.nii' % self .inputs .base_name ))
1619
+ '%s_tstat*.nii' % self .inputs .base_name ))
1600
1620
outputs ['fstat_files' ] = glob (self ._gen_fname (
1601
- '%s_fstat*.nii' % self .inputs .base_name ))
1621
+ '%s_fstat*.nii' % self .inputs .base_name ))
1602
1622
prefix = False
1603
1623
if self .inputs .tfce or self .inputs .tfce2D :
1604
1624
prefix = 'tfce'
@@ -1610,7 +1630,7 @@ def _list_outputs(self):
1610
1630
prefix = 'clusterm'
1611
1631
if prefix :
1612
1632
outputs ['t_p_files' ] = glob (self ._gen_fname (
1613
- '%s_%s_p_tstat*' % (self .inputs .base_name , prefix )))
1633
+ '%s_%s_p_tstat*' % (self .inputs .base_name , prefix )))
1614
1634
outputs ['t_corrected_p_files' ] = glob (self ._gen_fname (
1615
1635
'%s_%s_corrp_tstat*.nii' % (self .inputs .base_name , prefix )))
1616
1636
@@ -1625,22 +1645,22 @@ class GLMInputSpec(FSLCommandInputSpec):
1625
1645
in_file = File (exists = True , argstr = '-i %s' , mandatory = True , position = 1 ,
1626
1646
desc = 'input file name (text matrix or 3D/4D image file)' )
1627
1647
out_file = File (argstr = '-o %s' , genfile = True , position = 3 ,
1628
- desc = ('filename for GLM parameter estimates'
1629
- + ' (GLM betas)' ))
1648
+ desc = ('filename for GLM parameter estimates'
1649
+ + ' (GLM betas)' ))
1630
1650
design = File (exists = True , argstr = '-d %s' , mandatory = True , position = 2 ,
1631
- desc = ('file name of the GLM design matrix (text time'
1632
- + ' courses for temporal regression or an image'
1633
- + ' file for spatial regression)' ))
1651
+ desc = ('file name of the GLM design matrix (text time'
1652
+ + ' courses for temporal regression or an image'
1653
+ + ' file for spatial regression)' ))
1634
1654
contrasts = File (exists = True , argstr = '-c %s' , desc = ('matrix of t-statics'
1635
1655
+ ' contrasts' ))
1636
1656
mask = File (exists = True , argstr = '-m %s' , desc = ('mask image file name if'
1637
1657
+ ' input is image' ))
1638
1658
dof = traits .Int (argstr = '--dof %d' , desc = ('set degrees of freedom'
1639
1659
+ ' explicitly' ))
1640
1660
des_norm = traits .Bool (argstr = '--des_norm' , desc = ('switch on normalization'
1641
- + ' of the design matrix'
1642
- + ' columns to unit std'
1643
- + ' deviation' ))
1661
+ + ' of the design matrix'
1662
+ + ' columns to unit std'
1663
+ + ' deviation' ))
1644
1664
dat_norm = traits .Bool (argstr = '--dat_norm' , desc = ('switch on normalization'
1645
1665
+ ' of the data time'
1646
1666
+ ' series to unit std'
@@ -1652,30 +1672,30 @@ class GLMInputSpec(FSLCommandInputSpec):
1652
1672
out_cope = File (argstr = '--out_cope=%s' ,
1653
1673
desc = 'output file name for COPE (either as txt or image' )
1654
1674
out_z_name = File (argstr = '--out_z=%s' ,
1655
- desc = 'output file name for Z-stats (either as txt or image' )
1675
+ desc = 'output file name for Z-stats (either as txt or image' )
1656
1676
out_t_name = File (argstr = '--out_t=%s' ,
1657
- desc = 'output file name for t-stats (either as txt or image' )
1677
+ desc = 'output file name for t-stats (either as txt or image' )
1658
1678
1659
1679
out_p_name = File (argstr = '--out_p=%s' ,
1660
- desc = ('output file name for p-values of Z-stats (either as'
1661
- + ' text file or image)' ))
1680
+ desc = ('output file name for p-values of Z-stats (either as'
1681
+ + ' text file or image)' ))
1662
1682
out_f_name = File (argstr = '--out_f=%s' ,
1663
- desc = 'output file name for F-value of full model fit' )
1683
+ desc = 'output file name for F-value of full model fit' )
1664
1684
out_pf_name = File (argstr = '--out_pf=%s' ,
1665
- desc = 'output file name for p-value for full model fit' )
1685
+ desc = 'output file name for p-value for full model fit' )
1666
1686
out_res_name = File (argstr = '--out_res=%s' ,
1667
- desc = 'output file name for residuals' )
1687
+ desc = 'output file name for residuals' )
1668
1688
out_varcb_name = File (argstr = '--out_varcb=%s' ,
1669
- desc = 'output file name for variance of COPEs' )
1689
+ desc = 'output file name for variance of COPEs' )
1670
1690
1671
1691
out_sigsq_name = File (argstr = '--out_sigsq=%s' ,
1672
- desc = ('output file name for residual noise variance'
1673
- + ' sigma-square' ))
1692
+ desc = ('output file name for residual noise variance'
1693
+ + ' sigma-square' ))
1674
1694
out_data_name = File (argstr = '--out_data=%s' ,
1675
- desc = 'output file name for pre-processed data' )
1695
+ desc = 'output file name for pre-processed data' )
1676
1696
out_vnscales_name = File (argstr = '--out_vnscales=%s' ,
1677
- desc = ('output file name for scaling factors for variance'
1678
- + ' normalisation' ))
1697
+ desc = ('output file name for scaling factors for variance'
1698
+ + ' normalisation' ))
1679
1699
1680
1700
1681
1701
class GLMOutputSpec (TraitedSpec ):
0 commit comments