Skip to content

Commit

Permalink
Use strict file-matching in collect_run_data (PennLINC#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Feb 26, 2024
1 parent 1edc27f commit f748eea
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions xcp_d/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,18 @@ def collect_run_data(layout, bold_file, cifti, target_space):
"""
bids_file = layout.get_file(bold_file)
run_data, metadata = {}, {}

run_data["confounds"] = layout.get_nearest(
bids_file.path,
strict=False,
strict=True,
ignore_strict_entities=["space", "res", "den", "desc", "suffix", "extension"],
desc="confounds",
suffix="timeseries",
extension=".tsv",
)
if not run_data["confounds"]:
raise FileNotFoundError(f"No confounds file detected for {bids_file.path}")

run_data["confounds_json"] = layout.get_nearest(run_data["confounds"], extension=".json")
metadata["bold_metadata"] = layout.get_metadata(bold_file)
# Ensure that we know the TR
Expand All @@ -595,13 +600,15 @@ def collect_run_data(layout, bold_file, cifti, target_space):
if not cifti:
run_data["boldref"] = layout.get_nearest(
bids_file.path,
strict=False,
strict=True,
ignore_strict_entities=["desc", "suffix"],
suffix="boldref",
extension=[".nii", ".nii.gz"],
)
run_data["boldmask"] = layout.get_nearest(
bids_file.path,
strict=False,
strict=True,
ignore_strict_entities=["desc", "suffix"],
desc="brain",
suffix="mask",
extension=[".nii", ".nii.gz"],
Expand All @@ -614,7 +621,16 @@ def collect_run_data(layout, bold_file, cifti, target_space):

run_data["boldref"] = layout.get_nearest(
bids_file.path,
strict=False,
strict=True,
ignore_strict_entities=[
"cohort",
"space",
"res",
"den",
"desc",
"suffix",
"extension",
],
space=target_space,
cohort=cohort,
suffix="boldref",
Expand All @@ -623,7 +639,16 @@ def collect_run_data(layout, bold_file, cifti, target_space):
)
run_data["nifti_file"] = layout.get_nearest(
bids_file.path,
strict=False,
strict=True,
ignore_strict_entities=[
"cohort",
"space",
"res",
"den",
"desc",
"suffix",
"extension",
],
space=target_space,
cohort=cohort,
desc="preproc",
Expand Down

0 comments on commit f748eea

Please sign in to comment.