Skip to content

Commit fd53318

Browse files
authored
Merge branch 'main' into doc
2 parents 8ac9c18 + 8195c3b commit fd53318

File tree

8 files changed

+126
-28
lines changed

8 files changed

+126
-28
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ body:
9595
- `git rev-parse --abbrev-ref HEAD`
9696
- `git rev-parse --short HEAD`
9797
98+
In the MATLAB command line
99+
100+
- `[branch, commit] = getRepoInfo()`
101+
98102
render: markdown
99103
value: |
100104
- main 29b689dd

src/infra/getEnvInfo.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
opt.dryRun = false;
1818
end
1919

20+
[branch, commit] = getRepoInfo();
21+
2022
generatedBy(1).name = 'CPP SPM';
2123
generatedBy(1).Version = getVersion();
24+
generatedBy(1).Branch = branch;
25+
generatedBy(1).Commit = commit;
2226
generatedBy(1).Description = '';
2327
generatedBy(1).CodeURL = returnRepoURL();
2428
generatedBy(1).DOI = 'https://doi.org/10.5281/zenodo.3554331';

src/infra/getRepoInfo.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function [branch, commit] = getRepoInfo(rootDir)
2+
%
3+
% Return the branch and commit shasum
4+
%
5+
% USAGE::
6+
%
7+
% [branch, commit] = getRepoInfo()
8+
%
9+
% (C) Copyright 2022 CPP_SPM developers
10+
11+
if nargin < 1
12+
rootDir = returnRootDir;
13+
end
14+
15+
WD = pwd;
16+
cd(rootDir);
17+
18+
try
19+
[~, branch] = system('git rev-parse --abbrev-ref HEAD');
20+
branch = strrep(branch, newline, '');
21+
catch
22+
branch = 'unknown';
23+
end
24+
25+
try
26+
[~, commit] = system('git rev-parse --short HEAD');
27+
commit = strrep(commit, newline, '');
28+
catch
29+
commit = 'unknown';
30+
end
31+
32+
cd(WD);
33+
34+
end

src/messages/errorHandling.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ function errorHandling(varargin)
55
% errorHandling(functionName, id, msg, tolerant, verbose)
66
%
77
% :param functionName:
8-
% :type functionName: string
8+
% :type functionName: char
9+
%
910
% :param id: Error or warning id
10-
% :type id: string
11+
% :type id: char
12+
%
1113
% :param msg: Message to print
12-
% :type msg: string
14+
% :type msg: char
15+
%
1316
% :param tolerant: If set to ``true`` errors are converted into warnings
1417
% :type tolerant: boolean
18+
%
1519
% :param verbose: If set to ``0`` or ``false`` this will silence any warning
1620
% :type verbose: boolean
1721
%

src/utils/designMatrixFigureName.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
nameStructure = struct( ...
3333
'suffix', 'designmatrix', ...
3434
'ext', '.png', ...
35-
'entities', struct( ...
36-
'sub', args.Results.subLabel, ...
35+
'entities', struct('sub', args.Results.subLabel, ...
3736
'task', strjoin(args.Results.opt.taskName, ''), ...
3837
'space', args.Results.opt.space));
3938
nameStructure.entities.desc = args.Results.desc;

src/utils/renamePng.m

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
function renamePng(directory)
1+
function renamePng(directory, prefix)
22
%
3-
% removes the _XXX suffix before the PNG extension in files generated by SPM
4-
% in a directory
3+
% Removes the _XXX suffix before the PNG extension
4+
% in files generated by SPM in a directory
5+
%
6+
% Wil overwrite any file that already exists
57
%
68
% USAGE::
79
%
@@ -10,13 +12,37 @@ function renamePng(directory)
1012
%
1113
% (C) Copyright 2021 CPP_SPM developers
1214

13-
pngFiles = spm_select('FPList', directory, '^sub-.*[0-9].png$');
15+
if nargin < 1
16+
directory = pwd;
17+
end
18+
if nargin < 2
19+
prefix = 'sub';
20+
end
21+
22+
pngFiles = spm_select('FPList', directory, ['^' prefix '-.*[0-9].png$']);
1423

1524
for iFile = 1:size(pngFiles, 1)
25+
1626
source = deblank(pngFiles(iFile, :));
27+
1728
basename = spm_file(source, 'basename');
1829
target = spm_file(source, 'basename', basename(1:end - 4));
19-
movefile(source, target);
30+
31+
if exist(target, 'file')
32+
delete(target);
33+
end
34+
35+
try
36+
movefile(source, target);
37+
38+
catch
39+
tolerant = true;
40+
verbosity = 2;
41+
msg = sprintf('Could not move file %s to %s', source, target);
42+
errorHandling(mfilename(), 'cannotMoveFile', msg, tolerant, verbosity);
43+
44+
end
45+
2046
end
2147

2248
end

src/workflows/stats/bidsRFX.m

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,13 @@
127127
contrastsList, ...
128128
groups);
129129

