Skip to content

Commit 6f3e9cc

Browse files
authored
[FIX] copy to derivatives handles bids filter file and minimize re copying files that already exist (#1015)
* set overwrite to false by default when copying * split tests * better handle using bids filter file for copy * fix boilerplate cli errors * fix boilerplate cli errors * properly skip tests * fix path * skip the correct test * style * skip octave test
1 parent f61d350 commit 6f3e9cc

File tree

15 files changed

+498
-251
lines changed

15 files changed

+498
-251
lines changed

bidspm.m

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
addParameter(args, 'fwhm', 6, isPositiveScalar);
4343
addParameter(args, 'space', {}, isCellStr);
4444

45+
% copy only
46+
addParameter(args, 'force', false, isLogical);
47+
4548
% create_roi only
4649
addParameter(args, 'roi_dir', '', isChar);
4750
addParameter(args, 'hemisphere', {'L', 'R'}, isCellStr);
@@ -193,7 +196,30 @@ function copy(args)
193196
opt.query.desc = {'preproc', 'brain'};
194197
opt.query.suffix = {'T1w', 'bold', 'mask'};
195198
opt.query.space = opt.space;
196-
bidsCopyInputFolder(opt);
199+
200+
bidsFilterFile = get_bidsFilterFile(args);
201+
if ~isempty(bidsFilterFile)
202+
suffixes = fieldnames(bidsFilterFile);
203+
modalities = {};
204+
for i = 1:numel(suffixes)
205+
modalities{end + 1} = bidsFilterFile.(suffixes{i}).modality; %#ok<*AGROW>
206+
if isfield(bidsFilterFile.(suffixes{i}), 'suffix')
207+
opt.query.suffix = cat(2, ...
208+
opt.query.suffix, ...
209+
bidsFilterFile.(suffixes{i}).suffix);
210+
end
211+
if isfield(bidsFilterFile.(suffixes{i}), 'desc')
212+
opt.query.desc = cat(2, ...
213+
opt.query.desc, ...
214+
bidsFilterFile.(suffixes{i}).desc);
215+
end
216+
end
217+
opt.query.modality = unique(modalities);
218+
end
219+
opt.query.suffix = unique(opt.query.suffix);
220+
opt.query.desc = unique(opt.query.desc);
221+
222+
bidsCopyInputFolder(opt, 'unzip', true, 'force', args.Results.force);
197223

198224
end
199225

@@ -657,6 +683,16 @@ function update()
657683

658684
%% helpers functions
659685

686+
function bidsFilterFile = get_bidsFilterFile(args)
687+
688+
if isstruct(args.Results.bids_filter_file)
689+
bidsFilterFile = args.Results.bids_filter_file;
690+
else
691+
bidsFilterFile = bids.util.jsondecode(args.Results.bids_filter_file);
692+
end
693+
694+
end
695+
660696
function detectBidspm()
661697

662698
workflowsDir = cellstr(which('bidsSpatialPrepro.m', '-ALL'));

src/messages/bidspmHelp.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ function bidspmHelp()
140140
%
141141
% **COPY:**
142142
%
143-
% Copies fmriprep data for smoothing.
143+
% Copies and unzips input data to output dir.
144+
% For example for fmriprep data before smoothing.
144145
%
145146
% .. code-block:: matlab
146147
%
@@ -152,8 +153,11 @@ function bidspmHelp()
152153
% 'space', {'individual', 'IXI549Space'}, ...
153154
% 'options', struct([]), ...
154155
% 'task', {}, ...
155-
% 'skip_validation', false)
156+
% 'skip_validation', false, ...
157+
% 'force', false)
156158
%
159+
% :param force: overwrites previous data if true
160+
% :type force: logical
157161
%
158162
% **CREATE_ROI:**
159163
%
@@ -189,6 +193,8 @@ function bidspmHelp()
189193
%
190194
% **SMOOTH:**
191195
%
196+
% Copies files to output dir and smooths them.
197+
%
192198
% .. code-block:: matlab
193199
%
194200
% bidspm(bids_dir, output_dir, 'subject', ...
@@ -201,7 +207,11 @@ function bidspmHelp()
201207
% 'options', struct([]), ...
202208
% 'task', {}, ...
203209
% 'fwhm', 6, ...
204-
% 'skip_validation', false)
210+
% 'skip_validation', false
211+
% 'force', false)
212+
%
213+
% :param force: overwrites previous data if true
214+
% :type force: logical
205215
%
206216
%
207217
% **DEFAULT_MODEL:**

src/workflows/bidsCopyInputFolder.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function bidsCopyInputFolder(varargin)
1616
% :param unzip: defaults to true
1717
% :type unzip: boolean
1818
%
19-
% :param unzip: defaults to true
20-
% :type unzip: boolean
19+
% :param force: defaults to true
20+
% :type force: boolean
2121
%
2222
% See also: bids.copy_to_derivative
2323
%
@@ -31,7 +31,7 @@ function bidsCopyInputFolder(varargin)
3131

3232
addRequired(args, 'opt', @isstruct);
3333
addParameter(args, 'unzip', true, @islogical);
34-
addParameter(args, 'force', true, @islogical);
34+
addParameter(args, 'force', false, @islogical);
3535

3636
parse(args, varargin{:});
3737

@@ -52,7 +52,6 @@ function bidsCopyInputFolder(varargin)
5252
% raw directory and derivatives directory
5353
createDerivativeDir(opt);
5454

55-
%% Loop through the groups, subjects, sessions
5655
[BIDS, opt] = getData(opt, opt.dir.input);
5756

5857
use_schema = true;

tests/tests_batches/stats/test_setBatchSubjectLevelResults.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ function test_setBatchSubjectLevelResults_basic()
5353
function test_setBatchSubjectLevelResults_missing_contrast_name()
5454

5555
if bids.internal.is_octave()
56-
% 'Octave:mixed-string-concat'
57-
return
56+
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
5857
end
5958

6059
[subLabel, opt, result] = setUp('vismotion');
@@ -73,8 +72,7 @@ function test_setBatchSubjectLevelResults_missing_contrast_name()
7372
function test_setBatchSubjectLevelResults_error_no_matching_contrast()
7473

7574
if bids.internal.is_octave()
76-
% 'Octave:mixed-string-concat'
77-
return
75+
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
7876
end
7977

8078
contrast_name = 'NotAContrast';

tests/tests_cli/test_bidspm.m

Lines changed: 0 additions & 221 deletions
This file was deleted.

0 commit comments

Comments
 (0)