@@ -72,6 +72,7 @@ def init_dwi_preproc_wf(dwi_file, has_fieldmap=False):
72
72
SimpleBeforeAfterRPT as SimpleBeforeAfter ,
73
73
)
74
74
from niworkflows .workflows .epi .refmap import init_epi_reference_wf
75
+ from sdcflows .workflows .ancillary import init_brainextraction_wf
75
76
76
77
from ...interfaces .vectors import CheckGradientTable
77
78
from .outputs import init_dwi_derivatives_wf , init_reportlets_wf
@@ -148,7 +149,16 @@ def init_dwi_preproc_wf(dwi_file, has_fieldmap=False):
148
149
name = "dwi_reference_wf" ,
149
150
)
150
151
151
- dwi_derivatives_wf = init_dwi_derivatives_wf (output_dir = str (config .execution .output_dir ))
152
+ brainextraction_wf = init_brainextraction_wf ()
153
+ dwi_derivatives_wf = init_dwi_derivatives_wf (
154
+ output_dir = str (config .execution .output_dir )
155
+ )
156
+
157
+ # If has_fieldmaps this will hold the corrected reference, original otherwise
158
+ buffernode = pe .Node (
159
+ niu .IdentityInterface (fields = ["dwi_reference" , "dwi_mask" ]),
160
+ name = "buffernode" ,
161
+ )
152
162
153
163
# MAIN WORKFLOW STRUCTURE
154
164
# fmt: off
@@ -158,12 +168,16 @@ def init_dwi_preproc_wf(dwi_file, has_fieldmap=False):
158
168
("in_bvec" , "in_bvec" ),
159
169
("in_bval" , "in_bval" )]),
160
170
(inputnode , dwi_reference_wf , [(("dwi_file" , _aslist ), "inputnode.in_files" )]),
171
+ (dwi_reference_wf , brainextraction_wf , [
172
+ ("outputnode.epi_ref_file" , "inputnode.in_file" )]),
161
173
(gradient_table , dwi_reference_wf , [(("b0_mask" , _aslist ), "inputnode.t_masks" )]),
162
- (gradient_table , outputnode , [("out_rasb" , "gradients_rasb" )]),
163
- (outputnode , dwi_derivatives_wf , [
174
+ (buffernode , dwi_derivatives_wf , [
164
175
("dwi_reference" , "inputnode.dwi_ref" ),
165
176
("dwi_mask" , "inputnode.dwi_mask" ),
166
177
]),
178
+ (buffernode , outputnode , [("dwi_reference" , "dwi_reference" ),
179
+ ("dwi_mask" , "dwi_mask" )]),
180
+ (gradient_table , outputnode , [("out_rasb" , "gradients_rasb" )]),
167
181
])
168
182
# fmt: on
169
183
@@ -205,21 +219,14 @@ def _bold_reg_suffix(fallback):
205
219
("t1w_mask" , "in_mask" )]),
206
220
(inputnode , ds_report_reg , [("dwi_file" , "source_file" )]),
207
221
# BBRegister
208
- (dwi_reference_wf , bbr_wf , [
209
- ("outputnode.epi_ref_file" , "inputnode.in_file" )
210
- ]),
222
+ (buffernode , bbr_wf , [("dwi_reference" , "inputnode.in_file" )]),
211
223
(bbr_wf , ds_report_reg , [
212
- (' outputnode.out_report' , ' in_file' ),
213
- ((' outputnode.fallback' , _bold_reg_suffix ), ' desc' )]),
224
+ (" outputnode.out_report" , " in_file" ),
225
+ ((" outputnode.fallback" , _bold_reg_suffix ), " desc" )]),
214
226
])
215
227
# fmt: on
216
228
217
229
if "eddy" not in config .workflow .ignore :
218
- from sdcflows .workflows .ancillary import init_brainextraction_wf
219
-
220
- # Brain extraction not run just yet
221
- brainextraction_wf = init_brainextraction_wf ()
222
-
223
230
# Eddy distortion correction
224
231
eddy_wf = init_eddy_wf (debug = config .execution .debug )
225
232
eddy_wf .inputs .inputnode .metadata = layout .get_metadata (str (dwi_file ))
@@ -249,13 +256,9 @@ def _bold_reg_suffix(fallback):
249
256
("in_bvec" , "inputnode.in_bvec" ),
250
257
("in_bval" , "inputnode.in_bval" )]),
251
258
(inputnode , ds_report_eddy , [("dwi_file" , "source_file" )]),
252
- (dwi_reference_wf , brainextraction_wf , [
253
- ("outputnode.epi_ref_file" , "inputnode.in_file" )]),
254
- (brainextraction_wf , eddy_wf , [
255
- ("outputnode.out_mask" , "inputnode.dwi_mask" ),
256
- ]),
259
+ (brainextraction_wf , eddy_wf , [("outputnode.out_mask" , "inputnode.dwi_mask" )]),
257
260
(brainextraction_wf , eddy_report , [("outputnode.out_file" , "before" )]),
258
- (eddy_wf , eddy_report , [(' outputnode.eddy_ref_image' , ' after' )]),
261
+ (eddy_wf , eddy_report , [(" outputnode.eddy_ref_image" , " after" )]),
259
262
(eddy_report , ds_report_eddy , [("out_report" , "in_file" )]),
260
263
])
261
264
# fmt:on
@@ -281,7 +284,10 @@ def _bold_reg_suffix(fallback):
281
284
if not has_fieldmap :
282
285
# fmt: off
283
286
workflow .connect ([
284
- (dwi_reference_wf , outputnode , [("outputnode.epi_ref_file" , "dwi_reference" )]),
287
+ (brainextraction_wf , buffernode , [
288
+ ("outputnode.out_file" , "dwi_reference" ),
289
+ ("outputnode.out_mask" , "dwi_mask" ),
290
+ ]),
285
291
])
286
292
# fmt: on
287
293
return workflow
@@ -337,11 +343,11 @@ def _bold_reg_suffix(fallback):
337
343
(dwi_reference_wf , unwarp_wf , [("outputnode.epi_ref_file" , "inputnode.distorted" )]),
338
344
(coeff2epi_wf , unwarp_wf , [
339
345
("outputnode.fmap_coeff" , "inputnode.fmap_coeff" )]),
340
- (dwi_reference_wf , sdc_report , [("outputnode.epi_ref_file " , "before" )]),
346
+ (brainextraction_wf , sdc_report , [("outputnode.out_file " , "before" )]),
341
347
(unwarp_wf , sdc_report , [("outputnode.corrected" , "after" ),
342
348
("outputnode.corrected_mask" , "wm_seg" )]),
343
349
(sdc_report , reportlets_wf , [("out_report" , "inputnode.sdc_report" )]),
344
- (unwarp_wf , outputnode , [("outputnode.corrected" , "dwi_reference" ),
350
+ (unwarp_wf , buffernode , [("outputnode.corrected" , "dwi_reference" ),
345
351
("outputnode.corrected_mask" , "dwi_mask" )]),
346
352
])
347
353
# fmt: on
@@ -355,10 +361,10 @@ def _get_wf_name(filename):
355
361
356
362
Examples
357
363
--------
358
- >>> _get_wf_name(' /completely/made/up/path/sub-01_dir-AP_acq-64grad_dwi.nii.gz' )
364
+ >>> _get_wf_name(" /completely/made/up/path/sub-01_dir-AP_acq-64grad_dwi.nii.gz" )
359
365
'dwi_preproc_dir_AP_acq_64grad_wf'
360
366
361
- >>> _get_wf_name(' /completely/made/up/path/sub-01_dir-RL_run-01_echo-1_dwi.nii.gz' )
367
+ >>> _get_wf_name(" /completely/made/up/path/sub-01_dir-RL_run-01_echo-1_dwi.nii.gz" )
362
368
'dwi_preproc_dir_RL_run_01_echo_1_wf'
363
369
364
370
"""
0 commit comments