Skip to content

Commit ebb474d

Browse files
authored
update rename to store original spm name in metadata (#987)
1 parent 661901e commit ebb474d

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/workflows/bidsRename.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function bidsRename(opt)
1+
function createdFiles = bidsRename(opt)
22
%
33
% Renames SPM output into BIDS compatible files.
44
%
@@ -54,12 +54,16 @@ function bidsRename(opt)
5454

5555
json = updateSource(json, data{iFile}, opt);
5656

57+
json.content.SpmFilename = spm_file(data{iFile}, 'filename');
58+
5759
msg = sprintf('%s --> %s\n', spm_file(data{iFile}, 'filename'), newFilename);
5860
printToScreen(msg, opt);
5961

6062
renameFileAndUpdateMetadata(opt, data{iFile}, newFilename, json, createdFiles);
6163

62-
createdFiles{end + 1, 1} = newFilename;
64+
createdFiles{end + 1, 1} = spm_file(data{iFile}, ...
65+
'filename', ...
66+
newFilename); %#ok<*AGROW>
6367

6468
end
6569

tests/tests_workflows/test_bidsRename.m

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ function test_bidsRename_basic()
1717
opt = setOptions('MoAE-preproc');
1818

1919
% move test data into temp directory to test renaming
20-
tmpDir = fullfile(pwd, 'tmp');
21-
if isdir(tmpDir)
22-
rmdir(tmpDir, 's');
23-
end
20+
tmpDir = tempname;
2421
spm_mkdir(tmpDir);
2522
copyfile(opt.dir.preproc, tmpDir);
2623

@@ -32,6 +29,7 @@ function test_bidsRename_basic()
3229
opt.dir.preproc = bidsDir;
3330

3431
BIDS = bids.layout(bidsDir, 'use_schema', false);
32+
3533
files = bids.query(BIDS, 'data', 'prefix', '');
3634
for i = 1:numel(files)
3735
delete(files{i});
@@ -40,8 +38,17 @@ function test_bidsRename_basic()
4038
opt.dryRun = false;
4139
opt.verbosity = 2;
4240

43-
bidsRename(opt);
44-
45-
rmdir(tmpDir, 's');
41+
createdFiles = bidsRename(opt);
42+
43+
files = bids.query(BIDS, 'data');
44+
for i = 1:numel(createdFiles)
45+
jsonFile = spm_file(createdFiles{i}, 'ext', '.json');
46+
if exist(jsonFile, 'file')
47+
content = bids.util.jsondecode(jsonFile);
48+
if isfield(content, 'SpmFilename')
49+
assert(size(content.SpmFilename, 1) == 1);
50+
end
51+
end
52+
end
4653

4754
end

0 commit comments

Comments
 (0)