Skip to content

Commit

Permalink
Add normalization report
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Sep 2, 2024
1 parent e689043 commit cffd29c
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/fmripost_aroma/data/io_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
"extension": [
".tsv"
]
},
"anat_dseg": {
"datatype": "anat",
"space": null,
"res": null,
"den": null,
"desc": null,
"suffix": "dseg",
"extension": [
".nii.gz",
".nii"
]
}
},
"transforms": {
Expand Down
11 changes: 10 additions & 1 deletion src/fmripost_aroma/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def init_single_run_wf(bold_file):

from fmripost_aroma.utils.bids import collect_derivatives, extract_entities
from fmripost_aroma.workflows.aroma import init_denoise_wf, init_ica_aroma_wf
from fmripost_aroma.workflows.outputs import init_func_fit_reports_wf

Check warning on line 288 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L288

Added line #L288 was not covered by tests

spaces = config.workflow.spaces
omp_nthreads = config.nipype.omp_nthreads

Check warning on line 291 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L291

Added line #L291 was not covered by tests
Expand All @@ -294,7 +295,6 @@ def init_single_run_wf(bold_file):

bold_metadata = config.execution.layout.get_metadata(bold_file)
mem_gb = estimate_bold_mem_usage(bold_file)[1]

Check warning on line 297 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L297

Added line #L297 was not covered by tests
ica_aroma_wf = init_ica_aroma_wf(bold_file=bold_file, metadata=bold_metadata, mem_gb=mem_gb)

entities = extract_entities(bold_file)

Expand Down Expand Up @@ -365,6 +365,8 @@ def init_single_run_wf(bold_file):
)
skip_vols = get_nss(functional_cache['confounds'])

# Run ICA-AROMA
ica_aroma_wf = init_ica_aroma_wf(bold_file=bold_file, metadata=bold_metadata, mem_gb=mem_gb)

Check warning on line 369 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L369

Added line #L369 was not covered by tests
ica_aroma_wf.inputs.inputnode.confounds = functional_cache['confounds']
ica_aroma_wf.inputs.inputnode.skip_vols = skip_vols

Expand Down Expand Up @@ -479,6 +481,13 @@ def init_single_run_wf(bold_file):
]),
]) # fmt:skip

# Generate reportlets
func_fit_reports_wf = init_func_fit_reports_wf(output_dir=config.execution.output_dir)
func_fit_reports_wf.inputs.inputnode.source_file = bold_file
func_fit_reports_wf.inputs.inputnode.anat2std_xfm = functional_cache['anat2mni152nlin6asym']
func_fit_reports_wf.inputs.inputnode.anat_dseg = functional_cache['anat_dseg']
workflow.connect([(mni6_buffer, func_fit_reports_wf, [('bold', 'inputnode.bold_mni6')])])

Check warning on line 489 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L485-L489

Added lines #L485 - L489 were not covered by tests

if config.workflow.denoise_method:
# Now denoise the output-space BOLD data using ICA-AROMA
denoise_wf = init_denoise_wf(bold_file=bold_file, metadata=bold_metadata)
Expand Down
135 changes: 135 additions & 0 deletions src/fmripost_aroma/workflows/outputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Writing out derivative files."""

from __future__ import annotations

from fmriprep.utils.bids import dismiss_echo
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from niworkflows.utils.images import dseg_label

from fmripost_aroma.config import DEFAULT_MEMORY_MIN_GB
from fmripost_aroma.interfaces.bids import DerivativesDataSink


def init_func_fit_reports_wf(
*,
output_dir: str,
name='func_fit_reports_wf',
) -> pe.Workflow:
"""Set up a battery of datasinks to store reports in the right location.
Parameters
----------
freesurfer : :obj:`bool`
FreeSurfer was enabled
output_dir : :obj:`str`
Directory in which to save derivatives
name : :obj:`str`
Workflow name (default: func_fit_reports_wf)
Inputs
------
source_file
Input BOLD images
"""
from nireports.interfaces.reporting.base import (

Check warning on line 58 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L58

Added line #L58 was not covered by tests
SimpleBeforeAfterRPT as SimpleBeforeAfter,
)

from fmripost_aroma.interfaces.nilearn import MeanImage

Check warning on line 62 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L62

Added line #L62 was not covered by tests

workflow = pe.Workflow(name=name)

Check warning on line 64 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L64

Added line #L64 was not covered by tests

inputfields = [

Check warning on line 66 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L66

Added line #L66 was not covered by tests
'source_file',
'bold_mni6',
'anat_dseg',
'anat2std_xfm',
]
inputnode = pe.Node(niu.IdentityInterface(fields=inputfields), name='inputnode')

Check warning on line 72 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L72

Added line #L72 was not covered by tests

# Average the BOLD image over time
calculate_mean_bold = pe.Node(

Check warning on line 75 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L75

Added line #L75 was not covered by tests
MeanImage(),
name='calculate_mean_bold',
mem_gb=1,
)
workflow.connect([(inputnode, calculate_mean_bold, [('bold_mni6', 'bold_file')])])

Check warning on line 80 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L80

Added line #L80 was not covered by tests

# Warp the tissue segmentation to MNI
dseg_to_mni6 = pe.Node(

Check warning on line 83 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L83

Added line #L83 was not covered by tests
ApplyTransforms(interpolation='MultiLabel'),
name='dseg_to_mni6',
mem_gb=1,
)
workflow.connect([

Check warning on line 88 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L88

Added line #L88 was not covered by tests
(inputnode, dseg_to_mni6, [
('anat_dseg', 'input_image'),
('anat2std_xfm', 'transforms'),
('bold_mni6', 'reference_image'),
]),
]) # fmt:skip

mni6_wm = pe.Node(

Check warning on line 96 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L96

Added line #L96 was not covered by tests
niu.Function(function=dseg_label),
name='mni6_wm',
mem_gb=DEFAULT_MEMORY_MIN_GB,
)
mni6_wm.inputs.label = 2 # BIDS default is WM=2
workflow.connect([(dseg_to_mni6, mni6_wm, [('output_image', 'in_file')])])

Check warning on line 102 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L101-L102

Added lines #L101 - L102 were not covered by tests

# EPI-MNI registration
epi_mni_report = pe.Node(

Check warning on line 105 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L105

Added line #L105 was not covered by tests
SimpleBeforeAfter(
before_label='T1w',
after_label='EPI',
dismiss_affine=True,
),
name='epi_mni_report',
mem_gb=0.1,
)
workflow.connect([

Check warning on line 114 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L114

Added line #L114 was not covered by tests
(inputnode, epi_mni_report, [('coreg_boldref', 'after')]),
(calculate_mean_bold, epi_mni_report, [('out_file', 'before')]),
(mni6_wm, epi_mni_report, [('output_image', 'wm_seg')]),
]) # fmt:skip

ds_epi_mni_report = pe.Node(

Check warning on line 120 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L120

Added line #L120 was not covered by tests
DerivativesDataSink(
base_directory=output_dir,
desc='coreg',
suffix='bold',
datatype='figures',
dismiss_entities=dismiss_echo(),
),
name='ds_epi_mni_report',
)
workflow.connect([

Check warning on line 130 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L130

Added line #L130 was not covered by tests
(inputnode, ds_epi_mni_report, [('source_file', 'source_file')]),
(epi_mni_report, ds_epi_mni_report, [('out_report', 'in_file')]),
]) # fmt:skip

return workflow

Check warning on line 135 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L135

Added line #L135 was not covered by tests

0 comments on commit cffd29c

Please sign in to comment.