Skip to content

Commit

Permalink
Add templateflow to DatasetLinks (#3267)
Browse files Browse the repository at this point in the history
References #3261.

## Changes proposed in this pull request

- Add the TemplateFlow base directory to the DatasetLinks.
- Add the template used for normalization to the Sources for
standard-space volumetric outputs.
  • Loading branch information
tsalo authored Apr 1, 2024
1 parent 123c3f8 commit 1e45712
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion fmriprep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
import os
from multiprocessing import set_start_method

from templateflow.conf import TF_LAYOUT

# Disable NiPype etelemetry always
_disable_et = bool(os.getenv('NO_ET') is not None or os.getenv('NIPYPE_NO_ET') is not None)
os.environ['NIPYPE_NO_ET'] = '1'
Expand Down Expand Up @@ -525,7 +527,10 @@ def _process_value(value):
for k, v in filters.items():
cls.bids_filters[acq][k] = _process_value(v)

dataset_links = {'raw': cls.bids_dir}
dataset_links = {
'raw': cls.bids_dir,
'templateflow': Path(TF_LAYOUT.root),
}
for deriv_name, deriv_path in cls.derivatives.items():
dataset_links[deriv_name] = deriv_path
cls.dataset_links = dataset_links
Expand Down
2 changes: 2 additions & 0 deletions fmriprep/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def write_derivative_description(bids_dir, deriv_dir, dataset_links=None):
# Add DatasetLinks
if dataset_links:
desc['DatasetLinks'] = {k: str(v) for k, v in dataset_links.items()}
if 'templateflow' in dataset_links:
desc['DatasetLinks']['templateflow'] = 'https://github.com/templateflow/templateflow'

Path.write_text(deriv_dir / 'dataset_description.json', json.dumps(desc, indent=4))

Expand Down
5 changes: 5 additions & 0 deletions fmriprep/workflows/bold/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ def init_bold_wf(
('outputnode.bold_mask', 'inputnode.bold_mask'),
('outputnode.coreg_boldref', 'inputnode.bold_ref'),
('outputnode.boldref2anat_xfm', 'inputnode.boldref2anat_xfm'),
('outputnode.motion_xfm', 'inputnode.motion_xfm'),
('outputnode.boldref2fmap_xfm', 'inputnode.boldref2fmap_xfm'),
]),
(bold_native_wf, ds_bold_t1_wf, [('outputnode.t2star_map', 'inputnode.t2star')]),
(bold_anat_wf, ds_bold_t1_wf, [
Expand Down Expand Up @@ -474,6 +476,7 @@ def init_bold_wf(
]),
(inputnode, ds_bold_std_wf, [
('anat2std_xfm', 'inputnode.anat2std_xfm'),
('std_t1w', 'inputnode.template'),
('std_space', 'inputnode.space'),
('std_resolution', 'inputnode.resolution'),
('std_cohort', 'inputnode.cohort'),
Expand All @@ -482,6 +485,8 @@ def init_bold_wf(
('outputnode.bold_mask', 'inputnode.bold_mask'),
('outputnode.coreg_boldref', 'inputnode.bold_ref'),
('outputnode.boldref2anat_xfm', 'inputnode.boldref2anat_xfm'),
('outputnode.motion_xfm', 'inputnode.motion_xfm'),
('outputnode.boldref2fmap_xfm', 'inputnode.boldref2fmap_xfm'),
]),
(bold_native_wf, ds_bold_std_wf, [('outputnode.t2star_map', 'inputnode.t2star')]),
(bold_std_wf, ds_bold_std_wf, [
Expand Down
14 changes: 11 additions & 3 deletions fmriprep/workflows/bold/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ def init_ds_bold_native_wf(
('source_files', 'source_file'),
('bold', 'in_file'),
]),
(sources, ds_bold, [('out', 'Sources')]),
]) # fmt:skip

if bold_output and multiecho:
Expand Down Expand Up @@ -734,6 +735,7 @@ def init_ds_volumes_wf(
'bold_mask', # boldref space
'bold_ref', # boldref space
't2star', # boldref space
'template', # target reference image from original transform
# Anatomical
'boldref2anat_xfm',
# Template
Expand All @@ -742,14 +744,17 @@ def init_ds_volumes_wf(
'space',
'cohort',
'resolution',
# Transforms previously used to generate the outputs
'motion_xfm',
'boldref2fmap_xfm',
]
),
name='inputnode',
)

sources = pe.Node(
BIDSURI(
numinputs=3,
numinputs=6,
dataset_links=config.execution.dataset_links,
out_dir=str(config.execution.fmriprep_dir.absolute()),
),
Expand All @@ -774,8 +779,11 @@ def init_ds_volumes_wf(
workflow.connect([
(inputnode, sources, [
('source_files', 'in1'),
('boldref2anat_xfm', 'in2'),
('anat2std_xfm', 'in3'),
('motion_xfm', 'in2'),
('boldref2fmap_xfm', 'in3'),
('boldref2anat_xfm', 'in4'),
('anat2std_xfm', 'in5'),
('template', 'in6'),
]),
(inputnode, boldref2target, [
# Note that ANTs expects transforms in target-to-source order
Expand Down

0 comments on commit 1e45712

Please sign in to comment.