@@ -301,7 +301,8 @@ def run_dmriprep_pe(subject_id, dwi_file, dwi_file_AP, dwi_file_PA,
301
301
302
302
# write the graph (this is saved to the working dir)
303
303
wf .write_graph ()
304
-
304
+ wf .config ['execution' ]['remove_unnecessary_outputs' ] = False
305
+ wf .config ['execution' ]['keep_inputs' ] = True
305
306
wf .run ()
306
307
307
308
@@ -363,6 +364,31 @@ def get_dmriprep_pe_workflow():
363
364
import multiprocessing
364
365
eddy .inputs .num_threads = multiprocessing .cpu_count ()
365
366
367
+ eddy_quad = pe .Node (fsl .EddyQuad (verbose = True ), name = "eddy_quad" )
368
+ get_path = lambda x : x .split ('.nii.gz' )[0 ]
369
+ wf .connect (prep , ('fsl_eddy.out_corrected' , get_path ), eddy_quad , "base_name" )
370
+ wf .connect (inputspec , 'bval_file' , eddy_quad , 'bval_file' )
371
+ wf .connect (prep , 'Rotate_Bvec.out_file' , eddy_quad , 'bvec_file' )
372
+ wf .connect (prep , 'peb_correction.topup.out_field' , eddy_quad , 'field' )
373
+ wf .connect (prep , 'gen_index.out_file' , eddy_quad , 'idx_file' )
374
+ wf .connect (prep , 'peb_correction.topup.out_enc_file' , eddy_quad , 'param_file' )
375
+
376
+ # need a mask file for eddy_quad. lets get it from the B0.
377
+ def get_b0_mask_fn (b0_file ):
378
+ import nibabel as nib
379
+ from nipype .utils .filemanip import fname_presuffix
380
+ from dipy .segment .mask import median_otsu
381
+ import os
382
+
383
+ mask_file = fname_presuffix (b0_file , suffix = "_mask" , newpath = os .path .abspath ('.' ))
384
+ img = nib .load (b0_file )
385
+ data , aff = img .get_data (), img .affine
386
+ _ , mask = median_otsu (data , 2 , 1 )
387
+ nib .Nifti1Image (mask .astype (float ), aff ).to_filename (mask_file )
388
+ return mask_file
389
+
390
+
391
+
366
392
def id_outliers_fn (outlier_report , threshold , dwi_file ):
367
393
"""Get list of scans that exceed threshold for number of outliers
368
394
@@ -437,13 +463,19 @@ def num_outliers(scan, outliers):
437
463
wf .connect (inputspec , 'dwi_file_pa' , list_merge , 'in2' )
438
464
439
465
merge = pe .Node (fsl .Merge (dimension = 't' ), name = "mergeAPPA" )
440
- # merge.inputs.in_files = [dwi_file_ap, dwi_file_pa]
441
466
wf .connect (merge , 'merged_file' , prep , 'inputnode.alt_file' )
442
467
wf .connect (list_merge , 'out' , merge , 'in_files' )
443
468
444
469
fslroi = pe .Node (fsl .ExtractROI (t_min = 0 , t_size = 1 ), name = "fslroi" )
445
470
wf .connect (prep , "outputnode.out_file" , fslroi , "in_file" )
446
471
472
+ b0mask_node = pe .Node (niu .Function (input_names = ['b0_file' ],
473
+ output_names = ['mask_file' ],
474
+ function = get_b0_mask_fn ),
475
+ name = "getB0Mask" )
476
+ wf .connect (fslroi , 'roi_file' , b0mask_node , 'b0_file' )
477
+ wf .connect (b0mask_node , 'mask_file' , eddy_quad , 'mask_file' )
478
+
447
479
bbreg = pe .Node (fs .BBRegister (contrast_type = "t2" , init = "coreg" ,
448
480
out_fsl_file = True ,
449
481
# subjects_dir=subjects_dir,
@@ -487,7 +519,7 @@ def drop_outliers_fn(in_file, in_bval, in_bvec, drop_scans):
487
519
from nipype .utils .filemanip import fname_presuffix
488
520
489
521
img = nib .load (op .abspath (in_file ))
490
- img_data = img .get_fdata ()
522
+ img_data = img .get_data ()
491
523
img_data_thinned = np .delete (img_data ,
492
524
drop_scans ,
493
525
axis = 3 )
@@ -679,7 +711,7 @@ def binarize_aparc(aparc_aseg):
679
711
wf .connect (prep , "fsl_eddy.out_residuals" ,
680
712
datasink , "dmriprep.qc.@eddyresid" )
681
713
682
- # the file that told us which volumes to trop
714
+ # the file that told us which volumes to drop
683
715
wf .connect (id_outliers_node , "outpath" , datasink , "dmriprep.qc.@droppedscans" )
684
716
685
717
# the tensors of the dropped volumes dwi
@@ -700,6 +732,15 @@ def binarize_aparc(aparc_aseg):
700
732
wf .connect (get_tensor_eddy , "color_fa_file" , datasink , "dmriprep.dti_eddy.@colorfa" )
701
733
wf .connect (scale_tensor_eddy , "out_file" , datasink , "dmriprep.dti_eddy.@scaled_tensor" )
702
734
735
+ # all the eddy_quad stuff
736
+ wf .connect (eddy_quad , 'out_qc_json' , datasink , "dmriprep.qc.@eddyquad_json" )
737
+ wf .connect (eddy_quad , 'out_qc_pdf' , datasink , "dmriprep.qc.@eddyquad_pdf" )
738
+ wf .connect (eddy_quad , 'out_avg_b_png' , datasink , "dmriprep.qc.@eddyquad_bpng" )
739
+ wf .connect (eddy_quad , 'out_avg_b0_png' , datasink , "dmriprep.qc.@eddyquad_b0png" )
740
+ wf .connect (eddy_quad , 'out_cnr_png' , datasink , "dmriprep.qc.@eddyquad_cnr" )
741
+ wf .connect (eddy_quad , 'out_vdm_png' , datasink , "dmriprep.qc.@eddyquad_vdm" )
742
+ wf .connect (eddy_quad , 'out_residuals' , datasink , 'dmriprep.qc.@eddyquad_resid' )
743
+
703
744
# anatomical registration stuff
704
745
wf .connect (bbreg , "min_cost_file" , datasink , "dmriprep.reg.@mincost" )
705
746
wf .connect (bbreg , "out_fsl_file" , datasink , "dmriprep.reg.@fslfile" )
@@ -711,23 +752,26 @@ def binarize_aparc(aparc_aseg):
711
752
wf .connect (reslice_orig_to_dwi , 'out_file' , datasink , 'dmriprep.anat.@T1w' )
712
753
713
754
def report_fn (dwi_corrected_file , eddy_rms , eddy_report ,
714
- color_fa_file , anat_mask_file , outlier_indices ):
755
+ color_fa_file , anat_mask_file , outlier_indices ,
756
+ eddy_qc_file ):
715
757
from dmriprep .qc import create_report_json
716
758
717
759
report = create_report_json (dwi_corrected_file , eddy_rms , eddy_report ,
718
- color_fa_file , anat_mask_file , outlier_indices )
760
+ color_fa_file , anat_mask_file , outlier_indices ,
761
+ eddy_qc_file )
719
762
return report
720
763
721
764
report_node = pe .Node (niu .Function (
722
765
input_names = ['dwi_corrected_file' , 'eddy_rms' ,
723
766
'eddy_report' , 'color_fa_file' ,
724
- 'anat_mask_file' , 'outlier_indices' ],
767
+ 'anat_mask_file' , 'outlier_indices' , 'eddy_qc_file' ],
725
768
output_names = ['report' ],
726
769
function = report_fn
727
770
), name = "reportJSON" )
728
771
729
772
# for the report, lets show the eddy corrected (full volume) image
730
773
wf .connect (voltransform , "transformed_file" , report_node , 'dwi_corrected_file' )
774
+ wf .connect (eddy_quad , 'out_qc_json' , report_node , 'eddy_qc_file' )
731
775
732
776
# add the rms movement output from eddy
733
777
wf .connect (prep , "fsl_eddy.out_movement_rms" , report_node , 'eddy_rms' )
@@ -762,7 +806,6 @@ def name_files_nicely(dwi_file, subject_id):
762
806
("art.eddy_corrected_outliers" , dwi_fname .replace ("dwi" , "outliers" )),
763
807
("color_fa" , "colorfa" ),
764
808
("orig_out" , dwi_fname .replace ("_dwi" , "_T1w" )),
765
- # ("eddy_corrected_", dwi_fname.replace("dwi", "")),
766
809
("stats.eddy_corrected" , dwi_fname .replace ("dwi" , "artStats" )),
767
810
("eddy_corrected.eddy_parameters" , dwi_fname + ".eddy_parameters" ),
768
811
("qc/eddy_corrected" , "qc/" + dwi_fname ),
0 commit comments