130-
% make sure there is no SPM.mat in the target dir
131-
%
132-
% folders where the model is to be specified have already been emptied
133-
% if at this stage they are not, something has gone horribly wrong.
134-
%
135-
% also if we continued SPM would ask us to manually confirm the over-write
136-
% by clicking buttons and no one has got time this
137-
for j = 1:numel(matlabbatch)
138-
139-
if isfield(matlabbatch{j}.spm, 'stats') && ...
140-
isfield(matlabbatch{j}.spm.stats, 'fmri_est')
141-
if exist(matlabbatch{j}.spm.stats.fmri_est.spmmat{1}, 'file')
142-
error('PANIC! About to overwrite a model. That should not happen');
143-
end
144-
end
130+
checkDirIsEmpty(matlabbatch);
145131

146-
end
132+
status = saveAndRunWorkflow(matlabbatch, ...
133+
'group_level_model_specification_estimation', ...
134+
opt);
147135

148-
saveAndRunWorkflow(matlabbatch, 'group_level_model_specification_estimation', opt);
136+
renameDesignMatrixFigure(status, matlabbatch);
149137

150138
end
151139

@@ -163,6 +151,7 @@
163151
opt.pipeline.type = 'groupStats';
164152
initBids(opt, 'description', description, 'force', false);
165153
end
154+
166155
end
167156

168157
function checks(opt)
@@ -172,3 +161,41 @@ function checks(opt)
172161
errorHandling(mfilename(), 'tooManySpaces', msg, false, opt.verbosity);
173162
end
174163
end
164+
165+
function checkDirIsEmpty(matlabbatch)
166+
167+
% make sure there is no SPM.mat in the target dir
168+
%
169+
% folders where the model is to be specified have already been emptied
170+
% if at this stage they are not, something has gone horribly wrong.
171+
%
172+
% also if we continued SPM would ask us to manually confirm the over-write
173+
% by clicking buttons and no one has got time this
174+
for i = 1:numel(matlabbatch)
175+
176+
if isfield(matlabbatch{i}.spm, 'stats') && ...
177+
isfield(matlabbatch{i}.spm.stats, 'fmri_est')
178+
if exist(matlabbatch{i}.spm.stats.fmri_est.spmmat{1}, 'file')
179+
error('PANIC! About to overwrite a model. That should not happen');
180+
end
181+
end
182+
183+
end
184+
185+
end
186+
187+
function renameDesignMatrixFigure(status, matlabbatch)
188+
189+
if ~status
190+
return
191+
end
192+
193+
for j = 1:numel(matlabbatch)
194+
if isfield(matlabbatch{j}.spm, 'stats') && ...
195+
isfield(matlabbatch{j}.spm.stats, 'fmri_est')
196+
directory = fileparts(matlabbatch{j}.spm.stats.fmri_est.spmmat{1});
197+
renamePng(directory, 'task');
198+
end
199+
end
200+
201+
end

src/workflows/stats/bidsResults.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@
440440

441441
matlabbatch = setBatchGroupLevelResults(matlabbatch, opt, result);
442442

443-
matlabbatch = setBatchPrintFigure(matlabbatch, opt, fullfile(result.dir, figureName(opt)));
443+
% matlabbatch = setBatchPrintFigure(matlabbatch, opt, fullfile(result.dir, figureName(opt)));
444444

445445
results{end + 1} = result;
446446

0 commit comments

Comments
 (0)