diff --git a/hed/tools/bids/bids_dataset.py b/hed/tools/bids/bids_dataset.py index d6cd4592c..a5c475107 100644 --- a/hed/tools/bids/bids_dataset.py +++ b/hed/tools/bids/bids_dataset.py @@ -21,8 +21,8 @@ class BidsDataset: """ - def __init__(self, root_path, schema=None, tabular_types=None, - exclude_dirs=['sourcedata', 'derivatives', 'code', 'stimuli']): + def __init__(self, root_path, schema=None, tabular_types=['events'], + exclude_dirs=['sourcedata', 'derivatives', 'code', 'stimuli', 'phenotype']): """ Constructor for a BIDS dataset. Parameters: @@ -30,7 +30,7 @@ def __init__(self, root_path, schema=None, tabular_types=None, schema (HedSchema or HedSchemaGroup): A schema that overrides the one specified in dataset. tabular_types (list or None): List of strings specifying types of tabular types to include. If None or empty, then ['events'] is assumed. - exclude_dirs=['sourcedata', 'derivatives', 'code']: + exclude_dirs=['sourcedata', 'derivatives', 'code', 'phenotype']: """ self.root_path = os.path.realpath(root_path) @@ -42,7 +42,7 @@ def __init__(self, root_path, schema=None, tabular_types=None, self.schema = load_schema_version(self.dataset_description.get("HEDVersion", None)) self.exclude_dirs = exclude_dirs - self.tabular_files = {"participants": BidsFileGroup(root_path, suffix="participants", obj_type="tabular")} + self.tabular_files = {} if not tabular_types: self.tabular_files["events"] = BidsFileGroup(root_path, suffix="events", obj_type="tabular", exclude_dirs=exclude_dirs) diff --git a/tests/tools/bids/test_bids_dataset.py b/tests/tools/bids/test_bids_dataset.py index e4af39331..540899301 100644 --- a/tests/tools/bids/test_bids_dataset.py +++ b/tests/tools/bids/test_bids_dataset.py @@ -20,6 +20,9 @@ def test_constructor(self): bids = BidsDataset(Test.root_path) self.assertIsInstance(bids, BidsDataset, "BidsDataset should create a valid object from valid dataset") parts = bids.get_tabular_group("participants") + self.assertFalse(parts) + bids = BidsDataset(Test.root_path, tabular_types=['participants', 'events']) + parts = bids.get_tabular_group("participants") self.assertIsInstance(parts, BidsFileGroup, "BidsDataset participants should be a BidsFileGroup") self.assertEqual(len(parts.sidecar_dict), 1, "BidsDataset should have one participants.json file") self.assertEqual(len(parts.datafile_dict), 1, "BidsDataset should have one participants.tsv file") @@ -30,7 +33,7 @@ def test_constructor(self): self.assertIsInstance(bids.schema, HedSchema, "BidsDataset schema should be HedSchema") def test_constructor_libraries(self): - bids = BidsDataset(self.library_path) + bids = BidsDataset(self.library_path, tabular_types=['participants', 'events']) self.assertIsInstance(bids, BidsDataset, "BidsDataset with libraries should create a valid object from valid dataset") parts = bids.get_tabular_group("participants") @@ -48,9 +51,11 @@ def test_constructor_tabular(self): self.assertIsInstance(bids, BidsDataset, "BidsDataset with libraries should create a valid object from valid dataset") parts = bids.get_tabular_group("participants") - self.assertIsInstance(parts, BidsFileGroup, "BidsDataset participants should be a BidsFileGroup") - self.assertEqual(len(parts.sidecar_dict), 1, "BidsDataset should have one participants.json file") - self.assertEqual(len(parts.datafile_dict), 1, "BidsDataset should have one participants.tsv file") + self.assertFalse(parts) + chans = bids.get_tabular_group("channels") + self.assertIsInstance(chans, BidsFileGroup, "BidsDataset participants should be a BidsFileGroup") + self.assertFalse(chans.sidecar_dict) + self.assertEqual(len(chans.datafile_dict), 6, "BidsDataset should have one participants.tsv file") self.assertIsInstance(bids.dataset_description, dict, "BidsDataset dataset_description should be a dict") for group in bids.tabular_files.values(): self.assertIsInstance(group, BidsFileGroup, "BidsDataset event files should be in a BidsFileGroup") @@ -87,12 +92,12 @@ def test_with_schema_group(self): "library_schemas/score/hedxml/HED_score_1.0.0.xml" library2_url = "https://raw.githubusercontent.com/hed-standard/hed-schemas/main/" + \ "library_schemas/testlib/hedxml/HED_testlib_1.0.2.xml" - schema_list = [load_schema_version(xml_version=base_version)] - schema_list.append(load_schema(library1_url, schema_namespace="sc")) - schema_list.append(load_schema(library2_url, schema_namespace="test")) + schema_list = [load_schema_version(xml_version=base_version), + load_schema(library1_url, schema_namespace="sc"), + load_schema(library2_url, schema_namespace="test")] x = HedSchemaGroup(schema_list) - bids = BidsDataset(self.library_path, schema=x) - self.assertIsInstance(bids, BidsDataset, + bids = BidsDataset(self.library_path, schema=x, tabular_types=["participants"] ) + self.assertIsInstance(bids, BidsDataset, "BidsDataset with libraries should create a valid object from valid dataset") parts = bids.get_tabular_group("participants") self.assertIsInstance(parts, BidsFileGroup, "BidsDataset participants should be a BidsFileGroup") @@ -105,7 +110,7 @@ def test_with_schema_group(self): self.assertIsInstance(bids.schema, HedSchemaGroup, "BidsDataset with libraries should have schema that is a HedSchemaGroup") issues = bids.validate(check_for_warnings=True) - self.assertTrue(issues, "BidsDataset validate should return issues when check_for_warnings is True") + self.assertFalse(issues) def test_get_summary(self): bids1 = BidsDataset(self.root_path)