Skip to content

Commit

Permalink
[ENH] remove checks for participants.tsv or samples.tsv in derivatives (
Browse files Browse the repository at this point in the history
#666)

* no warning for missing participants.tsv in derivatives

* do not copy participants.tsv to derivatives

* skip for octave

* skip on windows
  • Loading branch information
Remi-Gau authored Jan 25, 2024
1 parent a995717 commit 8771359
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 68 deletions.
2 changes: 1 addition & 1 deletion +bids/+util/tsvwrite.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function tsvwrite(filename, var)
%
% USAGE::
%
% tsvwrite(f, var)
% tsvwrite(filename, var)
%
% :param filename:
% :type filename: string
Expand Down
19 changes: 0 additions & 19 deletions +bids/copy_to_derivative.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ function copy_to_derivative(varargin)

ds_desc.write(derivatives_folder);

copy_participants_tsv(BIDS, derivatives_folder, args);

% looping over selected files
for iFile = 1:numel(data_list)
copy_file(BIDS, derivatives_folder, data_list{iFile}, ...
Expand All @@ -178,23 +176,6 @@ function copy_to_derivative(varargin)

end

function copy_participants_tsv(BIDS, derivatives_folder, args)
%
% Very "brutal" approach where we copy the whole file
%
% TODO: if only certain subjects are copied only copy those entries from the TSV
%

if ~isempty(BIDS.participants)

src = fullfile(BIDS.pth, 'participants.tsv');
target = fullfile(derivatives_folder, 'participants.tsv');

copy_tsv(src, target, args);

end
end

function copy_tsv(src, target, args)

flag = false;
Expand Down
26 changes: 19 additions & 7 deletions +bids/layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@
% [sourcedata/] - ignore
% [phenotype/]

BIDS.participants = [];
BIDS.participants = manage_tsv(BIDS.participants, BIDS.pth, 'participants.tsv', verbose);

BIDS = index_phenotype(BIDS);

BIDS = index_root_directory(BIDS);
Expand Down Expand Up @@ -220,10 +217,7 @@

BIDS = index_derivatives_dir(BIDS, index_derivatives, verbose);

if ismember('micr', bids.query(BIDS, 'modalities'))
BIDS.samples = [];
BIDS.samples = manage_tsv(BIDS.samples, BIDS.pth, 'samples.tsv', verbose);
end
BIDS = index_participants_and_sample(BIDS, verbose);

end

Expand Down Expand Up @@ -259,6 +253,24 @@ function handle_invalid_input(ME, root)
end
end

function BIDS = index_participants_and_sample(BIDS, verbose)
warn_for_missing_tsv = verbose;
if isfield(BIDS.description, 'DatasetType') && ...
strcmp(BIDS.description.DatasetType, 'derivative')
warn_for_missing_tsv = false;
end

BIDS.participants = [];
BIDS.participants = manage_tsv(BIDS.participants, BIDS.pth, ...
'participants.tsv', warn_for_missing_tsv);

if ismember('micr', bids.query(BIDS, 'modalities'))
BIDS.samples = [];
BIDS.samples = manage_tsv(BIDS.samples, BIDS.pth, ...
'samples.tsv', warn_for_missing_tsv);
end
end

function value = exclude(filter, entity, label)
value = false;
% skip if not included in filter
Expand Down
4 changes: 1 addition & 3 deletions tests/test_bids_model.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ function test_model_default_no_events()

function test_model_validate()

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

bm = bids.Model();
bm.Nodes{1} = rmfield(bm.Nodes{1}, 'Name');
Expand Down
33 changes: 31 additions & 2 deletions tests/tests_layout/test_layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@
initTestSuite;
end

function test_warning_missing_participants_tsv()

skip_if_octave('mixed-string-concat warning thrown');

bids_dir = fullfile(get_test_data_dir(), 'qmri_tb1tfl');
assertWarning(@()bids.layout(bids_dir, ...
'verbose', true), ...
'layout:tsvMissing');

end

function test_no_warning_missing_participants_tsv_derivatives()

skip_if_octave('mixed-string-concat warning thrown');

bids_dir = fullfile(get_test_data_dir(), 'ds000001-fmriprep');
try
assertWarning(@()bids.layout(bids_dir, ...
'verbose', true, ...
'use_schema', false), ...
'layout:tsvMissing');
catch ME
assert(strcmp(ME.identifier, 'moxunit:warningNotRaised'));
end

end

function test_layout_do_not_include_empty_subject()

if ispc
Expand Down Expand Up @@ -33,8 +60,10 @@ function test_layout_do_not_include_empty_subject()

function test_layout_do_not_include_empty_subject_warning()

if bids.internal.is_octave() || ispc
moxunit_throw_test_skipped_exception('Octave mixed-string-concat or fail on windows');
skip_if_octave('mixed-string-concat warning thrown');
if ispc
% TODO investigate
moxunit_throw_test_skipped_exception('fail on windows');
end

bids_dir = fullfile(get_test_data_dir(), 'qmri_tb1tfl');
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_layout/test_layout_derivatives.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ function test_layout_warning_invalid_subfolder_struct_fieldname()
invalid_subfolder = fullfile(get_test_data_dir(), '..', ...
'data', 'synthetic', 'derivatives', 'invalid_subfolder');

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

assertWarning(@()bids.layout(invalid_subfolder, ...
'use_schema', false, ...
Expand Down
16 changes: 4 additions & 12 deletions tests/tests_private/test_append_to_layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ function test_layout_missing_subgroup()
synthetic_derivatives = fullfile(get_test_data_dir(), '..', ...
'data', 'synthetic', 'derivatives', 'manual');

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

assertWarning(@()bids.layout(synthetic_derivatives, 'verbose', true), ...
'append_to_layout:unknownSuffix');
Expand All @@ -24,9 +22,7 @@ function test_layout_missing_subgroup()

function test_append_to_layout_schema_unknown_entity()

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

[subject, modality, schema, previous] = set_up('meg');

Expand All @@ -39,9 +35,7 @@ function test_append_to_layout_schema_unknown_entity()

function test_append_to_layout_schema_unknown_extension()

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

[subject, modality, schema, previous] = set_up('meg');

Expand Down Expand Up @@ -91,9 +85,7 @@ function test_append_to_layout_basic()

function test_append_to_layout_schema_missing_required_entity()

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

[subject, modality, schema, previous] = set_up('func');

Expand Down
6 changes: 3 additions & 3 deletions tests/tests_private/test_list_all_trial_types.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function test_list_all_trial_types_warning()
trial_type_list = bids.internal.list_all_trial_types(BIDS, {'not', 'a', 'task'}, ...
'verbose', false);
assertEqual(trial_type_list, {});
if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end

skip_if_octave('mixed-string-concat warning thrown');

assertWarning(@() bids.internal.list_all_trial_types(BIDS, {'not', 'a', 'task'}, ...
'verbose', true), ...
'list_all_trial_types:noEventsFile');
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_private/test_parse_filename.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

function test_parse_filename_warnings()

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

fields = {};
tolerant = true;
Expand Down
4 changes: 1 addition & 3 deletions tests/tests_private/test_return_file_index.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ function test_return_file_index_basic()

function test_return_file_index_warning()

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

pth_bids_example = get_test_data_dir();

Expand Down
4 changes: 1 addition & 3 deletions tests/tests_utils/test_create_data_dict.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ function test_create_data_dict_schema()

function test_create_data_dict_warning

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

dataset = 'ds000248';

Expand Down
4 changes: 1 addition & 3 deletions tests/tests_utils/test_create_participants_tsv.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ function test_create_participants_tsv_basic()

function test_create_participants_tsv_already_exist()

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

bids_path = fullfile(get_test_data_dir(), 'ds210');

Expand Down
4 changes: 1 addition & 3 deletions tests/tests_utils/test_create_readme.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ function test_create_readme_basic()

function test_create_readme_warning_already_present()

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

bids_path = fullfile(get_test_data_dir(), 'ds116');

Expand Down
4 changes: 1 addition & 3 deletions tests/tests_utils/test_create_sessions_tsv.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ function test_create_sessions_tsv_no_session()

validate_dataset(bids_path);

if bids.internal.is_octave()
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
end
skip_if_octave('mixed-string-concat warning thrown');

assertWarning(@() bids.util.create_sessions_tsv(bids_path, 'verbose', true), ...
'create_sessions_tsv:noSessionInDataset');
Expand Down
6 changes: 6 additions & 0 deletions tests/utils/skip_if_octave.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function skip_if_octave(msg)
if bids.internal.is_octave()
moxunit_throw_test_skipped_exception(['Octave:', msg]);
end

end

0 comments on commit 8771359

Please sign in to comment.