Skip to content
Merged
8 changes: 4 additions & 4 deletions hed/tools/bids/bids_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ 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:
root_path (str): Root path of the BIDS dataset.
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)
Expand All @@ -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)
Expand Down
25 changes: 15 additions & 10 deletions tests/tools/bids/test_bids_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down