Skip to content

Commit da50908

Browse files
committed
reorganize tests and make list of target files to parse for meeg more general
1 parent 71a7eb4 commit da50908

8 files changed

+154
-24
lines changed

+bids/layout.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ function tolerant_message(tolerant, msg)
744744
pattern = '_task-.*\\.nii(\\.gz)|events\\.tsv|physio\\.tsv\\.gz|stim\\.tsv\\.gz?';
745745

746746
case {'eeg', 'meg', 'ieeg'}
747-
pattern = ['_task-.*_' modality '\\..*[^json]'];
747+
pattern = '_([a-zA-Z0-9]+){1}\\..*[^json]';
748748

749749
case 'beh'
750750
pattern = '_task-.*_(events\\.tsv|beh\\.json|physio\\.tsv\\.gz|stim\\.tsv\\.gz)';

+bids/query.m

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
% QUERY Query a directory structure formatted according to the BIDS standard
33
% FORMAT result = bids.query(BIDS,query,...)
44
% BIDS - BIDS directory name or BIDS structure (from bids.layout)
5-
% query - type of query: {'data', 'metadata', 'sessions', 'subjects',
6-
% 'runs', 'tasks', 'runs', 'types', 'modalities'}
5+
% query - type of query:
6+
% - 'data',
7+
% - 'metadata',
8+
% - 'sessions',
9+
% - 'subjects',
10+
% - 'runs',
11+
% - 'tasks',
12+
% - 'types',
13+
% - 'modalities'
714
% result - outcome of query
815
%
9-
% See also:
10-
% bids
1116

1217
% __________________________________________________________________________
1318
%

tests/test_bids_query.m

+11-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
end
88

99
function test_bids_query_basic()
10-
% Test BIDS queries on ds007
10+
% Test BIDS queries
1111
% This dataset comes from https://github.com/bids-standard/bids-examples
1212
% and is downloaded automatically by the continuous integration framework
1313
% and is required for the tests to be run.
@@ -30,8 +30,6 @@ function test_bids_query_basic()
3030
subjs = arrayfun(@(x) sprintf('%02d', x), 1:20, 'UniformOutput', false);
3131
assert(isequal(bids.query(BIDS, 'subjects'), subjs));
3232

33-
assert(isempty(bids.query(BIDS, 'sessions')));
34-
3533
assert(isequal(bids.query(BIDS, 'runs'), {'01', '02'}));
3634

