Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Resolve BIDS-URIs #349

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions sdcflows/utils/tests/test_wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
"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": [
Expand All @@ -76,13 +76,13 @@
"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": [
Expand Down Expand Up @@ -176,7 +176,7 @@
"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}},
Expand All @@ -203,7 +203,7 @@
"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}},
Expand Down Expand Up @@ -255,6 +255,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"
Expand Down
15 changes: 14 additions & 1 deletion sdcflows/utils/wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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,
Expand Down Expand Up @@ -426,7 +439,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
Expand Down
Loading