diff --git a/sdcflows/utils/tests/test_wrangler.py b/sdcflows/utils/tests/test_wrangler.py index 88a8639022..37891d07ec 100644 --- a/sdcflows/utils/tests/test_wrangler.py +++ b/sdcflows/utils/tests/test_wrangler.py @@ -74,13 +74,13 @@ def gen_layout(bids_dir, database_dir=None): "EchoTime": 1.2, "PhaseEncodingDirection": "j-", "TotalReadoutTime": 0.8, - "IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz" + "IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz" }}, {"suffix": "epi", "dir": "PA", "metadata": { "EchoTime": 1.2, "PhaseEncodingDirection": "j", "TotalReadoutTime": 0.8, - "IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz" + "IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz" }} ], "func": [ @@ -103,13 +103,13 @@ def gen_layout(bids_dir, database_dir=None): "EchoTime": 1.2, "PhaseEncodingDirection": "j-", "TotalReadoutTime": 0.8, - "IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz" + "IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz" }}, {"suffix": "epi", "dir": "PA", "metadata": { "EchoTime": 1.2, "PhaseEncodingDirection": "j", "TotalReadoutTime": 0.8, - "IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz" + "IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz" }} ], "func": [ @@ -203,7 +203,7 @@ def gen_layout(bids_dir, database_dir=None): "metadata": { "EchoTime1": 1.2, "EchoTime2": 1.4, - "IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz" + "IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz" } }, {"suffix": "magnitude1", "metadata": {"EchoTime": 1.2}}, @@ -230,7 +230,7 @@ def gen_layout(bids_dir, database_dir=None): "metadata": { "EchoTime1": 1.2, "EchoTime2": 1.4, - "IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz" + "IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz" } }, {"suffix": "magnitude1", "metadata": {"EchoTime": 1.2}}, @@ -282,6 +282,17 @@ def test_wrangler_filter(tmpdir, name, skeleton, estimations): assert len(est) == estimations clear_registry() +@pytest.mark.parametrize('name,skeleton,estimations', [ + ('pepolar', pepolar, 3), + ('phasediff', phasediff, 3), +]) +def test_wrangler_URIs(tmpdir, name, skeleton, estimations): + bids_dir = str(tmpdir / name) + generate_bids_skeleton(bids_dir, skeleton) + layout = gen_layout(bids_dir) + est = find_estimators(layout=layout, subject='01') + assert len(est) == estimations + clear_registry() def test_single_reverse_pedir(tmp_path): bids_dir = tmp_path / "bids" diff --git a/sdcflows/utils/wrangler.py b/sdcflows/utils/wrangler.py index f046642777..0c45ea35c2 100644 --- a/sdcflows/utils/wrangler.py +++ b/sdcflows/utils/wrangler.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """Find fieldmaps on the BIDS inputs for :abbr:`SDC (susceptibility distortion correction)`.""" +from __future__ import annotations import logging from functools import reduce from itertools import product @@ -33,6 +34,19 @@ from .. import fieldmaps as fm +def _resolve_intent( + intent: str, + layout: BIDSLayout, + subject: str +) -> str | None: + root = Path(layout.root) + if intent.startswith("bids::"): + return str(root / intent[6:]) + if not intent.startswith("bids:"): + return str(root / f"sub-{subject}" / intent) + return intent + + def find_estimators( *, layout: BIDSLayout, @@ -427,7 +441,7 @@ def find_estimators( # Find existing IntendedFor targets and warn if missing all_targets = [] for intent in listify(epi_base_md["IntendedFor"]): - target = layout.get_file(str(subject_root / intent)) + target = layout.get_file(_resolve_intent(intent, layout, subject)) if target is None: logger.debug("Single PE target %s not found", intent) continue