@@ -127,111 +127,6 @@ def _unique(inlist):
127
127
return {k : _unique (v ) for k , v in entities .items ()}
128
128
129
129
130
- def group_bolds_ref (* , layout , subject , sessions = None ):
131
- """
132
- Extracts BOLD files from a BIDS dataset and combines them into buckets.
133
- Files in a bucket share:
134
- 1) Session
135
- 2) Phase-encoding direction (PEdir)
136
- 3) Total readout time (TRT)
137
-
138
- Any files with missing data for (2) or (3) are put in their own bucket.
139
-
140
- Parameters
141
- ----------
142
- layout : pybids.layout.BIDSLayout
143
- Initialized BIDSLayout
144
- subject : str
145
- The subject ID
146
- sessions : None
147
-
148
- Outputs
149
- -------
150
- combinations : list of tuples
151
- Each tuple is composed of (session, PEdir, TRT)
152
- files : list of lists
153
- Files matching each combination.
154
-
155
- Limitations
156
- -----------
157
- Single-band reference (sbref) are excluded.
158
- """
159
- import re
160
- from contextlib import suppress
161
- from itertools import product
162
-
163
- from sdcflows .utils .epimanip import get_trt
164
-
165
- base_entities = {
166
- "subject" : subject ,
167
- "extension" : (".nii" , ".nii.gz" ),
168
- "scope" : "raw" , # Ensure derivatives are not captured
169
- }
170
- # dictionary containing unique Groupings and files
171
- groupings = {}
172
- # list of all BOLDS encountered
173
- all_bolds = []
174
-
175
- sessions = sessions if sessions else layout .get_sessions (subject = subject , scope = "raw" )
176
-
177
- for ses , suffix in sorted (product (sessions or (None ,), {"bold" })):
178
- # bold files same session
179
- bolds = layout .get (suffix = suffix , session = ses , ** base_entities )
180
- # some sessions may not have BOLD scans
181
- if bolds is None :
182
- continue
183
-
184
- for i , bold in enumerate (bolds ):
185
- multiecho_id = None
186
- # multi-echo should be grouped together
187
- if 'echo' in bold .entities :
188
- # create unique id by dropping "_echo-{i}"
189
- multiecho_id = re .sub (r"_echo-\d+" , "" , bold .filename )
190
-
191
- # session, pe, ro
192
- meta = bold .get_metadata ()
193
- pe_dir = meta .get ("PhaseEncodingDirection" )
194
-
195
- ro = None
196
- with suppress (ValueError ):
197
- ro = get_trt (meta , bold .path )
198
- if ro is not None :
199
- meta .update ({"TotalReadoutTime" : ro })
200
-
201
- grouping = BOLDGrouping (
202
- session = ses ,
203
- pe_dir = pe_dir ,
204
- readout = ro ,
205
- multiecho_id = multiecho_id ,
206
- )
207
-
208
- if any (v is None for v in (pe_dir , ro )):
209
- # cannot be certain so treat as unique
210
- grouping .add_file (bold .path )
211
- groupings [f'unknown{ i } ' ] = grouping
212
- else :
213
- try :
214
- grouping = groupings [grouping .name ]
215
- except KeyError :
216
- groupings [grouping .name ] = grouping
217
-
218
- grouping .add_file (bold .path )
219
-
220
- all_bolds += bolds
221
-
222
- if len (all_bolds ) != sum ([len (g .files ) for _ , g in groupings .items ()]):
223
- msg = f"""Error encountered when grouping BOLD runs.
224
- Combinations: { groupings }
225
- BOLD files: { bolds }
226
-
227
- Please file a bug-report with the nibabies developers at:
228
- https://github.com/nipreps/nibabies/issues/new/choose
229
- """
230
- raise RuntimeError (msg )
231
-
232
- return groupings
233
-
234
-
235
130
def validate_input_dir (exec_env , bids_dir , participant_label ):
236
131
# Ignore issues and warnings that should not influence NiBabies
237
132
import subprocess
0 commit comments