Skip to content

Commit 8ca5637

Browse files
authored
Merge pull request #349 from effigies/enh/bids-uris
ENH: Resolve BIDS-URIs
2 parents 45eb7d0 + cea2cee commit 8ca5637

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

sdcflows/utils/tests/test_wrangler.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ def gen_layout(bids_dir, database_dir=None):
7474
"EchoTime": 1.2,
7575
"PhaseEncodingDirection": "j-",
7676
"TotalReadoutTime": 0.8,
77-
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
77+
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
7878
}},
7979
{"suffix": "epi", "dir": "PA", "metadata": {
8080
"EchoTime": 1.2,
8181
"PhaseEncodingDirection": "j",
8282
"TotalReadoutTime": 0.8,
83-
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
83+
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
8484
}}
8585
],
8686
"func": [
@@ -103,13 +103,13 @@ def gen_layout(bids_dir, database_dir=None):
103103
"EchoTime": 1.2,
104104
"PhaseEncodingDirection": "j-",
105105
"TotalReadoutTime": 0.8,
106-
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
106+
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
107107
}},
108108
{"suffix": "epi", "dir": "PA", "metadata": {
109109
"EchoTime": 1.2,
110110
"PhaseEncodingDirection": "j",
111111
"TotalReadoutTime": 0.8,
112-
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
112+
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
113113
}}
114114
],
115115
"func": [
@@ -203,7 +203,7 @@ def gen_layout(bids_dir, database_dir=None):
203203
"metadata": {
204204
"EchoTime1": 1.2,
205205
"EchoTime2": 1.4,
206-
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
206+
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
207207
}
208208
},
209209
{"suffix": "magnitude1", "metadata": {"EchoTime": 1.2}},
@@ -230,7 +230,7 @@ def gen_layout(bids_dir, database_dir=None):
230230
"metadata": {
231231
"EchoTime1": 1.2,
232232
"EchoTime2": 1.4,
233-
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
233+
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
234234
}
235235
},
236236
{"suffix": "magnitude1", "metadata": {"EchoTime": 1.2}},
@@ -282,6 +282,17 @@ def test_wrangler_filter(tmpdir, name, skeleton, estimations):
282282
assert len(est) == estimations
283283
clear_registry()
284284

285+
@pytest.mark.parametrize('name,skeleton,estimations', [
286+
('pepolar', pepolar, 3),
287+
('phasediff', phasediff, 3),
288+
])
289+
def test_wrangler_URIs(tmpdir, name, skeleton, estimations):
290+
bids_dir = str(tmpdir / name)
291+
generate_bids_skeleton(bids_dir, skeleton)
292+
layout = gen_layout(bids_dir)
293+
est = find_estimators(layout=layout, subject='01')
294+
assert len(est) == estimations
295+
clear_registry()
285296

286297
def test_single_reverse_pedir(tmp_path):
287298
bids_dir = tmp_path / "bids"

sdcflows/utils/wrangler.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# https://www.nipreps.org/community/licensing/
2222
#
2323
"""Find fieldmaps on the BIDS inputs for :abbr:`SDC (susceptibility distortion correction)`."""
24+
from __future__ import annotations
2425
import logging
2526
from functools import reduce
2627
from itertools import product
@@ -33,6 +34,19 @@
3334
from .. import fieldmaps as fm
3435

3536

37+
def _resolve_intent(
38+
intent: str,
39+
layout: BIDSLayout,
40+
subject: str
41+
) -> str | None:
42+
root = Path(layout.root)
43+
if intent.startswith("bids::"):
44+
return str(root / intent[6:])
45+
if not intent.startswith("bids:"):
46+
return str(root / f"sub-{subject}" / intent)
47+
return intent
48+
49+
3650
def find_estimators(
3751
*,
3852
layout: BIDSLayout,
@@ -427,7 +441,7 @@ def find_estimators(
427441
# Find existing IntendedFor targets and warn if missing
428442
all_targets = []
429443
for intent in listify(epi_base_md["IntendedFor"]):
430-
target = layout.get_file(str(subject_root / intent))
444+
target = layout.get_file(_resolve_intent(intent, layout, subject))
431445
if target is None:
432446
logger.debug("Single PE target %s not found", intent)
433447
continue

0 commit comments

Comments
 (0)