Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTM] FIX: Use t1_2_fsnative registration when sampling to surface #762

Merged
merged 3 commits into from Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions fmriprep/workflows/anatomical.py
Expand Up @@ -156,6 +156,8 @@ def init_anat_preproc_wf(skull_strip_ants, skull_strip_template, output_spaces,
FreeSurfer SUBJECTS_DIR
subject_id
FreeSurfer subject ID
t1_2_fsnative_forward_transform
LTA-style affine matrix translating from T1w to FreeSurfer-conformed subject space
t1_2_fsnative_reverse_transform
LTA-style affine matrix translating from FreeSurfer-conformed subject space to T1w
surfaces
Expand All @@ -177,7 +179,8 @@ def init_anat_preproc_wf(skull_strip_ants, skull_strip_template, output_spaces,
fields=['t1_preproc', 't1_brain', 't1_mask', 't1_seg', 't1_tpms',
't1_2_mni', 't1_2_mni_forward_transform', 't1_2_mni_reverse_transform',
'mni_mask', 'mni_seg', 'mni_tpms',
'subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform', 'surfaces']),
'subjects_dir', 'subject_id', 't1_2_fsnative_forward_transform',
't1_2_fsnative_reverse_transform', 'surfaces']),
name='outputnode')

# 0. Reorient T1w image(s) to RAS and resample to common voxel space
Expand Down Expand Up @@ -319,6 +322,7 @@ def len_above_thresh(in_list, threshold, longitudinal):
(surface_recon_wf, outputnode, [
('outputnode.subjects_dir', 'subjects_dir'),
('outputnode.subject_id', 'subject_id'),
('outputnode.t1_2_fsnative_forward_transform', 't1_2_fsnative_forward_transform'),
('outputnode.t1_2_fsnative_reverse_transform', 't1_2_fsnative_reverse_transform'),
('outputnode.surfaces', 'surfaces')]),
])
Expand Down Expand Up @@ -368,7 +372,7 @@ def len_above_thresh(in_list, threshold, longitudinal):
('mni_mask', 'inputnode.mni_mask'),
('mni_seg', 'inputnode.mni_seg'),
('mni_tpms', 'inputnode.mni_tpms'),
('t1_2_fsnative_reverse_transform', 'inputnode.t1_2_fsnative_reverse_transform'),
('t1_2_fsnative_forward_transform', 'inputnode.t1_2_fsnative_forward_transform'),
('surfaces', 'inputnode.surfaces'),
]),
])
Expand Down Expand Up @@ -516,6 +520,8 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'):
FreeSurfer SUBJECTS_DIR
subject_id
FreeSurfer subject ID
t1_2_fsnative_forward_transform
LTA-style affine matrix translating from T1w to FreeSurfer-conformed subject space
t1_2_fsnative_reverse_transform
LTA-style affine matrix translating from FreeSurfer-conformed subject space to T1w
surfaces
Expand All @@ -538,7 +544,8 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'):
name='inputnode')
outputnode = pe.Node(
niu.IdentityInterface(
fields=['subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform', 'surfaces',
fields=['subjects_dir', 'subject_id', 't1_2_fsnative_forward_transform',
't1_2_fsnative_reverse_transform', 'surfaces',
'out_report']),
name='outputnode')

Expand All @@ -559,6 +566,8 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'):

fsnative_2_t1_xfm = pe.Node(fs.RobustRegister(auto_sens=True, est_int_scale=True),
name='fsnative_2_t1_xfm')
t1_2_fsnative_xfm = pe.Node(fs.utils.LTAConvert(out_lta=True, invert=True),
name='t1_2_fsnative_xfm')

autorecon_resume_wf = init_autorecon_resume_wf(omp_nthreads=omp_nthreads)
gifti_surface_wf = init_gifti_surface_wf()
Expand Down Expand Up @@ -591,11 +600,13 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'):
(autorecon1, fsnative_2_t1_xfm, [('T1', 'source_file')]),
(fsnative_2_t1_xfm, gifti_surface_wf, [
('out_reg_file', 'inputnode.t1_2_fsnative_reverse_transform')]),
(fsnative_2_t1_xfm, t1_2_fsnative_xfm, [('out_reg_file', 'in_lta')]),
# Output
(autorecon_resume_wf, outputnode, [('outputnode.subjects_dir', 'subjects_dir'),
('outputnode.subject_id', 'subject_id'),
('outputnode.out_report', 'out_report')]),
(gifti_surface_wf, outputnode, [('outputnode.surfaces', 'surfaces')]),
(t1_2_fsnative_xfm, outputnode, [('out_lta', 't1_2_fsnative_forward_transform')]),
(fsnative_2_t1_xfm, outputnode, [('out_reg_file', 't1_2_fsnative_reverse_transform')]),
])

