Skip to content

Commit

Permalink
Merge pull request #125 from slimnsour/enh/bbreg
Browse files Browse the repository at this point in the history
ENH: Port bbregister T1-to-dwi registration from fmriprep
  • Loading branch information
oesteban authored Dec 4, 2020
2 parents 7002869 + bc5b1af commit 6e409a2
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .maint/developers.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"name": "Lerma-Usabiaga, Garikoitz",
"orcid": "0000-0001-9800-4816"
},
{
"affiliation": "The Centre for Addiction and Mental Health",
"name": "Mansour, Salim",
"orcid": "0000-0002-1092-1650"
},
{
"affiliation": "Department of Psychology, University of Texas at Austin, TX, USA",
"name": "Pisner, Derek",
Expand Down
10 changes: 9 additions & 1 deletion dmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _bids_filter(value):
action="store",
nargs="+",
default=[],
choices=["fieldmaps", "slicetiming", "sbref"],
choices=["fieldmaps", "sbref"],
help="ignore selected aspects of the input dataset to disable corresponding "
"parts of the workflow (a space delimited list)",
)
Expand Down Expand Up @@ -219,6 +219,14 @@ def _bids_filter(value):
https://www.nipreps.org/dmriprep/en/%s/spaces.html"""
% (currentv.base_version if is_release else "latest"),
)
g_conf.add_argument(
"--dwi2t1w-init",
action="store",
default="register",
choices=["register", "header"],
help='Either "register" (the default) to initialize volumes at center or "header"'
" to use the header information when coregistering DWI to T1w images.",
)

# ANTs options
g_ants = parser.add_argument_group("Specific options for ANTs registrations")
Expand Down
3 changes: 3 additions & 0 deletions dmriprep/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ class workflow(_Config):

anat_only = False
"""Execute the anatomical preprocessing only."""
dwi2t1w_init = "register"
"""Whether to use standard coregistration ('register') or to initialize coregistration from the
DWI header ('header')."""
fmap_bspline = None
"""Regularize fieldmaps with a field of B-Spline basis."""
fmap_demean = None
Expand Down
17 changes: 17 additions & 0 deletions dmriprep/config/reports-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ sections:
all b=0 found in the dataset, after accounting for signal drift.
The red contour shows the brain mask calculated using this reference b=0.
subtitle: Reference b=0 and brain mask
- bids: {datatype: figures, desc: coreg, suffix: dwi}
caption: Diffusion-weighted data and anatomical data (EPI-space and T1w-space)
were aligned with <code>mri_coreg</code> (FreeSurfer).
WARNING - <code>bbregister</code> refinement rejected.
description: Note that nearest-neighbor interpolation is used in this reportlet
in order to highlight potential slice Inhomogeneities and other artifacts, whereas
the final images are resampled using cubic B-Spline interpolation.
static: false
subtitle: Alignment of functional and anatomical MRI data (volume based)
- bids: {datatype: figures, desc: bbregister, suffix: dwi}
caption: Diffusion-weighted data and anatomical data (EPI-space and T1w-space)
were aligned with <code>bbregister</code> (FreeSurfer).
description: Note that nearest-neighbor interpolation is used in this reportlet
in order to highlight potential slice Inhomogeneities and other artifacts, whereas
the final images are resampled using cubic B-Spline interpolation.
static: false
subtitle: Alignment of functional and anatomical MRI data (surface driven)
- name: About
reportlets:
- bids: {datatype: figures, desc: about, suffix: T1w}
50 changes: 49 additions & 1 deletion dmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from niworkflows.utils.misc import fix_multi_T1w_source_name
from niworkflows.utils.spaces import Reference
from smriprep.workflows.anatomical import init_anat_preproc_wf
from fmriprep.workflows.bold.registration import init_bbreg_wf

from ..interfaces import DerivativesDataSink, BIDSDataGrabber
from ..interfaces.reports import SubjectSummary, AboutSummary
Expand Down Expand Up @@ -287,7 +288,7 @@ def init_single_subject_wf(subject_id):
return workflow

# Append the dMRI section to the existing anatomical excerpt
# That way we do not need to stream down the number of bold datasets
# That way we do not need to stream down the number of DWI datasets
anat_preproc_wf.__postdesc__ = (
(anat_preproc_wf.__postdesc__ or "")
+ f"""
Expand Down Expand Up @@ -354,6 +355,53 @@ def init_single_subject_wf(subject_id):
])
# fmt:on

if config.workflow.run_reconall:
from niworkflows.interfaces.nibabel import ApplyMask

# Mask the T1w
t1w_brain = pe.Node(ApplyMask(), name="t1w_brain")

bbr_wf = init_bbreg_wf(
bold2t1w_dof=6,
bold2t1w_init=config.workflow.dwi2t1w_init,
omp_nthreads=config.nipype.omp_nthreads,
use_bbr=True,
)

ds_report_reg = pe.Node(
DerivativesDataSink(base_directory=str(output_dir), datatype="figures",),
name="ds_report_reg",
run_without_submitting=True,
)

def _bold_reg_suffix(fallback):
return "coreg" if fallback else "bbregister"

# fmt:off
workflow.connect([
# T1w Mask
(anat_preproc_wf, t1w_brain, [
("outputnode.t1w_preproc", "in_file"),
("outputnode.t1w_mask", "in_mask"),
]),
# BBRegister
(early_b0ref_wf, bbr_wf, [
("outputnode.dwi_reference", "inputnode.in_file")
]),
(t1w_brain, bbr_wf, [("out_file", "inputnode.t1w_brain")]),
(anat_preproc_wf, bbr_wf, [("outputnode.t1w_dseg", "inputnode.t1w_dseg")]),
(fsinputnode, bbr_wf, [("subjects_dir", "inputnode.subjects_dir")]),
(bids_info, bbr_wf, [(("subject", _prefix), "inputnode.subject_id")]),
(anat_preproc_wf, bbr_wf, [
("outputnode.fsnative2t1w_xfm", "inputnode.fsnative2t1w_xfm")
]),
(split_info, ds_report_reg, [("dwi_file", "source_file")]),
(bbr_wf, ds_report_reg, [
('outputnode.out_report', 'in_file'),
(('outputnode.fallback', _bold_reg_suffix), 'desc')]),
])
# fmt:on

fmap_estimation_wf = init_fmap_estimation_wf(
subject_data["dwi"], debug=config.execution.debug
)
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
git+https://github.com/AleksandarPetrov/napoleon.git@0dc3f28a309ad602be5f44a9049785a1026451b3#egg=sphinxcontrib-napoleon
git+https://github.com/rwblair/sphinxcontrib-versioning.git@39b40b0b84bf872fc398feff05344051bbce0f63#egg=sphinxcontrib-versioning
fmriprep
nbsphinx
nipype ~= 1.4
git+https://github.com/nipreps/niworkflows.git@master#egg=niworkflows
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ install_requires =
smriprep ~= 0.7.0
templateflow ~= 0.6
toml
fmriprep ~= 20.2
setup_requires =
setuptools >= 40.8.0
test_requires =
Expand Down

0 comments on commit 6e409a2

Please sign in to comment.