Skip to content

Commit 98696f1

Browse files
committed
updated auto-generated code with function tasks
1 parent 8359ed1 commit 98696f1

File tree

8 files changed

+121
-208
lines changed

8 files changed

+121
-208
lines changed

pydra/tasks/mriqc/interfaces/bids/iqm_file_sink.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def function(
7373
fields = list(set(fields) - set(self_dict["inputs"].copyable_trait_names()))
7474
self_dict["_input_names"] = fields
7575
undefined_traits = {
76-
key: _add_field(key, add_trait=add_trait, _outputs=_outputs)
76+
key: _add_field(key, _outputs=_outputs, add_trait=add_trait)
7777
for key in fields
7878
}
7979
self_dict["inputs"].trait_set(trait_change_notify=False, **undefined_traits)
@@ -82,7 +82,7 @@ def function(
8282
self_dict["_always_run"] = True
8383
self_dict = {}
8484
out_file = _gen_outfile(
85-
in_file=in_file, out_dir=out_dir, dismiss_entities=dismiss_entities
85+
dismiss_entities=dismiss_entities, out_dir=out_dir, in_file=in_file
8686
)
8787

8888
if root is not attrs.NOTHING:
@@ -151,14 +151,14 @@ def function(
151151
return out_file
152152

153153

154-
def _add_field(name, value=attrs.NOTHING, add_trait=None, _outputs=None):
154+
def _add_field(name, value=attrs.NOTHING, _outputs=None, add_trait=None):
155155
self_dict = {}
156156
self_dict["inputs"].add_trait(name, traits.Any)
157157
_outputs[name] = value
158158
return value
159159

160160

161-
def _gen_outfile(in_file=None, out_dir=None, dismiss_entities=None):
161+
def _gen_outfile(dismiss_entities=None, out_dir=None, in_file=None):
162162
out_dir = Path()
163163
if out_dir is not attrs.NOTHING:
164164
out_dir = Path(out_dir)

pydra/tasks/mriqc/workflows/anatomical/base.py

Lines changed: 36 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,7 @@ def anat_qc_workflow(
5151
wf_inputs_metadata=None,
5252
wf_species="human",
5353
wf_template_id="MNI152NLin2009cAsym",
54-
) -> [
55-
"ty.Any",
56-
"ty.Any",
57-
"ty.Any",
58-
"ty.Any",
59-
"ty.Any",
60-
"ty.Any",
61-
"ty.Any",
62-
"ty.Any",
63-
"ty.Any",
64-
]:
54+
) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any]:
6555
"""
6656
One-subject-one-session-one-run pipeline to extract the NR-IQMs from
6757
anatomical images
@@ -151,10 +141,10 @@ def anat_qc_workflow(
151141
norm = workflow.add(
152142
spatial_normalization(
153143
wf_species=wf_species,
144+
nipype_omp_nthreads=nipype_omp_nthreads,
154145
wf_template_id=wf_template_id,
155146
exec_ants_float=exec_ants_float,
156147
exec_debug=exec_debug,
157-
nipype_omp_nthreads=nipype_omp_nthreads,
158148
modality=modality,
159149
name="norm",
160150
)
@@ -196,9 +186,9 @@ def anat_qc_workflow(
196186
# Reports
197187
anat_report_wf = workflow.add(
198188
init_anat_report_wf(
199-
wf_species=wf_species,
200189
exec_verbose_reports=exec_verbose_reports,
201190
exec_work_dir=exec_work_dir,
191+
wf_species=wf_species,
202192
in_ras=to_ras.out_file,
203193
headmask=hmsk.out_file,
204194
airmask=amw.air_mask,
@@ -235,12 +225,12 @@ def anat_qc_workflow(
235225
# fmt: on
236226
outputs_["norm_report"] = norm.report
237227
outputs_["iqmswf_noise_report"] = iqmswf.noise_report
228+
outputs_["anat_report_wf_airmask_report"] = anat_report_wf.airmask_report
229+
outputs_["anat_report_wf_bg_report"] = anat_report_wf.bg_report
238230
outputs_["anat_report_wf_bmask_report"] = anat_report_wf.bmask_report
239231
outputs_["anat_report_wf_artmask_report"] = anat_report_wf.artmask_report
240-
outputs_["anat_report_wf_headmask_report"] = anat_report_wf.headmask_report
241-
outputs_["anat_report_wf_bg_report"] = anat_report_wf.bg_report
242-
outputs_["anat_report_wf_airmask_report"] = anat_report_wf.airmask_report
243232
outputs_["anat_report_wf_zoom_report"] = anat_report_wf.zoom_report
233+
outputs_["anat_report_wf_headmask_report"] = anat_report_wf.headmask_report
244234
outputs_["anat_report_wf_segm_report"] = anat_report_wf.segm_report
245235

246236
return tuple(outputs_)
@@ -252,7 +242,7 @@ def airmsk_wf(
252242
in_file: ty.Any = attrs.NOTHING,
253243
ind2std_xfm: ty.Any = attrs.NOTHING,
254244
name="AirMaskWorkflow",
255-
) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any"]:
245+
) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any]:
256246
"""
257247
Calculate air, artifacts and "hat" masks to evaluate noise in the background.
258248
@@ -314,7 +304,7 @@ def headmsk_wf(
314304
name="HeadMaskWorkflow",
315305
omp_nthreads=1,
316306
wf_species="human",
317-
) -> ["ty.Any", "ty.Any"]:
307+
) -> tuple[ty.Any, ty.Any]:
318308
"""
319309
Computes a head mask as in [Mortamet2009]_.
320310
@@ -337,56 +327,32 @@ def _select_wm(inlist):
337327
return [f for f in inlist if "WM" in f][0]
338328

339329
enhance = workflow.add(
340-
FunctionTask(
341-
func=_enhance,
342-
input_spec=SpecInfo(
343-
name="FunctionIn",
344-
bases=(BaseSpec,),
345-
fields=[("in_file", ty.Any), ("wm_tpm", ty.Any)],
346-
),
347-
output_spec=SpecInfo(
348-
name="FunctionOut", bases=(BaseSpec,), fields=[("out_file", ty.Any)]
349-
),
350-
in_file=in_file,
351-
wm_tpm=in_tpms,
352-
),
330+
python.define(
331+
_enhance,
332+
inputs={"in_file": ty.Any, "wm_tpm": ty.Any},
333+
outputs={"out_file": ty.Any},
334+
)(in_file=in_file, wm_tpm=in_tpms),
353335
name="enhance",
354336
)
355337
gradient = workflow.add(
356-
FunctionTask(
357-
func=image_gradient,
358-
input_spec=SpecInfo(
359-
name="FunctionIn",
360-
bases=(BaseSpec,),
361-
fields=[("in_file", ty.Any), ("brainmask", ty.Any), ("sigma", ty.Any)],
362-
),
363-
output_spec=SpecInfo(
364-
name="FunctionOut", bases=(BaseSpec,), fields=[("out_file", ty.Any)]
365-
),
366-
brainmask=brainmask,
367-
in_file=enhance.out_file,
368-
),
338+
python.define(
339+
image_gradient,
340+
inputs={"in_file": ty.Any, "brainmask": ty.Any, "sigma": ty.Any},
341+
outputs={"out_file": ty.Any},
342+
)(brainmask=brainmask, in_file=enhance.out_file),
369343
name="gradient",
370344
)
371345
thresh = workflow.add(
372-
FunctionTask(
373-
func=gradient_threshold,
374-
input_spec=SpecInfo(
375-
name="FunctionIn",
376-
bases=(BaseSpec,),
377-
fields=[
378-
("in_file", ty.Any),
379-
("brainmask", ty.Any),
380-
("aniso", ty.Any),
381-
("thresh", ty.Any),
382-
],
383-
),
384-
output_spec=SpecInfo(
385-
name="FunctionOut", bases=(BaseSpec,), fields=[("out_file", ty.Any)]
386-
),
387-
brainmask=brainmask,
388-
in_file=gradient.out_file,
389-
),
346+
python.define(
347+
gradient_threshold,
348+
inputs={
349+
"in_file": ty.Any,
350+
"brainmask": ty.Any,
351+
"aniso": ty.Any,
352+
"thresh": ty.Any,
353+
},
354+
outputs={"out_file": ty.Any},
355+
)(brainmask=brainmask, in_file=gradient.out_file),
390356
name="thresh",
391357
)
392358
if wf_species != "human":
@@ -412,7 +378,7 @@ def init_brain_tissue_segmentation(
412378
name="brain_tissue_segmentation",
413379
nipype_omp_nthreads=12,
414380
std_tpms: ty.Any = attrs.NOTHING,
415-
) -> ["ty.Any", "ty.Any"]:
381+
) -> tuple[ty.Any, ty.Any]:
416382
"""
417383
Setup a workflow for brain tissue segmentation.
418384
@@ -454,15 +420,12 @@ def _format_tpm_names(in_files, fname_string=None):
454420
return file_format, out_files
455421

