Skip to content

Commit 04feef5

Browse files
authored
Merge pull request #741 from effigies/fsfix_common [skip ci]
[RTM] RF: Miscellaneous registration refactorings
2 parents c821d61 + 7560f69 commit 04feef5

File tree

4 files changed

+107
-119
lines changed

4 files changed

+107
-119
lines changed

fmriprep/workflows/anatomical.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def init_anat_preproc_wf(skull_strip_ants, output_spaces, template, debug, frees
153153
FreeSurfer SUBJECTS_DIR
154154
subject_id
155155
FreeSurfer subject ID
156-
fs_2_t1_transform
156+
t1_2_fsnative_reverse_transform
157157
Affine transform from FreeSurfer subject space to T1w space
158158
surfaces
159159
GIFTI surfaces (gray/white boundary, midthickness, pial, inflated)
@@ -174,7 +174,7 @@ def init_anat_preproc_wf(skull_strip_ants, output_spaces, template, debug, frees
174174
fields=['t1_preproc', 't1_brain', 't1_mask', 't1_seg', 't1_tpms',
175175
't1_2_mni', 't1_2_mni_forward_transform', 't1_2_mni_reverse_transform',
176176
'mni_mask', 'mni_seg', 'mni_tpms',
177-
'subjects_dir', 'subject_id', 'fs_2_t1_transform', 'surfaces']),
177+
'subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform', 'surfaces']),
178178
name='outputnode')
179179

180180
# 0. Reorient T1w image(s) to RAS and resample to common voxel space
@@ -314,7 +314,7 @@ def len_above_thresh(in_list, threshold, longitudinal):
314314
(surface_recon_wf, outputnode, [
315315
('outputnode.subjects_dir', 'subjects_dir'),
316316
('outputnode.subject_id', 'subject_id'),
317-
('outputnode.fs_2_t1_transform', 'fs_2_t1_transform'),
317+
('outputnode.t1_2_fsnative_reverse_transform', 't1_2_fsnative_reverse_transform'),
318318
('outputnode.surfaces', 'surfaces')]),
319319
])
320320

@@ -499,7 +499,7 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'):
499499
FreeSurfer SUBJECTS_DIR
500500
subject_id
501501
FreeSurfer subject ID
502-
fs_2_t1_transform
502+
t1_2_fsnative_reverse_transform
503503
FSL-style affine matrix translating from FreeSurfer T1.mgz to T1w
504504
surfaces
505505
GIFTI surfaces for gray/white matter boundary, pial surface,
@@ -521,7 +521,8 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'):
521521
name='inputnode')
522522
outputnode = pe.Node(
523523
niu.IdentityInterface(
524-
fields=['subjects_dir', 'subject_id', 'fs_2_t1_transform', 'surfaces', 'out_report']),
524+
fields=['subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform', 'surfaces',
525+
'out_report']),
525526
name='outputnode')
526527

527528
recon_config = pe.Node(FSDetectInputs(hires_enabled=hires), name='recon_config',
@@ -542,6 +543,7 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'):
542543
fs_transform = pe.Node(
543544
fs.Tkregister2(fsl_out='freesurfer2subT1.mat', reg_header=True),
544545
name='fs_transform')
546+
fsl2lta = pe.Node(fs.utils.LTAConvert(out_lta=True), name='fsl2lta')
545547

546548
autorecon_resume_wf = init_autorecon_resume_wf(omp_nthreads=omp_nthreads)
547549
gifti_surface_wf = init_gifti_surface_wf()
@@ -572,12 +574,15 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'):
572574
# reoriented image
573575
(inputnode, fs_transform, [('t1w', 'target_image')]),
574576
(autorecon1, fs_transform, [('T1', 'moving_image')]),
577+
(inputnode, fsl2lta, [('t1w', 'target_file')]),
578+
(autorecon1, fsl2lta, [('T1', 'source_file')]),
579+
(fs_transform, fsl2lta, [('fsl_file', 'in_fsl')]),
575580
# Output
576581
(autorecon_resume_wf, outputnode, [('outputnode.subjects_dir', 'subjects_dir'),
577582
('outputnode.subject_id', 'subject_id'),
578583
('outputnode.out_report', 'out_report')]),
579584
(gifti_surface_wf, outputnode, [('outputnode.surfaces', 'surfaces')]),
580-
(fs_transform, outputnode, [('fsl_file', 'fs_2_t1_transform')]),
585+
(fsl2lta, outputnode, [('out_lta', 't1_2_fsnative_reverse_transform')]),
581586
])
582587

