Skip to content

Commit 272e441

Browse files
committed
Added human order sorting for FLAMEO outputs, fixed abspath for Cluster
outputs.
1 parent 4f13b1d commit 272e441

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

nipype/interfaces/fsl/model.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from nipype.utils.filemanip import (
2727
list_to_filename, filename_to_list, fname_presuffix)
2828
from nibabel import load
29+
from nipype.utils.misc import human_order_sorted
2930

3031
warn = warnings.warn
3132
warnings.filterwarnings('always', category=UserWarning)
@@ -734,51 +735,51 @@ def _list_outputs(self):
734735
outputs = self._outputs().get()
735736
pth = os.path.join(os.getcwd(), self.inputs.log_dir)
736737

737-
pes = glob(os.path.join(pth, 'pe[0-9]*.*'))
738+
pes = human_order_sorted(glob(os.path.join(pth, 'pe[0-9]*.*')))
738739
assert len(pes) >= 1, 'No pe volumes generated by FSL Estimate'
739740
outputs['pes'] = pes
740741

741-
res4d = glob(os.path.join(pth, 'res4d.*'))
742+
res4d = human_order_sorted(glob(os.path.join(pth, 'res4d.*')))
742743
assert len(res4d) == 1, 'No residual volume generated by FSL Estimate'
743744
outputs['res4d'] = res4d[0]
744745

745-
copes = glob(os.path.join(pth, 'cope[0-9]*.*'))
746+
copes = human_order_sorted(glob(os.path.join(pth, 'cope[0-9]*.*')))
746747
assert len(copes) >= 1, 'No cope volumes generated by FSL CEstimate'
747748
outputs['copes'] = copes
748749

749-
var_copes = glob(os.path.join(pth, 'varcope[0-9]*.*'))
750+
var_copes = human_order_sorted(glob(os.path.join(pth, 'varcope[0-9]*.*')))
750751
assert len(
751752
var_copes) >= 1, 'No varcope volumes generated by FSL CEstimate'
752753
outputs['var_copes'] = var_copes
753754

754-
zstats = glob(os.path.join(pth, 'zstat[0-9]*.*'))
755+
zstats = human_order_sorted(glob(os.path.join(pth, 'zstat[0-9]*.*')))
755756
assert len(zstats) >= 1, 'No zstat volumes generated by FSL CEstimate'
756757
outputs['zstats'] = zstats
757758

758759

759760
if isdefined(self.inputs.f_con_file):
760-
zfstats = glob(os.path.join(pth, 'zfstat[0-9]*.*'))
761+
zfstats = human_order_sorted(glob(os.path.join(pth, 'zfstat[0-9]*.*')))
761762
assert len(zfstats) >= 1, 'No zfstat volumes generated by FSL CEstimate'
762763
outputs['zfstats'] = zfstats
763764

764-
fstats = glob(os.path.join(pth, 'fstat[0-9]*.*'))
765+
fstats = human_order_sorted(glob(os.path.join(pth, 'fstat[0-9]*.*')))
765766
assert len(fstats) >= 1, 'No fstat volumes generated by FSL CEstimate'
766767
outputs['fstats'] = fstats
767768

768-
tstats = glob(os.path.join(pth, 'tstat[0-9]*.*'))
769+
tstats = human_order_sorted(glob(os.path.join(pth, 'tstat[0-9]*.*')))
769770
assert len(tstats) >= 1, 'No tstat volumes generated by FSL CEstimate'
770771
outputs['tstats'] = tstats
771772

772-
mrefs = glob(os.path.join(pth, 'mean_random_effects_var[0-9]*.*'))
773+
mrefs = human_order_sorted(glob(os.path.join(pth, 'mean_random_effects_var[0-9]*.*')))
773774
assert len(
774775
mrefs) >= 1, 'No mean random effects volumes generated by FLAMEO'
775776
outputs['mrefvars'] = mrefs
776777

777-
tdof = glob(os.path.join(pth, 'tdof_t[0-9]*.*'))
778+
tdof = human_order_sorted(glob(os.path.join(pth, 'tdof_t[0-9]*.*')))
778779
assert len(tdof) >= 1, 'No T dof volumes generated by FLAMEO'
779780
outputs['tdof'] = tdof
780781

781-
weights = glob(os.path.join(pth, 'weights[0-9]*.*'))
782+
weights = human_order_sorted(glob(os.path.join(pth, 'weights[0-9]*.*')))
782783
assert len(weights) >= 1, 'No weight volumes generated by FLAMEO'
783784
outputs['weights'] = weights
784785

@@ -1486,7 +1487,7 @@ def _list_outputs(self):
14861487
suffix='_' + suffix,
14871488
change_ext=change_ext)
14881489
else:
1489-
outputs[outkey] = os.pardir.abspath(inval)
1490+
outputs[outkey] = os.path.abspath(inval)
14901491
return outputs
14911492

14921493
def _format_arg(self, name, spec, value):

nipype/utils/misc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
import numpy as np
1010
from textwrap import dedent
1111
import sys
12+
import re
13+
14+
def human_order_sorted(l):
15+
"""Sorts string in human order (i.e. 'stat10' will go after 'stat2')"""
16+
def atoi(text):
17+
return int(text) if text.isdigit() else text
18+
19+
def natural_keys(text):
20+
return [ atoi(c) for c in re.split('(\d+)', text) ]
21+
22+
return sorted(l, key=natural_keys)
1223

1324
def trim(docstring, marker=None):
1425
if not docstring:

0 commit comments

Comments
 (0)