Skip to content

Commit 6e409a2

Browse files
authored
Merge pull request #125 from slimnsour/enh/bbreg
ENH: Port bbregister T1-to-dwi registration from fmriprep
2 parents 7002869 + bc5b1af commit 6e409a2

File tree

7 files changed

+85
-2
lines changed

7 files changed

+85
-2
lines changed

.maint/developers.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
"name": "Lerma-Usabiaga, Garikoitz",
2323
"orcid": "0000-0001-9800-4816"
2424
},
25+
{
26+
"affiliation": "The Centre for Addiction and Mental Health",
27+
"name": "Mansour, Salim",
28+
"orcid": "0000-0002-1092-1650"
29+
},
2530
{
2631
"affiliation": "Department of Psychology, University of Texas at Austin, TX, USA",
2732
"name": "Pisner, Derek",

dmriprep/cli/parser.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def _bids_filter(value):
191191
action="store",
192192
nargs="+",
193193
default=[],
194-
choices=["fieldmaps", "slicetiming", "sbref"],
194+
choices=["fieldmaps", "sbref"],
195195
help="ignore selected aspects of the input dataset to disable corresponding "
196196
"parts of the workflow (a space delimited list)",
197197
)
@@ -219,6 +219,14 @@ def _bids_filter(value):
219219
https://www.nipreps.org/dmriprep/en/%s/spaces.html"""
220220
% (currentv.base_version if is_release else "latest"),
221221
)
222+
g_conf.add_argument(
223+
"--dwi2t1w-init",
224+
action="store",
225+
default="register",
226+
choices=["register", "header"],
227+
help='Either "register" (the default) to initialize volumes at center or "header"'
228+
" to use the header information when coregistering DWI to T1w images.",
229+
)
222230

223231
# ANTs options
224232
g_ants = parser.add_argument_group("Specific options for ANTs registrations")

dmriprep/config/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ class workflow(_Config):
425425

426426
anat_only = False
427427
"""Execute the anatomical preprocessing only."""
428+
dwi2t1w_init = "register"
429+
"""Whether to use standard coregistration ('register') or to initialize coregistration from the
430+
DWI header ('header')."""
428431
fmap_bspline = None
429432
"""Regularize fieldmaps with a field of B-Spline basis."""
430433
fmap_demean = None

dmriprep/config/reports-spec.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ sections:
4949
all b=0 found in the dataset, after accounting for signal drift.
5050
The red contour shows the brain mask calculated using this reference b=0.
5151
subtitle: Reference b=0 and brain mask
52+
- bids: {datatype: figures, desc: coreg, suffix: dwi}
53+
caption: Diffusion-weighted data and anatomical data (EPI-space and T1w-space)
54+
were aligned with <code>mri_coreg</code> (FreeSurfer).
55+
WARNING - <code>bbregister</code> refinement rejected.
56+
description: Note that nearest-neighbor interpolation is used in this reportlet
57+
in order to highlight potential slice Inhomogeneities and other artifacts, whereas
58+
the final images are resampled using cubic B-Spline interpolation.
59+
static: false
60+
subtitle: Alignment of functional and anatomical MRI data (volume based)
61+
- bids: {datatype: figures, desc: bbregister, suffix: dwi}
62+
caption: Diffusion-weighted data and anatomical data (EPI-space and T1w-space)
63+
were aligned with <code>bbregister</code> (FreeSurfer).
64+
description: Note that nearest-neighbor interpolation is used in this reportlet
65+
in order to highlight potential slice Inhomogeneities and other artifacts, whereas
66+
the final images are resampled using cubic B-Spline interpolation.
67+
static: false
68+
subtitle: Alignment of functional and anatomical MRI data (surface driven)
5269
- name: About
5370
reportlets:
5471
- bids: {datatype: figures, desc: about, suffix: T1w}

dmriprep/workflows/base.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from niworkflows.utils.misc import fix_multi_T1w_source_name
1313
from niworkflows.utils.spaces import Reference
1414
from smriprep.workflows.anatomical import init_anat_preproc_wf
15+
from fmriprep.workflows.bold.registration import init_bbreg_wf
1516

