Skip to content

Commit

Permalink
allow indexing of files missing session entity when schemaless
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Jul 30, 2023
1 parent 1faff9b commit 6134f92
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
3 changes: 2 additions & 1 deletion +bids/layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@

% sub and ses part
pattern = [prefix subject.name '_'];
if ~isempty(subject.session)
if isempty(schema.content)
elseif ~isempty(subject.session)
pattern = [pattern subject.session '_'];
end

Expand Down
9 changes: 0 additions & 9 deletions tests/tests_layout/test_layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ function test_layout_filter_regex()

end

function test_layout_empty_subject_folder_allowed_when_schemaless()

verbose = false;

bids.util.mkdir(fullfile(pwd, 'tmp/sub-01'));
bids.layout(fullfile(pwd, 'tmp'), 'use_schema', false, 'verbose', verbose);
rmdir(fullfile(pwd, 'tmp'), 's');
end

function test_layout_smoke_test()

verbose = false;
Expand Down
49 changes: 49 additions & 0 deletions tests/tests_layout/test_layout_schemaless.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function test_suite = test_layout_schemaless %#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_layout_no_schema_no_ses_in_filename()

% filter for speed
filter = struct('sub', {{'01'}});

verbose = false;

bids_dir = tempname();

% create dummy file
copyfile(fullfile(get_test_data_dir(), 'ds006'), bids_dir);
ses_folder = fullfile(bids_dir, 'sub-01', 'ses-post', 'anat');
copyfile(fullfile(ses_folder, 'sub-01_ses-post_T1w.nii.gz'), ...
fullfile(ses_folder, 'sub-01_T1w.nii.gz'));

BIDS = bids.layout(bids_dir, ...
'verbose', verbose, ...
'use_schema', true, ...
'filter', filter);

files = bids.query(BIDS, 'data', 'sub', '01', 'suffix', 'T1w');
assert(numel(files) == 2);

BIDS = bids.layout(bids_dir, ...
'verbose', verbose, ...
'use_schema', false, ...
'filter', filter);

files = bids.query(BIDS, 'data', 'sub', '01', 'suffix', 'T1w');
assert(numel(files) == 3);

end

function test_layout_empty_subject_folder_allowed_when_schemaless()

verbose = false;

bids.util.mkdir(fullfile(pwd, 'tmp/sub-01'));
bids.layout(fullfile(pwd, 'tmp'), 'use_schema', false, 'verbose', verbose);
rmdir(fullfile(pwd, 'tmp'), 's');
end

0 comments on commit 6134f92

Please sign in to comment.