From 9fed90c28b0853eb81bc64292d7eac9673475811 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Wed, 4 Sep 2024 09:04:33 -0400 Subject: [PATCH] Use GenericLabel and set nprocs. --- src/fmripost_rapidtide/interfaces/misc.py | 54 +++++++++++++++++++ .../interfaces/rapidtide.py | 6 +++ src/fmripost_rapidtide/workflows/base.py | 3 +- src/fmripost_rapidtide/workflows/confounds.py | 2 +- src/fmripost_rapidtide/workflows/outputs.py | 2 +- src/fmripost_rapidtide/workflows/rapidtide.py | 3 +- 6 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/fmripost_rapidtide/interfaces/misc.py diff --git a/src/fmripost_rapidtide/interfaces/misc.py b/src/fmripost_rapidtide/interfaces/misc.py new file mode 100644 index 0000000..0064d71 --- /dev/null +++ b/src/fmripost_rapidtide/interfaces/misc.py @@ -0,0 +1,54 @@ +"""Miscellaneous interfaces for fmriprep-rapidtide.""" + +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(ApplyTransforms, self)._run_interface(runtime) + return runtime diff --git a/src/fmripost_rapidtide/interfaces/rapidtide.py b/src/fmripost_rapidtide/interfaces/rapidtide.py index 6a3c93a..0f8afc5 100644 --- a/src/fmripost_rapidtide/interfaces/rapidtide.py +++ b/src/fmripost_rapidtide/interfaces/rapidtide.py @@ -252,6 +252,12 @@ class _RapidtideInputSpec(CommandLineInputSpec): argstr='--autorespdelete', mandatory=False, ) + nprocs = traits.Int( + default=1, + usedefault=True, + argstr='--nprocs %d', + mandatory=False, + ) class _RapidtideOutputSpec(TraitedSpec): diff --git a/src/fmripost_rapidtide/workflows/base.py b/src/fmripost_rapidtide/workflows/base.py index 8312c2e..f411bba 100644 --- a/src/fmripost_rapidtide/workflows/base.py +++ b/src/fmripost_rapidtide/workflows/base.py @@ -391,10 +391,11 @@ def init_single_run_wf(bold_file): # Resample to MNI152NLin6Asym:res-2, for rapidtide denoising 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_rapidtide.interfaces.misc import ApplyTransforms + workflow.__desc__ += """\ Raw BOLD series were resampled to MNI152NLin6Asym:res-2, for rapidtide denoising. """ diff --git a/src/fmripost_rapidtide/workflows/confounds.py b/src/fmripost_rapidtide/workflows/confounds.py index 57f9075..5be5ad2 100644 --- a/src/fmripost_rapidtide/workflows/confounds.py +++ b/src/fmripost_rapidtide/workflows/confounds.py @@ -82,12 +82,12 @@ 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_rapidtide.config import DEFAULT_MEMORY_MIN_GB from fmripost_rapidtide.interfaces import DerivativesDataSink from fmripost_rapidtide.interfaces.confounds import FMRISummary + from fmripost_rapidtide.interfaces.misc import ApplyTransforms inputnode = pe.Node( niu.IdentityInterface( diff --git a/src/fmripost_rapidtide/workflows/outputs.py b/src/fmripost_rapidtide/workflows/outputs.py index 194dd32..f24a50e 100644 --- a/src/fmripost_rapidtide/workflows/outputs.py +++ b/src/fmripost_rapidtide/workflows/outputs.py @@ -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_rapidtide.config import DEFAULT_MEMORY_MIN_GB from fmripost_rapidtide.interfaces.bids import DerivativesDataSink +from fmripost_rapidtide.interfaces.misc import ApplyTransforms def init_func_fit_reports_wf( diff --git a/src/fmripost_rapidtide/workflows/rapidtide.py b/src/fmripost_rapidtide/workflows/rapidtide.py index 0c9e93e..4e64477 100644 --- a/src/fmripost_rapidtide/workflows/rapidtide.py +++ b/src/fmripost_rapidtide/workflows/rapidtide.py @@ -135,7 +135,6 @@ def init_rapidtide_wf( rapidtide = pe.Node( Rapidtide( outputname='rapidtide', - denoising=True, datatstep=metadata['RepetitionTime'], autosync=config.workflow.autosync, filterband=config.workflow.filterband, @@ -169,9 +168,11 @@ def init_rapidtide_wf( outputlevel=config.workflow.outputlevel, territorymap=config.workflow.territorymap or Undefined, autorespdelete=config.workflow.autorespdelete, + nprocs=config.nipype.omp_nthreads, ), name='rapidtide', mem_gb=mem_gb['largemem'], + n_procs=config.nipype.omp_nthreads, ) workflow.connect([ (inputnode, rapidtide, [