Skip to content

Commit

Permalink
fix not finding tasks when another task has a run entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Aug 10, 2024
1 parent 0a42633 commit 65140b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
13 changes: 7 additions & 6 deletions bidsmreye/bids_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
from bidsmreye.logging import bidsmreye_log
from bidsmreye.methods import methods
from bidsmreye.utils import copy_license, create_dir_if_absent
from bidsmreye.utils import copy_license, create_dir_if_absent, return_regex

log = bidsmreye_log("bidsmreye")

Expand Down Expand Up @@ -60,9 +60,10 @@ def check_layout(cfg: Config, layout: BIDSLayout, for_file: str = "bold") -> Non
if generated_by["Name"].lower() == "bidsmreye":
this_filter = get_bids_filter_config()["mask"]

this_filter["task"] = cfg.task
this_filter["space"] = cfg.space
this_filter["run"] = cfg.run
this_filter["task"] = return_regex(cfg.task)
this_filter["space"] = return_regex(cfg.space) or ".*"
if cfg.run:
this_filter["run"] = cfg.run

log.debug(f"Looking for files with filter\n{this_filter}")

Expand All @@ -78,8 +79,8 @@ def check_layout(cfg: Config, layout: BIDSLayout, for_file: str = "bold") -> Non
raise RuntimeError(
f"Input dataset {layout.root} does not have "
f"any data to process for filter\n{this_filter}.\n"
f"This dataset contains subjects: {subjects}."
f"This dataset contains tasks: {tasks}."
f"This dataset contains subjects: {subjects}.\n"
f"This dataset contains tasks: {tasks}.\n"
"Is your dataset a BIDS derivative dataset?\n"
"Check the FAQ for more information: "
"https://bidsmreye.readthedocs.io/en/latest/FAQ.html"
Expand Down
3 changes: 3 additions & 0 deletions bidsmreye/bidsmreye.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,17 @@ def dispatch(analysis_level: str, action: str, cfg: Config) -> None:

prepare_data(cfg)
generalize(cfg)

elif action == "prepare":
from bidsmreye.prepare_data import prepare_data

prepare_data(cfg)

elif action == "generalize":
from bidsmreye.generalize import generalize

generalize(cfg)

elif action == "qc":
from bidsmreye.quality_control import quality_control_input

Expand Down
19 changes: 14 additions & 5 deletions bidsmreye/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def __attrs_post_init__(self) -> None:

self.check_argument(attribute="subjects", layout_in=layout_in)
self.check_argument(attribute="task", layout_in=layout_in)
self.check_argument(attribute="run", layout_in=layout_in)
self.check_argument(attribute="space", layout_in=layout_in)
self.check_argument(attribute="run", layout_in=layout_in)

def check_argument(self, attribute: str, layout_in: BIDSLayout) -> Config:
"""Check an attribute value compared to the input dataset content.
Expand All @@ -125,9 +125,15 @@ def check_argument(self, attribute: str, layout_in: BIDSLayout) -> Config:
if attribute == "subjects":
value = layout_in.get_subjects()
elif attribute == "task":
value = layout_in.get_tasks()
value = layout_in.get_tasks(subject=self.subjects)
elif attribute in {"space", "run"}:
value = layout_in.get(return_type="id", target=attribute, datatype="func")
value = layout_in.get(
return_type="id",
target=attribute,
datatype="func",
subject=self.subjects,
task=self.task,
)

self.listify(attribute)

Expand All @@ -148,9 +154,12 @@ def check_argument(self, attribute: str, layout_in: BIDSLayout) -> Config:
)
value = list(set(getattr(self, attribute)) & set(value))

setattr(self, attribute, value)

# run and space can be empty if their entity are not used
# we will figure out the values for run
# in subject / task wise manner later on
if attribute not in ["run"]:
setattr(self, attribute, value)

if attribute not in ["run", "space"] and not getattr(self, attribute):
raise RuntimeError(f"No {attribute} found in {self.input_dir}")

Expand Down

0 comments on commit 65140b6

Please sign in to comment.