Skip to content

Commit 89ccbb4

Browse files
authored
Creating behavioral protocol (#52)
* protocol * deling with no task * behavioral_protocol * adding test for behavioral_protocols * adding behavioral_protocol_number to test_bids_examples.py
1 parent 14ed965 commit 89ccbb4

4 files changed

Lines changed: 63 additions & 12 deletions

File tree

bids2openminds/converter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ def convert(input_path, save_output=False, output_path=None, multiple_files=Fals
2121

2222
subjects_id = bids_layout.get_subjects()
2323

24-
tasks = bids_layout.get_task()
25-
2624
# imprting the dataset description file containing some of the
2725
dataset_description_path = utility.table_filter(layout_df, "description")
2826

@@ -31,11 +29,14 @@ def convert(input_path, save_output=False, output_path=None, multiple_files=Fals
3129
[subjects_dict, subject_state_dict, subjects_list] = main.create_subjects(
3230
subjects_id, layout_df, bids_layout, collection)
3331

32+
behavioral_protocols, behavioral_protocols_dict = main.create_behavioral_protocol(
33+
bids_layout, collection)
34+
3435
[files_list, file_repository] = main.create_file(
3536
layout_df, input_path, collection)
3637

3738
dataset_version = main.create_dataset_version(
38-
bids_layout, dataset_description, layout_df, subjects_list, file_repository, collection)
39+
bids_layout, dataset_description, layout_df, subjects_list, file_repository, behavioral_protocols, collection)
3940

4041
dataset = main.create_dataset(
4142
dataset_description, dataset_version, collection)

bids2openminds/main.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ def create_persons(dataset_description, collection):
7272
return openminds_list
7373

7474

75+
def create_behavioral_protocol(layout, collection):
76+
behavioral_protocols_dict = {}
77+
behavioral_protocols = []
78+
tasks = layout.get_tasks()
79+
80+
if not tasks:
81+
return None, None
82+
83+
for task in tasks:
84+
85+
behavioral_protocol = omcore.BehavioralProtocol(name=task,
86+
internal_identifier=task,
87+
description="To be defined")
88+
behavioral_protocols.append(behavioral_protocol)
89+
behavioral_protocols_dict[task] = behavioral_protocol
90+
collection.add(behavioral_protocol)
91+
92+
return behavioral_protocols, behavioral_protocols_dict
93+
94+
7595
def create_techniques(layout_df):
7696
suffixs = layout_df["suffix"].unique().tolist()
7797
techniques = []
@@ -126,7 +146,7 @@ def create_openminds_age(data_subject):
126146
return None
127147

128148

129-
def create_dataset_version(bids_layout, dataset_description, layout_df, studied_specimens, file_repository, collection):
149+
def create_dataset_version(bids_layout, dataset_description, layout_df, studied_specimens, file_repository, behavioral_protocols, collection):
130150

131151
# Fetch the dataset type from dataset description file
132152

@@ -179,6 +199,7 @@ def create_dataset_version(bids_layout, dataset_description, layout_df, studied_
179199
techniques=techniques,
180200
how_to_cite=how_to_cite,
181201
repository=file_repository,
202+
behavioral_protocols=behavioral_protocols
182203
# other_contributions=other_contribution # needs to be a Contribution object
183204
# version_identifier
184205
)

test/test_bids_examples.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
import bids2openminds.converter
55

66

7-
# Dataset information in following order dataset_label, dataset_subject_number, dataset_subject_state_number, dataset_person_number, dataset_files_number
8-
example_dataset = [("ds003", 13, 13, 2, 58),
9-
("ds000247", 6, 10, 5, 202),
7+
# Dataset information in following order dataset_label, dataset_subject_number, dataset_subject_state_number, dataset_person_number, dataset_files_number, dataset_behavioral_protocol_number
8+
example_dataset = [("ds003", 13, 13, 2, 58, 1),
9+
("ds000247", 6, 10, 5, 202, 2),
1010
# The authors list in 'eeg_cbm' contains non person entities 2 is not correct name (issue raied #43)
11-
("eeg_cbm", 20, 20, 2, 104),
12-
("asl001", 1, 1, 2, 8),
11+
("eeg_cbm", 20, 20, 2, 104, 1),
12+
("asl001", 1, 1, 2, 8, 0),
1313
# Number of files in 'eeg_rest_fmri' is not correct as it doesn't contain files in derivated (issue raied #42)
14-
("eeg_rest_fmri", 3, 3, 6, 46)]
14+
("eeg_rest_fmri", 3, 3, 6, 46, 1)]
1515

1616

17-
@pytest.mark.parametrize("dataset_label, dataset_subject_number, dataset_subject_state_number, dataset_person_number, dataset_files_number", example_dataset)
18-
def test_example_datasets(dataset_label, dataset_subject_number, dataset_subject_state_number, dataset_person_number, dataset_files_number):
17+
@pytest.mark.parametrize("dataset_label, dataset_subject_number, dataset_subject_state_number, dataset_person_number, dataset_files_number, dataset_behavioral_protocol_number", example_dataset)
18+
def test_example_datasets(dataset_label, dataset_subject_number, dataset_subject_state_number, dataset_person_number, dataset_files_number, dataset_behavioral_protocol_number):
1919
test_dir = os.path.join("bids-examples", dataset_label)
2020
bids2openminds.converter.convert(test_dir, save_output=True)
2121
c = Collection()
@@ -25,6 +25,7 @@ def test_example_datasets(dataset_label, dataset_subject_number, dataset_subject
2525
subject_state_number = 0
2626
person_number = 0
2727
files_number = 0
28+
behavioral_protocol_number = 0
2829

2930
for item in c:
3031
match item.type_:
@@ -36,8 +37,11 @@ def test_example_datasets(dataset_label, dataset_subject_number, dataset_subject
3637
person_number += 1
3738
case "https://openminds.ebrains.eu/core/File":
3839
files_number += 1
40+
case "https://openminds.ebrains.eu/core/BehavioralProtocol":
41+
behavioral_protocol_number += 1
3942

4043
assert dataset_subject_number == subject_number
4144
assert dataset_subject_state_number == subject_state_number
4245
assert dataset_person_number == person_number
4346
assert dataset_files_number == files_number
47+
assert dataset_behavioral_protocol_number == behavioral_protocol_number

test/test_task.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
from bids import BIDSLayout
3+
from openminds import Collection
4+
import os
5+
from bids2openminds.main import create_behavioral_protocol
6+
7+
(datasets, tasks) = ("ds002", ("deterministicclassification",
8+
"mixedeventrelatedprobe", "probabilisticclassification"))
9+
10+
11+
@pytest.fixture
12+
def creating_behavioral_protocols():
13+
c = Collection()
14+
test_dir = os.path.join("bids-examples", datasets)
15+
bids_layout = BIDSLayout(test_dir)
16+
_, behavioral_protocols_dict = create_behavioral_protocol(
17+
bids_layout, c)
18+
return behavioral_protocols_dict
19+
20+
21+
def test_behavioral_protocols(creating_behavioral_protocols):
22+
assert len(tasks) == len(creating_behavioral_protocols)
23+
for item in creating_behavioral_protocols:
24+
assert item in tasks
25+
assert creating_behavioral_protocols[item].internal_identifier == item

0 commit comments

Comments
 (0)