Skip to content

Commit 064b556

Browse files
committed
ENH: Resolve BIDS-URIs
1 parent 0c497ab commit 064b556

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

sdcflows/utils/tests/test_wrangler.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
"EchoTime": 1.2,
4747
"PhaseEncodingDirection": "j-",
4848
"TotalReadoutTime": 0.8,
49-
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
49+
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
5050
}},
5151
{"suffix": "epi", "dir": "PA", "metadata": {
5252
"EchoTime": 1.2,
5353
"PhaseEncodingDirection": "j",
5454
"TotalReadoutTime": 0.8,
55-
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
55+
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
5656
}}
5757
],
5858
"func": [
@@ -75,13 +75,13 @@
7575
"EchoTime": 1.2,
7676
"PhaseEncodingDirection": "j-",
7777
"TotalReadoutTime": 0.8,
78-
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
78+
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
7979
}},
8080
{"suffix": "epi", "dir": "PA", "metadata": {
8181
"EchoTime": 1.2,
8282
"PhaseEncodingDirection": "j",
8383
"TotalReadoutTime": 0.8,
84-
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
84+
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
8585
}}
8686
],
8787
"func": [
@@ -138,7 +138,7 @@
138138
"metadata": {
139139
"EchoTime1": 1.2,
140140
"EchoTime2": 1.4,
141-
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
141+
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
142142
}
143143
},
144144
{"suffix": "magnitude1", "metadata": {"EchoTime": 1.2}},
@@ -165,7 +165,7 @@
165165
"metadata": {
166166
"EchoTime1": 1.2,
167167
"EchoTime2": 1.4,
168-
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
168+
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
169169
}
170170
},
171171
{"suffix": "magnitude1", "metadata": {"EchoTime": 1.2}},
@@ -216,3 +216,16 @@ def test_wrangler_filter(tmpdir, name, skeleton, estimations):
216216
est = find_estimators(layout=layout, subject='01', bids_filters=filters['fmap'])
217217
assert len(est) == estimations
218218
clear_registry()
219+
220+
221+
@pytest.mark.parametrize('name,skeleton,estimations', [
222+
('pepolar', pepolar, 3),
223+
('phasediff', phasediff, 3),
224+
])
225+
def test_wrangler_URIs(tmpdir, name, skeleton, estimations):
226+
bids_dir = str(tmpdir / name)
227+
generate_bids_skeleton(bids_dir, skeleton)
228+
layout = gen_layout(bids_dir)
229+
est = find_estimators(layout=layout, subject='01')
230+
assert len(est) == estimations
231+
clear_registry()

sdcflows/utils/wrangler.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
from .. import fieldmaps as fm
3434

3535

36+
def _resolve_intent(
37+
intent: str,
38+
layout: BIDSLayout,
39+
subject: str
40+
) -> str | None:
41+
root = Path(layout.root)
42+
if intent.startswith("bids::"):
43+
return str(root / intent[6:])
44+
if not intent.startswith("bids:"):
45+
return str(root / f"sub-{subject}" / intent)
46+
return intent
47+
48+
3649
def find_estimators(
3750
*,
3851
layout: BIDSLayout,
@@ -404,7 +417,7 @@ def find_estimators(
404417
# Find existing IntendedFor targets and warn if missing
405418
all_targets = []
406419
for intent in listify(epi_base_md["IntendedFor"]):
407-
target = layout.get_file(str(subject_root / intent))
420+
target = layout.get_file(_resolve_intent(intent, layout, subject))
408421
if target is None:
409422
logger.debug("Single PE target %s not found", intent)
410423
continue

0 commit comments

Comments
 (0)