1617
from ..interfaces import DerivativesDataSink, BIDSDataGrabber
1718
from ..interfaces.reports import SubjectSummary, AboutSummary
@@ -287,7 +288,7 @@ def init_single_subject_wf(subject_id):
287288
return workflow
288289

289290
# Append the dMRI section to the existing anatomical excerpt
290-
# That way we do not need to stream down the number of bold datasets
291+
# That way we do not need to stream down the number of DWI datasets
291292
anat_preproc_wf.__postdesc__ = (
292293
(anat_preproc_wf.__postdesc__ or "")
293294
+ f"""
@@ -354,6 +355,53 @@ def init_single_subject_wf(subject_id):
354355
])
355356
# fmt:on
356357

358+
if config.workflow.run_reconall:
359+
from niworkflows.interfaces.nibabel import ApplyMask
360+
361+
# Mask the T1w
362+
t1w_brain = pe.Node(ApplyMask(), name="t1w_brain")
363+
364+
bbr_wf = init_bbreg_wf(
365+
bold2t1w_dof=6,
366+
bold2t1w_init=config.workflow.dwi2t1w_init,
367+
omp_nthreads=config.nipype.omp_nthreads,
368+
use_bbr=True,
369+
)
370+
371+
ds_report_reg = pe.Node(
372+
DerivativesDataSink(base_directory=str(output_dir), datatype="figures",),
373+
name="ds_report_reg",
374+
run_without_submitting=True,
375+
)
376+
377+
def _bold_reg_suffix(fallback):
378+
return "coreg" if fallback else "bbregister"
379+
380+
# fmt:off
381+
workflow.connect([
382+
# T1w Mask
383+
(anat_preproc_wf, t1w_brain, [
384+
("outputnode.t1w_preproc", "in_file"),
385+
("outputnode.t1w_mask", "in_mask"),
386+
]),
387+
# BBRegister
388+
(early_b0ref_wf, bbr_wf, [
389+
("outputnode.dwi_reference", "inputnode.in_file")
390+
]),
391+
(t1w_brain, bbr_wf, [("out_file", "inputnode.t1w_brain")]),
392+
(anat_preproc_wf, bbr_wf, [("outputnode.t1w_dseg", "inputnode.t1w_dseg")]),
393+
(fsinputnode, bbr_wf, [("subjects_dir", "inputnode.subjects_dir")]),
394+
(bids_info, bbr_wf, [(("subject", _prefix), "inputnode.subject_id")]),
395+
(anat_preproc_wf, bbr_wf, [
396+
("outputnode.fsnative2t1w_xfm", "inputnode.fsnative2t1w_xfm")
397+
]),
398+
(split_info, ds_report_reg, [("dwi_file", "source_file")]),
399+
(bbr_wf, ds_report_reg, [
400+
('outputnode.out_report', 'in_file'),
401+
(('outputnode.fallback', _bold_reg_suffix), 'desc')]),
402+
])
403+
# fmt:on
404+
357405
fmap_estimation_wf = init_fmap_estimation_wf(
358406
subject_data["dwi"], debug=config.execution.debug
359407
)

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
git+https://github.com/AleksandarPetrov/napoleon.git@0dc3f28a309ad602be5f44a9049785a1026451b3#egg=sphinxcontrib-napoleon
22
git+https://github.com/rwblair/sphinxcontrib-versioning.git@39b40b0b84bf872fc398feff05344051bbce0f63#egg=sphinxcontrib-versioning
3+
fmriprep
34
nbsphinx
45
nipype ~= 1.4
56
git+https://github.com/nipreps/niworkflows.git@master#egg=niworkflows

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ install_requires =
3333
smriprep ~= 0.7.0
3434
templateflow ~= 0.6
3535
toml
36+
fmriprep ~= 20.2
3637
setup_requires =
3738
setuptools >= 40.8.0
3839
test_requires =

0 commit comments

Comments
 (0)