9
9
10
10
11
11
def run_dmriprep (dwi_file , bvec_file , bval_file ,
12
- subjects_dir , working_dir , out_dir ):
12
+ subjects_dir , working_dir , out_dir ):
13
13
14
14
"""
15
15
Runs dmriprep for acquisitions with just one PE direction.
@@ -234,7 +234,7 @@ def rang(b):
234
234
return dmri_corrected , bvec_rotated , art_file , motion_file , outlier_file
235
235
236
236
237
- def run_dmriprep_pe (subject_id , dwi_file , dwi_file_ap , dwi_file_pa ,
237
+ def run_dmriprep_pe (subject_id , dwi_file , dwi_file_AP , dwi_file_PA ,
238
238
bvec_file , bval_file ,
239
239
subjects_dir , working_dir , out_dir ,
240
240
eddy_niter = 5 , slice_outlier_threshold = 0.02 ):
@@ -248,10 +248,10 @@ def run_dmriprep_pe(subject_id, dwi_file, dwi_file_ap, dwi_file_pa,
248
248
dwi_file : str
249
249
Path to dwi nifti file
250
250
251
- dwi_file_ap : str
251
+ dwi_file_AP : str
252
252
Path to EPI nifti file (anterior-posterior)
253
253
254
- dwi_file_pa : str
254
+ dwi_file_PA : str
255
255
Path to EPI nifti file (posterior-anterior)
256
256
257
257
bvec_file : str
@@ -289,43 +289,33 @@ def run_dmriprep_pe(subject_id, dwi_file, dwi_file_ap, dwi_file_pa,
289
289
--------
290
290
dmriprep.run.get_dmriprep_pe_workflow
291
291
"""
292
- wf = get_dmriprep_pe_workflow (
293
- eddy_niter = eddy_niter ,
294
- slice_outlier_threshold = slice_outlier_threshold
295
- )
292
+ wf = get_dmriprep_pe_workflow ()
296
293
wf .base_dir = op .join (op .abspath (working_dir ), subject_id )
297
294
298
295
inputspec = wf .get_node ('inputspec' )
299
296
inputspec .inputs .subject_id = subject_id
300
297
inputspec .inputs .dwi_file = dwi_file
301
- inputspec .inputs .dwi_file_ap = dwi_file_ap
302
- inputspec .inputs .dwi_file_pa = dwi_file_pa
298
+ inputspec .inputs .dwi_file_ap = dwi_file_AP
299
+ inputspec .inputs .dwi_file_pa = dwi_file_PA
303
300
inputspec .inputs .bvec_file = bvec_file
304
301
inputspec .inputs .bval_file = bval_file
305
302
inputspec .inputs .subjects_dir = subjects_dir
306
303
inputspec .inputs .out_dir = op .abspath (out_dir )
304
+ inputspec .inputs .eddy_niter = eddy_niter
305
+ inputspec .inputs .slice_outlier_threshold = slice_outlier_threshold
307
306
308
307
# write the graph (this is saved to the working dir)
309
308
wf .write_graph ()
310
309
311
310
wf .run ()
312
311
313
312
314
- def get_dmriprep_pe_workflow (eddy_niter = 5 , slice_outlier_threshold = 0.02 ):
313
+ def get_dmriprep_pe_workflow ():
315
314
"""Return the dmriprep (phase encoded) nipype workflow
316
315
317
316
Parameters
318
317
----------
319
- eddy_niter : int, default=5
320
- Fixed number of eddy iterations. See
321
- https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/eddy/UsersGuide#A--niter
322
318
323
- slice_outlier_threshold: int or float
324
- Number of allowed outlier slices per volume. If this is exceeded the
325
- volume is dropped from analysis. If `slice_outlier_threshold` is an
326
- int, it is treated as number of allowed outlier slices. If
327
- `slice_outlier_threshold` is a float between 0 and 1 (exclusive), it is
328
- treated the fraction of allowed outlier slices.
329
319
330
320
Returns
331
321
-------
@@ -353,24 +343,11 @@ def get_dmriprep_pe_workflow(eddy_niter=5, slice_outlier_threshold=0.02):
353
343
'bvec_file' ,
354
344
'bval_file' ,
355
345
'subjects_dir' ,
356
- 'out_dir'
346
+ 'out_dir' ,
347
+ 'eddy_niter' ,
348
+ 'slice_outlier_threshold'
357
349
]), name = "inputspec" )
358
350
359
- # inputspec.inputs.subject_id = subject_id
360
- # inputspec.inputs.dwi_file = dwi_file
361
- # inputspec.inputs.dwi_file_ap = dwi_file_ap
362
- # inputspec.inputs.dwi_file_pa = dwi_file_pa
363
- # inputspec.inputs.bvec_file = bvec_file
364
- # inputspec.inputs.bval_file = bval_file
365
- # inputspec.inputs.subjects_dir = subjects_dir
366
- # inputspec.inputs.out_dir = op.abspath(out_dir)
367
- #
368
- # # some bookkeeping (getting the filename, getting the BIDS subject name)
369
- # dwi_fname = op.split(dwi_file)[1].split(".nii.gz")[0]
370
- # bids_sub_name = subject_id
371
- # assert bids_sub_name.startswith("sub-")
372
-
373
- # Grab the preprocessing all_fsl_pipeline
374
351
# AK: watch out, other datasets might be encoded LR
375
352
epi_ap = {'echospacing' : 66.5e-3 , 'enc_dir' : 'y-' }
376
353
epi_pa = {'echospacing' : 66.5e-3 , 'enc_dir' : 'y' }
@@ -379,17 +356,13 @@ def get_dmriprep_pe_workflow(eddy_niter=5, slice_outlier_threshold=0.02):
379
356
# initialize an overall workflow
380
357
wf = pe .Workflow (name = "dmriprep" )
381
358
382
- # prep.inputs.inputnode.in_file = dwi_file
383
- # prep.inputs.inputnode.in_bvec = bvec_file
384
- # prep.inputs.inputnode.in_bval = bval_file
385
-
386
359
wf .connect (inputspec , 'dwi_file' , prep , 'inputnode.in_file' )
387
360
wf .connect (inputspec , 'bvec_file' , prep , 'inputnode.in_bvec' )
388
361
wf .connect (inputspec , 'bval_file' , prep , 'inputnode.in_bval' )
362
+ wf .connect (inputspec , 'eddy_niter' , prep , 'fsl_eddy.niter' )
389
363
390
364
eddy = prep .get_node ('fsl_eddy' )
391
365
eddy .inputs .repol = True
392
- eddy .inputs .niter = eddy_niter
393
366
394
367
def id_outliers_fn (outlier_report , threshold , dwi_file ):
395
368
"""Get list of scans that exceed threshold for number of outliers
@@ -453,9 +426,9 @@ def num_outliers(scan, outliers):
453
426
name = "id_outliers_node"
454
427
)
455
428
456
- id_outliers_node .inputs .threshold = slice_outlier_threshold
457
429
wf .connect (inputspec , 'dwi_file' , id_outliers_node , 'dwi_file' )
458
- # id_outliers_node.inputs.dwi_file = dwi_file
430
+ wf .connect (inputspec , 'slice_outlier_threshold' , id_outliers_node , 'threshold' )
431
+
459
432
wf .connect (prep , "fsl_eddy.out_outlier_report" ,
460
433
id_outliers_node , "outlier_report" )
461
434
@@ -590,7 +563,6 @@ def apply_transform_to_bvecs_fn(bvec_file, reg_mat_file):
590
563
wf .connect (id_outliers_node , "drop_scans" , drop_outliers_node , "drop_scans" )
591
564
wf .connect (voltransform , "transformed_file" , drop_outliers_node , "in_file" )
592
565
wf .connect (inputspec , 'bval_file' , drop_outliers_node , 'in_bval' )
593
- # drop_outliers_node.inputs.in_bval = bval_file
594
566
wf .connect (apply_transform_to_bvecs_node , "out_bvec" , drop_outliers_node , "in_bvec" )
595
567
596
568
# lets compute the tensor on both the dropped volume scan
@@ -604,7 +576,6 @@ def apply_transform_to_bvecs_fn(bvec_file, reg_mat_file):
604
576
wf .connect (voltransform , 'transformed_file' , get_tensor_eddy , "in_file" )
605
577
wf .connect (apply_transform_to_bvecs_node , 'out_bvec' , get_tensor_eddy , "in_bvec" )
606
578
wf .connect (inputspec , 'bval_file' , get_tensor_eddy , 'in_bval' )
607
- # get_tensor_eddy.inputs.in_bval = bval_file
608
579
609
580
# AK: What is this, some vestigal node from a previous workflow?
610
581
# I'm not sure why the tensor gets scaled. but i guess lets scale it for
@@ -671,8 +642,6 @@ def binarize_aparc(aparc_aseg):
671
642
datasink = pe .Node (nio .DataSink (), name = "sinker" )
672
643
wf .connect (inputspec , 'out_dir' , datasink , 'base_directory' )
673
644
wf .connect (inputspec , 'subject_id' , datasink , 'container' )
674
- # datasink.inputs.base_directory = op.join(op.abspath(out_dir), subject_id)
675
- # datasink.inputs.container = subject_id
676
645
677
646
wf .connect (drop_outliers_node , "out_file" , datasink , "dmriprep.dwi.@thinned" )
678
647
wf .connect (drop_outliers_node , "out_bval" , datasink , "dmriprep.dwi.@bval_thinned" )
0 commit comments