Skip to content

Commit f23ea1c

Browse files
authored
Merge pull request #24 from fliem/long
fixes behav in singl-session-subjects in long study
2 parents c2892d6 + 230da75 commit f23ea1c

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test:
2727
override:
2828
# print version
2929
- 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
30-
- 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:
30+
- 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 :
3131
timeout: 21600
3232
# group2 tests
3333
- 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 :

run.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,41 @@ def run(command, env={}, ignore_errors=False):
8989
run("bids-validator " + args.bids_dir)
9090

9191
subject_dirs = glob(os.path.join(args.bids_dir, "sub-*"))
92+
9293
if args.acquisition_label:
9394
acq_tpl = "*acq-%s*" % args.acquisition_label
9495
else:
9596
acq_tpl = "*"
9697

98+
# if there are session folders, check if study is truly longitudinal by
99+
# searching for the first subject with more than one valid sessions
100+
multi_session_study = False
101+
if glob(os.path.join(args.bids_dir, "sub-*", "ses-*")):
102+
subjects = [subject_dir.split("-")[-1] for subject_dir in subject_dirs]
103+
for subject_label in subjects:
104+
session_dirs = glob(os.path.join(args.bids_dir,"sub-%s"%subject_label,"ses-*"))
105+
sessions = [os.path.split(dr)[-1].split("-")[-1] for dr in session_dirs]
106+
n_valid_sessions = 0
107+
for session_label in sessions:
108+
if glob(os.path.join(args.bids_dir, "sub-%s"%subject_label,
109+
"ses-%s"%session_label,
110+
"anat",
111+
"%s_T1w.nii*"%acq_tpl)):
112+
n_valid_sessions += 1
113+
if n_valid_sessions > 1:
114+
multi_session_study = True
115+
break
116+
117+
if multi_session_study and (args.multiple_sessions == "longitudinal"):
118+
longitudinal_study = True
119+
else:
120+
longitudinal_study = False
121+
97122
if args.refine_pial_acquisition_label:
98123
acq_t2 = "*acq-%s*" % args.refine_pial_acquisition_label
99124
else:
100125
acq_t2 = "*"
101126

102-
103127
subjects_to_analyze = []
104128
# only for a subset of subjects
105129
if args.participant_label:
@@ -125,23 +149,10 @@ def run(command, env={}, ignore_errors=False):
125149
ignore_errors=True)
126150

127151
for subject_label in subjects_to_analyze:
128-
129-
# Check for multiple sessions to combine as a multiday session or as a longitudinal stream
130152
session_dirs = glob(os.path.join(args.bids_dir,"sub-%s"%subject_label,"ses-*"))
131153
sessions = [os.path.split(dr)[-1].split("-")[-1] for dr in session_dirs]
132-
longitudinal_study = False
133-
n_valid_sessions = 0
134-
for session_label in sessions:
135-
if glob(os.path.join(args.bids_dir, "sub-%s"%subject_label,
136-
"ses-%s"%session_label,
137-
"anat",
138-
"%s_T1w.nii*"%acq_tpl)):
139-
n_valid_sessions += 1
140-
if n_valid_sessions > 1 and args.multiple_sessions == "longitudinal":
141-
longitudinal_study = True
142154

143155
timepoints = []
144-
145156
if len(sessions) > 0 and longitudinal_study == True:
146157
# Running each session separately, prior to doing longitudinal pipeline
147158
for session_label in sessions:

0 commit comments

Comments
 (0)