Skip to content

Commit

Permalink
reorganize tests and make list of target files to parse for meeg more…
Browse files Browse the repository at this point in the history
… general
  • Loading branch information
Remi-Gau committed Feb 7, 2021
1 parent 71a7eb4 commit da50908
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 24 deletions.
2 changes: 1 addition & 1 deletion +bids/layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down
13 changes: 9 additions & 4 deletions +bids/query.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

% __________________________________________________________________________
%
Expand Down
27 changes: 11 additions & 16 deletions tests/test_bids_query.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = { ...
Expand All @@ -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'};
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bids_query_asl.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

function test_bids_query_asl_basic()
%
% asl specific queries
% asl queries
%

pth_bids_example = get_test_data_dir();
Expand Down
64 changes: 64 additions & 0 deletions tests/test_bids_query_eeg.m
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions tests/test_bids_query_ieeg.m
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions tests/test_bids_query_meg.m
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions tests/test_layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit da50908

Please sign in to comment.