456422
format_tpm_names = workflow.add(
457-
FunctionTask(
423+
python.define(
424+
_format_tpm_names,
425+
inputs={"in_files": ty.Any},
426+
outputs={"file_format": ty.Any},
427+
)(
458428
execution={"keep_inputs": True, "remove_unnecessary_outputs": False},
459-
func=_format_tpm_names,
460-
input_spec=SpecInfo(
461-
name="FunctionIn", bases=(BaseSpec,), fields=[("in_files", ty.Any)]
462-
),
463-
output_spec=SpecInfo(
464-
name="FunctionOut", bases=(BaseSpec,), fields=[("file_format", ty.Any)]
465-
),
466429
in_files=std_tpms,
467430
),
468431
name="format_tpm_names",
@@ -510,7 +473,7 @@ def spatial_normalization(
510473
nipype_omp_nthreads=12,
511474
wf_species="human",
512475
wf_template_id="MNI152NLin2009cAsym",
513-
) -> ["ty.Any", "ty.Any", "ty.Any"]:
476+
) -> tuple[ty.Any, ty.Any, ty.Any]:
514477
"""Create a simplified workflow to perform fast spatial normalization."""
515478
from pydra.tasks.niworkflows.interfaces.reportlets.registration import (
516479
SpatialNormalizationRPT as RobustMNINormalization,
@@ -595,7 +558,7 @@ def compute_iqms(
595558
segmentation: ty.Any = attrs.NOTHING,
596559
std_tpms: ty.Any = attrs.NOTHING,
597560
wf_species="human",
598-
) -> ["ty.Any", "ty.Any"]:
561+
) -> tuple[ty.Any, ty.Any]:
599562
"""
600563
Setup the workflow that actually computes the IQMs.
601564

pydra/tasks/mriqc/workflows/anatomical/output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def init_anat_report_wf(
3030
name: str = "anat_report_wf",
3131
segmentation: ty.Any = attrs.NOTHING,
3232
wf_species="human",
33-
) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any"]:
33+
) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any]:
3434
"""
3535
Generate the components of the individual report.
3636

pydra/tasks/mriqc/workflows/diffusion/base.py

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,8 @@ def dmri_qc_workflow(
4444
wf_inputs_metadata=None,
4545
wf_species="human",
4646
wf_template_id="MNI152NLin2009cAsym",
47-
) -> [
48-
"ty.Any",
49-
"ty.Any",
50-
"ty.Any",
51-
"ty.Any",
52-
"ty.Any",
53-
"ty.Any",
54-
"ty.Any",
55-
"ty.Any",
56-
"ty.Any",
57-
"ty.Any",
47+
) -> tuple[
48+
ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any
5849
]:
5950
"""
6051
Initialize the dMRI-QC workflow.
@@ -209,12 +200,12 @@ def dmri_qc_workflow(
209200
# EPI to MNI registration
210201
spatial_norm = workflow.add(
211202
epi_mni_align(
212-
nipype_omp_nthreads=nipype_omp_nthreads,
213203
wf_species=wf_species,
214-
wf_template_id=wf_template_id,
204+
nipype_omp_nthreads=nipype_omp_nthreads,
215205
nipype_nprocs=nipype_nprocs,
216-
exec_debug=exec_debug,
206+
wf_template_id=wf_template_id,
217207
exec_ants_float=exec_ants_float,
208+
exec_debug=exec_debug,
218209
epi_mean=dwi_ref.out_file,
219210
epi_mask=dmri_bmsk.out_mask,
220211
name="spatial_norm",
@@ -249,11 +240,11 @@ def dmri_qc_workflow(
249240
# Generate outputs
250241
dwi_report_wf = workflow.add(
251242
init_dwi_report_wf(
252-
wf_species=wf_species,
253-
wf_biggest_file_gb=wf_biggest_file_gb,
254243
exec_verbose_reports=exec_verbose_reports,
255-
wf_fd_thres=wf_fd_thres,
256244
exec_work_dir=exec_work_dir,
245+
wf_species=wf_species,
246+
wf_fd_thres=wf_fd_thres,
247+
wf_biggest_file_gb=wf_biggest_file_gb,
257248
in_bdict=shells.b_dict,
258249
brain_mask=dmri_bmsk.out_mask,
259250
in_avgmap=averages.out_file,
@@ -313,14 +304,14 @@ def averages_out_file_to_iqms_wf_in_b0_callable(in_: ty.Any) -> ty.Any:
313304
# fmt: on
314305
outputs_["iqms_wf_out_file"] = iqms_wf.out_file
315306
outputs_["iqms_wf_noise_floor"] = iqms_wf.noise_floor
316-
outputs_["dwi_report_wf_noise_report"] = dwi_report_wf.noise_report
307+
outputs_["dwi_report_wf_heatmap_report"] = dwi_report_wf.heatmap_report
308+
outputs_["dwi_report_wf_spikes_report"] = dwi_report_wf.spikes_report
309+
outputs_["dwi_report_wf_fa_report"] = dwi_report_wf.fa_report
310+
outputs_["dwi_report_wf_carpet_report"] = dwi_report_wf.carpet_report
317311
outputs_["dwi_report_wf_md_report"] = dwi_report_wf.md_report
318-
outputs_["dwi_report_wf_bmask_report"] = dwi_report_wf.bmask_report
312+
outputs_["dwi_report_wf_noise_report"] = dwi_report_wf.noise_report
319313
outputs_["dwi_report_wf_snr_report"] = dwi_report_wf.snr_report
320-
outputs_["dwi_report_wf_carpet_report"] = dwi_report_wf.carpet_report
321-
outputs_["dwi_report_wf_fa_report"] = dwi_report_wf.fa_report
322-
outputs_["dwi_report_wf_spikes_report"] = dwi_report_wf.spikes_report
323-
outputs_["dwi_report_wf_heatmap_report"] = dwi_report_wf.heatmap_report
314+
outputs_["dwi_report_wf_bmask_report"] = dwi_report_wf.bmask_report
324315

325316
return tuple(outputs_)
326317

@@ -332,7 +323,7 @@ def hmc_workflow(
332323
name="dMRI_HMC",
333324
reference: ty.Any = attrs.NOTHING,
334325
wf_fd_radius=50,
335-
) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any"]:
326+
) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any]:
336327
"""
337328
Create a :abbr:`HMC (head motion correction)` workflow for dMRI.
338329
@@ -406,7 +397,7 @@ def epi_mni_align(
406397
nipype_omp_nthreads=12,
407398
wf_species="human",
408399
wf_template_id="MNI152NLin2009cAsym",
409-
) -> ["ty.Any", "ty.Any", "ty.Any"]:
400+
) -> tuple[ty.Any, ty.Any, ty.Any]:
410401
"""
411402
Estimate the transform that maps the EPI space into MNI152NLin2009cAsym.
412403
@@ -487,9 +478,7 @@ def epi_mni_align(
487478
suffix="mask",
488479
)[0]
489480
)
490-
bspline_grid = workflow.add(
491-
FunctionTask(func=_bspline_grid), name="bspline_grid"
492-
)
481+
bspline_grid = workflow.add(python.define(_bspline_grid)(), name="bspline_grid")
493482
# fmt: off
494483
bspline_grid.inputs.in_file = epi_mean
495484
n4itk.inputs.args = bspline_grid.out
@@ -557,7 +546,7 @@ def compute_iqms(
557546
qspace_neighbors: ty.Any = attrs.NOTHING,
558547
spikes_mask: ty.Any = attrs.NOTHING,
559548
wm_mask: ty.Any = attrs.NOTHING,
560-
) -> ["ty.Any", "ty.Any"]:
549+
) -> tuple[ty.Any, ty.Any]:
561550
"""
562551
Initialize the workflow that actually computes the IQMs.
563552
@@ -582,7 +571,7 @@ def compute_iqms(
582571
# from mriqc.workflows.utils import _tofloat, get_fwhmx
583572

584573
estimate_sigma = workflow.add(
585-
FunctionTask(func=_estimate_sigma, in_file=in_noise, mask=brain_mask),
574+
python.define(_estimate_sigma)(in_file=in_noise, mask=brain_mask),
586575
name="estimate_sigma",
587576
)
588577
measures = workflow.add(

pydra/tasks/mriqc/workflows/diffusion/output.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import attrs
22
import logging
33
from pathlib import Path
4-
from pydra.compose import workflow
4+
from pydra.compose import python, workflow
55
from pydra.tasks.mriqc.workflows.diffusion.output import init_dwi_report_wf
66
from pydra.tasks.nireports.interfaces.dmri import DWIHeatmap
77
from pydra.tasks.nireports.interfaces.reporting.base import (
@@ -41,7 +41,7 @@ def init_dwi_report_wf(
4141
wf_biggest_file_gb=1,
4242
wf_fd_thres=0.2,
4343
wf_species="human",
44-
) -> ["ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any", "ty.Any"]:
44+
) -> tuple[ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any, ty.Any]:
4545
"""
4646
Write out individual reportlets.
4747
@@ -118,7 +118,7 @@ def _gen_entity(inlist):
118118
outputs_['md_report'] = mosaic_md.out_file
119119
# fmt: on
120120
get_wm = workflow.add(
121-
FunctionTask(func=_get_wm, in_file=in_parcellation), name="get_wm"
121+
python.define(_get_wm)(in_file=in_parcellation), name="get_wm"
122122
)
123123
plot_heatmap = workflow.add(
124124
DWIHeatmap(

0 commit comments

Comments
 (0)