Skip to content

Commit

Permalink
Use GenericLabel over MultiLabel (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Sep 4, 2024
1 parent 25bf8c2 commit 440fdf9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 63 deletions.
54 changes: 54 additions & 0 deletions src/fmripost_aroma/interfaces/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Miscellaneous interfaces for fmriprep-aroma."""

from nipype.interfaces.base import (
isdefined,
traits,
)
from nipype.utils.filemanip import fname_presuffix
from niworkflows.interfaces.fixes import (
FixHeaderApplyTransforms,
_FixTraitApplyTransformsInputSpec,
)


class _ApplyTransformsInputSpec(_FixTraitApplyTransformsInputSpec):
# Nipype's version doesn't have GenericLabel
interpolation = traits.Enum(
'Linear',
'NearestNeighbor',
'CosineWindowedSinc',
'WelchWindowedSinc',
'HammingWindowedSinc',
'LanczosWindowedSinc',
'MultiLabel',
'Gaussian',
'BSpline',
'GenericLabel',
argstr='%s',
usedefault=True,
)


class ApplyTransforms(FixHeaderApplyTransforms):
"""A modified version of FixHeaderApplyTransforms from niworkflows.
The niworkflows version of ApplyTransforms "fixes the resampled image header
to match the xform of the reference image".
This modification overrides the allowed interpolation values,
since FixHeaderApplyTransforms doesn't support GenericLabel,
which is preferred over MultiLabel.
"""

input_spec = _ApplyTransformsInputSpec

def _run_interface(self, runtime):
if not isdefined(self.inputs.output_image):
self.inputs.output_image = fname_presuffix(
self.inputs.input_image,
suffix='_trans.nii.gz',
newpath=runtime.cwd,
use_ext=False,
)

runtime = super()._run_interface(runtime)
return runtime
57 changes: 0 additions & 57 deletions src/fmripost_aroma/interfaces/resampler.py

This file was deleted.

5 changes: 3 additions & 2 deletions src/fmripost_aroma/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,11 @@ def init_single_run_wf(bold_file):
# Resample to MNI152NLin6Asym:res-2, for ICA-AROMA classification
from fmriprep.workflows.bold.apply import init_bold_volumetric_resample_wf
from fmriprep.workflows.bold.stc import init_bold_stc_wf
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from niworkflows.interfaces.header import ValidateImage
from templateflow.api import get as get_template

from fmripost_aroma.interfaces.misc import ApplyTransforms

workflow.__desc__ += """\
Raw BOLD series were resampled to MNI152NLin6Asym:res-2, for ICA-AROMA classification.
"""
Expand Down Expand Up @@ -451,7 +452,7 @@ def init_single_run_wf(bold_file):
# Warp the mask as well
mask_to_mni6 = pe.Node(
ApplyTransforms(
interpolation='MultiLabel',
interpolation='GenericLabel',
input_image=functional_cache['bold_mask_native'],
reference_image=mni6_mask,
transforms=[
Expand Down
4 changes: 2 additions & 2 deletions src/fmripost_aroma/workflows/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def init_carpetplot_wf(
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from templateflow.api import get as get_template

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

inputnode = pe.Node(
niu.IdentityInterface(
Expand Down Expand Up @@ -154,7 +154,7 @@ def init_carpetplot_wf(
),
),
],
interpolation='MultiLabel',
interpolation='GenericLabel',
args='-u int',
),
name='resample_parc',
Expand Down
4 changes: 2 additions & 2 deletions src/fmripost_aroma/workflows/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
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
from fmripost_aroma.interfaces.misc import ApplyTransforms


def init_func_fit_reports_wf(
Expand Down Expand Up @@ -82,7 +82,7 @@ def init_func_fit_reports_wf(

# Warp the tissue segmentation to MNI
dseg_to_mni6 = pe.Node(
ApplyTransforms(interpolation='MultiLabel'),
ApplyTransforms(interpolation='GenericLabel'),
name='dseg_to_mni6',
mem_gb=1,
)
Expand Down

0 comments on commit 440fdf9

Please sign in to comment.