@@ -28,8 +28,8 @@ def init_dmriprep_wf(
28
28
output_resolution ,
29
29
bet_dwi ,
30
30
bet_mag ,
31
- omp_nthreads ,
32
31
acqp_file ,
32
+ omp_nthreads ,
33
33
ignore ,
34
34
work_dir ,
35
35
synb0_dir
@@ -55,8 +55,8 @@ def init_dmriprep_wf(
55
55
output_resolution=(1, 1, 1),
56
56
bet_dwi=0.3,
57
57
bet_mag=0.3,
58
- omp_nthreads=1,
59
58
acqp_file='',
59
+ omp_nthreads=1,
60
60
ignore=[],
61
61
work_dir='.',
62
62
synb0_dir=''
@@ -87,13 +87,14 @@ def init_dmriprep_wf(
87
87
acqp_file: str
88
88
Optionally supply eddy acquisition parameters file
89
89
ignore: list
90
- Preprocessing steps to skip (may include 'denoise', 'unring', 'fieldmaps'
90
+ Preprocessing steps to skip (may include 'denoise', 'unring', 'fieldmaps')
91
91
work_dir: str
92
92
Directory in which to store workflow execution state and temporary files
93
93
synb0_dir: str
94
94
Direction in which synb0 derivatives are saved
95
95
96
96
"""
97
+
97
98
dmriprep_wf = pe .Workflow (name = 'dmriprep_wf' )
98
99
dmriprep_wf .base_dir = work_dir
99
100
@@ -231,47 +232,100 @@ def init_single_subject_wf(
231
232
subject_wf = pe .Workflow (name = name )
232
233
233
234
for dwi_file in subject_data ['dwi' ]:
235
+ multiple_dwis = isinstance (dwi_file , list )
236
+
237
+ if multiple_dwis :
238
+ print (dwi_file )
239
+ ref_file = dwi_file [0 ]
240
+
241
+ from .dwi import init_dwi_concat_wf
242
+
243
+ dwi_concat_wf = init_dwi_concat_wf (ref_file , dwi_file )
244
+
245
+ concat_spec = dwi_concat_wf .get_node ('inputnode' )
246
+ concat_spec .inputs .ref_file = ref_file
247
+ concat_spec .inputs .dwi_list = dwi_file
248
+ concat_spec .inputs .bvec_list = [layout .get_bvec (bvec ) for bvec in dwi_file ]
249
+ concat_spec .inputs .bval_list = [layout .get_bval (bval ) for bval in dwi_file ]
250
+
251
+ metadata = layout .get_metadata (ref_file )
252
+
253
+ dwi_preproc_wf = init_dwi_preproc_wf (
254
+ layout = layout ,
255
+ output_dir = output_dir ,
256
+ subject_id = subject_id ,
257
+ dwi_file = dwi_file ,
258
+ metadata = metadata ,
259
+ b0_thresh = b0_thresh ,
260
+ output_resolution = output_resolution ,
261
+ bet_dwi = bet_dwi ,
262
+ bet_mag = bet_mag ,
263
+ omp_nthreads = omp_nthreads ,
264
+ acqp_file = acqp_file ,
265
+ ignore = ignore ,
266
+ synb0_dir = synb0_dir
267
+ )
268
+
269
+ dwi_preproc_wf .base_dir = os .path .join (
270
+ os .path .abspath (work_dir ), subject_id
271
+ )
272
+
273
+ inputspec = dwi_preproc_wf .get_node ('inputnode' )
274
+ inputspec .inputs .subject_id = subject_id
275
+ inputspec .inputs .dwi_meta = metadata
276
+ inputspec .inputs .out_dir = os .path .abspath (output_dir )
277
+
278
+ subject_wf .connect ([
279
+ (dwi_concat_wf , dwi_preproc_wf , [('outputnode.dwi_file' , 'inputnode.dwi_file' ),
280
+ ('outputnode.bvec_file' , 'inputnode.bvec_file' ),
281
+ ('outputnode.bval_file' , 'inputnode.bval_file' )])
282
+ ])
283
+
284
+ else :
285
+ ref_file = dwi_file
286
+
287
+ metadata = layout .get_metadata (ref_file )
288
+
289
+ dwi_preproc_wf = init_dwi_preproc_wf (
290
+ layout = layout ,
291
+ output_dir = output_dir ,
292
+ subject_id = subject_id ,
293
+ dwi_file = dwi_file ,
294
+ metadata = metadata ,
295
+ b0_thresh = b0_thresh ,
296
+ output_resolution = output_resolution ,
297
+ bet_dwi = bet_dwi ,
298
+ bet_mag = bet_mag ,
299
+ omp_nthreads = omp_nthreads ,
300
+ acqp_file = acqp_file ,
301
+ ignore = ignore ,
302
+ synb0_dir = synb0_dir
303
+ )
304
+
305
+ dwi_preproc_wf .base_dir = os .path .join (
306
+ os .path .abspath (work_dir ), subject_id
307
+ )
308
+
309
+ inputspec = dwi_preproc_wf .get_node ('inputnode' )
310
+ inputspec .inputs .subject_id = subject_id
311
+ inputspec .inputs .dwi_file = dwi_file
312
+ inputspec .inputs .dwi_meta = metadata
313
+ inputspec .inputs .bvec_file = layout .get_bvec (dwi_file )
314
+ inputspec .inputs .bval_file = layout .get_bval (dwi_file )
315
+ inputspec .inputs .out_dir = os .path .abspath (output_dir )
316
+
234
317
entities = layout .parse_file_entities (dwi_file )
235
318
if 'session' in entities :
236
319
session_id = entities ['session' ]
237
320
else :
238
321
session_id = None
239
- metadata = layout .get_metadata (dwi_file )
240
-
241
- dwi_preproc_wf = init_dwi_preproc_wf (
242
- layout = layout ,
243
- output_dir = output_dir ,
244
- subject_id = subject_id ,
245
- dwi_file = dwi_file ,
246
- metadata = metadata ,
247
- b0_thresh = b0_thresh ,
248
- output_resolution = output_resolution ,
249
- bet_dwi = bet_dwi ,
250
- bet_mag = bet_mag ,
251
- omp_nthreads = omp_nthreads ,
252
- acqp_file = acqp_file ,
253
- ignore = ignore ,
254
- synb0_dir = synb0_dir
255
- )
256
322
257
323
datasink_wf = init_dwi_derivatives_wf (
258
324
subject_id = subject_id ,
259
325
session_id = session_id ,
260
326
output_folder = output_dir
261
327
)
262
328
263
- dwi_preproc_wf .base_dir = os .path .join (
264
- os .path .abspath (work_dir ), subject_id
265
- )
266
-
267
- inputspec = dwi_preproc_wf .get_node ('inputnode' )
268
- inputspec .inputs .subject_id = subject_id
269
- inputspec .inputs .dwi_file = dwi_file
270
- inputspec .inputs .dwi_meta = metadata
271
- inputspec .inputs .bvec_file = layout .get_bvec (dwi_file )
272
- inputspec .inputs .bval_file = layout .get_bval (dwi_file )
273
- inputspec .inputs .out_dir = os .path .abspath (output_dir )
274
-
275
329
ds_inputspec = datasink_wf .get_node ('inputnode' )
276
330
ds_inputspec .inputs .subject_id = subject_id
277
331
ds_inputspec .inputs .session_id = session_id
@@ -312,23 +366,3 @@ def init_single_subject_wf(
312
366
subject_wf .add_nodes ([full_wf ])
313
367
314
368
return subject_wf
315
-
316
-
317
- def group_dwis (dwi_files , sessions , concat_dwis ):
318
-
319
- all_dwis = []
320
-
321
- if sessions :
322
- session_dwi_groups = []
323
- for session in sessions :
324
- session_dwi_files = [img for img in dwi_files if 'ses-{}' .format (session ) in img ]
325
- for f in session_dwi_files :
326
- if any (acq in f for acq in concat_dwis ):
327
- session_dwi_groups .append (f )
328
- else :
329
- all_dwis .append (f )
330
- all_dwis .append (session_dwi_groups )
331
- else :
332
- all_dwis .append (f )
333
-
334
- return all_dwis
0 commit comments