Skip to content

Commit

Permalink
RF: Compute T1w-fsnative transform LTA from fsnative2t1w_xfm
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jan 19, 2023
1 parent 23d8c2b commit 66cb0bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
1 change: 0 additions & 1 deletion fmriprep/workflows/base.py
Expand Up @@ -421,7 +421,6 @@ def init_single_subject_wf(subject_id):
# Undefined if --fs-no-reconall, but this is safe
('outputnode.subjects_dir', 'inputnode.subjects_dir'),
('outputnode.subject_id', 'inputnode.subject_id'),
('outputnode.t1w2fsnative_xfm', 'inputnode.t1w2fsnative_xfm'),
('outputnode.fsnative2t1w_xfm', 'inputnode.fsnative2t1w_xfm')]),
])
# fmt:on
Expand Down
5 changes: 1 addition & 4 deletions fmriprep/workflows/bold/base.py
Expand Up @@ -107,8 +107,6 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False):
FreeSurfer SUBJECTS_DIR
subject_id
FreeSurfer subject ID
t1w2fsnative_xfm
LTA-style affine matrix translating from T1w to FreeSurfer-conformed subject space
fsnative2t1w_xfm
LTA-style affine matrix translating from FreeSurfer-conformed subject space to T1w
Expand Down Expand Up @@ -347,7 +345,6 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False):
"anat2std_xfm",
"std2anat_xfm",
"template",
"t1w2fsnative_xfm",
"fsnative2t1w_xfm",
"fmap",
"fmap_ref",
Expand Down Expand Up @@ -949,7 +946,7 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False):
(inputnode, bold_surf_wf, [
("subjects_dir", "inputnode.subjects_dir"),
("subject_id", "inputnode.subject_id"),
("t1w2fsnative_xfm", "inputnode.t1w2fsnative_xfm"),
("fsnative2t1w_xfm", "inputnode.fsnative2t1w_xfm"),
]),
(bold_t1_trans_wf, bold_surf_wf, [("outputnode.bold_t1", "inputnode.source_file")]),
(bold_surf_wf, outputnode, [("outputnode.surfaces", "surfaces")]),
Expand Down
31 changes: 11 additions & 20 deletions fmriprep/workflows/bold/resampling.py
Expand Up @@ -75,8 +75,8 @@ def init_bold_surf_wf(*, mem_gb, surface_spaces, medial_surface_nan, name="bold_
FreeSurfer SUBJECTS_DIR
subject_id
FreeSurfer subject ID
t1w2fsnative_xfm
LTA-style affine matrix translating from T1w to FreeSurfer-conformed subject space
fsnative2t1w_xfm
ITK-style affine matrix translating from FreeSurfer-conformed subject space to T1w
Outputs
-------
Expand All @@ -86,6 +86,7 @@ def init_bold_surf_wf(*, mem_gb, surface_spaces, medial_surface_nan, name="bold_
"""
from nipype.interfaces.io import FreeSurferSource
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from niworkflows.interfaces.nitransforms import ConcatenateXFMs
from niworkflows.interfaces.surf import GiftiSetAnatomicalStructure

workflow = Workflow(name=name)
Expand All @@ -99,7 +100,7 @@ def init_bold_surf_wf(*, mem_gb, surface_spaces, medial_surface_nan, name="bold_

inputnode = pe.Node(
niu.IdentityInterface(
fields=["source_file", "subject_id", "subjects_dir", "t1w2fsnative_xfm"]
fields=["source_file", "subject_id", "subjects_dir", "fsnative2t1w_xfm"]
),
name="inputnode",
)
Expand All @@ -126,7 +127,9 @@ def select_target(subject_id, space):
run_without_submitting=True,
mem_gb=DEFAULT_MEMORY_MIN_GB,
)
itk2lta = pe.Node(niu.Function(function=_itk2lta), name="itk2lta", run_without_submitting=True)
itk2lta = pe.Node(
ConcatenateXFMs(out_fmt="fs", inverse=True), name="itk2lta", run_without_submitting=True
)
sampler = pe.MapNode(
fs.SampleToSurface(
interp_method="trilinear",
Expand Down Expand Up @@ -160,14 +163,14 @@ def select_target(subject_id, space):
("subjects_dir", "subjects_dir")]),
(inputnode, targets, [("subject_id", "subject_id")]),
(inputnode, rename_src, [("source_file", "in_file")]),
(inputnode, itk2lta, [("source_file", "src_file"),
("t1w2fsnative_xfm", "in_file")]),
(get_fsnative, itk2lta, [("T1", "dst_file")]),
(inputnode, itk2lta, [("source_file", "reference"),
("fsnative2t1w_xfm", "in_xfms")]),
(get_fsnative, itk2lta, [("T1", "moving")]),
(inputnode, sampler, [("subjects_dir", "subjects_dir"),
("subject_id", "subject_id")]),
(itersource, targets, [("target", "space")]),
(itersource, rename_src, [("target", "subject")]),
(itk2lta, sampler, [("out", "reg_file")]),
(itk2lta, sampler, [("out_inv", "reg_file")]),
(targets, sampler, [("out", "target_subject")]),
(rename_src, sampler, [("out_file", "source_file")]),
(update_metadata, outputnode, [("out_file", "surfaces")]),
Expand Down Expand Up @@ -885,15 +888,3 @@ def _aslist(in_value):

def _is_native(in_value):
return in_value.get("resolution") == "native" or in_value.get("res") == "native"


def _itk2lta(in_file, src_file, dst_file):
from pathlib import Path

import nitransforms as nt

out_file = Path("out.lta").absolute()
nt.linear.load(
in_file, fmt="fs" if in_file.endswith(".lta") else "itk", reference=src_file
).to_filename(out_file, moving=dst_file, fmt="fs")
return str(out_file)

0 comments on commit 66cb0bb

Please sign in to comment.