diff --git a/circle.yml b/circle.yml index dda2e21..32c1df3 100644 --- a/circle.yml +++ b/circle.yml @@ -27,7 +27,7 @@ test: override: # print version - docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset bids/${CIRCLE_PROJECT_REPONAME,,} --version - - docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/outputs1:/outputs bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs participant --participant_label 01 --license_key="~/test.key" --stages autorecon1: + - docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/outputs1:/outputs bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs participant --participant_label 01 --license_key="~/test.key" --stages autorecon1 && cat ${HOME}/outputs1/sub-01/scripts/recon-all.done : timeout: 21600 # group2 tests - docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/data/ds114_test1_freesurfer:/outputs bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs group2 --license_key="~/test.key" && mkdir -p ${HOME}/outputs1/ && sudo mv ${HOME}/data/ds114_test1_freesurfer/00_group* ${HOME}/outputs1/ && cat ${HOME}/outputs1/00_group2_stats_tables/lh.aparc.thickness.tsv : diff --git a/run.py b/run.py index f9aa8fb..151389f 100755 --- a/run.py +++ b/run.py @@ -89,17 +89,41 @@ 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 = "*" +# 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 + if args.refine_pial_acquisition_label: acq_t2 = "*acq-%s*" % args.refine_pial_acquisition_label else: acq_t2 = "*" - subjects_to_analyze = [] # only for a subset of subjects if args.participant_label: @@ -125,23 +149,10 @@ def run(command, env={}, ignore_errors=False): ignore_errors=True) 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": - longitudinal_study = True timepoints = [] - if len(sessions) > 0 and longitudinal_study == True: # Running each session separately, prior to doing longitudinal pipeline for session_label in sessions: