Skip to content

Commit 03c5435

Browse files
authored
Merge pull request #476 from mgxd/enh/tag-fit
ENH: Tag structural workflows
2 parents 44c976f + eb52174 commit 03c5435

File tree

5 files changed

+32
-29
lines changed

5 files changed

+32
-29
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
"matplotlib >= 3.5",
2727
"nibabel >= 4.0.1",
2828
"nipype >= 1.8.5",
29-
"niworkflows >= 1.12.1",
29+
"niworkflows @ git+https://github.com/nipreps/niworkflows.git@master",
3030
"numpy >= 1.24",
3131
"packaging >= 24",
3232
"pybids >= 0.16",

src/smriprep/workflows/anatomical.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from nipype.interfaces.ants.base import Info as ANTsInfo
4040
from nipype.pipeline import engine as pe
4141
from niworkflows.anat.ants import init_brain_extraction_wf, init_n4_only_wf
42-
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
42+
from niworkflows.engine import Workflow, tag
4343
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
4444
from niworkflows.interfaces.freesurfer import (
4545
PatchedLTAConvert as LTAConvert,
@@ -463,6 +463,7 @@ def init_anat_preproc_wf(
463463
return workflow
464464

465465

466+
@tag('anat.fit')
466467
def init_anat_fit_wf(
467468
*,
468469
bids_root: str,

src/smriprep/workflows/fit/registration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
from nipype.interfaces import utility as niu
2929
from nipype.interfaces.ants.base import Info as ANTsInfo
3030
from nipype.pipeline import engine as pe
31-
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
31+
from niworkflows.engine import Workflow, tag
3232
from niworkflows.interfaces.norm import SpatialNormalization
3333
from templateflow import __version__ as tf_ver
3434
from templateflow.api import get_metadata
3535

3636
from ...interfaces.templateflow import TemplateDesc, TemplateFlowSelect
3737

3838

39+
@tag('anat.register-template')
3940
def init_register_template_wf(
4041
*,
4142
sloppy: bool,

src/smriprep/workflows/outputs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from nipype.interfaces import utility as niu
2828
from nipype.pipeline import engine as pe
29-
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
29+
from niworkflows.engine import Workflow, tag
3030
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
3131
from niworkflows.interfaces.nibabel import ApplyMask, GenerateSamplingReference
3232
from niworkflows.interfaces.space import SpaceDataSource
@@ -41,6 +41,7 @@
4141
BIDS_TISSUE_ORDER = ('GM', 'WM', 'CSF')
4242

4343

44+
@tag('anat.reports')
4445
def init_anat_reports_wf(*, spaces, freesurfer, output_dir, sloppy=False, name='anat_reports_wf'):
4546
"""
4647
Set up a battery of datasinks to store reports in the right location.

src/smriprep/workflows/surfaces.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from nipype.interfaces import utility as niu
3636
from nipype.interfaces.base import Undefined
3737
from nipype.pipeline import engine as pe
38-
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
38+
from niworkflows.engine import Workflow, tag
3939
from niworkflows.interfaces.freesurfer import (
4040
FSDetectInputs,
4141
FSInjectBrainExtracted,
@@ -62,6 +62,7 @@
6262
from ..interfaces.workbench import CreateSignedDistanceVolume
6363

6464

65+
@tag('anat.recon')
6566
def init_surface_recon_wf(
6667
*,
6768
omp_nthreads: int,
@@ -329,6 +330,7 @@ def init_surface_recon_wf(
329330
return workflow
330331

331332

333+
@tag('anat.mask-refine')
332334
def init_refinement_wf(
333335
*, image_type: ty.Literal['T1w', 'T2w'] = 'T1w', name: str = 'refinement_wf'
334336
) -> Workflow:
@@ -420,6 +422,7 @@ def init_refinement_wf(
420422
return workflow
421423

422424

425+
@tag('anat.fs-autorecon-resume')
423426
def init_autorecon_resume_wf(*, omp_nthreads, name='autorecon_resume_wf'):
424427
r"""
425428
Resume recon-all execution, assuming the `-autorecon1` stage has been completed.
@@ -569,7 +572,6 @@ def _dedup(in_list):
569572
raise ValueError(f"Non-identical values can't be deduplicated:\n{in_list!r}")
570573
return vals.pop()
571574

572-
# fmt:off
573575
workflow.connect([
574576
(inputnode, cortribbon, [('use_T2', 'use_T2'),
575577
('use_FLAIR', 'use_FLAIR')]),
@@ -587,12 +589,12 @@ def _dedup(in_list):
587589
(('subject_id', _dedup), 'subject_id')]),
588590
(autorecon3, outputnode, [('subjects_dir', 'subjects_dir'),
589591
('subject_id', 'subject_id')]),
590-
])
591-
# fmt:on
592+
]) # fmt:skip
592593

