From 8b6851ba52ef4ec4ee0a7c986846e0c6336a1d84 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Thu, 21 Apr 2022 11:11:15 -0400 Subject: [PATCH] FIX: Account for potential lists of lists in multi-echo cases --- niworkflows/utils/misc.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/niworkflows/utils/misc.py b/niworkflows/utils/misc.py index 0cf1c13b735..1de8dadb6ab 100644 --- a/niworkflows/utils/misc.py +++ b/niworkflows/utils/misc.py @@ -107,11 +107,20 @@ def fix_multi_T1w_source_name(in_files): ... '/path/to/sub-045_ses-retest_T1w.nii.gz']) '/path/to/sub-045_T1w.nii.gz' + + >>> fix_multi_T1w_source_name([ + ... ('/path/to/sub-045-echo-1_T1w.nii.gz', 'path/to/sub-045-echo-2_T1w.nii.gz')]) + '/path/to/sub-045_T1w.nii.gz' + """ import os from nipype.utils.filemanip import filename_to_list - base, in_file = os.path.split(filename_to_list(in_files)[0]) + in_file = filename_to_list(in_files)[0] + if isinstance(in_file, (list, tuple)): + in_file = in_file[0] + + base, in_file = os.path.split(in_file) subject_label = in_file.split("_", 1)[0].split("-")[1] return os.path.join(base, "sub-%s_T1w.nii.gz" % subject_label)