Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ body:
- `git rev-parse --abbrev-ref HEAD`
- `git rev-parse --short HEAD`

In the MATLAB command line

- `[branch, commit] = getRepoInfo()`

render: markdown
value: |
- main 29b689dd
Expand Down
4 changes: 4 additions & 0 deletions src/infra/getEnvInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
opt.dryRun = false;
end

[branch, commit] = getRepoInfo();

generatedBy(1).name = 'CPP SPM';
generatedBy(1).Version = getVersion();
generatedBy(1).Branch = branch;
generatedBy(1).Commit = commit;
generatedBy(1).Description = '';
generatedBy(1).CodeURL = returnRepoURL();
generatedBy(1).DOI = 'https://doi.org/10.5281/zenodo.3554331';
Expand Down
34 changes: 34 additions & 0 deletions src/infra/getRepoInfo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function [branch, commit] = getRepoInfo(rootDir)
%
% Return the branch and commit shasum
%
% USAGE::
%
% [branch, commit] = getRepoInfo()
%
% (C) Copyright 2022 CPP_SPM developers

if nargin < 1
rootDir = returnRootDir;
end

WD = pwd;
cd(rootDir);

try
[~, branch] = system('git rev-parse --abbrev-ref HEAD');
branch = strrep(branch, newline, '');
catch
branch = 'unknown';
end

try
[~, commit] = system('git rev-parse --short HEAD');
commit = strrep(commit, newline, '');
catch
commit = 'unknown';
end

cd(WD);

end
10 changes: 7 additions & 3 deletions src/messages/errorHandling.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ function errorHandling(varargin)
% errorHandling(functionName, id, msg, tolerant, verbose)
%
% :param functionName:
% :type functionName: string
% :type functionName: char
%
% :param id: Error or warning id
% :type id: string
% :type id: char
%
% :param msg: Message to print
% :type msg: string
% :type msg: char
%
% :param tolerant: If set to ``true`` errors are converted into warnings
% :type tolerant: boolean
%
% :param verbose: If set to ``0`` or ``false`` this will silence any warning
% :type verbose: boolean
%
Expand Down
3 changes: 1 addition & 2 deletions src/utils/designMatrixFigureName.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
nameStructure = struct( ...
'suffix', 'designmatrix', ...
'ext', '.png', ...
'entities', struct( ...
'sub', args.Results.subLabel, ...
'entities', struct('sub', args.Results.subLabel, ...
'task', strjoin(args.Results.opt.taskName, ''), ...
'space', args.Results.opt.space));
nameStructure.entities.desc = args.Results.desc;
Expand Down
36 changes: 31 additions & 5 deletions src/utils/renamePng.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function renamePng(directory)
function renamePng(directory, prefix)
%
% removes the _XXX suffix before the PNG extension in files generated by SPM
% in a directory
% Removes the _XXX suffix before the PNG extension
% in files generated by SPM in a directory
%
% Wil overwrite any file that already exists
%
% USAGE::
%
Expand All @@ -10,13 +12,37 @@ function renamePng(directory)
%
% (C) Copyright 2021 CPP_SPM developers

pngFiles = spm_select('FPList', directory, '^sub-.*[0-9].png$');
if nargin < 1
directory = pwd;
end
if nargin < 2
prefix = 'sub';
end

pngFiles = spm_select('FPList', directory, ['^' prefix '-.*[0-9].png$']);

for iFile = 1:size(pngFiles, 1)

source = deblank(pngFiles(iFile, :));

basename = spm_file(source, 'basename');
target = spm_file(source, 'basename', basename(1:end - 4));
movefile(source, target);

if exist(target, 'file')
delete(target);
end

try
movefile(source, target);

catch
tolerant = true;
verbosity = 2;
msg = sprintf('Could not move file %s to %s', source, target);
errorHandling(mfilename(), 'cannotMoveFile', msg, tolerant, verbosity);

end

end

end
61 changes: 44 additions & 17 deletions src/workflows/stats/bidsRFX.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,13 @@
contrastsList, ...
groups);

% make sure there is no SPM.mat in the target dir
%
% folders where the model is to be specified have already been emptied
% if at this stage they are not, something has gone horribly wrong.
%
% also if we continued SPM would ask us to manually confirm the over-write
% by clicking buttons and no one has got time this
for j = 1:numel(matlabbatch)

if isfield(matlabbatch{j}.spm, 'stats') && ...
isfield(matlabbatch{j}.spm.stats, 'fmri_est')
if exist(matlabbatch{j}.spm.stats.fmri_est.spmmat{1}, 'file')
error('PANIC! About to overwrite a model. That should not happen');
end
end
checkDirIsEmpty(matlabbatch);

end
status = saveAndRunWorkflow(matlabbatch, ...
'group_level_model_specification_estimation', ...
opt);

saveAndRunWorkflow(matlabbatch, 'group_level_model_specification_estimation', opt);
renameDesignMatrixFigure(status, matlabbatch);

end

Expand All @@ -163,6 +151,7 @@
opt.pipeline.type = 'groupStats';
initBids(opt, 'description', description, 'force', false);
end

end

function checks(opt)
Expand All @@ -172,3 +161,41 @@ function checks(opt)
errorHandling(mfilename(), 'tooManySpaces', msg, false, opt.verbosity);
end
end

function checkDirIsEmpty(matlabbatch)

% make sure there is no SPM.mat in the target dir
%
% folders where the model is to be specified have already been emptied
% if at this stage they are not, something has gone horribly wrong.
%
% also if we continued SPM would ask us to manually confirm the over-write
% by clicking buttons and no one has got time this
for i = 1:numel(matlabbatch)

if isfield(matlabbatch{i}.spm, 'stats') && ...
isfield(matlabbatch{i}.spm.stats, 'fmri_est')
if exist(matlabbatch{i}.spm.stats.fmri_est.spmmat{1}, 'file')
error('PANIC! About to overwrite a model. That should not happen');
end
end

end

end

function renameDesignMatrixFigure(status, matlabbatch)

if ~status
return
end

for j = 1:numel(matlabbatch)
if isfield(matlabbatch{j}.spm, 'stats') && ...
isfield(matlabbatch{j}.spm.stats, 'fmri_est')
directory = fileparts(matlabbatch{j}.spm.stats.fmri_est.spmmat{1});
renamePng(directory, 'task');
end
end

end
2 changes: 1 addition & 1 deletion src/workflows/stats/bidsResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@

matlabbatch = setBatchGroupLevelResults(matlabbatch, opt, result);

matlabbatch = setBatchPrintFigure(matlabbatch, opt, fullfile(result.dir, figureName(opt)));
% matlabbatch = setBatchPrintFigure(matlabbatch, opt, fullfile(result.dir, figureName(opt)));

results{end + 1} = result;

Expand Down