Skip to content

Commit

Permalink
use objects for levels (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau authored Sep 11, 2023
1 parent 2efd714 commit 64b4613
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 88 deletions.
9 changes: 8 additions & 1 deletion +bids/+util/create_data_dict.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
'new_level_name', {{}});

for i = 1:numel(headers)
if strcmp(bids.internal.file_utils(tsv_file{1}, ...
'basename'), ...
'participants') && ...
strcmp(headers{i}, 'participant_id')
continue
end
data_dict.(headers{i}) = set_dict(headers{i}, schema);
[data_dict, modified_levels] = add_levels_desc(data_dict, ...
headers{i}, ...
Expand Down Expand Up @@ -242,7 +248,8 @@
warning_modified_level_name(level_name_before, hdr, this_level, verbose);
end

json.(hdr).Levels.(this_level) = 'TODO';
json.(hdr).Levels.(this_level) = struct('Description', level_name_before, ...
'TermURL', 'TODO');

end

Expand Down
184 changes: 97 additions & 87 deletions tests/tests_utils/test_create_data_dict.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,103 @@
initTestSuite;
end

function test_create_data_dict_several_tsv()

%% WITH SCHEMA
% data time (sec)
% eeg_face13 0.387
% ds003 0.480
% eeg_cbm 0.636
% ds101 0.963
% genetics_ukbb 0.989
% ieeg_visual_multimodal 1.014
% ds005 1.060
% ds105 1.064
% ds102 1.281
% ds052 1.293
% eeg_rishikesh 1.486
% ds008 1.498
% ds011 1.654
% ds114 1.667
% ds109 1.767
% ds002 1.855
% ds051 1.873
% eeg_ds000117 1.900
% ds116 1.975
% ds007 2.356
% ds107 2.386
% ds113b 2.554
% ds009 2.732
% ds210 2.820
% ds110 3.263
% ds006 3.378
% ds108 3.897
% ds000117 5.958

datasets = {'ds000248'; ...
'ds000246'; ...
'ieeg_visual'; ...
'ieeg_epilepsy_ecog'; ...
'eeg_matchingpennies'; ...
'ds000247'; ...
'ieeg_filtered_speech'; ...
'eeg_face13'; ...
'ds005'; ...
'ds105'; ...
'ds102'; ...
'ds052'; ...
'eeg_rishikesh'; ...
'ds008'; ...
'ds011'; ...
'ds114'; ...
'ds109'; ...
'ds002'; ...
'ds051' };

schema = bids.Schema();
schema.load_schema_metadata = true;
schema = schema.load();

pth_bids_example = get_test_data_dir();

for i_dataset = 1:numel(datasets)

dataset = datasets{i_dataset};

BIDS = bids.layout(fullfile(pth_bids_example, dataset), ...
'index_dependencies', false);

tasks = bids.query(BIDS, 'tasks');

for i_task = 1:numel(tasks)

tsv_files = bids.query(BIDS, 'data', ...
'task', tasks{i_task}, ...
'suffix', 'events');

data_dict = bids.util.create_data_dict(tsv_files, ...
'output', [dataset '_' tasks{i_task} '.json'], ...
'schema', schema, ...
'level_limit', 50, ...
'verbose', false);
teardown([dataset '_' tasks{i_task} '.json']);

end

end

end

function test_create_data_dict_participants_tsv()

pth_bids_example = get_test_data_dir();

tsv_file = fullfile(pth_bids_example, 'ds008', 'participants.tsv');
data_dict = bids.util.create_data_dict(tsv_file, 'output', [], 'schema', true);
assertEqual(fieldnames(data_dict), {'sex'; 'age'});

end

function test_create_data_dict_basic()

pth_bids_example = get_test_data_dir();
Expand Down Expand Up @@ -94,93 +191,6 @@ function test_create_data_dict_schema()

end

function test_create_data_dict_several_tsv()

%% WITH SCHEMA
% data time (sec)
% eeg_face13 0.387
% ds003 0.480
% eeg_cbm 0.636
% ds101 0.963
% genetics_ukbb 0.989
% ieeg_visual_multimodal 1.014
% ds005 1.060
% ds105 1.064
% ds102 1.281
% ds052 1.293
% eeg_rishikesh 1.486
% ds008 1.498
% ds011 1.654
% ds114 1.667
% ds109 1.767
% ds002 1.855
% ds051 1.873
% eeg_ds000117 1.900
% ds116 1.975
% ds007 2.356
% ds107 2.386
% ds113b 2.554
% ds009 2.732
% ds210 2.820
% ds110 3.263
% ds006 3.378
% ds108 3.897
% ds000117 5.958

datasets = {'ds000248'; ...
'ds000246'; ...
'ieeg_visual'; ...
'ieeg_epilepsy_ecog'; ...
'eeg_matchingpennies'; ...
'ds000247'; ...
'ieeg_filtered_speech'; ...
'eeg_face13'; ...
'ds005'; ...
'ds105'; ...
'ds102'; ...
'ds052'; ...
'eeg_rishikesh'; ...
'ds008'; ...
'ds011'; ...
'ds114'; ...
'ds109'; ...
'ds002'; ...
'ds051' };

schema = bids.Schema();
schema.load_schema_metadata = true;
schema = schema.load();

pth_bids_example = get_test_data_dir();

for i_dataset = 1:numel(datasets)

dataset = datasets{i_dataset};

BIDS = bids.layout(fullfile(pth_bids_example, dataset), ...
'index_dependencies', false);

tasks = bids.query(BIDS, 'tasks');

for i_task = 1:numel(tasks)

tsv_files = bids.query(BIDS, 'data', ...
'task', tasks{i_task}, ...
'suffix', 'events');

data_dict = bids.util.create_data_dict(tsv_files, ...
'output', [dataset '_' tasks{i_task} '.json'], ...
'schema', schema, ...
'level_limit', 50, ...
'verbose', false);
teardown([dataset '_' tasks{i_task} '.json']);

end

end

end

function teardown(files)
if nargin < 1
files = [];
Expand Down

0 comments on commit 64b4613

Please sign in to comment.