From 98696f1612b9c59efb03f0de5ec4f1aebc924c41 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 27 Jun 2025 12:47:18 +1000 Subject: [PATCH] updated auto-generated code with function tasks --- .../mriqc/interfaces/bids/iqm_file_sink.py | 8 +- .../tasks/mriqc/workflows/anatomical/base.py | 109 +++++---------- .../mriqc/workflows/anatomical/output.py | 2 +- pydra/tasks/mriqc/workflows/diffusion/base.py | 49 +++---- .../tasks/mriqc/workflows/diffusion/output.py | 6 +- .../tasks/mriqc/workflows/functional/base.py | 124 +++++++----------- .../mriqc/workflows/functional/output.py | 29 ++-- pydra/tasks/mriqc/workflows/shared.py | 2 +- 8 files changed, 121 insertions(+), 208 deletions(-) diff --git a/pydra/tasks/mriqc/interfaces/bids/iqm_file_sink.py b/pydra/tasks/mriqc/interfaces/bids/iqm_file_sink.py index 10dce50..9e5adf8 100644 --- a/pydra/tasks/mriqc/interfaces/bids/iqm_file_sink.py +++ b/pydra/tasks/mriqc/interfaces/bids/iqm_file_sink.py @@ -73,7 +73,7 @@ def function( fields = list(set(fields) - set(self_dict["inputs"].copyable_trait_names())) self_dict["_input_names"] = fields undefined_traits = { - key: _add_field(key, add_trait=add_trait, _outputs=_outputs) + key: _add_field(key, _outputs=_outputs, add_trait=add_trait) for key in fields } self_dict["inputs"].trait_set(trait_change_notify=False, **undefined_traits) @@ -82,7 +82,7 @@ def function( self_dict["_always_run"] = True self_dict = {} out_file = _gen_outfile( - in_file=in_file, out_dir=out_dir, dismiss_entities=dismiss_entities + dismiss_entities=dismiss_entities, out_dir=out_dir, in_file=in_file ) if root is not attrs.NOTHING: @@ -151,14 +151,14 @@ def function( return out_file -def _add_field(name, value=attrs.NOTHING, add_trait=None, _outputs=None): +def _add_field(name, value=attrs.NOTHING, _outputs=None, add_trait=None): self_dict = {} self_dict["inputs"].add_trait(name, traits.Any) _outputs[name] = value return value -def _gen_outfile(in_file=None, out_dir=None, dismiss_entities=None): +def _gen_outfile(dismiss_entities=None, out_dir=None, in_file=None): out_dir = Path() if out_dir is not attrs.NOTHING: out_dir = Path(out_dir) diff --git a/pydra/tasks/mriqc/workflows/anatomical/base.py b/pydra/tasks/mriqc/workflows/anatomical/base.py index 1795675..2625b98 100644 --- a/pydra/tasks/mriqc/workflows/anatomical/base.py +++ b/pydra/tasks/mriqc/workflows/anatomical/base.py @@ -51,17 +51,7 @@ def anat_qc_workflow( wf_inputs_metadata=None, wf_species="human", wf_template_id="MNI152NLin2009cAsym", -) -> [ - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", -]: +) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any]: """ One-subject-one-session-one-run pipeline to extract the NR-IQMs from anatomical images @@ -151,10 +141,10 @@ def anat_qc_workflow( norm = workflow.add( spatial_normalization( wf_species=wf_species, + nipype_omp_nthreads=nipype_omp_nthreads, wf_template_id=wf_template_id, exec_ants_float=exec_ants_float, exec_debug=exec_debug, - nipype_omp_nthreads=nipype_omp_nthreads, modality=modality, name="norm", ) @@ -196,9 +186,9 @@ def anat_qc_workflow( # Reports anat_report_wf = workflow.add( init_anat_report_wf( - wf_species=wf_species, exec_verbose_reports=exec_verbose_reports, exec_work_dir=exec_work_dir, + wf_species=wf_species, in_ras=to_ras.out_file, headmask=hmsk.out_file, airmask=amw.air_mask, @@ -235,12 +225,12 @@ def anat_qc_workflow( # fmt: on outputs_["norm_report"] = norm.report outputs_["iqmswf_noise_report"] = iqmswf.noise_report + outputs_["anat_report_wf_airmask_report"] = anat_report_wf.airmask_report + outputs_["anat_report_wf_bg_report"] = anat_report_wf.bg_report outputs_["anat_report_wf_bmask_report"] = anat_report_wf.bmask_report outputs_["anat_report_wf_artmask_report"] = anat_report_wf.artmask_report - outputs_["anat_report_wf_headmask_report"] = anat_report_wf.headmask_report - outputs_["anat_report_wf_bg_report"] = anat_report_wf.bg_report - outputs_["anat_report_wf_airmask_report"] = anat_report_wf.airmask_report outputs_["anat_report_wf_zoom_report"] = anat_report_wf.zoom_report + outputs_["anat_report_wf_headmask_report"] = anat_report_wf.headmask_report outputs_["anat_report_wf_segm_report"] = anat_report_wf.segm_report return tuple(outputs_) @@ -252,7 +242,7 @@ def airmsk_wf( in_file: ty.Any = attrs.NOTHING, ind2std_xfm: ty.Any = attrs.NOTHING, name="AirMaskWorkflow", -) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any]: """ Calculate air, artifacts and "hat" masks to evaluate noise in the background. @@ -314,7 +304,7 @@ def headmsk_wf( name="HeadMaskWorkflow", omp_nthreads=1, wf_species="human", -) -> ["ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any]: """ Computes a head mask as in [Mortamet2009]_. @@ -337,56 +327,32 @@ def _select_wm(inlist): return [f for f in inlist if "WM" in f][0] enhance = workflow.add( - FunctionTask( - func=_enhance, - input_spec=SpecInfo( - name="FunctionIn", - bases=(BaseSpec,), - fields=[("in_file", ty.Any), ("wm_tpm", ty.Any)], - ), - output_spec=SpecInfo( - name="FunctionOut", bases=(BaseSpec,), fields=[("out_file", ty.Any)] - ), - in_file=in_file, - wm_tpm=in_tpms, - ), + python.define( + _enhance, + inputs={"in_file": ty.Any, "wm_tpm": ty.Any}, + outputs={"out_file": ty.Any}, + )(in_file=in_file, wm_tpm=in_tpms), name="enhance", ) gradient = workflow.add( - FunctionTask( - func=image_gradient, - input_spec=SpecInfo( - name="FunctionIn", - bases=(BaseSpec,), - fields=[("in_file", ty.Any), ("brainmask", ty.Any), ("sigma", ty.Any)], - ), - output_spec=SpecInfo( - name="FunctionOut", bases=(BaseSpec,), fields=[("out_file", ty.Any)] - ), - brainmask=brainmask, - in_file=enhance.out_file, - ), + python.define( + image_gradient, + inputs={"in_file": ty.Any, "brainmask": ty.Any, "sigma": ty.Any}, + outputs={"out_file": ty.Any}, + )(brainmask=brainmask, in_file=enhance.out_file), name="gradient", ) thresh = workflow.add( - FunctionTask( - func=gradient_threshold, - input_spec=SpecInfo( - name="FunctionIn", - bases=(BaseSpec,), - fields=[ - ("in_file", ty.Any), - ("brainmask", ty.Any), - ("aniso", ty.Any), - ("thresh", ty.Any), - ], - ), - output_spec=SpecInfo( - name="FunctionOut", bases=(BaseSpec,), fields=[("out_file", ty.Any)] - ), - brainmask=brainmask, - in_file=gradient.out_file, - ), + python.define( + gradient_threshold, + inputs={ + "in_file": ty.Any, + "brainmask": ty.Any, + "aniso": ty.Any, + "thresh": ty.Any, + }, + outputs={"out_file": ty.Any}, + )(brainmask=brainmask, in_file=gradient.out_file), name="thresh", ) if wf_species != "human": @@ -412,7 +378,7 @@ def init_brain_tissue_segmentation( name="brain_tissue_segmentation", nipype_omp_nthreads=12, std_tpms: ty.Any = attrs.NOTHING, -) -> ["ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any]: """ Setup a workflow for brain tissue segmentation. @@ -454,15 +420,12 @@ def _format_tpm_names(in_files, fname_string=None): return file_format, out_files format_tpm_names = workflow.add( - FunctionTask( + python.define( + _format_tpm_names, + inputs={"in_files": ty.Any}, + outputs={"file_format": ty.Any}, + )( execution={"keep_inputs": True, "remove_unnecessary_outputs": False}, - func=_format_tpm_names, - input_spec=SpecInfo( - name="FunctionIn", bases=(BaseSpec,), fields=[("in_files", ty.Any)] - ), - output_spec=SpecInfo( - name="FunctionOut", bases=(BaseSpec,), fields=[("file_format", ty.Any)] - ), in_files=std_tpms, ), name="format_tpm_names", @@ -510,7 +473,7 @@ def spatial_normalization( nipype_omp_nthreads=12, wf_species="human", wf_template_id="MNI152NLin2009cAsym", -) -> ["ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any]: """Create a simplified workflow to perform fast spatial normalization.""" from pydra.tasks.niworkflows.interfaces.reportlets.registration import ( SpatialNormalizationRPT as RobustMNINormalization, @@ -595,7 +558,7 @@ def compute_iqms( segmentation: ty.Any = attrs.NOTHING, std_tpms: ty.Any = attrs.NOTHING, wf_species="human", -) -> ["ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any]: """ Setup the workflow that actually computes the IQMs. diff --git a/pydra/tasks/mriqc/workflows/anatomical/output.py b/pydra/tasks/mriqc/workflows/anatomical/output.py index e2ba900..4c500af 100644 --- a/pydra/tasks/mriqc/workflows/anatomical/output.py +++ b/pydra/tasks/mriqc/workflows/anatomical/output.py @@ -30,7 +30,7 @@ def init_anat_report_wf( name: str = "anat_report_wf", segmentation: ty.Any = attrs.NOTHING, wf_species="human", -) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any]: """ Generate the components of the individual report. diff --git a/pydra/tasks/mriqc/workflows/diffusion/base.py b/pydra/tasks/mriqc/workflows/diffusion/base.py index 4a67a5e..50c7cb0 100644 --- a/pydra/tasks/mriqc/workflows/diffusion/base.py +++ b/pydra/tasks/mriqc/workflows/diffusion/base.py @@ -44,17 +44,8 @@ def dmri_qc_workflow( wf_inputs_metadata=None, wf_species="human", wf_template_id="MNI152NLin2009cAsym", -) -> [ - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", +) -> tuple[ + ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any ]: """ Initialize the dMRI-QC workflow. @@ -209,12 +200,12 @@ def dmri_qc_workflow( # EPI to MNI registration spatial_norm = workflow.add( epi_mni_align( - nipype_omp_nthreads=nipype_omp_nthreads, wf_species=wf_species, - wf_template_id=wf_template_id, + nipype_omp_nthreads=nipype_omp_nthreads, nipype_nprocs=nipype_nprocs, - exec_debug=exec_debug, + wf_template_id=wf_template_id, exec_ants_float=exec_ants_float, + exec_debug=exec_debug, epi_mean=dwi_ref.out_file, epi_mask=dmri_bmsk.out_mask, name="spatial_norm", @@ -249,11 +240,11 @@ def dmri_qc_workflow( # Generate outputs dwi_report_wf = workflow.add( init_dwi_report_wf( - wf_species=wf_species, - wf_biggest_file_gb=wf_biggest_file_gb, exec_verbose_reports=exec_verbose_reports, - wf_fd_thres=wf_fd_thres, exec_work_dir=exec_work_dir, + wf_species=wf_species, + wf_fd_thres=wf_fd_thres, + wf_biggest_file_gb=wf_biggest_file_gb, in_bdict=shells.b_dict, brain_mask=dmri_bmsk.out_mask, in_avgmap=averages.out_file, @@ -313,14 +304,14 @@ def averages_out_file_to_iqms_wf_in_b0_callable(in_: ty.Any) -> ty.Any: # fmt: on outputs_["iqms_wf_out_file"] = iqms_wf.out_file outputs_["iqms_wf_noise_floor"] = iqms_wf.noise_floor - outputs_["dwi_report_wf_noise_report"] = dwi_report_wf.noise_report + outputs_["dwi_report_wf_heatmap_report"] = dwi_report_wf.heatmap_report + outputs_["dwi_report_wf_spikes_report"] = dwi_report_wf.spikes_report + outputs_["dwi_report_wf_fa_report"] = dwi_report_wf.fa_report + outputs_["dwi_report_wf_carpet_report"] = dwi_report_wf.carpet_report outputs_["dwi_report_wf_md_report"] = dwi_report_wf.md_report - outputs_["dwi_report_wf_bmask_report"] = dwi_report_wf.bmask_report + outputs_["dwi_report_wf_noise_report"] = dwi_report_wf.noise_report outputs_["dwi_report_wf_snr_report"] = dwi_report_wf.snr_report - outputs_["dwi_report_wf_carpet_report"] = dwi_report_wf.carpet_report - outputs_["dwi_report_wf_fa_report"] = dwi_report_wf.fa_report - outputs_["dwi_report_wf_spikes_report"] = dwi_report_wf.spikes_report - outputs_["dwi_report_wf_heatmap_report"] = dwi_report_wf.heatmap_report + outputs_["dwi_report_wf_bmask_report"] = dwi_report_wf.bmask_report return tuple(outputs_) @@ -332,7 +323,7 @@ def hmc_workflow( name="dMRI_HMC", reference: ty.Any = attrs.NOTHING, wf_fd_radius=50, -) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any]: """ Create a :abbr:`HMC (head motion correction)` workflow for dMRI. @@ -406,7 +397,7 @@ def epi_mni_align( nipype_omp_nthreads=12, wf_species="human", wf_template_id="MNI152NLin2009cAsym", -) -> ["ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any]: """ Estimate the transform that maps the EPI space into MNI152NLin2009cAsym. @@ -487,9 +478,7 @@ def epi_mni_align( suffix="mask", )[0] ) - bspline_grid = workflow.add( - FunctionTask(func=_bspline_grid), name="bspline_grid" - ) + bspline_grid = workflow.add(python.define(_bspline_grid)(), name="bspline_grid") # fmt: off bspline_grid.inputs.in_file = epi_mean n4itk.inputs.args = bspline_grid.out @@ -557,7 +546,7 @@ def compute_iqms( qspace_neighbors: ty.Any = attrs.NOTHING, spikes_mask: ty.Any = attrs.NOTHING, wm_mask: ty.Any = attrs.NOTHING, -) -> ["ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any]: """ Initialize the workflow that actually computes the IQMs. @@ -582,7 +571,7 @@ def compute_iqms( # from mriqc.workflows.utils import _tofloat, get_fwhmx estimate_sigma = workflow.add( - FunctionTask(func=_estimate_sigma, in_file=in_noise, mask=brain_mask), + python.define(_estimate_sigma)(in_file=in_noise, mask=brain_mask), name="estimate_sigma", ) measures = workflow.add( diff --git a/pydra/tasks/mriqc/workflows/diffusion/output.py b/pydra/tasks/mriqc/workflows/diffusion/output.py index 59d5766..48995e8 100644 --- a/pydra/tasks/mriqc/workflows/diffusion/output.py +++ b/pydra/tasks/mriqc/workflows/diffusion/output.py @@ -1,7 +1,7 @@ import attrs import logging from pathlib import Path -from pydra.compose import workflow +from pydra.compose import python, workflow from pydra.tasks.mriqc.workflows.diffusion.output import init_dwi_report_wf from pydra.tasks.nireports.interfaces.dmri import DWIHeatmap from pydra.tasks.nireports.interfaces.reporting.base import ( @@ -41,7 +41,7 @@ def init_dwi_report_wf( wf_biggest_file_gb=1, wf_fd_thres=0.2, wf_species="human", -) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any]: """ Write out individual reportlets. @@ -118,7 +118,7 @@ def _gen_entity(inlist): outputs_['md_report'] = mosaic_md.out_file # fmt: on get_wm = workflow.add( - FunctionTask(func=_get_wm, in_file=in_parcellation), name="get_wm" + python.define(_get_wm)(in_file=in_parcellation), name="get_wm" ) plot_heatmap = workflow.add( DWIHeatmap( diff --git a/pydra/tasks/mriqc/workflows/functional/base.py b/pydra/tasks/mriqc/workflows/functional/base.py index 89290b5..fd63a25 100644 --- a/pydra/tasks/mriqc/workflows/functional/base.py +++ b/pydra/tasks/mriqc/workflows/functional/base.py @@ -1,4 +1,5 @@ import attrs +from fileformats.field import Integer import logging from pydra.tasks.mriqc.workflows.functional.output import init_func_report_wf from pydra.tasks.niworkflows.utils.connections import pop_file as _pop @@ -12,9 +13,7 @@ @workflow.define(outputs=["out_file"]) -def fmri_bmsk_workflow( - in_file: ty.Any = attrs.NOTHING, name="fMRIBrainMask" -) -> ["ty.Any"]: +def fmri_bmsk_workflow(in_file: ty.Any = attrs.NOTHING, name="fMRIBrainMask") -> ty.Any: """ Compute a brain mask for the input :abbr:`fMRI (functional MRI)` dataset. @@ -55,7 +54,7 @@ def epi_mni_align( nipype_omp_nthreads=12, wf_species="human", wf_template_id="MNI152NLin2009cAsym", -) -> ["ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any]: """ Estimate the transform that maps the EPI space into MNI152NLin2009cAsym. @@ -136,9 +135,7 @@ def epi_mni_align( suffix="mask", )[0] ) - bspline_grid = workflow.add( - FunctionTask(func=_bspline_grid), name="bspline_grid" - ) + bspline_grid = workflow.add(python.define(_bspline_grid)(), name="bspline_grid") # fmt: off bspline_grid.inputs.in_file = epi_mean n4itk.inputs.args = bspline_grid.out @@ -191,7 +188,7 @@ def hmc( wf_biggest_file_gb=1, wf_deoblique=False, wf_despike=False, -) -> ["ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any]: """ Create a :abbr:`HMC (head motion correction)` workflow for fMRI. @@ -234,19 +231,10 @@ def hmc( ) # Apply transforms to other echos apply_hmc = workflow.add( - FunctionTask( - func=_apply_transforms, - input_spec=SpecInfo( - name="FunctionIn", - bases=(BaseSpec,), - fields=[ - ("in_file", ty.Any), - ("in_xfm", ty.Any), - ("max_concurrent", ty.Any), - ], - ), - in_xfm=estimate_hm.oned_matrix_save, - ), + python.define( + _apply_transforms, + inputs={"in_file": ty.Any, "in_xfm": ty.Any, "max_concurrent": ty.Any}, + )(in_xfm=estimate_hm.oned_matrix_save), name="apply_hmc", ) apply_hmc.inputs.inputs.max_concurrent = 4 @@ -349,7 +337,7 @@ def compute_iqms( name="ComputeIQMs", wf_biggest_file_gb=1, wf_fft_spikes_detector=False, -) -> ["ty.Any", "ty.Any", "ty.Any", "Integer", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any, Integer, ty.Any, ty.Any]: """ Initialize the workflow that actually computes the IQMs. @@ -444,21 +432,11 @@ def fwhm_fwhm_to_measures_in_fwhm_callable(in_: ty.Any) -> ty.Any: from pydra.tasks.mriqc.workflows.utils import slice_wise_fft spikes_fft = workflow.add( - FunctionTask( - func=slice_wise_fft, - input_spec=SpecInfo( - name="FunctionIn", bases=(BaseSpec,), fields=[("in_file", ty.Any)] - ), - output_spec=SpecInfo( - name="FunctionOut", - bases=(BaseSpec,), - fields=[ - ("n_spikes", ty.Any), - ("out_spikes", ty.Any), - ("out_fft", ty.Any), - ], - ), - ), + python.define( + slice_wise_fft, + inputs={"in_file": ty.Any}, + outputs={"n_spikes": ty.Any, "out_spikes": ty.Any, "out_fft": ty.Any}, + )(), name="spikes_fft", ) # fmt: off @@ -539,20 +517,20 @@ def fmri_qc_workflow( wf_inputs_metadata=None, wf_species="human", wf_template_id="MNI152NLin2009cAsym", -) -> [ - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", - "ty.Any", +) -> tuple[ + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, + ty.Any, ]: """ Initialize the (f)MRIQC workflow. @@ -626,8 +604,8 @@ def fmri_qc_workflow( hmcwf = workflow.add( hmc( omp_nthreads=nipype_omp_nthreads, - wf_biggest_file_gb=wf_biggest_file_gb, wf_deoblique=wf_deoblique, + wf_biggest_file_gb=wf_biggest_file_gb, wf_despike=wf_despike, in_file=sanitize.out_file, name="hmcwf", @@ -645,20 +623,20 @@ def fmri_qc_workflow( # EPI to MNI registration ema = workflow.add( epi_mni_align( - nipype_omp_nthreads=nipype_omp_nthreads, wf_species=wf_species, - wf_template_id=wf_template_id, + nipype_omp_nthreads=nipype_omp_nthreads, nipype_nprocs=nipype_nprocs, - exec_debug=exec_debug, + wf_template_id=wf_template_id, exec_ants_float=exec_ants_float, + exec_debug=exec_debug, name="ema", ) ) # 7. Compute IQMs iqmswf = workflow.add( compute_iqms( - wf_fft_spikes_detector=wf_fft_spikes_detector, wf_biggest_file_gb=wf_biggest_file_gb, + wf_fft_spikes_detector=wf_fft_spikes_detector, in_ras=sanitize.out_file, epi_mean=mean.out_file, hmc_epi=hmcwf.out_file, @@ -670,11 +648,11 @@ def fmri_qc_workflow( # Reports func_report_wf = workflow.add( init_func_report_wf( - wf_fft_spikes_detector=wf_fft_spikes_detector, - wf_species=wf_species, - wf_biggest_file_gb=wf_biggest_file_gb, exec_verbose_reports=exec_verbose_reports, exec_work_dir=exec_work_dir, + wf_species=wf_species, + wf_biggest_file_gb=wf_biggest_file_gb, + wf_fft_spikes_detector=wf_fft_spikes_detector, meta_sidecar=metadata, in_ras=sanitize.out_file, epi_mean=mean.out_file, @@ -727,17 +705,11 @@ def mean_out_file_to_skullstrip_epi_in_files_callable(in_: ty.Any) -> ty.Any: from pydra.tasks.mriqc.workflows.anatomical.base import _binarize binarise_labels = workflow.add( - FunctionTask( - func=_binarize, - input_spec=SpecInfo( - name="FunctionIn", - bases=(BaseSpec,), - fields=[("in_file", ty.Any), ("threshold", ty.Any)], - ), - output_spec=SpecInfo( - name="FunctionOut", bases=(BaseSpec,), fields=[("out_file", ty.Any)] - ), - ), + python.define( + _binarize, + inputs={"in_file": ty.Any, "threshold": ty.Any}, + outputs={"out_file": ty.Any}, + )(), name="binarise_labels", ) # fmt: off @@ -754,17 +726,17 @@ def mean_out_file_to_skullstrip_epi_in_files_callable(in_: ty.Any) -> ty.Any: outputs_['iqmswf_out_file'] = iqmswf.out_file # fmt: on outputs_["ema_report"] = ema.report + outputs_["iqmswf_outliers"] = iqmswf.outliers + outputs_["iqmswf_spikes"] = iqmswf.spikes + outputs_["iqmswf_out_file"] = iqmswf.out_file outputs_["iqmswf_spikes_num"] = iqmswf.spikes_num outputs_["iqmswf_fft"] = iqmswf.fft outputs_["iqmswf_dvars"] = iqmswf.dvars - outputs_["iqmswf_spikes"] = iqmswf.spikes - outputs_["iqmswf_out_file"] = iqmswf.out_file - outputs_["iqmswf_outliers"] = iqmswf.outliers outputs_["func_report_wf_carpet_report"] = func_report_wf.carpet_report - outputs_["func_report_wf_zoomed_report"] = func_report_wf.zoomed_report - outputs_["func_report_wf_mean_report"] = func_report_wf.mean_report - outputs_["func_report_wf_spikes_report"] = func_report_wf.spikes_report outputs_["func_report_wf_background_report"] = func_report_wf.background_report + outputs_["func_report_wf_spikes_report"] = func_report_wf.spikes_report + outputs_["func_report_wf_mean_report"] = func_report_wf.mean_report outputs_["func_report_wf_stdev_report"] = func_report_wf.stdev_report + outputs_["func_report_wf_zoomed_report"] = func_report_wf.zoomed_report return tuple(outputs_) diff --git a/pydra/tasks/mriqc/workflows/functional/output.py b/pydra/tasks/mriqc/workflows/functional/output.py index dfc51d0..de2ac45 100644 --- a/pydra/tasks/mriqc/workflows/functional/output.py +++ b/pydra/tasks/mriqc/workflows/functional/output.py @@ -1,7 +1,7 @@ import attrs import logging from pathlib import Path -from pydra.compose import workflow +from pydra.compose import python, workflow import typing as ty @@ -38,7 +38,7 @@ def init_func_report_wf( wf_biggest_file_gb=1, wf_fft_spikes_detector=False, wf_species="human", -) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any]: """ Write out individual reportlets. @@ -78,20 +78,11 @@ def init_func_report_wf( # Set FD threshold spmask = workflow.add( - FunctionTask( - func=spikes_mask, - input_spec=SpecInfo( - name="FunctionIn", - bases=(BaseSpec,), - fields=[("in_file", ty.Any), ("in_mask", ty.Any)], - ), - output_spec=SpecInfo( - name="FunctionOut", - bases=(BaseSpec,), - fields=[("out_file", ty.Any), ("out_plot", ty.Any)], - ), - in_file=in_ras, - ), + python.define( + spikes_mask, + inputs={"in_file": ty.Any, "in_mask": ty.Any}, + outputs={"out_file": ty.Any, "out_plot": ty.Any}, + )(in_file=in_ras), name="spmask", ) spikes_bg = workflow.add( @@ -106,10 +97,8 @@ def init_func_report_wf( name="subtract_mask", ) parcels = workflow.add( - FunctionTask( - func=_carpet_parcellation, - crown_mask=subtract_mask.out_mask, - segmentation=epi_parc, + python.define(_carpet_parcellation)( + crown_mask=subtract_mask.out_mask, segmentation=epi_parc ), name="parcels", ) diff --git a/pydra/tasks/mriqc/workflows/shared.py b/pydra/tasks/mriqc/workflows/shared.py index c8e199c..04f4fa1 100644 --- a/pydra/tasks/mriqc/workflows/shared.py +++ b/pydra/tasks/mriqc/workflows/shared.py @@ -10,7 +10,7 @@ @workflow.define(outputs=["out_brain", "bias_image", "out_mask", "out_corrected"]) def synthstrip_wf( in_files: ty.Any = attrs.NOTHING, name="synthstrip_wf", omp_nthreads=None -) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any"]: +) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any]: """Create a brain-extraction workflow using SynthStrip.""" from pydra.tasks.ants.auto import N4BiasFieldCorrection