From 7ffffc2fe1204ce34b092c6aa9466dfdf90ea3fa Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 1 Jun 2023 07:56:12 -0400 Subject: [PATCH 1/2] FIX: Ensure IntendedFor metadata is a subject-relative path --- sdcflows/utils/wrangler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdcflows/utils/wrangler.py b/sdcflows/utils/wrangler.py index 2cb9c9414c..ebea2cac3d 100644 --- a/sdcflows/utils/wrangler.py +++ b/sdcflows/utils/wrangler.py @@ -459,7 +459,10 @@ def find_estimators( # The new estimator is IntendedFor the individual targets, # even if the EPI file is IntendedFor multiple estimator_md = epi_base_md.copy() - estimator_md["IntendedFor"] = intent + estimator_md["IntendedFor"] = [ + str(Path(pathlike).relative_to(subject_root)) + for pathlike in intent + ] try: e = fm.FieldmapEstimation( [ From c4ebb64bc38ffdf1adc82602672d0f85330009a6 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 1 Jun 2023 08:18:18 -0400 Subject: [PATCH 2/2] TEST: Regression test for stringified intents --- sdcflows/utils/tests/test_wrangler.py | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/sdcflows/utils/tests/test_wrangler.py b/sdcflows/utils/tests/test_wrangler.py index 7f79ef4d3c..b162e8c82c 100644 --- a/sdcflows/utils/tests/test_wrangler.py +++ b/sdcflows/utils/tests/test_wrangler.py @@ -95,6 +95,43 @@ } } ] + }, + { + "session": "04", + "anat": [{"suffix": "T1w", "metadata": {"EchoTime": 1}}], + "fmap": [ + {"suffix": "epi", "dir": "AP", "metadata": { + "EchoTime": 1.2, + "PhaseEncodingDirection": "j-", + "TotalReadoutTime": 0.8, + "IntendedFor": [ + "ses-04/func/sub-01_ses-04_task-rest_run-1_bold.nii.gz", + "ses-04/func/sub-01_ses-04_task-rest_run-2_bold.nii.gz", + ], + }}, + ], + "func": [ + { + "task": "rest", + "run": 1, + "suffix": "bold", + "metadata": { + "RepetitionTime": 0.8, + "TotalReadoutTime": 0.5, + "PhaseEncodingDirection": "j" + } + }, + { + "task": "rest", + "run": 2, + "suffix": "bold", + "metadata": { + "RepetitionTime": 0.8, + "TotalReadoutTime": 0.5, + "PhaseEncodingDirection": "j" + } + }, + ] } ] } @@ -216,3 +253,20 @@ def test_wrangler_filter(tmpdir, name, skeleton, estimations): est = find_estimators(layout=layout, subject='01', bids_filters=filters['fmap']) assert len(est) == estimations clear_registry() + + +def test_single_reverse_pedir(tmp_path): + bids_dir = tmp_path / "bids" + generate_bids_skeleton(bids_dir, pepolar) + layout = gen_layout(bids_dir) + est = find_estimators(layout=layout, subject='01', bids_filters={'session': '04'}) + assert len(est) == 2 + subject_root = bids_dir / 'sub-01' + for estimator in est: + assert len(estimator.sources) == 2 + epi, bold = estimator.sources + # Just checking order + assert epi.entities['fmap'] == 'epi' + # IntendedFor is a list of strings + # REGRESSION: The result was a PyBIDS BIDSFile (fmriprep#3020) + assert epi.metadata['IntendedFor'] == [str(bold.path.relative_to(subject_root))]