diff --git a/+bids/layout.m b/+bids/layout.m index 950d91948..ba68e7735 100644 --- a/+bids/layout.m +++ b/+bids/layout.m @@ -744,7 +744,7 @@ function tolerant_message(tolerant, msg) pattern = '_task-.*\\.nii(\\.gz)|events\\.tsv|physio\\.tsv\\.gz|stim\\.tsv\\.gz?'; case {'eeg', 'meg', 'ieeg'} - pattern = ['_task-.*_' modality '\\..*[^json]']; + pattern = '_([a-zA-Z0-9]+){1}\\..*[^json]'; case 'beh' pattern = '_task-.*_(events\\.tsv|beh\\.json|physio\\.tsv\\.gz|stim\\.tsv\\.gz)'; diff --git a/+bids/query.m b/+bids/query.m index 80bbe10ff..90d41e8ca 100644 --- a/+bids/query.m +++ b/+bids/query.m @@ -2,12 +2,17 @@ % QUERY Query a directory structure formatted according to the BIDS standard % FORMAT result = bids.query(BIDS,query,...) % BIDS - BIDS directory name or BIDS structure (from bids.layout) - % query - type of query: {'data', 'metadata', 'sessions', 'subjects', - % 'runs', 'tasks', 'runs', 'types', 'modalities'} + % query - type of query: + % - 'data', + % - 'metadata', + % - 'sessions', + % - 'subjects', + % - 'runs', + % - 'tasks', + % - 'types', + % - 'modalities' % result - outcome of query % - % See also: - % bids % __________________________________________________________________________ % diff --git a/tests/test_bids_query.m b/tests/test_bids_query.m index 31b4e2836..48b559575 100644 --- a/tests/test_bids_query.m +++ b/tests/test_bids_query.m @@ -7,7 +7,7 @@ end function test_bids_query_basic() - % Test BIDS queries on ds007 + % Test BIDS queries % This dataset comes from https://github.com/bids-standard/bids-examples % and is downloaded automatically by the continuous integration framework % and is required for the tests to be run. @@ -30,8 +30,6 @@ function test_bids_query_basic() subjs = arrayfun(@(x) sprintf('%02d', x), 1:20, 'UniformOutput', false); assert(isequal(bids.query(BIDS, 'subjects'), subjs)); - assert(isempty(bids.query(BIDS, 'sessions'))); - assert(isequal(bids.query(BIDS, 'runs'), {'01', '02'})); tasks = { ... @@ -46,10 +44,6 @@ function test_bids_query_basic() data = bids.query(BIDS, 'data', 'sub', '01', 'task', 'stopsignalwithpseudowordnaming'); assertEqual(size(data, 1), 4); - mods = {'anat', 'func'}; - assert(isequal(bids.query(BIDS, 'modalities'), mods)); - assert(isequal(bids.query(BIDS, 'modalities', 'sub', '01'), mods)); - assert(isempty(bids.query(BIDS, 'runs', 'type', 'T1w'))); runs = {'01', '02'}; @@ -79,31 +73,32 @@ function test_bids_query_basic() end function test_bids_query_sessions() - % - % parse a folder with sessions - % pth_bids_example = get_test_data_dir(); BIDS = bids.layout(fullfile(pth_bids_example, 'synthetic')); - - % test sessions = {'01', '02'}; assert(isequal(bids.query(BIDS, 'sessions'), sessions)); assert(isequal(bids.query(BIDS, 'sessions', 'sub', '02'), sessions)); + BIDS = bids.layout(fullfile(pth_bids_example, 'ds007')); + + assert(isempty(bids.query(BIDS, 'sessions'))); + end function test_bids_query_modalities() - % - % parse a folder with different modalities per session - % pth_bids_example = get_test_data_dir(); + BIDS = bids.layout(fullfile(pth_bids_example, 'ds007')); + + mods = {'anat', 'func'}; + assert(isequal(bids.query(BIDS, 'modalities'), mods)); + assert(isequal(bids.query(BIDS, 'modalities', 'sub', '01'), mods)); + BIDS = bids.layout(fullfile(pth_bids_example, '7t_trt')); - % test mods = {'anat', 'fmap', 'func'}; assert(isequal(bids.query(BIDS, 'modalities'), mods)); diff --git a/tests/test_bids_query_asl.m b/tests/test_bids_query_asl.m index a6951f17a..624ce6261 100644 --- a/tests/test_bids_query_asl.m +++ b/tests/test_bids_query_asl.m @@ -8,7 +8,7 @@ function test_bids_query_asl_basic() % - % asl specific queries + % asl queries % pth_bids_example = get_test_data_dir(); diff --git a/tests/test_bids_query_eeg.m b/tests/test_bids_query_eeg.m new file mode 100644 index 000000000..f407b992b --- /dev/null +++ b/tests/test_bids_query_eeg.m @@ -0,0 +1,64 @@ +function test_suite = test_bids_query_eeg %#ok<*STOUT> + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); %#ok<*NASGU> + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + +function test_bids_query_eeg_basic() + % + % eeg queries + % + + pth_bids_example = get_test_data_dir(); + + %% + BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_cbm')); + + modalities = {'eeg'}; + assertEqual(bids.query(BIDS, 'modalities'), modalities); + + types = {'channels', 'eeg', 'events'}; + assertEqual(bids.query(BIDS, 'types'), types); + + %% + BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_ds000117')); + + modalities = {'anat', 'eeg'}; + assertEqual(bids.query(BIDS, 'modalities'), modalities); + + types = {'T1w', 'eeg', 'electrodes', 'events'}; + % Missing: 'coordsystem', 'channels' + assertEqual(bids.query(BIDS, 'types'), types); + + %% + BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_face13')); + + modalities = {'eeg'}; + assertEqual(bids.query(BIDS, 'modalities'), modalities); + + types = {'channels', 'eeg', 'events'}; + % Missing: 'electrodes' + % skipped as it contains a task entity and thus does not match the schema + assertEqual(bids.query(BIDS, 'types'), types); + + %% + BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_matchingpennies')); + + modalities = {'eeg'}; + assertEqual(bids.query(BIDS, 'modalities'), modalities); + + types = {'channels', 'eeg', 'events'}; + assertEqual(bids.query(BIDS, 'types'), types); + + %% + BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_rishikesh')); + + modalities = {'eeg'}; + assertEqual(bids.query(BIDS, 'modalities'), modalities); + + types = {'channels', 'eeg', 'events'}; + assertEqual(bids.query(BIDS, 'types'), types); + +end diff --git a/tests/test_bids_query_ieeg.m b/tests/test_bids_query_ieeg.m new file mode 100644 index 000000000..d72099a44 --- /dev/null +++ b/tests/test_bids_query_ieeg.m @@ -0,0 +1,36 @@ +function test_suite = test_bids_query_ieeg %#ok<*STOUT> + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); %#ok<*NASGU> + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + +function test_bids_query_ieeg_basic() + % + % eeg queries + % + + pth_bids_example = get_test_data_dir(); + + %% + BIDS = bids.layout(fullfile(pth_bids_example, 'ieeg_epilepsy')); + + modalities = {'anat', 'ieeg'}; + assertEqual(bids.query(BIDS, 'modalities'), modalities); + + types = {'T1w', 'channels', 'electrodes', 'events', 'ieeg'}; + % Missing: 'coordsystem' + assertEqual(bids.query(BIDS, 'types'), types); + + %% + BIDS = bids.layout(fullfile(pth_bids_example, 'ieeg_epilepsy_ecog')); + + modalities = {'anat', 'ieeg'}; + assertEqual(bids.query(BIDS, 'modalities'), modalities); + + types = {'T1w', 'channels', 'electrodes', 'events', 'ieeg', 'photo'}; + % Missing: 'coordsystem' + assertEqual(bids.query(BIDS, 'types'), types); + +end diff --git a/tests/test_bids_query_meg.m b/tests/test_bids_query_meg.m new file mode 100644 index 000000000..ac7f76086 --- /dev/null +++ b/tests/test_bids_query_meg.m @@ -0,0 +1,28 @@ +function test_suite = test_bids_query_meg %#ok<*STOUT> + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); %#ok<*NASGU> + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + +function test_bids_query_meg_basic() + % + % meg queries + % + + pth_bids_example = get_test_data_dir(); + + BIDS = bids.layout(fullfile(pth_bids_example, 'ds000246')); + + modalities = {'anat', 'meg'}; + assertEqual(bids.query(BIDS, 'modalities'), modalities); + + types = {'T1w', 'channels', 'photo'}; + % missing: 'meg' 'coordsystem', 'headshape' + assertEqual(bids.query(BIDS, 'types'), types); + + BIDS = bids.layout(fullfile(pth_bids_example, 'ds000247')); + BIDS = bids.layout(fullfile(pth_bids_example, 'ds000248')); + +end diff --git a/tests/test_layout.m b/tests/test_layout.m index 619d9a56b..30eb4c838 100644 --- a/tests/test_layout.m +++ b/tests/test_layout.m @@ -9,7 +9,9 @@ function test_layout_smoke_test() pth_bids_example = get_test_data_dir(); - BIDS = bids.layout(fullfile(pth_bids_example, '7t_trt')); - BIDS = bids.layout(fullfile(pth_bids_example, 'asl001')); + + BIDS = bids.layout(fullfile(pth_bids_example, 'genetics_ukbb')); + + BIDS = bids.layout(fullfile(pth_bids_example, 'ds210')); end