From 5e8aaa5efc1a2032011c473a86e27dab1fc9d097 Mon Sep 17 00:00:00 2001 From: fliem Date: Tue, 31 Jan 2017 18:38:35 +0100 Subject: [PATCH] added mulit_session_study var --- run.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/run.py b/run.py index 9678b6d..b8100e3 100755 --- a/run.py +++ b/run.py @@ -75,28 +75,36 @@ def run(command, env={}, ignore_errors=False): run("bids-validator " + args.bids_dir) subject_dirs = glob(os.path.join(args.bids_dir, "sub-*")) + if args.acquisition_label: acq_tpl = "*acq-%s*" % args.acquisition_label else: acq_tpl = "*" -# check if study is truly longitudinal -subject_dirs = glob(os.path.join(args.bids_dir, "sub-*")) -subjects_to_analyze = [subject_dir.split("-")[-1] for subject_dir in subject_dirs] -for subject_label in subjects_to_analyze: - # Check for multiple sessions to combine as a multiday session or as a longitudinal stream - session_dirs = glob(os.path.join(args.bids_dir,"sub-%s"%subject_label,"ses-*")) - sessions = [os.path.split(dr)[-1].split("-")[-1] for dr in session_dirs] - longitudinal_study = False - n_valid_sessions = 0 - for session_label in sessions: - if glob(os.path.join(args.bids_dir, "sub-%s"%subject_label, - "ses-%s"%session_label, - "anat", - "%s_T1w.nii*"%acq_tpl)): - n_valid_sessions += 1 -if n_valid_sessions > 1 and args.multiple_sessions == "longitudinal": +# if there are session folders, check if study is truly longitudinal by +# searching for the first subject with more than one valid sessions +multi_session_study = False +if glob(os.path.join(args.bids_dir, "sub-*", "ses-*")): + subjects = [subject_dir.split("-")[-1] for subject_dir in subject_dirs] + for subject_label in subjects: + session_dirs = glob(os.path.join(args.bids_dir,"sub-%s"%subject_label,"ses-*")) + sessions = [os.path.split(dr)[-1].split("-")[-1] for dr in session_dirs] + n_valid_sessions = 0 + for session_label in sessions: + if glob(os.path.join(args.bids_dir, "sub-%s"%subject_label, + "ses-%s"%session_label, + "anat", + "%s_T1w.nii*"%acq_tpl)): + n_valid_sessions += 1 + if n_valid_sessions > 1: + multi_session_study = True + break + +if multi_session_study and (args.multiple_sessions == "longitudinal"): longitudinal_study = True +else: + longitudinal_study = False + subjects_to_analyze = [] # only for a subset of subjects