Skip to content

Commit

Permalink
fix 627
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Jul 9, 2024
1 parent 10c1d33 commit 8e571b2
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/IO/getData.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
if ~anatOnly && isfield(opt, 'taskName') && ...
~any(ismember(opt.taskName, bids.query(BIDS, 'tasks')))

msg = sprintf(['The task %s that you have asked for ', ...
msg = sprintf(['The task "%s" that you have asked for ', ...
'does not exist in this dataset.\n', ...
'List of tasks present in this dataset:\n%s'], ...
strjoin(opt.taskName), ...
Expand Down
55 changes: 29 additions & 26 deletions src/cli/cliCopy.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,44 @@ function cliCopy(varargin)

opt = checkOptions(opt);

opt.query.desc = {'preproc', 'brain'};
opt.query.suffix = {'T1w', 'bold', 'mask'};
if opt.anatOnly
opt.query.suffix = {'T1w', 'mask'};
end
bidsFilterFile = getBidsFilterFile(args);

if isempty(opt.taskName)
opt = rmfield(opt, 'taskName');
end
opt.query.space = opt.space;

bidsFilterFile = getBidsFilterFile(args);
if isempty(bidsFilterFile)
opt.query.desc = {'preproc', 'brain'};

opt.query.suffix = {'T1w', 'mask', 'bold', 'events'};

if opt.anatOnly
opt.query.suffix = {'T1w', 'mask'};
end

opt.query.space = opt.space;

saveOptions(opt);

bidsCopyInputFolder(opt, 'unzip', true, 'force', args.Results.force);

else

if ~isempty(bidsFilterFile)
suffixes = fieldnames(bidsFilterFile);
modalities = {};
for i = 1:numel(suffixes)
modalities{end + 1} = bidsFilterFile.(suffixes{i}).modality; %#ok<*AGROW>
if isfield(bidsFilterFile.(suffixes{i}), 'suffix')
opt.query.suffix = cat(2, ...
opt.query.suffix, ...
bidsFilterFile.(suffixes{i}).suffix);
end
if isfield(bidsFilterFile.(suffixes{i}), 'desc')
opt.query.desc = cat(2, ...
opt.query.desc, ...
bidsFilterFile.(suffixes{i}).desc);

if opt.anatOnly && ~strcmp(bidsFilterFile.(suffixes{i}).modality, 'anat')
continue
end
end
opt.query.modality = unique(modalities);
end
opt.query.suffix = unique(opt.query.suffix);
opt.query.desc = unique(opt.query.desc);

saveOptions(opt);
opt.query = bidsFilterFile.(suffixes{i});

bidsCopyInputFolder(opt, 'unzip', true, 'force', args.Results.force);
saveOptions(opt);

bidsCopyInputFolder(opt, 'unzip', true, 'force', args.Results.force);

end

end

end
1 change: 0 additions & 1 deletion src/cli/getOptionsFromCliArgument.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
if opt.verbosity > 3
unfold(opt);
end
unfold(opt);

end

Expand Down
5 changes: 3 additions & 2 deletions src/workflows/bidsCopyInputFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ function bidsCopyInputFolder(varargin)
filter.sub = opt.subjects;

if strcmp(filter.modality, 'func')
filter.task = opt.taskName;
if isempty(filter.task)
if ~isfield(opt, 'taskName') || isempty(opt.taskName)
filter.task = bids.query(BIDS, 'tasks', filter);
else
filter.task = opt.taskName;
end
end

Expand Down
110 changes: 110 additions & 0 deletions tests/tests_cli/test_bidspm_copy_raw.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,113 @@ function test_copy_anat_only()
assertEqual(numel(bids.query(BIDS, 'data')), 1);

end

function test_copy_no_task()

inputPath = fullfile(getMoaeDir(), 'inputs', 'raw');

outputPath = tempName();

bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'verbosity', 0);

BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);

assertEqual(numel(bids.query(BIDS, 'data')), 3);

end

function test_copy_filter_suffix()

inputPath = fullfile(getMoaeDir(), 'inputs', 'raw');

outputPath = tempName();

bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'bids_filter_file', struct('bold', struct('modality', 'func', ...
'suffix', 'events')), ...
'verbosity', 0);

BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);

assertEqual(numel(bids.query(BIDS, 'data')), 1);

end

function test_copy_filter_session()

inputPath = getTestDataDir('raw');

outputPath = tempName();

bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'participant_label', {'01', 'ctrl01'}, ...
'task', {'vismotion'}, ...
'bids_filter_file', struct('bold', struct('modality', 'func', ...
'suffix', 'events', ...
'ses', '01')), ...
'verbosity', 0);

BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);

assertEqual(numel(bids.query(BIDS, 'data')), 8);

end

function test_copy_filter_anat()

inputPath = getTestDataDir('raw');

outputPath = tempName();

bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'participant_label', {'01', 'ctrl01'}, ...
'task', {'vismotion'}, ...
'bids_filter_file', struct('anat', struct('modality', 'anat', ...
'suffix', 'T1w', ...
'ses', '01')), ...
'verbosity', 0);

BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);

assertEqual(numel(bids.query(BIDS, 'data')), 2);

end

function test_copy_several_filter()

inputPath = getTestDataDir('raw');

outputPath = tempName();

bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'participant_label', {'01', 'ctrl01'}, ...
'task', {'vismotion'}, ...
'bids_filter_file', struct('anat', struct('modality', 'anat', ...
'suffix', 'T1w', ...
'ses', '01'), ...
'bold', struct('modality', 'func', ...
'suffix', 'events', ...
'ses', '01')), ...
'verbosity', 0);

BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);

assertEqual(numel(bids.query(BIDS, 'data')), 10);

end

0 comments on commit 8e571b2

Please sign in to comment.