Skip to content

Commit 2203620

Browse files
committed
RF: Remove reporting from coregistration workflows
1 parent a549a33 commit 2203620

File tree

2 files changed

+32
-106
lines changed

2 files changed

+32
-106
lines changed

fmriprep/workflows/bold/fit.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,11 @@ def init_bold_fit_wf(
567567
bold_reg_wf = init_bold_reg_wf(
568568
bold2t1w_dof=config.workflow.bold2t1w_dof,
569569
bold2t1w_init=config.workflow.bold2t1w_init,
570+
use_bbr=config.workflow.use_bbr,
570571
freesurfer=config.workflow.run_reconall,
571-
mem_gb=mem_gb["resampled"],
572-
name="bold_reg_wf",
573572
omp_nthreads=omp_nthreads,
573+
mem_gb=mem_gb["resampled"],
574574
sloppy=config.execution.sloppy,
575-
use_bbr=config.workflow.use_bbr,
576-
use_compression=False,
577-
write_report=False,
578575
)
579576

580577
ds_boldreg_wf = init_ds_registration_wf(

fmriprep/workflows/bold/registration.py

Lines changed: 30 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ def init_bold_reg_wf(
5858
omp_nthreads: int,
5959
name: str = 'bold_reg_wf',
6060
sloppy: bool = False,
61-
use_compression: bool = True,
62-
write_report: bool = True,
6361
):
6462
"""
6563
Build a workflow to run same-subject, BOLD-to-T1w image-registration.
@@ -103,12 +101,6 @@ def init_bold_reg_wf(
103101
Maximum number of threads an individual process may use
104102
name : :obj:`str`
105103
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
112104
113105
Inputs
114106
------
@@ -180,7 +172,7 @@ def init_bold_reg_wf(
180172
sloppy=sloppy,
181173
omp_nthreads=omp_nthreads,
182174
)
183-
# fmt:off
175+
184176
workflow.connect([
185177
(inputnode, bbr_wf, [
186178
('ref_bold_brain', 'inputnode.in_file'),
@@ -191,32 +183,12 @@ def init_bold_reg_wf(
191183
('t1w_mask', 'inputnode.t1w_mask'),
192184
('t1w_dseg', 'inputnode.t1w_dseg'),
193185
]),
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
220192

221193
return workflow
222194

@@ -501,18 +473,13 @@ def init_bbreg_wf(
501473
Affine transform from ``ref_bold_brain`` to T1 space (ITK format)
502474
itk_t1_to_bold
503475
Affine transform from T1 space to BOLD space (ITK format)
504-
out_report
505-
Reportlet for assessing registration quality
506476
fallback
507477
Boolean indicating whether BBR was rejected (mri_coreg registration returned)
508478
509479
"""
480+
from nipype.interfaces.freesurfer import BBRegister, MRICoreg
510481
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
514482
from niworkflows.interfaces.freesurfer import PatchedLTAConvert as LTAConvert
515-
from niworkflows.interfaces.freesurfer import PatchedMRICoregRPT as MRICoregRPT
516483
from niworkflows.interfaces.nitransforms import ConcatenateXFMs
517484

518485
workflow = Workflow(name=name)
@@ -542,7 +509,7 @@ def init_bbreg_wf(
542509
name='inputnode',
543510
)
544511
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']),
546513
name='outputnode',
547514
)
548515

@@ -560,21 +527,17 @@ def init_bbreg_wf(
560527

561528
# Define both nodes, but only connect conditionally
562529
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),
566531
name='mri_coreg',
567532
n_procs=omp_nthreads,
568533
mem_gb=5,
569534
)
570535

571536
bbregister = pe.Node(
572-
BBRegisterRPT(
537+
BBRegister(
573538
dof=bold2t1w_dof,
574539
contrast_type='t2',
575-
registered_file=True,
576540
out_lta_file=True,
577-
generate_report=True,
578541
),
579542
name='bbregister',
580543
mem_gb=12,
@@ -583,41 +546,35 @@ def init_bbreg_wf(
583546
bbregister.inputs.init = "header"
584547

585548
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-
)
589549
# In cases where Merge(2) only has `in1` or `in2` defined
590550
# output list will just contain a single element
591551
select_transform = pe.Node(
592552
niu.Select(index=0), run_without_submitting=True, name='select_transform'
593553
)
594554
merge_ltas = pe.Node(niu.Merge(2), name='merge_ltas', run_without_submitting=True)
595555
concat_xfm = pe.Node(ConcatenateXFMs(inverse=True), name='concat_xfm')
596-
# fmt:off
556+
597557
workflow.connect([
598558
(inputnode, merge_ltas, [('fsnative2t1w_xfm', 'in2')]),
599559
# 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')]),
602561
(select_transform, merge_ltas, [('out', 'in1')]),
603562
(merge_ltas, concat_xfm, [('out', 'in_xfms')]),
604563
(concat_xfm, outputnode, [('out_xfm', 'itk_bold_to_t1')]),
605564
(concat_xfm, outputnode, [('out_inv', 'itk_t1_to_bold')]),
606-
])
607-
# fmt:on
565+
]) # fmt:skip
566+
608567
# Do not initialize with header, use mri_coreg
609568
if bold2t1w_init == "register":
610-
# fmt:off
611569
workflow.connect([
612570
(inputnode, mri_coreg, [('subjects_dir', 'subjects_dir'),
613571
('subject_id', 'subject_id'),
614572
('in_file', 'source_file')]),
615573
(mri_coreg, transforms, [('out_lta_file', 'in2')]),
616-
])
617-
# fmt:on
574+
]) # fmt:skip
575+
618576
# Short-circuit workflow building, use initial registration
619577
if use_bbr is False:
620-
workflow.connect(mri_coreg, 'out_report', outputnode, 'out_report')
621578
outputnode.inputs.fallback = True
622579