Expand Down Expand Up @@ -875,7 +886,7 @@ def init_anat_derivatives_wf(output_dir, output_spaces, template, freesurfer,
fields=['source_file', 't1_preproc', 't1_mask', 't1_seg', 't1_tpms',
't1_2_mni_forward_transform', 't1_2_mni_reverse_transform',
't1_2_mni', 'mni_mask', 'mni_seg', 'mni_tpms',
't1_2_fsnative_reverse_transform', 'surfaces']),
't1_2_fsnative_forward_transform', 'surfaces']),
name='inputnode')

ds_t1_preproc = pe.Node(
Expand Down Expand Up @@ -930,7 +941,7 @@ def init_anat_derivatives_wf(output_dir, output_spaces, template, freesurfer,
DerivativesDataSink(base_directory=output_dir, suffix=suffix_fmt(template, 'warp')),
name='ds_t1_mni_warp', run_without_submitting=True)

lta_2_itk = pe.Node(fs.utils.LTAConvert(out_itk=True, invert=True), name='lta_2_itk')
lta_2_itk = pe.Node(fs.utils.LTAConvert(out_itk=True), name='lta_2_itk')

ds_t1_fsnative = pe.Node(
DerivativesDataSink(base_directory=output_dir, suffix=suffix_fmt('fsnative', 'affine')),
Expand Down Expand Up @@ -959,7 +970,7 @@ def init_anat_derivatives_wf(output_dir, output_spaces, template, freesurfer,

if freesurfer:
workflow.connect([
(inputnode, lta_2_itk, [('t1_2_fsnative_reverse_transform', 'in_lta')]),
(inputnode, lta_2_itk, [('t1_2_fsnative_forward_transform', 'in_lta')]),
(inputnode, ds_t1_fsnative, [('source_file', 'source_file')]),
(lta_2_itk, ds_t1_fsnative, [('out_itk', 'in_file')]),
(inputnode, name_surfs, [('surfaces', 'in_file')]),
Expand Down
18 changes: 8 additions & 10 deletions fmriprep/workflows/base.py
Expand Up @@ -447,16 +447,14 @@ def init_single_subject_wf(subject_id, task_id, name,
('outputnode.t1_seg', 'inputnode.t1_seg'),
('outputnode.t1_tpms', 'inputnode.t1_tpms'),
('outputnode.t1_2_mni_forward_transform', 'inputnode.t1_2_mni_forward_transform'),
('outputnode.t1_2_mni_reverse_transform', 'inputnode.t1_2_mni_reverse_transform')])
])

if freesurfer:
workflow.connect([
(anat_preproc_wf, func_preproc_wf,
[('outputnode.subjects_dir', 'inputnode.subjects_dir'),
('outputnode.subject_id', 'inputnode.subject_id'),
('outputnode.t1_2_fsnative_reverse_transform',
'inputnode.t1_2_fsnative_reverse_transform')]),
('outputnode.t1_2_mni_reverse_transform', 'inputnode.t1_2_mni_reverse_transform'),
# Undefined if --no-freesurfer, but this is safe
('outputnode.subjects_dir', 'inputnode.subjects_dir'),
('outputnode.subject_id', 'inputnode.subject_id'),
('outputnode.t1_2_fsnative_forward_transform',
'inputnode.t1_2_fsnative_forward_transform'),
('outputnode.t1_2_fsnative_reverse_transform',
'inputnode.t1_2_fsnative_reverse_transform')]),
])

return workflow
37 changes: 28 additions & 9 deletions fmriprep/workflows/bold.py
Expand Up @@ -179,8 +179,10 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
FreeSurfer SUBJECTS_DIR
subject_id
FreeSurfer subject ID
t1_2_fsnative_forward_transform
LTA-style affine matrix translating from T1w to FreeSurfer-conformed subject space
t1_2_fsnative_reverse_transform
Affine transform from FreeSurfer subject space to T1w space
LTA-style affine matrix translating from FreeSurfer-conformed subject space to T1w


**Outputs**
Expand Down Expand Up @@ -268,7 +270,8 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
inputnode = pe.Node(niu.IdentityInterface(
fields=['bold_file', 't1_preproc', 't1_brain', 't1_mask', 't1_seg', 't1_tpms',
't1_2_mni_forward_transform', 't1_2_mni_reverse_transform',
'subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform']),
'subjects_dir', 'subject_id', 't1_2_fsnative_forward_transform',
't1_2_fsnative_reverse_transform']),
name='inputnode')
inputnode.inputs.bold_file = bold_file

