Skip to content

Commit 74364b6

Browse files
committed
FIX: BOLD grouping across sessions
Encountered in #134 These changes refine the BOLD grouping algorithm. Mainly handling two edge cases: - Sessions with `_bold` files are present within the BIDS dataset, but not for the subject of interest. - Sessions without `_bold` files are present within the BIDS dataset.
1 parent 1d32d9d commit 74364b6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

nibabies/utils/bids.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,22 @@ def group_bolds_ref(*, layout, subject):
153153
combinations = []
154154
# list of lists containing filenames that apply per combination
155155
files = []
156+
# list of all BOLDS encountered
157+
all_bolds = []
156158

157159
for ses, suffix in sorted(
158160
product(
159-
layout.get_sessions() or (None,),
161+
layout.get_sessions(subject=subject) or (None,),
160162
{
161163
"bold",
162164
},
163165
)
164166
):
165167
# bold files same session
166168
bolds = layout.get(suffix=suffix, session=ses, **base_entities)
169+
# some sessions may not have BOLD scans
170+
if bolds is None:
171+
continue
167172

168173
for bold in bolds:
169174
# session, pe, ro
@@ -192,7 +197,9 @@ def group_bolds_ref(*, layout, subject):
192197
combinations.append(comb)
193198
files.append([bold.path])
194199

195-
if (len(combinations) != len(files)) or (len(bolds) != sum([len(x) for x in files])):
200+
all_bolds += bolds
201+
202+
if (len(combinations) != len(files)) or (len(all_bolds) != sum([len(x) for x in files])):
196203
msg = f"""Error encountered when grouping BOLD runs.
197204
Combinations: {combinations}
198205
Sorted files: {files}

0 commit comments

Comments
 (0)