593594
return workflow
594595

595596

597+
@tag('anat.surface-derivatives')
596598
def init_surface_derivatives_wf(
597599
*,
598600
image_type: ty.Literal['T1w', 'T2w'] = 'T1w',
@@ -703,6 +705,7 @@ def init_surface_derivatives_wf(
703705
return workflow
704706

705707

708+
@tag('anat.fslr-reg')
706709
def init_fsLR_reg_wf(*, name='fsLR_reg_wf'):
707710
"""Generate GIFTI registration files to fsLR space"""
708711
from ..interfaces.workbench import SurfaceSphereProjectUnproject
@@ -743,6 +746,7 @@ def init_fsLR_reg_wf(*, name='fsLR_reg_wf'):
743746
return workflow
744747

745748

749+
@tag('anat.msm-sulc')
746750
def init_msm_sulc_wf(*, sloppy: bool = False, name: str = 'msm_sulc_wf'):
747751
"""Run MSMSulc registration to fsLR surfaces, per hemisphere."""
748752
from ..interfaces.msm import MSM
@@ -1024,6 +1028,7 @@ def init_gifti_morphometrics_wf(
10241028
return workflow
10251029

10261030

1031+
@tag('anat.hcp-morphs')
10271032
def init_hcp_morphometrics_wf(
10281033
*,
10291034
omp_nthreads: int,
@@ -1167,6 +1172,7 @@ def init_hcp_morphometrics_wf(
11671172
return workflow
11681173

11691174

1175+
@tag('anat.segs-to-anat')
11701176
def init_segs_to_native_wf(
11711177
*,
11721178
image_type: ty.Literal['T1w', 'T2w'] = 'T1w',
@@ -1247,6 +1253,7 @@ def init_segs_to_native_wf(
12471253
return workflow
12481254

12491255

1256+
@tag('anat.ribbon-mask')
12501257
def init_anat_ribbon_wf(name='anat_ribbon_wf'):
12511258
"""Create anatomical ribbon mask
12521259
@@ -1296,23 +1303,19 @@ def init_anat_ribbon_wf(name='anat_ribbon_wf'):
12961303

12971304
make_ribbon = pe.Node(MakeRibbon(), name='make_ribbon', mem_gb=DEFAULT_MEMORY_MIN_GB)
12981305

1299-
# fmt: off
1300-
workflow.connect(
1301-
[
1302-
(inputnode, create_wm_distvol, [
1303-
('white', 'surf_file'),
1304-
('ref_file', 'ref_file'),
1305-
]),
1306-
(inputnode, create_pial_distvol, [
1307-
('pial', 'surf_file'),
1308-
('ref_file', 'ref_file'),
1309-
]),
1310-
(create_wm_distvol, make_ribbon, [('out_file', 'white_distvols')]),
1311-
(create_pial_distvol, make_ribbon, [('out_file', 'pial_distvols')]),
1312-
(make_ribbon, outputnode, [('ribbon', 'anat_ribbon')]),
1313-
]
1314-
)
1315-
# fmt: on
1306+
workflow.connect([
1307+
(inputnode, create_wm_distvol, [
1308+
('white', 'surf_file'),
1309+
('ref_file', 'ref_file'),
1310+
]),
1311+
(inputnode, create_pial_distvol, [
1312+
('pial', 'surf_file'),
1313+
('ref_file', 'ref_file'),
1314+
]),
1315+
(create_wm_distvol, make_ribbon, [('out_file', 'white_distvols')]),
1316+
(create_pial_distvol, make_ribbon, [('out_file', 'pial_distvols')]),
1317+
(make_ribbon, outputnode, [('ribbon', 'anat_ribbon')]),
1318+
]) # fmt:skip
13161319
return workflow
13171320

13181321

@@ -1423,6 +1426,7 @@ def init_resample_surfaces_wf(
14231426
return workflow
14241427

14251428

1429+
@tag('anat.resample-morphs-grayords')
14261430
def init_morph_grayords_wf(
14271431
grayord_density: ty.Literal['91k', '170k'],
14281432
omp_nthreads: int,
@@ -1636,10 +1640,6 @@ def _sorted_by_basename(inlist):
16361640
return sorted(inlist, key=lambda x: str(basename(x)))
16371641

16381642

1639-
def _collate(files):
1640-
return [files[i : i + 2] for i in range(0, len(files), 2)]
1641-
1642-
16431643
def _extract_fs_fields(filenames: str | list[str]) -> tuple[str, str]:
16441644
from pathlib import Path
16451645

0 commit comments

Comments
 (0)