3735
tasks = { ...
@@ -46,10 +44,6 @@ function test_bids_query_basic()
4644
data = bids.query(BIDS, 'data', 'sub', '01', 'task', 'stopsignalwithpseudowordnaming');
4745
assertEqual(size(data, 1), 4);
4846

49-
mods = {'anat', 'func'};
50-
assert(isequal(bids.query(BIDS, 'modalities'), mods));
51-
assert(isequal(bids.query(BIDS, 'modalities', 'sub', '01'), mods));
52-
5347
assert(isempty(bids.query(BIDS, 'runs', 'type', 'T1w')));
5448

5549
runs = {'01', '02'};
@@ -79,31 +73,32 @@ function test_bids_query_basic()
7973
end
8074

8175
function test_bids_query_sessions()
82-
%
83-
% parse a folder with sessions
84-
%
8576

8677
pth_bids_example = get_test_data_dir();
8778

8879
BIDS = bids.layout(fullfile(pth_bids_example, 'synthetic'));
89-
90-
% test
9180
sessions = {'01', '02'};
9281
assert(isequal(bids.query(BIDS, 'sessions'), sessions));
9382
assert(isequal(bids.query(BIDS, 'sessions', 'sub', '02'), sessions));
9483

84+
BIDS = bids.layout(fullfile(pth_bids_example, 'ds007'));
85+
86+
assert(isempty(bids.query(BIDS, 'sessions')));
87+
9588
end
9689

9790
function test_bids_query_modalities()
98-
%
99-
% parse a folder with different modalities per session
100-
%
10191

10292
pth_bids_example = get_test_data_dir();
10393

94+
BIDS = bids.layout(fullfile(pth_bids_example, 'ds007'));
95+
96+
mods = {'anat', 'func'};
97+
assert(isequal(bids.query(BIDS, 'modalities'), mods));
98+
assert(isequal(bids.query(BIDS, 'modalities', 'sub', '01'), mods));
99+
104100
BIDS = bids.layout(fullfile(pth_bids_example, '7t_trt'));
105101

106-
% test
107102
mods = {'anat', 'fmap', 'func'};
108103

109104
assert(isequal(bids.query(BIDS, 'modalities'), mods));

tests/test_bids_query_asl.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
function test_bids_query_asl_basic()
1010
%
11-
% asl specific queries
11+
% asl queries
1212
%
1313

1414
pth_bids_example = get_test_data_dir();

tests/test_bids_query_eeg.m

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
function test_suite = test_bids_query_eeg %#ok<*STOUT>
2+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
3+
test_functions = localfunctions(); %#ok<*NASGU>
4+
catch % no problem; early Matlab versions can use initTestSuite fine
5+
end
6+
initTestSuite;
7+
end
8+
9+
function test_bids_query_eeg_basic()
10+
%
11+
% eeg queries
12+
%
13+
14+
pth_bids_example = get_test_data_dir();
15+
16+
%%
17+
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_cbm'));
18+
19+
modalities = {'eeg'};
20+
assertEqual(bids.query(BIDS, 'modalities'), modalities);
21+
22+
types = {'channels', 'eeg', 'events'};
23+
assertEqual(bids.query(BIDS, 'types'), types);
24+
25+
%%
26+
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_ds000117'));
27+
28+
modalities = {'anat', 'eeg'};
29+
assertEqual(bids.query(BIDS, 'modalities'), modalities);
30+
31+
types = {'T1w', 'eeg', 'electrodes', 'events'};
32+
% Missing: 'coordsystem', 'channels'
33+
assertEqual(bids.query(BIDS, 'types'), types);
34+
35+
%%
36+
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_face13'));
37+
38+
modalities = {'eeg'};
39+
assertEqual(bids.query(BIDS, 'modalities'), modalities);
40+
41+
types = {'channels', 'eeg', 'events'};
42+
% Missing: 'electrodes'
43+
% skipped as it contains a task entity and thus does not match the schema
44+
assertEqual(bids.query(BIDS, 'types'), types);
45+
46+
%%
47+
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_matchingpennies'));
48+
49+
modalities = {'eeg'};
50+
assertEqual(bids.query(BIDS, 'modalities'), modalities);
51+
52+
types = {'channels', 'eeg', 'events'};
53+
assertEqual(bids.query(BIDS, 'types'), types);
54+
55+
%%
56+
BIDS = bids.layout(fullfile(pth_bids_example, 'eeg_rishikesh'));
57+
58+
modalities = {'eeg'};
59+
assertEqual(bids.query(BIDS, 'modalities'), modalities);
60+
61+
types = {'channels', 'eeg', 'events'};
62+
assertEqual(bids.query(BIDS, 'types'), types);
63+
64+
end

tests/test_bids_query_ieeg.m

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function test_suite = test_bids_query_ieeg %#ok<*STOUT>
2+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
3+
test_functions = localfunctions(); %#ok<*NASGU>
4+
catch % no problem; early Matlab versions can use initTestSuite fine
5+
end
6+
initTestSuite;
7+
end
8+
9+
function test_bids_query_ieeg_basic()
10+
%
11+
% eeg queries
12+
%
13+
14+
pth_bids_example = get_test_data_dir();
15+
16+
%%
17+
BIDS = bids.layout(fullfile(pth_bids_example, 'ieeg_epilepsy'));
18+
19+
modalities = {'anat', 'ieeg'};
20+
assertEqual(bids.query(BIDS, 'modalities'), modalities);
21+
22+
types = {'T1w', 'channels', 'electrodes', 'events', 'ieeg'};
23+
% Missing: 'coordsystem'
24+
assertEqual(bids.query(BIDS, 'types'), types);
25+
26+
%%
27+
BIDS = bids.layout(fullfile(pth_bids_example, 'ieeg_epilepsy_ecog'));
28+
29+
modalities = {'anat', 'ieeg'};
30+
assertEqual(bids.query(BIDS, 'modalities'), modalities);
31+
32+
types = {'T1w', 'channels', 'electrodes', 'events', 'ieeg', 'photo'};
33+
% Missing: 'coordsystem'
34+
assertEqual(bids.query(BIDS, 'types'), types);
35+
36+
end

tests/test_bids_query_meg.m

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function test_suite = test_bids_query_meg %#ok<*STOUT>
2+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
3+
test_functions = localfunctions(); %#ok<*NASGU>
4+
catch % no problem; early Matlab versions can use initTestSuite fine
5+
end
6+
initTestSuite;
7+
end
8+
9+
function test_bids_query_meg_basic()
10+
%
11+
% meg queries
12+
%
13+
14+
pth_bids_example = get_test_data_dir();
15+
16+
BIDS = bids.layout(fullfile(pth_bids_example, 'ds000246'));
17+
18+
modalities = {'anat', 'meg'};
19+
assertEqual(bids.query(BIDS, 'modalities'), modalities);
20+
21+
types = {'T1w', 'channels', 'photo'};
22+
% missing: 'meg' 'coordsystem', 'headshape'
23+
assertEqual(bids.query(BIDS, 'types'), types);
24+
25+
BIDS = bids.layout(fullfile(pth_bids_example, 'ds000247'));
26+
BIDS = bids.layout(fullfile(pth_bids_example, 'ds000248'));
27+
28+
end

tests/test_layout.m

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
function test_layout_smoke_test()
1010

1111
pth_bids_example = get_test_data_dir();
12-
BIDS = bids.layout(fullfile(pth_bids_example, '7t_trt'));
13-
BIDS = bids.layout(fullfile(pth_bids_example, 'asl001'));
12+
13+
BIDS = bids.layout(fullfile(pth_bids_example, 'genetics_ukbb'));
14+
15+
BIDS = bids.layout(fullfile(pth_bids_example, 'ds210'));
1416

1517
end

0 commit comments

Comments
 (0)