10
10
11
11
from bids import BIDSLayout
12
12
from nipype .pipeline import engine as pe
13
- from nipype .interfaces import ants , fsl , mrtrix3 , utility as niu
13
+ from nipype .interfaces import fsl , mrtrix3 , utility as niu
14
14
from numba import cuda
15
15
16
- from .prep_dwi import init_prep_dwi_wf
17
- from .tensor import init_tensor_wf
16
+ from .artifacts import init_dwi_artifacts_wf
17
+ from .tensor import init_dwi_tensor_wf
18
18
19
- # from ..fieldmap.base import init_sdc_prep_wf
19
+ from ..fieldmap .base import init_sdc_prep_wf
20
20
21
21
FMAP_PRIORITY = {"epi" : 0 , "fieldmap" : 1 , "phasediff" : 2 , "phase" : 3 , "syn" : 4 }
22
22
23
23
24
- def init_dwi_preproc_wf (subject_id , dwi_file , metadata , parameters ):
24
+ def init_dwi_preproc_wf (
25
+ subject_id ,
26
+ dwi_file ,
27
+ metadata ,
28
+ layout ,
29
+ ignore ,
30
+ b0_thresh ,
31
+ output_resolution ,
32
+ bet_dwi ,
33
+ bet_mag ,
34
+ omp_nthreads ,
35
+ synb0_dir
36
+ ):
37
+
38
+ fmaps = []
39
+ synb0 = ""
40
+
41
+ # If use_synb0 set, get synb0 from files
42
+ if synb0_dir :
43
+ synb0_layout = BIDSLayout (
44
+ synb0_dir , validate = False , derivatives = True
45
+ )
46
+ synb0 = synb0_layout .get (subject = subject_id , return_type = "file" )[0 ]
47
+ else :
48
+ fmaps = layout .get_fieldmap (dwi_file , return_list = True )
49
+ if not fmaps :
50
+ raise Exception (
51
+ "No fieldmaps found for participant {}. "
52
+ "All workflows require fieldmaps" .format (subject_id )
53
+ )
25
54
26
- # fmaps = []
27
- # synb0 = ""
28
- #
29
- # # If use_synb0 set, get synb0 from files
30
- # if parameters.synb0_dir:
31
- # synb0_layout = BIDSLayout(
32
- # parameters.synb0_dir, validate=False, derivatives=True
33
- # )
34
- # synb0 = synb0_layout.get(subject=subject_id, return_type="file")[0]
35
- # else:
36
- # fmaps = parameters.layout.get_fieldmap(dwi_file, return_list=True)
37
- # if not fmaps:
38
- # raise Exception(
39
- # "No fieldmaps found for participant {}. "
40
- # "All workflows require fieldmaps".format(subject_id)
41
- # )
42
- #
43
- # for fmap in fmaps:
44
- # fmap["metadata"] = parameters.layout.get_metadata(
45
- # fmap[fmap["suffix"]]
46
- # )
47
- #
48
- # sdc_wf = init_sdc_prep_wf(
49
- # subject_id,
50
- # fmaps,
51
- # metadata,
52
- # parameters.layout,
53
- # parameters.bet_mag,
54
- # synb0,
55
- # )
55
+ for fmap in fmaps :
56
+ fmap ["metadata" ] = layout .get_metadata (
57
+ fmap [fmap ["suffix" ]]
58
+ )
59
+
60
+ sdc_wf = init_sdc_prep_wf (
61
+ subject_id ,
62
+ fmaps ,
63
+ metadata ,
64
+ layout ,
65
+ bet_mag ,
66
+ synb0 ,
67
+ )
56
68
57
69
multiple_runs = isinstance (dwi_file , list )
58
70
@@ -102,7 +114,7 @@ def init_dwi_preproc_wf(subject_id, dwi_file, metadata, parameters):
102
114
name = "outputnode" ,
103
115
)
104
116
105
- dwi_prep_wf = init_prep_dwi_wf ( parameters . ignore , parameters . output_resolution )
117
+ dwi_artifacts_wf = init_dwi_artifacts_wf ( ignore )
106
118
107
119
def gen_index (in_file ):
108
120
"""
@@ -118,6 +130,7 @@ def gen_index(in_file):
118
130
119
131
out_file
120
132
The output index file.
133
+
121
134
"""
122
135
123
136
import os
@@ -143,6 +156,23 @@ def gen_index(in_file):
143
156
)
144
157
145
158
def gen_acqparams (in_file , metadata ):
159
+ """
160
+ Create an acquisition parameters file for ``eddy``
161
+
162
+ **Inputs**
163
+
164
+ in_file
165
+ The dwi file
166
+ metadata
167
+ The BIDS metadata of the dwi file
168
+
169
+ **Outputs**
170
+
171
+ out_file
172
+ The output acquisition parameters file
173
+
174
+ """
175
+
146
176
import os
147
177
from nipype .utils .filemanip import fname_presuffix
148
178
@@ -189,7 +219,7 @@ def gen_acqparams(in_file, metadata):
189
219
190
220
def b0_average (in_dwi , in_bval , b0_thresh , out_file = None ):
191
221
"""
192
- A function that averages the *b0* volumes from a DWI dataset.
222
+ Averages the *b0* volumes from a DWI dataset.
193
223
As current dMRI data are being acquired with all b-values > 0.0,
194
224
the *lowb* volumes are selected by specifying the parameter b0_thresh.
195
225
.. warning:: *b0* should be already registered (head motion artifact
@@ -229,16 +259,16 @@ def b0_average(in_dwi, in_bval, b0_thresh, out_file=None):
229
259
name = "b0_avg_pre" ,
230
260
)
231
261
232
- avg_b0_0 .inputs .b0_thresh = parameters . b0_thresh
262
+ avg_b0_0 .inputs .b0_thresh = b0_thresh
233
263
234
264
bet_dwi0 = pe .Node (
235
- fsl .BET (frac = parameters . bet_dwi , mask = True , robust = True ), name = "bet_dwi_pre"
265
+ fsl .BET (frac = bet_dwi , mask = True , robust = True ), name = "bet_dwi_pre"
236
266
)
237
267
238
268
ecc = pe .Node (fsl .Eddy (repol = True , cnr_maps = True , residuals = True ), name = "fsl_eddy" )
239
269
240
- if parameters . omp_nthreads :
241
- ecc .inputs .num_threads = parameters . omp_nthreads
270
+ if omp_nthreads :
271
+ ecc .inputs .num_threads = omp_nthreads
242
272
243
273
try :
244
274
if cuda .gpus :
@@ -253,15 +283,6 @@ def b0_average(in_dwi, in_bval, b0_thresh, out_file=None):
253
283
get_path = lambda x : x .split (".nii.gz" )[0 ].split ("_fix" )[0 ]
254
284
get_qc_path = lambda x : x .split (".nii.gz" )[0 ] + ".qc"
255
285
256
- if set (parameters .ignore ) == set (["denoise" , "unring" ]):
257
- wf .connect (
258
- [
259
- (inputnode , avg_b0_0 , [("dwi_file" , "in_file" )])(
260
- inputnode , ecc , [("dwi_file" , "in_file" )]
261
- )
262
- ]
263
- )
264
-
265
286
fslroi = pe .Node (fsl .ExtractROI (t_min = 0 , t_size = 1 ), name = "fslroi" )
266
287
267
288
bias_correct = pe .Node (mrtrix3 .DWIBiasCorrect (use_ants = True ), name = "bias_correct" )
@@ -342,7 +363,7 @@ def get_b0_mask_fn(b0_file):
342
363
)
343
364
344
365
# # If synb0 is meant to be used
345
- # if parameters. synb0_dir:
366
+ # if synb0_dir:
346
367
# dwi_wf.connect(
347
368
# [
348
369
# (
@@ -360,7 +381,7 @@ def get_b0_mask_fn(b0_file):
360
381
# ),
361
382
# ]
362
383
# )
363
- # ecc.inputs.in_acqp = parameters. acqp_file
384
+ # ecc.inputs.in_acqp = acqp_file
364
385
# else:
365
386
# # Decide what ecc will take: topup or fmap
366
387
# fmaps.sort(key=lambda fmap: FMAP_PRIORITY[fmap["suffix"]])
0 commit comments