583588
return workflow

fmriprep/workflows/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ def init_single_subject_wf(subject_id, task_id, name,
437437
(anat_preproc_wf, func_preproc_wf,
438438
[('outputnode.subjects_dir', 'inputnode.subjects_dir'),
439439
('outputnode.subject_id', 'inputnode.subject_id'),
440-
('outputnode.fs_2_t1_transform', 'inputnode.fs_2_t1_transform')]),
440+
('outputnode.t1_2_fsnative_reverse_transform',
441+
'inputnode.t1_2_fsnative_reverse_transform')]),
441442
])
442443

443444
return workflow

fmriprep/workflows/bold.py

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from niworkflows.nipype import logging
3737
from niworkflows.nipype.utils.filemanip import split_filename
3838
from niworkflows.nipype.pipeline import engine as pe
39-
from niworkflows.nipype.interfaces import ants, afni, c3, fsl
39+
from niworkflows.nipype.interfaces import ants, afni, fsl
4040
from niworkflows.nipype.interfaces import utility as niu
4141
from niworkflows.nipype.interfaces import freesurfer as fs
4242

@@ -173,7 +173,7 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
173173
FreeSurfer SUBJECTS_DIR
174174
subject_id
175175
FreeSurfer subject ID
176-
fs_2_t1_transform
176+
t1_2_fsnative_reverse_transform
177177
Affine transform from FreeSurfer subject space to T1w space
178178
179179
@@ -245,7 +245,7 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
245245
inputnode = pe.Node(niu.IdentityInterface(
246246
fields=['bold_file', 't1_preproc', 't1_brain', 't1_mask', 't1_seg', 't1_tpms',
247247
't1_2_mni_forward_transform', 't1_2_mni_reverse_transform',
248-
'subjects_dir', 'subject_id', 'fs_2_t1_transform']),
248+
'subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform']),
249249
name='inputnode')
250250
inputnode.inputs.bold_file = bold_file
251251

