diff --git a/snakebids/core/datasets.py b/snakebids/core/datasets.py index ab27b1ec..e24915fc 100644 --- a/snakebids/core/datasets.py +++ b/snakebids/core/datasets.py @@ -2,6 +2,7 @@ import itertools as it import operator as op +import warnings from collections import UserDict from string import Formatter from typing import TYPE_CHECKING, Any, Iterable, Optional, Union, cast @@ -289,9 +290,7 @@ def subjects(self): return [ *{ *it.chain.from_iterable( - input_list["subject"] - for input_list in self.entities.values() - if "subject" in input_list + component.entities.get("subject", []) for component in self.values() ) } ] @@ -302,9 +301,7 @@ def sessions(self): return [ *{ *it.chain.from_iterable( - input_list["session"] - for input_list in self.entities.values() - if "session" in input_list + component.entities.get("session", []) for component in self.values() ) } ] @@ -334,15 +331,17 @@ def as_dict(self): ------- BidsDatasetDict """ - return BidsDatasetDict( - input_path=self.input_path, - input_lists=self.entities, - input_wildcards=self.input_wildcards, - input_zip_lists=self.input_zip_lists, - subjects=self.subjects, - sessions=self.sessions, - subj_wildcards=self.subj_wildcards, - ) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + return BidsDatasetDict( + input_path=self.input_path, + input_lists=self.entities, + input_wildcards=self.input_wildcards, + input_zip_lists=self.input_zip_lists, + subjects=self.subjects, + sessions=self.sessions, + subj_wildcards=self.subj_wildcards, + ) @classmethod def from_iterable(cls, iterable: Iterable[BidsComponent]): diff --git a/snakebids/project_template/{{cookiecutter.app_name}}/workflow/Snakefile b/snakebids/project_template/{{cookiecutter.app_name}}/workflow/Snakefile index 9eb7661b..a09a583f 100644 --- a/snakebids/project_template/{{cookiecutter.app_name}}/workflow/Snakefile +++ b/snakebids/project_template/{{cookiecutter.app_name}}/workflow/Snakefile @@ -26,14 +26,14 @@ wildcard_constraints: **snakebids.get_wildcard_constraints(config['pybids_input rule smooth: - input: inputs.path['bold'] + input: inputs['bold'].path output: bids( root=config['root'], datatype='func', desc='smooth{fwhm}mm', suffix='bold.nii.gz', - **inputs.wildcards['bold'] + **inputs['bold'].wildcards ) container: config['singularity']['fsl'] log: @@ -41,7 +41,7 @@ rule smooth: root='logs', suffix='smooth.log', fwhm='{fwhm}', - **inputs.wildcards['bold'] + **inputs['bold'].wildcards ) params: sigma = lambda wildcards: f'{float(wildcards.fwhm)/2.355:0.2f}' shell: 'fslmaths {input} -s {params.sigma} {output}' @@ -56,6 +56,6 @@ rule all: allow_missing=True, ), zip, - **inputs.zip_lists['bold'] + **inputs['bold'].zip_lists ) default_target: True diff --git a/snakebids/tests/test_datasets.py b/snakebids/tests/test_datasets.py index b6b837e9..9fe4ae47 100644 --- a/snakebids/tests/test_datasets.py +++ b/snakebids/tests/test_datasets.py @@ -1,5 +1,6 @@ import copy import itertools as it +import warnings from typing import Any, Dict, List import more_itertools as itx @@ -31,11 +32,13 @@ def test_bids_component_aliases_are_correctly_set(self, component: BidsComponent @given(sb_st.bids_components()) def test_bids_dataset_aliases_are_correctly_set(self, component: BidsComponent): - dataset = BidsDataset.from_iterable([component]) - assert dataset.input_path == dataset.path - assert dataset.input_zip_lists == dataset.zip_lists - assert dataset.input_lists == dataset.input_lists - assert dataset.input_wildcards == dataset.wildcards + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + dataset = BidsDataset.from_iterable([component]) + assert dataset.input_path == dataset.path + assert dataset.input_zip_lists == dataset.zip_lists + assert dataset.input_lists == dataset.input_lists + assert dataset.input_wildcards == dataset.wildcards class TestBidsComponentValidation: diff --git a/snakebids/tests/test_generate_inputs.py b/snakebids/tests/test_generate_inputs.py index 1d80f5db..e741186c 100644 --- a/snakebids/tests/test_generate_inputs.py +++ b/snakebids/tests/test_generate_inputs.py @@ -58,7 +58,6 @@ def tmpdir(self, fakefs_tmpdir: Path): def disambiguate_components(self, dataset: BidsDataset): assert len(dataset) == 2 - dataset.zip_lists comp1, comp2 = dataset.values() return sorted([comp1, comp2], key=lambda comp: len(comp.entities.keys())) @@ -271,9 +270,7 @@ def test_missing_filters(self, tmpdir: Path): pybids_config=str(Path(__file__).parent / "data" / "custom_config.json"), use_bids_inputs=True, ) - template = BidsDataset( - {"t1": BidsComponent("t1", config.input_path["t1"], zip_list)} - ) + template = BidsDataset({"t1": BidsComponent("t1", config["t1"].path, zip_list)}) # Order of the subjects is not deterministic assert template == config assert config.subj_wildcards == {"subject": "{subject}"} @@ -297,7 +294,7 @@ def test_missing_wildcards(self, tmpdir: Path): pybids_config=str(Path(__file__).parent / "data" / "custom_config.json"), use_bids_inputs=True, ) - template = BidsDataset({"t1": BidsComponent("t1", config.input_path["t1"], {})}) + template = BidsDataset({"t1": BidsComponent("t1", config["t1"].path, {})}) assert template == config assert config.subj_wildcards == {"subject": "{subject}"} @@ -573,7 +570,7 @@ def test_custom_pybids_config(tmpdir: Path): } ) assert template == result - assert result.input_wildcards == {"t1": {"foo": "{foo}", "subject": "{subject}"}} + assert result["t1"].wildcards == {"foo": "{foo}", "subject": "{subject}"} # Order of the subjects is not deterministic assert result.subj_wildcards == {"subject": "{subject}"} @@ -647,7 +644,7 @@ def test_t1w(): { "t1": BidsComponent( "t1", - result.input_path["t1"], + result["t1"].path, {"acq": ["mprage", "mprage"], "subject": ["001", "002"]}, ) } @@ -678,14 +675,16 @@ def test_t1w(): participant_label="001", use_bids_inputs=True, ) - assert result.entities == { - "scan": {"acq": ["mprage"], "subject": ["001"], "suffix": ["T1w"]} + assert result["scan"].entities == { + "acq": ["mprage"], + "subject": ["001"], + "suffix": ["T1w"], } template = BidsDataset( { "scan": BidsComponent( "scan", - result.input_path["scan"], + result["scan"].path, { "acq": [ "mprage", @@ -751,15 +750,13 @@ def test_t1w(): { "t1": BidsComponent( "t1", - result.input_path["t1"], + result["t1"].path, { "acq": ["mprage", "mprage"], "subject": ["001", "002"], }, ), - "t2": BidsComponent( - "t2", result.input_path["t2"], {"subject": ["002"]} - ), + "t2": BidsComponent("t2", result["t2"].path, {"subject": ["002"]}), } ) # Order of the subjects is not deterministic