From e3bb3562def4a8caaa88d58ed06ac3bc627638dd Mon Sep 17 00:00:00 2001 From: perronea Date: Thu, 7 May 2020 11:35:01 -0700 Subject: [PATCH] replace hardcoded run number removal with regex --- dcan_bold_proc.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dcan_bold_proc.py b/dcan_bold_proc.py index 12f0631..543967a 100755 --- a/dcan_bold_proc.py +++ b/dcan_bold_proc.py @@ -35,6 +35,7 @@ import subprocess import shutil import sys +import re here = os.path.dirname(os.path.realpath(__file__)) @@ -350,7 +351,9 @@ def interface(subject, output_folder, task=None, fd_threshold=None, elif teardown: output_results = os.path.join(output_folder, 'MNINonLinear', 'Results') alltasks = os.listdir(output_results) - tasknames = sorted(list(set([d[:-2] for d in alltasks + expr = re.compile(r'.*(task-[^_]+).*([0-9]+).*') + #tasknames = sorted(list(set([d[:-2] for d in alltasks + tasknames = sorted(list(set([expr.match(d).group(1) for d in alltasks if os.path.isdir(os.path.join(output_results,d)) and 'task-' in d]))) @@ -369,7 +372,9 @@ def interface(subject, output_folder, task=None, fd_threshold=None, repetition_time = get_repetition_time(input_spec['fmri_volume']) for concat in concatlist: if len(concat) > 0: - taskset = concat[0][:-2] + #taskset = concat[0][:-2] + expr = re.compile(r'.*(task-[^_]+).*([0-9]+).*') + taskset = expr.match(concat[0]).group(1) print('Running analyses_v2 on %s' % taskset) @@ -601,7 +606,10 @@ def concatenate(concatlist, output_folder): for concat in concatlist: for i,task in enumerate(concat): - taskname = task[:-2] + #taskname = task[:-2] + expr = re.compile(r'.*(task-[^_]+).*([0-9]+).*') + taskname = expr.match(task).group(1) + base_results_folder = os.path.join(output_folder, 'MNINonLinear', 'Results') input_task_dtseries = os.path.join(base_results_folder, task,