From 65140b6d9941061bd90c960e153b69ddefe5a1e4 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Sat, 10 Aug 2024 11:12:16 +0200 Subject: [PATCH 1/6] fix not finding tasks when another task has a run entity --- bidsmreye/bids_utils.py | 13 +++++++------ bidsmreye/bidsmreye.py | 3 +++ bidsmreye/configuration.py | 19 ++++++++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/bidsmreye/bids_utils.py b/bidsmreye/bids_utils.py index 4e10bf3..7f08e6b 100644 --- a/bidsmreye/bids_utils.py +++ b/bidsmreye/bids_utils.py @@ -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") @@ -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}") @@ -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" diff --git a/bidsmreye/bidsmreye.py b/bidsmreye/bidsmreye.py index 94bf70d..76c0a9e 100755 --- a/bidsmreye/bidsmreye.py +++ b/bidsmreye/bidsmreye.py @@ -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 diff --git a/bidsmreye/configuration.py b/bidsmreye/configuration.py index 213025b..f856731 100644 --- a/bidsmreye/configuration.py +++ b/bidsmreye/configuration.py @@ -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. @@ -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) @@ -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}") From 1ecd9d99e9035d3a0b3e660a6b68a1d9185900c8 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Sat, 10 Aug 2024 11:29:07 +0200 Subject: [PATCH 2/6] do not apply to space --- bidsmreye/bids_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bidsmreye/bids_utils.py b/bidsmreye/bids_utils.py index 7f08e6b..434e011 100644 --- a/bidsmreye/bids_utils.py +++ b/bidsmreye/bids_utils.py @@ -61,7 +61,7 @@ def check_layout(cfg: Config, layout: BIDSLayout, for_file: str = "bold") -> Non this_filter = get_bids_filter_config()["mask"] this_filter["task"] = return_regex(cfg.task) - this_filter["space"] = return_regex(cfg.space) or ".*" + this_filter["space"] = cfg.space if cfg.run: this_filter["run"] = cfg.run From 46a48e3451494981d5da8a0d6f07850507c347b2 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Sat, 10 Aug 2024 11:58:42 +0200 Subject: [PATCH 3/6] update test --- docs/source/CHANGELOG.md | 2 ++ tests/test_utils.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/CHANGELOG.md b/docs/source/CHANGELOG.md index db7e6dd..0c926a0 100644 --- a/docs/source/CHANGELOG.md +++ b/docs/source/CHANGELOG.md @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +* [FIX] do not apply run found for one task to all tasks by @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/228 + ### Security diff --git a/tests/test_utils.py b/tests/test_utils.py index 67c50d5..702461d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -87,7 +87,6 @@ def test_set_this_filter_bold(pybids_test_dataset, output_dir): "datatype": "func", "desc": "preproc", "extension": "nii.*", - "run": "1|2", "subject": "001", "suffix": "^bold$", } From 6cbf29876c44466c7cda822c831a2d7efb24621a Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Sat, 10 Aug 2024 12:26:43 +0200 Subject: [PATCH 4/6] pin antspyx --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 7a5b0ab..58796d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ dependencies = [ "kaleido", "pooch>=1.6.0", "pybids", + "antspyx<5", "tqdm", "tomli; python_version < '3.11'", "keras<3.0.0", From 04ee19b65599ede6d77f6015db3a2ff8dff93737 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Sat, 10 Aug 2024 12:27:51 +0200 Subject: [PATCH 5/6] update requirements.txt --- requirements.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d656165..68ae0d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,9 @@ absl-py==2.1.0 # tensorboard # tensorflow antspyx==0.4.2 - # via deepmreye + # via + # bidsmreye (pyproject.toml) + # deepmreye anyio==4.4.0 # via # httpx @@ -430,6 +432,8 @@ rfc3986-validator==0.1.1 # jsonschema # jupyter-events rich==13.7.1 + # via rich-argparse +rich-argparse==1.5.2 # via bidsmreye (pyproject.toml) rpds-py==0.19.1 # via From ca9af5fe4fb4ced988af5f4524ac574272c75da4 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Sat, 10 Aug 2024 12:34:26 +0200 Subject: [PATCH 6/6] update requirements.txt --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 58796d2..69de0c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dependencies = [ "kaleido", "pooch>=1.6.0", "pybids", - "antspyx<5", + "antspyx<0.5", "tqdm", "tomli; python_version < '3.11'", "keras<3.0.0",