Skip to content

Commit

Permalink
[ENH] overwrite files when renaming by default (#1051)
Browse files Browse the repository at this point in the history
* overwrite files when renaming by default

* fix tests
  • Loading branch information
Remi-Gau authored Jun 19, 2023
1 parent a8349fc commit 1673401
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/source/default_options.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
opt.query.modality{1} = 'anat' ;
opt.query.modality{2} = 'func' ;
opt.realign.useUnwarp = 1, ;
opt.rename = 1, ;
opt.rename.do = 1, ;
opt.results.MC = 'FWE' ;
opt.results.atlas = 'Neuromorphometrics' ;
opt.results.binary = 0, ;
Expand Down
7 changes: 5 additions & 2 deletions src/defaults/checkOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@
% - ``opt.zeropad = 2`` - number of zeros used for padding subject numbers, in case
% subjects should be fetched by their number ``1`` and not their label ``O1'``.
%
% - ``opt.rename = true`` - to skip renaming files with ``bidsRename()``.
% - ``opt.rename.do = true`` - to skip renaming files with ``bidsRename()``.
% Mostly for debugging as the output files won't be usable by any of the stats
% workflows.
% - ``opt.rename.overwrite = true`` - To overwrite any eventual previous output of
% ``bidsRename()``.
%
% - ``opt.msg.color = blue`` - default font color of the prompt messages.
%
Expand Down Expand Up @@ -262,7 +264,8 @@
fieldsToSet.subjects = {[]};
fieldsToSet.zeropad = 2;

fieldsToSet.rename = true;
fieldsToSet.rename.do = true;
fieldsToSet.rename.overwrite = true;

fieldsToSet.query.modality = {'anat', 'func'};

Expand Down
7 changes: 4 additions & 3 deletions src/workflows/bidsRename.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

% (C) Copyright 2019 bidspm developers

if ~opt.rename
if ~opt.rename.do
return
end

createdFiles = {};

if not(isfield(opt, 'spm_2_bids'))
if ~(isfield(opt, 'spm_2_bids'))
opt = set_spm_2_bids_defaults(opt);
end

Expand Down Expand Up @@ -82,7 +82,8 @@ function renameFileAndUpdateMetadata(opt, data, newFilename, json, createdFiles)
end

% TODO write test for this
if exist(outputFile, 'file') || ismember(newFilename, createdFiles)
if ~opt.rename.overwrite && exist(outputFile, 'file') || ...
ismember(newFilename, createdFiles)

msg = sprintf('This file already exists. Will not overwrite.\n\t%s\n', ...
newFilename);
Expand Down
4 changes: 2 additions & 2 deletions src/workflows/preproc/bidsCreateVDM.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function bidsCreateVDM(opt)
[BIDS, opt] = setUpWorkflow(opt, 'create voxel displacement map');

% why?
opt.rename = false;
opt.rename.do = false;

opt.query.desc = '';

Expand All @@ -43,7 +43,7 @@ function bidsCreateVDM(opt)

if any(ismember(suffixes, {'phase12', 'phasediff', 'fieldmap', 'epi'}))

opt.rename = true;
opt.rename.do = true;

printProcessingSubject(iSub, subLabel, opt);

Expand Down
2 changes: 1 addition & 1 deletion src/workflows/preproc/bidsRealignReslice.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function bidsRealignReslice(opt)

saveAndRunWorkflow(matlabbatch, 'realign_reslice', opt, subLabel);

if ~opt.dryRun && opt.rename
if ~opt.dryRun && opt.rename.do

copyFigures(BIDS, opt, subLabel);

Expand Down
2 changes: 1 addition & 1 deletion src/workflows/preproc/bidsRealignUnwarp.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function bidsRealignUnwarp(opt)

cleanUpWorkflow(opt);

if ~opt.dryRun && opt.rename
if ~opt.dryRun && opt.rename.do
opt = set_spm_2_bids_defaults(opt);
prefix = get_spm_prefix_list();
opt.query.prefix = prefix.unwarp;
Expand Down
4 changes: 2 additions & 2 deletions src/workflows/preproc/bidsSegmentSkullStrip.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@

saveAndRunWorkflow(matlabbatch, 'segment_skullstrip', opt, subLabel);

if ~opt.dryRun && opt.rename
if ~opt.dryRun && opt.rename.do
renameSegmentParameter(BIDS, subLabel, opt);
end

end

cleanUpWorkflow(opt);

if opt.dryRun || ~opt.rename
if opt.dryRun || ~opt.rename.do
return
end

Expand Down
2 changes: 1 addition & 1 deletion src/workflows/preproc/bidsSpatialPrepro.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

function renameFiles(BIDS, opt)

if ~opt.rename || opt.dryRun
if ~opt.rename.do || opt.dryRun
return
end

Expand Down
3 changes: 2 additions & 1 deletion tests/utils/defaultOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@

expectedOptions.zeropad = 2;

expectedOptions.rename = true;
expectedOptions.rename.do = true;
expectedOptions.rename.overwrite = true;

expectedOptions.QA.glm.do = false;

Expand Down

0 comments on commit 1673401

Please sign in to comment.