Skip to content

Commit

Permalink
added mulit_session_study var
Browse files Browse the repository at this point in the history
  • Loading branch information
fliem committed Jan 31, 2017
1 parent 2ca45c4 commit 5e8aaa5
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e8aaa5

Please sign in to comment.