6
6
7
7
from niworkflows .engine .workflows import LiterateWorkflow as Workflow
8
8
from ...interfaces import DerivativesDataSink
9
- from sdcflows .workflows .apply .registration import init_coeff2epi_wf
10
9
11
- def init_dwi_preproc_wf (dwi_file ):
10
+
11
+ def init_dwi_preproc_wf (dwi_file , has_fieldmap = False ):
12
12
"""
13
13
Build a preprocessing workflow for one DWI run.
14
14
@@ -30,7 +30,8 @@ def init_dwi_preproc_wf(dwi_file):
30
30
----------
31
31
dwi_file : :obj:`os.PathLike`
32
32
One diffusion MRI dataset to be processed.
33
- sdc : :bool:
33
+ has_fieldmap : :obj:`bool`
34
+ Build the workflow with a path to register a fieldmap to the DWI.
34
35
35
36
Inputs
36
37
------
@@ -82,6 +83,11 @@ def init_dwi_preproc_wf(dwi_file):
82
83
"dwi_file" ,
83
84
"in_bvec" ,
84
85
"in_bval" ,
86
+ # From fmap
87
+ "fmap" ,
88
+ "fmap_ref" ,
89
+ "fmap_coeff" ,
90
+ "fmap_mask" ,
85
91
# From anatomical
86
92
"t1w_preproc" ,
87
93
"t1w_mask" ,
@@ -115,26 +121,21 @@ def init_dwi_preproc_wf(dwi_file):
115
121
mem_gb = config .DEFAULT_MEMORY_MIN_GB , omp_nthreads = config .nipype .omp_nthreads
116
122
)
117
123
118
- coeff2epi_wf = init_coeff2epi_wf (omp_nthreads = config .nipype .omp_nthreads , write_coeff = True )
119
-
120
124
# MAIN WORKFLOW STRUCTURE
121
- # fmt:off
125
+ # fmt: off
122
126
workflow .connect ([
123
127
(inputnode , gradient_table , [("dwi_file" , "dwi_file" ),
124
128
("in_bvec" , "in_bvec" ),
125
129
("in_bval" , "in_bval" )]),
126
130
(inputnode , dwi_reference_wf , [("dwi_file" , "inputnode.dwi_file" )]),
127
131
(gradient_table , dwi_reference_wf , [("b0_ixs" , "inputnode.b0_ixs" )]),
128
- (dwi_reference_wf , coeff2epi_wf , [
129
- ("outputnode.ref_image" , "target_ref" ),
130
- ("outputnode.dwi_mask" , "target_mask" ),
131
132
#outputnode, [
132
133
# ("outputnode.ref_image", "dwi_reference"),
133
134
# ("outputnode.dwi_mask", "dwi_mask"),
134
- ]),
135
+ # ]),
135
136
(gradient_table , outputnode , [("out_rasb" , "gradients_rasb" )]),
136
137
])
137
- # fmt:on
138
+ # fmt: on
138
139
139
140
if config .workflow .run_reconall :
140
141
from niworkflows .interfaces .nibabel import ApplyMask
@@ -162,7 +163,7 @@ def init_dwi_preproc_wf(dwi_file):
162
163
def _bold_reg_suffix (fallback ):
163
164
return "coreg" if fallback else "bbregister"
164
165
165
- # fmt:off
166
+ # fmt: off
166
167
workflow .connect ([
167
168
(inputnode , bbr_wf , [
168
169
("fsnative2t1w_xfm" , "inputnode.fsnative2t1w_xfm" ),
@@ -181,11 +182,30 @@ def _bold_reg_suffix(fallback):
181
182
('outputnode.out_report' , 'in_file' ),
182
183
(('outputnode.fallback' , _bold_reg_suffix ), 'desc' )]),
183
184
])
184
- # fmt:on
185
+ # fmt: on
186
+
187
+ if has_fieldmap :
188
+ from sdcflows .workflows .apply .registration import init_coeff2epi_wf
189
+ from sdcflows .workflows .apply .correction import init_unwarp_wf
190
+
191
+ coeff2epi_wf = init_coeff2epi_wf (
192
+ omp_nthreads = config .nipype .omp_nthreads , write_coeff = True
193
+ )
194
+ unwarp_wf = init_unwarp_wf (omp_nthreads = config .nipype .omp_nthreads )
195
+
196
+ # fmt: off
197
+ workflow .connect ([
198
+ (dwi_reference_wf , coeff2epi_wf , [
199
+ ("outputnode.ref_image" , "inputnode.target_ref" ),
200
+ ("outputnode.dwi_mask" , "inputnode.target_mask" )]),
201
+ (coeff2epi_wf , unwarp_wf , [
202
+ ("outputnode.fmap_coeff" , "inputnode.fmap_coeff" )])
203
+ ])
204
+ # fmt: on
185
205
186
206
# REPORTING ############################################################
187
207
reportlets_wf = init_reportlets_wf (str (config .execution .output_dir ))
188
- # fmt:off
208
+ # fmt: off
189
209
workflow .connect ([
190
210
(inputnode , reportlets_wf , [("dwi_file" , "inputnode.source_file" )]),
191
211
(dwi_reference_wf , reportlets_wf , [
@@ -194,7 +214,7 @@ def _bold_reg_suffix(fallback):
194
214
("outputnode.validation_report" , "inputnode.validation_report" ),
195
215
]),
196
216
])
197
- # fmt:on
217
+ # fmt: on
198
218
199
219
return workflow
200
220
0 commit comments