Skip to content

Commit

Permalink
schemaless layout indexes json files
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Feb 15, 2021
1 parent 4a60dc6 commit 12be509
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 28 deletions.
5 changes: 5 additions & 0 deletions +bids/+internal/append_to_layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
entities = bids.schema.return_modality_entities(schema.datatypes.(modality)(idx), schema);
p = bids.internal.parse_filename(file, entities);

% do not index json files when using the schema
if ~isempty(p) && strcmp(p.ext, '.json')
return
end

end

% Check any new entity field that needs to be added into the layout or the output
Expand Down
13 changes: 8 additions & 5 deletions +bids/layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

subject = bids.internal.add_missing_field(subject, modality);

file_list = return_file_list(modality, subject);
file_list = return_file_list(modality, subject, schema);

for i = 1:numel(file_list)

Expand Down Expand Up @@ -220,7 +220,7 @@

subject = bids.internal.add_missing_field(subject, modality);

file_list = return_file_list(modality, subject);
file_list = return_file_list(modality, subject, schema);

for i = 1:numel(file_list)

Expand Down Expand Up @@ -256,7 +256,7 @@

subject = bids.internal.add_missing_field(subject, modality);

file_list = return_file_list(modality, subject);
file_list = return_file_list(modality, subject, schema);

for i = 1:numel(file_list)

Expand Down Expand Up @@ -316,7 +316,7 @@

subject = bids.internal.add_missing_field(subject, modality);

file_list = return_file_list(modality, subject);
file_list = return_file_list(modality, subject, schema);

for i = 1:numel(file_list)

Expand Down Expand Up @@ -420,7 +420,7 @@ function tolerant_message(use_schema, msg)
end
end

function file_list = return_file_list(modality, subject)
function file_list = return_file_list(modality, subject, schema)

% We list anything but json files

Expand All @@ -433,6 +433,9 @@ function tolerant_message(use_schema, msg)

% jn to omit json but not .pos file for headshape.pos
pattern = '_([a-zA-Z0-9]+){1}\\..*[^jn]';
if isempty(schema)
pattern = '_([a-zA-Z0-9]+){1}\\..*';
end

pth = fullfile(subject.path, modality);

Expand Down
5 changes: 5 additions & 0 deletions +bids/query.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@

for j = 1:numel(modalities)

% Only continue if this modality is one of those filtered
if ~ismember(modalities{j}, fieldnames(BIDS.subjects(i)))
continue
end

d = BIDS.subjects(i).(modalities{j});

for k = 1:numel(d)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_bids_query.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

end

function test_bids_query_data()
function test_query_data()

pth_bids_example = get_test_data_dir();

Expand All @@ -46,7 +46,7 @@ function test_bids_query_data()

end

function test_bids_query_metadata()
function test_query_metadata()

pth_bids_example = get_test_data_dir();

Expand All @@ -63,7 +63,7 @@ function test_bids_query_metadata()

end

function test_bids_query_modalities()
function test_query_modalities()

pth_bids_example = get_test_data_dir();

Expand Down Expand Up @@ -98,7 +98,7 @@ function test_bids_query_modalities()

end

function test_bids_query_basic()
function test_query_basic()

pth_bids_example = get_test_data_dir();

Expand All @@ -118,7 +118,7 @@ function test_bids_query_basic()

end

function test_bids_query_subjects()
function test_query_subjects()

pth_bids_example = get_test_data_dir();

Expand All @@ -129,7 +129,7 @@ function test_bids_query_subjects()

end

function test_bids_query_sessions()
function test_query_sessions()

pth_bids_example = get_test_data_dir();

Expand All @@ -144,7 +144,7 @@ function test_bids_query_sessions()

end

function test_bids_query_suffixes()
function test_query_suffixes()

pth_bids_example = get_test_data_dir();

Expand Down
22 changes: 11 additions & 11 deletions tests/test_bids_query_eeg.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@ function test_bids_query_eeg_basic()
pth_bids_example = get_test_data_dir();

%%
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_cbm'));
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_face13'));

modalities = {'eeg'};
assertEqual(bids.query(BIDS, 'modalities'), modalities);

suffixes = {'channels', 'eeg', 'events'};
% Missing: 'electrodes'
% skipped as it contains a task entity and thus does not match the schema
assertEqual(bids.query(BIDS, 'suffixes'), suffixes);

%%
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_ds000117'));
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_cbm'));

modalities = {'anat', 'eeg'};
modalities = {'eeg'};
assertEqual(bids.query(BIDS, 'modalities'), modalities);

suffixes = {'T1w', 'eeg', 'electrodes', 'events'};
% Missing: 'coordsystem',
% Missing: 'channels' in root folder
suffixes = {'channels', 'eeg', 'events'};
assertEqual(bids.query(BIDS, 'suffixes'), suffixes);

%%
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_face13'));
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_ds000117'));

modalities = {'eeg'};
modalities = {'anat', 'eeg'};
assertEqual(bids.query(BIDS, 'modalities'), modalities);

suffixes = {'channels', 'eeg', 'events'};
% Missing: 'electrodes'
% skipped as it contains a task entity and thus does not match the schema
suffixes = {'T1w', 'eeg', 'electrodes', 'events'};
% Missing: 'coordsystem',
% Missing: 'channels' in root folder
assertEqual(bids.query(BIDS, 'suffixes'), suffixes);

%%
Expand Down
34 changes: 29 additions & 5 deletions tests/test_layout_derivatives.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@
initTestSuite;
end

function test_layout_parse_json()

pth_bids_example = get_test_data_dir();

BIDS = bids.layout(fullfile(pth_bids_example, 'ds000248'));

data = bids.query(BIDS, 'data', ...
'sub', '01', ...
'modality', 'anat');

assertEqual(size(data, 1), 2);

%%
use_schema = false();

BIDS = bids.layout(fullfile(pth_bids_example, 'ds000248'), use_schema);

data = bids.query(BIDS, 'data', ...
'sub', '01', ...
'modality', 'anat');

assertEqual(size(data, 1), 4);

end

function test_layout_schemaless()

pth_bids_example = get_test_data_dir();
Expand All @@ -18,7 +43,6 @@ function test_layout_schemaless()
modalities = {'anat', 'figures', 'func'};
assertEqual(bids.query(BIDS, 'modalities'), modalities);

% Those fail for now
data = bids.query(BIDS, 'data', ...
'sub', '10', ...
'modality', 'func', ...
Expand All @@ -27,10 +51,10 @@ function test_layout_schemaless()
'res', '2');

basename = bids.internal.file_utils(data, 'basename');
assertEqual(basename, {
['sub-10_task-balloonanalogrisktask_run-1', ...
'_space-MNI152NLin2009cAsym_res-2_desc-preproc_bold.nii']
});
assertEqual(basename(2), {
['sub-10_task-balloonanalogrisktask_run-1', ...
'_space-MNI152NLin2009cAsym_res-2_desc-preproc_bold.nii']
});

data = bids.query(BIDS, 'data', ...
'sub', '10', ...
Expand Down

0 comments on commit 12be509

Please sign in to comment.