Skip to content

Commit b10de08

Browse files
authored
Merge pull request #434 from tsalo/fmapid
Remove non-alphanumeric characters from workflow names and output entities
2 parents 2456489 + a18cdb2 commit b10de08

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

sdcflows/fieldmaps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ def get_workflow(self, set_inputs=True, **kwargs):
446446
return self._wf
447447

448448
# Override workflow name
449-
kwargs["name"] = f"wf_{self.bids_id}"
449+
clean_bids_id = re.sub(r'[^a-zA-Z0-9]', '', self.bids_id)
450+
kwargs["name"] = f"wf_{clean_bids_id}"
450451

451452
if self.method in (EstimatorType.MAPPED, EstimatorType.PHASEDIFF):
452453
from .workflows.fit.fieldmap import init_fmap_wf

sdcflows/workflows/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# https://www.nipreps.org/community/licensing/
2222
#
2323
"""Estimate fieldmaps for :abbr:`SDC (susceptibility distortion correction)`."""
24+
import re
25+
2426
from nipype import logging
2527
from nipype.pipeline import engine as pe
2628
from nipype.interfaces import utility as niu
@@ -106,6 +108,7 @@ def init_fmap_preproc_wf(
106108
)
107109

108110
for n, estimator in enumerate(estimators, 1):
111+
clean_bids_id = re.sub(r'[^a-zA-Z0-9]', '', estimator.bids_id)
109112
est_wf = estimator.get_workflow(
110113
omp_nthreads=omp_nthreads,
111114
debug=debug,
@@ -116,15 +119,15 @@ def init_fmap_preproc_wf(
116119
]
117120

118121
out_map = pe.Node(
119-
niu.IdentityInterface(fields=out_fields), name=f"out_{estimator.bids_id}"
122+
niu.IdentityInterface(fields=out_fields), name=f"out_{clean_bids_id}"
120123
)
121124
out_map.inputs.fmap_id = estimator.bids_id
122125

123126
fmap_derivatives_wf = init_fmap_derivatives_wf(
124127
output_dir=str(output_dir),
125128
write_coeff=True,
126129
bids_fmap_id=estimator.bids_id,
127-
name=f"fmap_derivatives_wf_{estimator.bids_id}",
130+
name=f"fmap_derivatives_wf_{clean_bids_id}",
128131
)
129132
fmap_derivatives_wf.inputs.inputnode.source_files = source_files
130133
fmap_derivatives_wf.inputs.inputnode.fmap_meta = [
@@ -135,15 +138,15 @@ def init_fmap_preproc_wf(
135138
output_dir=str(output_dir),
136139
fmap_type=str(estimator.method).rpartition(".")[-1].lower(),
137140
bids_fmap_id=estimator.bids_id,
138-
name=f"fmap_reports_wf_{estimator.bids_id}",
141+
name=f"fmap_reports_wf_{clean_bids_id}",
139142
)
140143
fmap_reports_wf.inputs.inputnode.source_files = source_files
141144

142145
if estimator.method not in (EstimatorType.MAPPED, EstimatorType.PHASEDIFF):
143146
fields = INPUT_FIELDS[estimator.method]
144147
inputnode = pe.Node(
145148
niu.IdentityInterface(fields=fields),
146-
name=f"in_{estimator.bids_id}",
149+
name=f"in_{clean_bids_id}",
147150
)
148151
# fmt:off
149152
workflow.connect([

sdcflows/workflows/fit/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
def init_sdcflows_wf():
2727
"""Create a multi-subject, multi-estimator *SDCFlows* workflow."""
28+
import re
29+
2830
from nipype.pipeline.engine import Workflow
2931
from niworkflows.utils.bids import collect_participants
3032

@@ -51,6 +53,8 @@ def init_sdcflows_wf():
5153

5254
for subject, sub_estimators in estimators_record.items():
5355
for estim in sub_estimators:
56+
clean_bids_id = re.sub(r'[^a-zA-Z0-9]', '', estim.bids_id)
57+
5458
estim_wf = estim.get_workflow(
5559
omp_nthreads=config.nipype.omp_nthreads,
5660
sloppy=False,
@@ -61,7 +65,7 @@ def init_sdcflows_wf():
6165
output_dir=config.execution.output_dir,
6266
bids_fmap_id=estim.bids_id,
6367
write_coeff=True,
64-
name=f"fmap_derivatives_{estim.bids_id}",
68+
name=f"fmap_derivatives_{clean_bids_id}",
6569
)
6670

6771
source_paths = [
@@ -76,7 +80,7 @@ def init_sdcflows_wf():
7680
fmap_type=estim.method,
7781
output_dir=config.execution.output_dir,
7882
bids_fmap_id=estim.bids_id,
79-
name=f"fmap_reports_{estim.bids_id}",
83+
name=f"fmap_reports_{clean_bids_id}",
8084
)
8185
reportlets_wf.inputs.inputnode.source_files = source_paths
8286

sdcflows/workflows/outputs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# https://www.nipreps.org/community/licensing/
2222
#
2323
"""Writing out outputs."""
24+
import re
25+
2426
from nipype.pipeline import engine as pe
2527
from nipype.interfaces import utility as niu
2628
from niworkflows.interfaces.bids import DerivativesDataSink as _DDS
@@ -77,7 +79,7 @@ def init_fmap_reports_wf(
7779

7880
custom_entities = custom_entities or {}
7981
if bids_fmap_id:
80-
custom_entities["fmapid"] = bids_fmap_id.replace("_", "")
82+
custom_entities["fmapid"] = re.sub(r'[^a-zA-Z0-9]', '', bids_fmap_id)
8183

8284
workflow = pe.Workflow(name=name)
8385
inputnode = pe.Node(
@@ -156,7 +158,7 @@ def init_fmap_derivatives_wf(
156158
"""
157159
custom_entities = custom_entities or {}
158160
if bids_fmap_id:
159-
custom_entities["fmapid"] = bids_fmap_id.replace("_", "")
161+
custom_entities["fmapid"] = re.sub(r'[^a-zA-Z0-9]', '', bids_fmap_id)
160162

161163
workflow = pe.Workflow(name=name)
162164
inputnode = pe.Node(

sdcflows/workflows/tests/test_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
"""Test the base workflow."""
2424
from pathlib import Path
2525
import os
26+
import re
27+
2628
import pytest
29+
2730
from sdcflows import fieldmaps as fm
2831
from sdcflows.utils.wrangler import find_estimators
2932
from sdcflows.workflows.base import init_fmap_preproc_wf
@@ -55,7 +58,8 @@ def test_fmap_wf(tmpdir, workdir, outdir, bids_layouts, dataset, subject):
5558
if estimator.method != fm.EstimatorType.PEPOLAR:
5659
continue
5760

58-
inputnode = wf.get_node(f"in_{estimator.bids_id}")
61+
clean_bids_id = re.sub(r'[^a-zA-Z0-9]', '', estimator.bids_id)
62+
inputnode = wf.get_node(f"in_{clean_bids_id}")
5963
inputnode.inputs.in_data = [str(f.path) for f in estimator.sources]
6064
inputnode.inputs.metadata = [f.metadata for f in estimator.sources]
6165

0 commit comments

Comments
 (0)