Skip to content

Commit

Permalink
Merge pull request #24 from fliem/long
Browse files Browse the repository at this point in the history
fixes behav in singl-session-subjects in long study
  • Loading branch information
chrisgorgo authored Feb 13, 2017
2 parents c2892d6 + 230da75 commit f23ea1c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
39 changes: 25 additions & 14 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit f23ea1c

Please sign in to comment.