10
10
11
11
from nipype .pipeline import engine as pe
12
12
from nipype .interfaces import fsl , mrtrix3 , utility as niu
13
- from numba import cuda
14
13
15
14
from .artifacts import init_dwi_artifacts_wf
15
+ from .eddy import init_dwi_eddy_wf
16
16
from .tensor import init_dwi_tensor_wf
17
- from ..fieldmap .base import init_sdc_prep_wf
17
+ from ..fieldmap .base import init_sdc_wf
18
18
19
19
FMAP_PRIORITY = {'epi' : 0 , 'fieldmap' : 1 , 'phasediff' : 2 , 'phase' : 3 , 'syn' : 4 }
20
20
@@ -32,6 +32,8 @@ def init_dwi_preproc_wf(
32
32
acqp_file ,
33
33
omp_nthreads ,
34
34
ignore ,
35
+ use_ants ,
36
+ use_brainsuite ,
35
37
synb0_dir
36
38
):
37
39
"""
@@ -50,6 +52,37 @@ def init_dwi_preproc_wf(
50
52
51
53
wf_name = _get_wf_name (dwi_file )
52
54
55
+ if isinstance (dwi_file , list ):
56
+ ref_file = dwi_file [0 ]
57
+ else :
58
+ ref_file = dwi_file
59
+
60
+ # For doc building purposes
61
+ if not hasattr (layout , 'parse_file_entities' ):
62
+ metadata = {
63
+ 'PhaseEncodingDirection' : 'j-' ,
64
+ 'TotalReadoutTime' : 0.05
65
+ }
66
+ fmaps = [{
67
+ 'suffix' : 'phasediff' ,
68
+ 'phasediff' : 'sub-01/fmap/sub-01_phasediff.nii.gz' ,
69
+ 'magnitude1' : 'sub-01/fmap/sub-01_magnitude1.nii.gz' ,
70
+ 'magnitude2' : 'sub-01/fmap/sub-01_magnitude2.nii.gz'
71
+ }]
72
+ else :
73
+ metadata = layout .get_metadata (ref_file )
74
+ # Find fieldmaps. Options: (epi|fieldmap|phasediff|phase1|phase2|syn)
75
+ fmaps = []
76
+ if 'fieldmaps' not in ignore :
77
+ for fmap in layout .get_fieldmap (ref_file , return_list = True ):
78
+ fmap ['metadata' ] = layout .get_metadata (fmap [fmap ['suffix' ]])
79
+ fmaps .append (fmap )
80
+
81
+ if (use_ants and not fmaps ):
82
+ fmaps .append ({'suffix' : 'ants' })
83
+ if (use_brainsuite and not fmaps ):
84
+ fmaps .append ({'suffix' : 'brainsuite' })
85
+
53
86
dwi_wf = pe .Workflow (name = wf_name )
54
87
55
88
# # If use_synb0 set, get synb0 from files
@@ -69,7 +102,7 @@ def init_dwi_preproc_wf(
69
102
)
70
103
fmaps .append (fmap )
71
104
72
- sdc_wf = init_sdc_prep_wf (
105
+ dwi_sdc_wf = init_sdc_wf (
73
106
subject_id ,
74
107
fmaps ,
75
108
metadata ,
@@ -246,14 +279,16 @@ def b0_average(in_dwi, in_bval, b0_thresh, out_file=None):
246
279
fsl .BET (frac = bet_dwi , mask = True , robust = True ), name = 'bet_dwi_pre'
247
280
)
248
281
249
- ecc = pe .Node (
250
- fsl .Eddy (num_threads = omp_nthreads , repol = True , cnr_maps = True , residuals = True ),
251
- name = 'fsl_eddy' )
252
- try :
253
- if cuda .gpus :
254
- ecc .inputs .use_cuda = True
255
- except :
256
- ecc .inputs .use_cuda = False
282
+ dwi_eddy_wf = init_dwi_eddy_wf ()
283
+
284
+ # ecc = pe.Node(
285
+ # fsl.Eddy(num_threads=omp_nthreads, repol=True, cnr_maps=True, residuals=True),
286
+ # name='fsl_eddy')
287
+ # try:
288
+ # if cuda.gpus:
289
+ # ecc.inputs.use_cuda = True
290
+ # except:
291
+ # ecc.inputs.use_cuda = False
257
292
258
293
denoise_eddy = pe .Node (mrtrix3 .DWIDenoise (), name = 'denoise_eddy' )
259
294
@@ -286,44 +321,45 @@ def get_b0_mask_fn(b0_file):
286
321
input_names = ['b0_file' ], output_names = ['mask_file' ], function = get_b0_mask_fn ),
287
322
name = 'getB0Mask' )
288
323
289
- tensor_wf = init_dwi_tensor_wf ()
324
+ dwi_tensor_wf = init_dwi_tensor_wf ()
290
325
291
326
dwi_wf .connect ([
292
327
(inputnode , gen_idx , [('dwi_file' , 'in_file' )]),
293
328
(inputnode , acqp , [('dwi_file' , 'in_file' ), ('dwi_meta' , 'metadata' )]),
294
329
(inputnode , dwi_artifacts_wf , [('dwi_file' , 'inputnode.dwi_file' )]),
295
330
(dwi_artifacts_wf , avg_b0_0 , [('outputnode.out_file' , 'in_dwi' )]),
296
- (dwi_artifacts_wf , ecc , [('outputnode.out_file' , 'in_file ' )]),
331
+ (dwi_artifacts_wf , dwi_eddy_wf , [('outputnode.out_file' , 'inputnode.dwi_file ' )]),
297
332
(inputnode , avg_b0_0 , [('bval_file' , 'in_bval' )]),
298
333
(avg_b0_0 , bet_dwi0 , [('out_file' , 'in_file' )]),
299
- (inputnode , ecc , [('bval_file' , 'in_bval ' ),
300
- ('bvec_file' , 'in_bvec ' )]),
301
- (bet_dwi0 , ecc , [('mask_file' , 'in_mask ' )]),
302
- (gen_idx , ecc , [('out_file' , 'in_index ' )]),
303
- (ecc , denoise_eddy , [('out_corrected ' , 'in_file' )]),
304
- (ecc , bias_correct , [('out_corrected ' , 'in_file' ),
305
- ( 'out_rotated_bvecs ' , 'in_bvec' )]),
334
+ (inputnode , dwi_eddy_wf , [('bval_file' , 'inputnode.bval_file ' ),
335
+ ('bvec_file' , 'inputnode.bvec_file ' )]),
336
+ (bet_dwi0 , dwi_eddy_wf , [('mask_file' , 'inputnode.mask_file ' )]),
337
+ (gen_idx , dwi_eddy_wf , [('out_file' , 'inputnode.index ' )]),
338
+ (dwi_eddy_wf , denoise_eddy , [('outputnode.out_file ' , 'in_file' )]),
339
+ (dwi_eddy_wf , bias_correct , [('outputnode.out_file ' , 'in_file' ),
340
+ ( 'outputnode.out_bvec ' , 'in_bvec' )]),
306
341
(inputnode , bias_correct , [('bval_file' , 'in_bval' )]),
307
342
(bias_correct , fslroi , [('out_file' , 'in_file' )]),
308
343
(fslroi , b0mask_node , [('roi_file' , 'b0_file' )]),
309
- (ecc , eddy_quad , [(('out_corrected ' , get_path ), 'base_name' ),
310
- (('out_corrected ' , get_qc_path ), 'output_dir' ),
311
- ( 'out_rotated_bvecs ' , 'bvec_file' )]),
344
+ (dwi_eddy_wf , eddy_quad , [(('outputnode.out_file ' , get_path ), 'base_name' ),
345
+ (('outputnode.out_file ' , get_qc_path ), 'output_dir' ),
346
+ ( 'outputnode.out_bvec ' , 'bvec_file' )]),
312
347
(inputnode , eddy_quad , [('bval_file' , 'bval_file' )]),
313
348
(b0mask_node , eddy_quad , [('mask_file' , 'mask_file' )]),
314
349
(gen_idx , eddy_quad , [('out_file' , 'idx_file' )]),
315
- (inputnode , tensor_wf , [('bval_file' , 'inputnode.bval_file' )]),
316
- (b0mask_node , tensor_wf , [('mask_file' , 'inputnode.mask_file' )]),
317
- (ecc , tensor_wf , [('out_corrected ' , 'inputnode.dwi_file' ),
318
- ( 'out_rotated_bvecs ' , 'inputnode.bvec_file' )])
350
+ (inputnode , dwi_tensor_wf , [('bval_file' , 'inputnode.bval_file' )]),
351
+ (b0mask_node , dwi_tensor_wf , [('mask_file' , 'inputnode.mask_file' )]),
352
+ (dwi_eddy_wf , dwi_tensor_wf , [('outputnode.out_file ' , 'inputnode.dwi_file' ),
353
+ ( 'outputnode.out_bvec ' , 'inputnode.bvec_file' )])
319
354
])
320
355
321
356
if acqp_file :
322
- ecc .inputs .in_acqp = acqp_file
357
+ eddy_inputspec = dwi_eddy_wf .get_node ('inputnode' )
358
+ eddy_inputspec .inputs .acqp = acqp_file
323
359
eddy_quad .inputs .param_file = acqp_file
324
360
else :
325
361
dwi_wf .connect ([
326
- (acqp , ecc , [('out_file' , 'in_acqp ' )]),
362
+ (acqp , dwi_eddy_wf , [('out_file' , 'inputnode.acqp ' )]),
327
363
(acqp , eddy_quad , [('out_file' , 'param_file' )])
328
364
])
329
365
@@ -349,38 +385,39 @@ def get_b0_mask_fn(b0_file):
349
385
# ecc.inputs.in_acqp = acqp_file
350
386
# else:
351
387
# Decide what ecc will take: topup or fmap
352
- fmaps .sort (key = lambda fmap : FMAP_PRIORITY [fmap ['suffix' ]])
353
- fmap = fmaps [0 ]
354
- # Else If epi files detected
355
- if fmap ['suffix' ] == 'epi' :
356
- dwi_wf .connect ([
357
- (sdc_wf , ecc , [('outputnode.out_topup' , 'in_topup_fieldcoef' ),
358
- ('outputnode.out_movpar' , 'in_topup_movpar' )])
359
- ])
360
- # Otherwise (fieldmaps)
361
- else :
362
- dwi_wf .connect ([
363
- (bet_dwi0 , sdc_wf , [('out_file' , 'inputnode.b0_stripped' )]),
364
- (sdc_wf , ecc , [('outputnode.out_fmap' , 'field' )])
365
- ])
388
+ if fmaps :
389
+ fmaps .sort (key = lambda fmap : FMAP_PRIORITY [fmap ['suffix' ]])
390
+ fmap = fmaps [0 ]
391
+ # Else If epi files detected
392
+ if fmap ['suffix' ] == 'epi' :
393
+ dwi_wf .connect ([
394
+ (dwi_sdc_wf , dwi_eddy_wf , [('outputnode.out_topup' , 'inputnode.topup_fieldcoef' ),
395
+ ('outputnode.out_movpar' , 'inputnode.topup_movpar' )])
396
+ ])
397
+ # Otherwise (fieldmaps)
398
+ else :
399
+ dwi_wf .connect ([
400
+ (bet_dwi0 , dwi_sdc_wf , [('out_file' , 'inputnode.b0_stripped' )]),
401
+ (dwi_sdc_wf , dwi_eddy_wf , [('outputnode.out_fmap' , 'inputnode.fieldmap_file' )])
402
+ ])
366
403
367
404
dwi_wf .connect ([
368
- (ecc , outputnode , [('out_corrected ' , 'out_dwi' )]),
405
+ (dwi_eddy_wf , outputnode , [('outputnode.out_file ' , 'out_dwi' )]),
369
406
(inputnode , outputnode , [('bval_file' , 'out_bval' )]),
370
- (ecc , outputnode , [('out_rotated_bvecs ' , 'out_bvec' )]),
407
+ (dwi_eddy_wf , outputnode , [('outputnode.out_bvec ' , 'out_bvec' )]),
371
408
(gen_idx , outputnode , [('out_file' , 'index' )]),
372
409
(acqp , outputnode , [('out_file' , 'acq_params' )]),
373
410
(b0mask_node , outputnode , [('mask_file' , 'out_mask' )]),
374
411
(avg_b0_0 , outputnode , [('out_file' , 'out_b0_pre' )]),
375
412
(bet_dwi0 , outputnode , [('mask_file' , 'out_b0_mask_pre' )]),
376
413
(eddy_quad , outputnode , [('qc_json' , 'out_eddy_quad_json' ),
377
414
('qc_pdf' , 'out_eddy_quad_pdf' )]),
378
- (tensor_wf , outputnode , [('outputnode.FA_file' , 'out_dtifit_FA' ),
379
- ('outputnode.MD_file' , 'out_dtifit_MD' ),
380
- ('outputnode.AD_file' , 'out_dtifit_AD' ),
381
- ('outputnode.RD_file' , 'out_dtifit_RD' ),
382
- ('outputnode.V1_file' , 'out_dtifit_V1' ),
383
- ('outputnode.sse_file' , 'out_dtifit_sse' )])
415
+ (dwi_tensor_wf , outputnode , [('outputnode.FA_file' , 'out_dtifit_FA' ),
416
+ ('outputnode.MD_file' , 'out_dtifit_MD' ),
417
+ ('outputnode.AD_file' , 'out_dtifit_AD' ),
418
+ ('outputnode.RD_file' , 'out_dtifit_RD' ),
419
+ ('outputnode.V1_file' , 'out_dtifit_V1' ),
420
+ ('outputnode.sse_file' , 'out_dtifit_sse' )])
384
421
])
385
422
386
423
return dwi_wf
0 commit comments