diff --git a/+bids/+internal/append_to_layout.m b/+bids/+internal/append_to_layout.m index 11c3a76e..86715331 100644 --- a/+bids/+internal/append_to_layout.m +++ b/+bids/+internal/append_to_layout.m @@ -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 diff --git a/+bids/layout.m b/+bids/layout.m index 4d3f0fcf..07c30a27 100644 --- a/+bids/layout.m +++ b/+bids/layout.m @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 @@ -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); diff --git a/+bids/query.m b/+bids/query.m index cbed700d..dff0dcbf 100644 --- a/+bids/query.m +++ b/+bids/query.m @@ -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) diff --git a/tests/test_bids_query.m b/tests/test_bids_query.m index 07e9f287..46160b0a 100644 --- a/tests/test_bids_query.m +++ b/tests/test_bids_query.m @@ -23,7 +23,7 @@ end -function test_bids_query_data() +function test_query_data() pth_bids_example = get_test_data_dir(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/tests/test_bids_query_eeg.m b/tests/test_bids_query_eeg.m index 7421638c..cc9dbdca 100644 --- a/tests/test_bids_query_eeg.m +++ b/tests/test_bids_query_eeg.m @@ -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); %% diff --git a/tests/test_layout_derivatives.m b/tests/test_layout_derivatives.m index ae6923ad..944b8758 100644 --- a/tests/test_layout_derivatives.m +++ b/tests/test_layout_derivatives.m @@ -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(); @@ -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', ... @@ -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', ...