diff --git a/sdcflows/fieldmaps.py b/sdcflows/fieldmaps.py index 0909592ee8..c03b52890e 100644 --- a/sdcflows/fieldmaps.py +++ b/sdcflows/fieldmaps.py @@ -446,7 +446,8 @@ def get_workflow(self, set_inputs=True, **kwargs): return self._wf # Override workflow name - kwargs["name"] = f"wf_{self.bids_id}" + clean_bids_id = re.sub(r'[^a-zA-Z0-9]', '', self.bids_id) + kwargs["name"] = f"wf_{clean_bids_id}" if self.method in (EstimatorType.MAPPED, EstimatorType.PHASEDIFF): from .workflows.fit.fieldmap import init_fmap_wf diff --git a/sdcflows/workflows/base.py b/sdcflows/workflows/base.py index 7c9c609d10..4a9f632fdd 100644 --- a/sdcflows/workflows/base.py +++ b/sdcflows/workflows/base.py @@ -21,6 +21,8 @@ # https://www.nipreps.org/community/licensing/ # """Estimate fieldmaps for :abbr:`SDC (susceptibility distortion correction)`.""" +import re + from nipype import logging from nipype.pipeline import engine as pe from nipype.interfaces import utility as niu @@ -106,6 +108,7 @@ def init_fmap_preproc_wf( ) for n, estimator in enumerate(estimators, 1): + clean_bids_id = re.sub(r'[^a-zA-Z0-9]', '', estimator.bids_id) est_wf = estimator.get_workflow( omp_nthreads=omp_nthreads, debug=debug, @@ -116,7 +119,7 @@ def init_fmap_preproc_wf( ] out_map = pe.Node( - niu.IdentityInterface(fields=out_fields), name=f"out_{estimator.bids_id}" + niu.IdentityInterface(fields=out_fields), name=f"out_{clean_bids_id}" ) out_map.inputs.fmap_id = estimator.bids_id @@ -124,7 +127,7 @@ def init_fmap_preproc_wf( output_dir=str(output_dir), write_coeff=True, bids_fmap_id=estimator.bids_id, - name=f"fmap_derivatives_wf_{estimator.bids_id}", + name=f"fmap_derivatives_wf_{clean_bids_id}", ) fmap_derivatives_wf.inputs.inputnode.source_files = source_files fmap_derivatives_wf.inputs.inputnode.fmap_meta = [ @@ -135,7 +138,7 @@ def init_fmap_preproc_wf( output_dir=str(output_dir), fmap_type=str(estimator.method).rpartition(".")[-1].lower(), bids_fmap_id=estimator.bids_id, - name=f"fmap_reports_wf_{estimator.bids_id}", + name=f"fmap_reports_wf_{clean_bids_id}", ) fmap_reports_wf.inputs.inputnode.source_files = source_files @@ -143,7 +146,7 @@ def init_fmap_preproc_wf( fields = INPUT_FIELDS[estimator.method] inputnode = pe.Node( niu.IdentityInterface(fields=fields), - name=f"in_{estimator.bids_id}", + name=f"in_{clean_bids_id}", ) # fmt:off workflow.connect([ diff --git a/sdcflows/workflows/fit/base.py b/sdcflows/workflows/fit/base.py index 1010b8b65f..09fc928221 100644 --- a/sdcflows/workflows/fit/base.py +++ b/sdcflows/workflows/fit/base.py @@ -25,6 +25,8 @@ def init_sdcflows_wf(): """Create a multi-subject, multi-estimator *SDCFlows* workflow.""" + import re + from nipype.pipeline.engine import Workflow from niworkflows.utils.bids import collect_participants @@ -51,6 +53,8 @@ def init_sdcflows_wf(): for subject, sub_estimators in estimators_record.items(): for estim in sub_estimators: + clean_bids_id = re.sub(r'[^a-zA-Z0-9]', '', estim.bids_id) + estim_wf = estim.get_workflow( omp_nthreads=config.nipype.omp_nthreads, sloppy=False, @@ -61,7 +65,7 @@ def init_sdcflows_wf(): output_dir=config.execution.output_dir, bids_fmap_id=estim.bids_id, write_coeff=True, - name=f"fmap_derivatives_{estim.bids_id}", + name=f"fmap_derivatives_{clean_bids_id}", ) source_paths = [ @@ -76,7 +80,7 @@ def init_sdcflows_wf(): fmap_type=estim.method, output_dir=config.execution.output_dir, bids_fmap_id=estim.bids_id, - name=f"fmap_reports_{estim.bids_id}", + name=f"fmap_reports_{clean_bids_id}", ) reportlets_wf.inputs.inputnode.source_files = source_paths diff --git a/sdcflows/workflows/outputs.py b/sdcflows/workflows/outputs.py index 01477a5aaf..35e0c72004 100644 --- a/sdcflows/workflows/outputs.py +++ b/sdcflows/workflows/outputs.py @@ -79,7 +79,7 @@ def init_fmap_reports_wf( custom_entities = custom_entities or {} if bids_fmap_id: - custom_entities["fmapid"] = bids_fmap_id.replace("_", "") + custom_entities["fmapid"] = re.sub(r'[^a-zA-Z0-9]', '', bids_fmap_id) workflow = pe.Workflow(name=name) inputnode = pe.Node(