Expand Down Expand Up @@ -572,8 +575,11 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
medial_surface_nan=medial_surface_nan,
name='bold_surf_wf')
workflow.connect([
(inputnode, bold_surf_wf, [('subjects_dir', 'inputnode.subjects_dir'),
('subject_id', 'inputnode.subject_id')]),
(inputnode, bold_surf_wf, [
('t1_preproc', 'inputnode.t1_preproc'),
('subjects_dir', 'inputnode.subjects_dir'),
('subject_id', 'inputnode.subject_id'),
('t1_2_fsnative_forward_transform', 'inputnode.t1_2_fsnative_forward_transform')]),
(bold_reg_wf, bold_surf_wf, [('outputnode.bold_t1', 'inputnode.source_file')]),
(bold_surf_wf, outputnode, [('outputnode.surfaces', 'surfaces')]),
])
Expand Down Expand Up @@ -897,7 +903,7 @@ def init_bold_reg_wf(freesurfer, use_bbr, bold2t1w_dof, bold_file_size_gb, omp_n
subject_id
FreeSurfer subject ID
t1_2_fsnative_reverse_transform
Affine transform from FreeSurfer subject space to T1w space
LTA-style affine matrix translating from FreeSurfer-conformed subject space to T1w
fieldwarp
a :abbr:`DFM (displacements field map)` in ITK format

Expand Down Expand Up @@ -1041,10 +1047,14 @@ def init_bold_surf_wf(output_spaces, medial_surface_nan, name='bold_surf_wf'):

source_file
Motion-corrected BOLD series in T1 space
t1_preproc
Bias-corrected structural template image
subjects_dir
FreeSurfer SUBJECTS_DIR
subject_id
FreeSurfer subject ID
t1_2_fsnative_forward_transform
LTA-style affine matrix translating from T1w to FreeSurfer-conformed subject space

**Outputs**

Expand All @@ -1054,7 +1064,8 @@ def init_bold_surf_wf(output_spaces, medial_surface_nan, name='bold_surf_wf'):
"""
workflow = pe.Workflow(name=name)
inputnode = pe.Node(
niu.IdentityInterface(fields=['source_file', 'subject_id', 'subjects_dir']),
niu.IdentityInterface(fields=['source_file', 't1_preproc', 'subject_id', 'subjects_dir',
't1_2_fsnative_forward_transform']),
name='inputnode')

outputnode = pe.Node(niu.IdentityInterface(fields=['surfaces']), name='outputnode')
Expand All @@ -1076,11 +1087,14 @@ def select_target(subject_id, space):
mem_gb=DEFAULT_MEMORY_MIN_GB)
rename_src.inputs.subject = spaces

resampling_xfm = pe.Node(fs.utils.LTAConvert(in_lta='identity.nofile', out_lta=True),
name='resampling_xfm')
set_xfm_source = pe.Node(fs.ConcatenateLTA(out_type='RAS2RAS'), name='set_xfm_source')

sampler = pe.MapNode(
fs.SampleToSurface(sampling_method='average', sampling_range=(0, 1, 0.2),
sampling_units='frac', reg_header=True,
interp_method='trilinear', cortex_mask=True,
out_type='gii'),
sampling_units='frac', interp_method='trilinear', cortex_mask=True,
override_reg_subj=True, out_type='gii'),
iterfield=['source_file', 'target_subject'],
iterables=('hemi', ['lh', 'rh']),
name='sampler')
Expand Down Expand Up @@ -1121,8 +1135,13 @@ def medial_wall_to_nan(in_file, subjects_dir, target_subject):
workflow.connect([
(inputnode, targets, [('subject_id', 'subject_id')]),
(inputnode, rename_src, [('source_file', 'in_file')]),
(inputnode, resampling_xfm, [('source_file', 'source_file'),
('t1_preproc', 'target_file')]),
(inputnode, set_xfm_source, [('t1_2_fsnative_forward_transform', 'in_lta2')]),
(resampling_xfm, set_xfm_source, [('out_lta', 'in_lta1')]),
(inputnode, sampler, [('subjects_dir', 'subjects_dir'),
('subject_id', 'subject_id')]),
(set_xfm_source, sampler, [('out_file', 'reg_file')]),
(targets, sampler, [('out', 'target_subject')]),
(rename_src, sampler, [('out_file', 'source_file')]),
(merger, update_metadata, [('out', 'in_file')]),
Expand Down