@@ -320,16 +320,17 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
320320
(inputnode, bold_reference_wf, [('bold_file', 'inputnode.bold_file')]),
321321
(bold_reference_wf, bold_hmc_wf, [
322322
('outputnode.raw_ref_image', 'inputnode.raw_ref_image')]),
323-
(inputnode, bold_reg_wf, [('bold_file', 'inputnode.name_source'),
324-
('t1_preproc', 'inputnode.t1_preproc'),
325-
('t1_brain', 'inputnode.t1_brain'),
326-
('t1_mask', 'inputnode.t1_mask'),
327-
('t1_seg', 'inputnode.t1_seg'),
328-
# Undefined if --no-freesurfer, but this is safe
329-
('subjects_dir', 'inputnode.subjects_dir'),
330-
('subject_id', 'inputnode.subject_id'),
331-
('fs_2_t1_transform', 'inputnode.fs_2_t1_transform')
332-
]),
323+
(inputnode, bold_reg_wf, [
324+
('bold_file', 'inputnode.name_source'),
325+
('t1_preproc', 'inputnode.t1_preproc'),
326+
('t1_brain', 'inputnode.t1_brain'),
327+
('t1_mask', 'inputnode.t1_mask'),
328+
('t1_seg', 'inputnode.t1_seg'),
329+
# Undefined if --no-freesurfer, but this is safe
330+
('subjects_dir', 'inputnode.subjects_dir'),
331+
('subject_id', 'inputnode.subject_id'),
332+
('t1_2_fsnative_reverse_transform', 'inputnode.t1_2_fsnative_reverse_transform')
333+
]),
333334
(inputnode, bold_confounds_wf, [('t1_tpms', 'inputnode.t1_tpms'),
334335
('t1_mask', 'inputnode.t1_mask')]),
335336
(bold_hmc_wf, bold_reg_wf, [('outputnode.bold_split', 'inputnode.bold_split'),
@@ -859,17 +860,13 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads,
859860
FreeSurfer SUBJECTS_DIR
860861
subject_id
861862
FreeSurfer subject ID
862-
fs_2_t1_transform
863+
t1_2_fsnative_reverse_transform
863864
Affine transform from FreeSurfer subject space to T1w space
864865
fieldwarp
865866
a :abbr:`DFM (displacements field map)` in ITK format
866867
867868
Outputs
868869
869-
mat_bold_to_t1
870-
Affine transform from ``ref_bold_brain`` to T1 space (FSL format)
871-
mat_t1_to_bold
872-
Affine transform from T1 space to BOLD space (FSL format)
873870
itk_bold_to_t1
874871
Affine transform from ``ref_bold_brain`` to T1 space (ITK format)
875872
itk_t1_to_bold
@@ -878,25 +875,22 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads,
878875
Motion-corrected BOLD series in T1 space
879876
bold_mask_t1
880877
BOLD mask in T1 space
881-
fs_reg_file
882-
Affine transform from ``ref_bold_brain`` to T1 space (FreeSurfer ``reg`` format)
883878
out_report
884879
Reportlet visualizing quality of registration
885880
886881
"""
887882
workflow = pe.Workflow(name=name)
888883
inputnode = pe.Node(
889-
niu.IdentityInterface(fields=['name_source', 'ref_bold_brain', 'ref_bold_mask',
890-
't1_preproc', 't1_brain', 't1_mask',
891-
't1_seg', 'bold_split', 'hmc_xforms',
892-
'subjects_dir', 'subject_id', 'fs_2_t1_transform',
893-
'fieldwarp']),
884+
niu.IdentityInterface(
885+
fields=['name_source', 'ref_bold_brain', 'ref_bold_mask',
886+
't1_preproc', 't1_brain', 't1_mask',
887+
't1_seg', 'bold_split', 'hmc_xforms',
888+
'subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform', 'fieldwarp']),
894889
name='inputnode'
895890
)
896891
outputnode = pe.Node(
897-
niu.IdentityInterface(fields=['mat_bold_to_t1', 'mat_t1_to_bold',
898-
'itk_bold_to_t1', 'itk_t1_to_bold',
899-
'bold_t1', 'bold_mask_t1', 'fs_reg_file',
892+
niu.IdentityInterface(fields=['itk_bold_to_t1', 'itk_t1_to_bold',
893+
'bold_t1', 'bold_mask_t1',
900894
'out_report']),
901895
name='outputnode'
902896
)
@@ -906,37 +900,17 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads,
906900
else:
907901
bbr_wf = init_fsl_bbr_wf(bold2t1w_dof, report=True)
908902

909-
# make equivalent warp fields
910-
invt_bbr = pe.Node(fsl.ConvertXFM(invert_xfm=True), name='invt_bbr',
911-
mem_gb=DEFAULT_MEMORY_MIN_GB)
912-
913-
# BOLD to T1 transform matrix is from fsl, using c3 tools to convert to
914-
# something ANTs will like.
915-
fsl2itk_fwd = pe.Node(c3.C3dAffineTool(fsl2ras=True, itk_transform=True),
916-
name='fsl2itk_fwd', mem_gb=DEFAULT_MEMORY_MIN_GB)
917-
fsl2itk_inv = pe.Node(c3.C3dAffineTool(fsl2ras=True, itk_transform=True),
918-
name='fsl2itk_inv', mem_gb=DEFAULT_MEMORY_MIN_GB)
919-
920903
workflow.connect([
921-
(inputnode, bbr_wf, [('ref_bold_brain', 'inputnode.in_file'),
922-
('fs_2_t1_transform', 'inputnode.fs_2_t1_transform'),
923-
('subjects_dir', 'inputnode.subjects_dir'),
924-
('subject_id', 'inputnode.subject_id'),
925-
('t1_seg', 'inputnode.t1_seg'),
926-
('t1_brain', 'inputnode.t1_brain')]),
927-
(inputnode, fsl2itk_fwd, [('t1_preproc', 'reference_file'),
928-
('ref_bold_brain', 'source_file')]),
929-
(inputnode, fsl2itk_inv, [('ref_bold_brain', 'reference_file'),
930-
('t1_preproc', 'source_file')]),
931-
(bbr_wf, invt_bbr, [('outputnode.out_matrix_file', 'in_file')]),
932-
(bbr_wf, fsl2itk_fwd, [('outputnode.out_matrix_file', 'transform_file')]),
933-
(invt_bbr, fsl2itk_inv, [('out_file', 'transform_file')]),
934-
(bbr_wf, outputnode, [('outputnode.out_matrix_file', 'mat_bold_to_t1'),
935-
('outputnode.out_reg_file', 'fs_reg_file'),
904+
(inputnode, bbr_wf, [
905+
('ref_bold_brain', 'inputnode.in_file'),
906+
('t1_2_fsnative_reverse_transform', 'inputnode.t1_2_fsnative_reverse_transform'),
907+
('subjects_dir', 'inputnode.subjects_dir'),
908+
('subject_id', 'inputnode.subject_id'),
909+
('t1_seg', 'inputnode.t1_seg'),
910+
('t1_brain', 'inputnode.t1_brain')]),
911+
(bbr_wf, outputnode, [('outputnode.itk_bold_to_t1', 'itk_bold_to_t1'),
912+
('outputnode.itk_t1_to_bold', 'itk_t1_to_bold'),
936913
('outputnode.out_report', 'out_report')]),
937-
(invt_bbr, outputnode, [('out_file', 'mat_t1_to_bold')]),
938-
(fsl2itk_fwd, outputnode, [('itk_transform', 'itk_bold_to_t1')]),
939-
(fsl2itk_inv, outputnode, [('itk_transform', 'itk_t1_to_bold')]),
940914
])
941915

942916
gen_ref = pe.Node(GenerateSamplingReference(), name='gen_ref',
@@ -952,7 +926,7 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads,
952926
(inputnode, gen_ref, [('ref_bold_brain', 'moving_image'),
953927
('t1_brain', 'fixed_image')]),
954928
(gen_ref, mask_t1w_tfm, [('out_file', 'reference_image')]),
955-
(fsl2itk_fwd, mask_t1w_tfm, [('itk_transform', 'transforms')]),
929+
(bbr_wf, mask_t1w_tfm, [('outputnode.itk_bold_to_t1', 'transforms')]),
956930
(inputnode, mask_t1w_tfm, [('ref_bold_mask', 'input_image')]),
957931
(mask_t1w_tfm, outputnode, [('output_image', 'bold_mask_t1')])
958932
])
@@ -977,7 +951,7 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads,
977951
merge = pe.Node(Merge(compress=use_compression), name='merge', mem_gb=bold_file_size_gb * 3)
978952

979953
workflow.connect([
980-
(fsl2itk_fwd, merge_xforms, [('itk_transform', 'in1')]),
954+
(bbr_wf, merge_xforms, [('outputnode.itk_bold_to_t1', 'in1')]),
981955
(merge_xforms, bold_to_t1w_transform, [('out', 'transforms')]),
982956
(inputnode, merge, [('name_source', 'header_source')]),
983957
(merge, outputnode, [('out_file', 'bold_t1')]),

0 commit comments

Comments
 (0)