@@ -58,8 +58,6 @@ def init_bold_reg_wf(
58
58
omp_nthreads : int ,
59
59
name : str = 'bold_reg_wf' ,
60
60
sloppy : bool = False ,
61
- use_compression : bool = True ,
62
- write_report : bool = True ,
63
61
):
64
62
"""
65
63
Build a workflow to run same-subject, BOLD-to-T1w image-registration.
@@ -103,12 +101,6 @@ def init_bold_reg_wf(
103
101
Maximum number of threads an individual process may use
104
102
name : :obj:`str`
105
103
Name of workflow (default: ``bold_reg_wf``)
106
- use_compression : :obj:`bool`
107
- Save registered BOLD series as ``.nii.gz``
108
- use_fieldwarp : :obj:`bool`
109
- Include SDC warp in single-shot transform from BOLD to T1
110
- write_report : :obj:`bool`
111
- Whether a reportlet should be stored
112
104
113
105
Inputs
114
106
------
@@ -180,7 +172,7 @@ def init_bold_reg_wf(
180
172
sloppy = sloppy ,
181
173
omp_nthreads = omp_nthreads ,
182
174
)
183
- # fmt:off
175
+
184
176
workflow .connect ([
185
177
(inputnode , bbr_wf , [
186
178
('ref_bold_brain' , 'inputnode.in_file' ),
@@ -191,32 +183,12 @@ def init_bold_reg_wf(
191
183
('t1w_mask' , 'inputnode.t1w_mask' ),
192
184
('t1w_dseg' , 'inputnode.t1w_dseg' ),
193
185
]),
194
- (bbr_wf , outputnode , [('outputnode.itk_bold_to_t1' , 'itk_bold_to_t1' ),
195
- ('outputnode.itk_t1_to_bold' , 'itk_t1_to_bold' ),
196
- ('outputnode.fallback' , 'fallback' )]),
197
- ])
198
- # fmt:on
199
-
200
- if write_report :
201
- ds_report_reg = pe .Node (
202
- DerivativesDataSink (datatype = "figures" , dismiss_entities = ("echo" ,)),
203
- name = 'ds_report_reg' ,
204
- run_without_submitting = True ,
205
- mem_gb = DEFAULT_MEMORY_MIN_GB ,
206
- )
207
-
208
- def _bold_reg_suffix (fallback , freesurfer ):
209
- if fallback :
210
- return 'coreg' if freesurfer else 'flirtnobbr'
211
- return 'bbregister' if freesurfer else 'flirtbbr'
212
-
213
- # fmt:off
214
- workflow .connect ([
215
- (bbr_wf , ds_report_reg , [
216
- ('outputnode.out_report' , 'in_file' ),
217
- (('outputnode.fallback' , _bold_reg_suffix , freesurfer ), 'desc' )]),
218
- ])
219
- # fmt:on
186
+ (bbr_wf , outputnode , [
187
+ ('outputnode.itk_bold_to_t1' , 'itk_bold_to_t1' ),
188
+ ('outputnode.itk_t1_to_bold' , 'itk_t1_to_bold' ),
189
+ ('outputnode.fallback' , 'fallback' ),
190
+ ]),
191
+ ]) # fmt:skip
220
192
221
193
return workflow
222
194
@@ -501,18 +473,13 @@ def init_bbreg_wf(
501
473
Affine transform from ``ref_bold_brain`` to T1 space (ITK format)
502
474
itk_t1_to_bold
503
475
Affine transform from T1 space to BOLD space (ITK format)
504
- out_report
505
- Reportlet for assessing registration quality
506
476
fallback
507
477
Boolean indicating whether BBR was rejected (mri_coreg registration returned)
508
478
509
479
"""
480
+ from nipype .interfaces .freesurfer import BBRegister , MRICoreg
510
481
from niworkflows .engine .workflows import LiterateWorkflow as Workflow
511
-
512
- # See https://github.com/nipreps/fmriprep/issues/768
513
- from niworkflows .interfaces .freesurfer import PatchedBBRegisterRPT as BBRegisterRPT
514
482
from niworkflows .interfaces .freesurfer import PatchedLTAConvert as LTAConvert
515
- from niworkflows .interfaces .freesurfer import PatchedMRICoregRPT as MRICoregRPT
516
483
from niworkflows .interfaces .nitransforms import ConcatenateXFMs
517
484
518
485
workflow = Workflow (name = name )
@@ -542,7 +509,7 @@ def init_bbreg_wf(
542
509
name = 'inputnode' ,
543
510
)
544
511
outputnode = pe .Node (
545
- niu .IdentityInterface (['itk_bold_to_t1' , 'itk_t1_to_bold' , 'out_report' , ' fallback' ]),
512
+ niu .IdentityInterface (['itk_bold_to_t1' , 'itk_t1_to_bold' , 'fallback' ]),
546
513
name = 'outputnode' ,
547
514
)
548
515
@@ -560,21 +527,17 @@ def init_bbreg_wf(
560
527
561
528
# Define both nodes, but only connect conditionally
562
529
mri_coreg = pe .Node (
563
- MRICoregRPT (
564
- dof = bold2t1w_dof , sep = [4 ], ftol = 0.0001 , linmintol = 0.01 , generate_report = not use_bbr
565
- ),
530
+ MRICoreg (dof = bold2t1w_dof , sep = [4 ], ftol = 0.0001 , linmintol = 0.01 ),
566
531
name = 'mri_coreg' ,
567
532
n_procs = omp_nthreads ,
568
533
mem_gb = 5 ,
569
534
)
570
535
571
536
bbregister = pe .Node (
572
- BBRegisterRPT (
537
+ BBRegister (
573
538
dof = bold2t1w_dof ,
574
539
contrast_type = 't2' ,
575
- registered_file = True ,
576
540
out_lta_file = True ,
577
- generate_report = True ,
578
541
),
579
542
name = 'bbregister' ,
580
543
mem_gb = 12 ,
@@ -583,41 +546,35 @@ def init_bbreg_wf(
583
546
bbregister .inputs .init = "header"
584
547
585
548
transforms = pe .Node (niu .Merge (2 ), run_without_submitting = True , name = 'transforms' )
586
- lta_ras2ras = pe .MapNode (
587
- LTAConvert (out_lta = True ), iterfield = ['in_lta' ], name = 'lta_ras2ras' , mem_gb = 2
588
- )
589
549
# In cases where Merge(2) only has `in1` or `in2` defined
590
550
# output list will just contain a single element
591
551
select_transform = pe .Node (
592
552
niu .Select (index = 0 ), run_without_submitting = True , name = 'select_transform'
593
553
)
594
554
merge_ltas = pe .Node (niu .Merge (2 ), name = 'merge_ltas' , run_without_submitting = True )
595
555
concat_xfm = pe .Node (ConcatenateXFMs (inverse = True ), name = 'concat_xfm' )
596
- # fmt:off
556
+
597
557
workflow .connect ([
598
558
(inputnode , merge_ltas , [('fsnative2t1w_xfm' , 'in2' )]),
599
559
# Wire up the co-registration alternatives
600
- (transforms , lta_ras2ras , [('out' , 'in_lta' )]),
601
- (lta_ras2ras , select_transform , [('out_lta' , 'inlist' )]),
560
+ (transforms , select_transform , [('out' , 'inlist' )]),
602
561
(select_transform , merge_ltas , [('out' , 'in1' )]),
603
562
(merge_ltas , concat_xfm , [('out' , 'in_xfms' )]),
604
563
(concat_xfm , outputnode , [('out_xfm' , 'itk_bold_to_t1' )]),
605
564
(concat_xfm , outputnode , [('out_inv' , 'itk_t1_to_bold' )]),
606
- ])
607
- # fmt:on
565
+ ]) # fmt:skip
566
+
608
567
# Do not initialize with header, use mri_coreg
609
568
if bold2t1w_init == "register" :
610
- # fmt:off
611
569
workflow .connect ([
612
570
(inputnode , mri_coreg , [('subjects_dir' , 'subjects_dir' ),
613
571
('subject_id' , 'subject_id' ),
614
572
('in_file' , 'source_file' )]),
615
573
(mri_coreg , transforms , [('out_lta_file' , 'in2' )]),
616
- ])
617
- # fmt:on
574
+ ]) # fmt:skip
575
+
618
576
# Short-circuit workflow building, use initial registration
619
577
if use_bbr is False :
620
- workflow .connect (mri_coreg , 'out_report' , outputnode , 'out_report' )
621
578
outputnode .inputs .fallback = True
622
579
623
580
return workflow
@@ -626,41 +583,27 @@ def init_bbreg_wf(
626
583
workflow .connect (mri_coreg , 'out_lta_file' , bbregister , 'init_reg_file' )
627
584
628
585
# Use bbregister
629
- # fmt:off
630
586
workflow .connect ([
631
587
(inputnode , bbregister , [('subjects_dir' , 'subjects_dir' ),
632
588
('subject_id' , 'subject_id' ),
633
589
('in_file' , 'source_file' )]),
634
590
(bbregister , transforms , [('out_lta_file' , 'in1' )]),
635
- ])
636
- # fmt:on
591
+ ]) # fmt:skip
592
+
637
593
# Short-circuit workflow building, use boundary-based registration
638
594
if use_bbr is True :
639
- workflow .connect (bbregister , 'out_report' , outputnode , 'out_report' )
640
595
outputnode .inputs .fallback = False
641
596
642
597
return workflow
643
598
644
599
# Only reach this point if bold2t1w_init is "register" and use_bbr is None
645
- reports = pe .Node (niu .Merge (2 ), run_without_submitting = True , name = 'reports' )
646
-
647
600
compare_transforms = pe .Node (niu .Function (function = compare_xforms ), name = 'compare_transforms' )
648
- select_report = pe .Node (niu .Select (), run_without_submitting = True , name = 'select_report' )
649
- # fmt:off
601
+
650
602
workflow .connect ([
651
- # Normalize LTA transforms to RAS2RAS (inputs are VOX2VOX) and compare
652
- (lta_ras2ras , compare_transforms , [('out_lta' , 'lta_list' )]),
603
+ (transforms , compare_transforms , [('out' , 'lta_list' )]),
653
604
(compare_transforms , outputnode , [('out' , 'fallback' )]),
654
- # Select output transform
655
605
(compare_transforms , select_transform , [('out' , 'index' )]),
656
- # Select output report
657
- (bbregister , reports , [('out_report' , 'in1' )]),
658
- (mri_coreg , reports , [('out_report' , 'in2' )]),
659
- (reports , select_report , [('out' , 'inlist' )]),
660
- (compare_transforms , select_report , [('out' , 'index' )]),
661
- (select_report , outputnode , [('out' , 'out_report' )]),
662
- ])
663
- # fmt:on
606
+ ]) # fmt:skip
664
607
665
608
return workflow
666
609
@@ -735,17 +678,14 @@ def init_fsl_bbr_wf(
735
678
Affine transform from ``ref_bold_brain`` to T1w space (ITK format)
736
679
itk_t1_to_bold
737
680
Affine transform from T1 space to BOLD space (ITK format)
738
- out_report
739
- Reportlet for assessing registration quality
740
681
fallback
741
682
Boolean indicating whether BBR was rejected (rigid FLIRT registration returned)
742
683
743
684
"""
685
+ from nipype .interfaces .freesurfer import MRICoreg
744
686
from niworkflows .engine .workflows import LiterateWorkflow as Workflow
745
687
from niworkflows .interfaces .freesurfer import PatchedLTAConvert as LTAConvert
746
- from niworkflows .interfaces .freesurfer import PatchedMRICoregRPT as MRICoregRPT
747
688
from niworkflows .interfaces .nibabel import ApplyMask
748
- from niworkflows .interfaces .reportlets .registration import FLIRTRPT
749
689
from niworkflows .utils .images import dseg_label as _dseg_label
750
690
751
691
workflow = Workflow (name = name )
@@ -755,7 +695,7 @@ def init_fsl_bbr_wf(
755
695
with the boundary-based registration [@bbr] cost-function.
756
696
Co-registration was configured with {dof} degrees of freedom{reason}.
757
697
""" .format (
758
- fsl_ver = FLIRTRPT ().version or '<ver>' ,
698
+ fsl_ver = fsl . FLIRT ().version or '<ver>' ,
759
699
dof = {6 : 'six' , 9 : 'nine' , 12 : 'twelve' }[bold2t1w_dof ],
760
700
reason = ''
761
701
if bold2t1w_dof == 6
@@ -777,7 +717,7 @@ def init_fsl_bbr_wf(
777
717
name = 'inputnode' ,
778
718
)
779
719
outputnode = pe .Node (
780
- niu .IdentityInterface (['itk_bold_to_t1' , 'itk_t1_to_bold' , 'out_report' , ' fallback' ]),
720
+ niu .IdentityInterface (['itk_bold_to_t1' , 'itk_t1_to_bold' , 'fallback' ]),
781
721
name = 'outputnode' ,
782
722
)
783
723
@@ -794,9 +734,7 @@ def init_fsl_bbr_wf(
794
734
mask_t1w_brain = pe .Node (ApplyMask (), name = 'mask_t1w_brain' )
795
735
796
736
mri_coreg = pe .Node (
797
- MRICoregRPT (
798
- dof = bold2t1w_dof , sep = [4 ], ftol = 0.0001 , linmintol = 0.01 , generate_report = not use_bbr
799
- ),
737
+ MRICoreg (dof = bold2t1w_dof , sep = [4 ], ftol = 0.0001 , linmintol = 0.01 ),
800
738
name = 'mri_coreg' ,
801
739
n_procs = omp_nthreads ,
802
740
mem_gb = 5 ,
@@ -843,15 +781,14 @@ def init_fsl_bbr_wf(
843
781
workflow .connect ([
844
782
(lta_to_fsl , invt_bbr , [('out_fsl' , 'in_file' )]),
845
783
(lta_to_fsl , fsl2itk_fwd , [('out_fsl' , 'transform_file' )]),
846
- (mri_coreg , outputnode , [('out_report' , 'out_report' )]),
847
784
])
848
785
# fmt:on
849
786
outputnode .inputs .fallback = True
850
787
851
788
return workflow
852
789
853
790
flt_bbr = pe .Node (
854
- FLIRTRPT (cost_func = 'bbr' , dof = bold2t1w_dof , args = "-basescale 1" , generate_report = True ),
791
+ fsl . FLIRT (cost_func = 'bbr' , dof = bold2t1w_dof , args = "-basescale 1" ),
855
792
name = 'flt_bbr' ,
856
793
)
857
794
@@ -898,20 +835,17 @@ def init_fsl_bbr_wf(
898
835
workflow .connect ([
899
836
(flt_bbr , invt_bbr , [('out_matrix_file' , 'in_file' )]),
900
837
(flt_bbr , fsl2itk_fwd , [('out_matrix_file' , 'transform_file' )]),
901
- (flt_bbr , outputnode , [('out_report' , 'out_report' )]),
902
838
])
903
839
# fmt:on
904
840
outputnode .inputs .fallback = False
905
841
906
842
return workflow
907
843
908
844
transforms = pe .Node (niu .Merge (2 ), run_without_submitting = True , name = 'transforms' )
909
- reports = pe .Node (niu .Merge (2 ), run_without_submitting = True , name = 'reports' )
910
845
911
846
compare_transforms = pe .Node (niu .Function (function = compare_xforms ), name = 'compare_transforms' )
912
847
913
848
select_transform = pe .Node (niu .Select (), run_without_submitting = True , name = 'select_transform' )
914
- select_report = pe .Node (niu .Select (), run_without_submitting = True , name = 'select_report' )
915
849
916
850
fsl_to_lta = pe .MapNode (LTAConvert (out_lta = True ), iterfield = ['in_fsl' ], name = 'fsl_to_lta' )
917
851
# fmt:off
@@ -929,11 +863,6 @@ def init_fsl_bbr_wf(
929
863
(compare_transforms , select_transform , [('out' , 'index' )]),
930
864
(select_transform , invt_bbr , [('out' , 'in_file' )]),
931
865
(select_transform , fsl2itk_fwd , [('out' , 'transform_file' )]),
932
- (flt_bbr , reports , [('out_report' , 'in1' )]),
933
- (mri_coreg , reports , [('out_report' , 'in2' )]),
934
- (reports , select_report , [('out' , 'inlist' )]),
935
- (compare_transforms , select_report , [('out' , 'index' )]),
936
- (select_report , outputnode , [('out' , 'out_report' )]),
937
866
])
938
867
# fmt:on
939
868
@@ -972,11 +901,11 @@ def compare_xforms(lta_list, norm_threshold=15):
972
901
second transform relative to the first (default: `15`)
973
902
974
903
"""
904
+ import nitransforms as nt
975
905
from nipype .algorithms .rapidart import _calc_norm_affine
976
- from niworkflows .interfaces .surf import load_transform
977
906
978
- bbr_affine = load_transform (lta_list [0 ])
979
- fallback_affine = load_transform (lta_list [1 ])
907
+ bbr_affine = nt . linear . load (lta_list [0 ]). matrix
908
+ fallback_affine = nt . linear . load (lta_list [1 ]). matrix
980
909
981
910
norm , _ = _calc_norm_affine ([fallback_affine , bbr_affine ], use_differences = True )
982
911
0 commit comments