623580
return workflow
@@ -626,41 +583,27 @@ def init_bbreg_wf(
626583
workflow.connect(mri_coreg, 'out_lta_file', bbregister, 'init_reg_file')
627584

628585
# Use bbregister
629-
# fmt:off
630586
workflow.connect([
631587
(inputnode, bbregister, [('subjects_dir', 'subjects_dir'),
632588
('subject_id', 'subject_id'),
633589
('in_file', 'source_file')]),
634590
(bbregister, transforms, [('out_lta_file', 'in1')]),
635-
])
636-
# fmt:on
591+
]) # fmt:skip
592+
637593
# Short-circuit workflow building, use boundary-based registration
638594
if use_bbr is True:
639-
workflow.connect(bbregister, 'out_report', outputnode, 'out_report')
640595
outputnode.inputs.fallback = False
641596

642597
return workflow
643598

644599
# 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-
647600
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+
650602
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')]),
653604
(compare_transforms, outputnode, [('out', 'fallback')]),
654-
# Select output transform
655605
(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
664607

665608
return workflow
666609

@@ -735,17 +678,14 @@ def init_fsl_bbr_wf(
735678
Affine transform from ``ref_bold_brain`` to T1w space (ITK format)
736679
itk_t1_to_bold
737680
Affine transform from T1 space to BOLD space (ITK format)
738-
out_report
739-
Reportlet for assessing registration quality
740681
fallback
741682
Boolean indicating whether BBR was rejected (rigid FLIRT registration returned)
742683
743684
"""
685+
from nipype.interfaces.freesurfer import MRICoreg
744686
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
745687
from niworkflows.interfaces.freesurfer import PatchedLTAConvert as LTAConvert
746-
from niworkflows.interfaces.freesurfer import PatchedMRICoregRPT as MRICoregRPT
747688
from niworkflows.interfaces.nibabel import ApplyMask
748-
from niworkflows.interfaces.reportlets.registration import FLIRTRPT
749689
from niworkflows.utils.images import dseg_label as _dseg_label
750690

751691
workflow = Workflow(name=name)
@@ -755,7 +695,7 @@ def init_fsl_bbr_wf(
755695
with the boundary-based registration [@bbr] cost-function.
756696
Co-registration was configured with {dof} degrees of freedom{reason}.
757697
""".format(
758-
fsl_ver=FLIRTRPT().version or '<ver>',
698+
fsl_ver=fsl.FLIRT().version or '<ver>',
759699
dof={6: 'six', 9: 'nine', 12: 'twelve'}[bold2t1w_dof],
760700
reason=''
761701
if bold2t1w_dof == 6
@@ -777,7 +717,7 @@ def init_fsl_bbr_wf(
777717
name='inputnode',
778718
)
779719
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']),
781721
name='outputnode',
782722
)
783723

@@ -794,9 +734,7 @@ def init_fsl_bbr_wf(
794734
mask_t1w_brain = pe.Node(ApplyMask(), name='mask_t1w_brain')
795735

796736
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),
800738
name='mri_coreg',
801739
n_procs=omp_nthreads,
802740
mem_gb=5,
@@ -843,15 +781,14 @@ def init_fsl_bbr_wf(
843781
workflow.connect([
844782
(lta_to_fsl, invt_bbr, [('out_fsl', 'in_file')]),
845783
(lta_to_fsl, fsl2itk_fwd, [('out_fsl', 'transform_file')]),
846-
(mri_coreg, outputnode, [('out_report', 'out_report')]),
847784
])
848785
# fmt:on
849786
outputnode.inputs.fallback = True
850787

851788
return workflow
852789

853790
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"),
855792
name='flt_bbr',
856793
)
857794

@@ -898,20 +835,17 @@ def init_fsl_bbr_wf(
898835
workflow.connect([
899836
(flt_bbr, invt_bbr, [('out_matrix_file', 'in_file')]),
900837
(flt_bbr, fsl2itk_fwd, [('out_matrix_file', 'transform_file')]),
901-
(flt_bbr, outputnode, [('out_report', 'out_report')]),
902838
])
903839
# fmt:on
904840
outputnode.inputs.fallback = False
905841

906842
return workflow
907843

908844
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')
910845

911846
compare_transforms = pe.Node(niu.Function(function=compare_xforms), name='compare_transforms')
912847

913848
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')
915849

916850
fsl_to_lta = pe.MapNode(LTAConvert(out_lta=True), iterfield=['in_fsl'], name='fsl_to_lta')
917851
# fmt:off
@@ -929,11 +863,6 @@ def init_fsl_bbr_wf(
929863
(compare_transforms, select_transform, [('out', 'index')]),
930864
(select_transform, invt_bbr, [('out', 'in_file')]),
931865
(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')]),
937866
])
938867
# fmt:on
939868

@@ -972,11 +901,11 @@ def compare_xforms(lta_list, norm_threshold=15):
972901
second transform relative to the first (default: `15`)
973902
974903
"""
904+
import nitransforms as nt
975905
from nipype.algorithms.rapidart import _calc_norm_affine
976-
from niworkflows.interfaces.surf import load_transform
977906

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
980909

981910
norm, _ = _calc_norm_affine([fallback_affine, bbr_affine], use_differences=True)
982911

0 commit comments

Comments
 (0)