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
56 changes: 56 additions & 0 deletions src/batches/preproc/setBatchRenameSegmentParameter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function matlabbatch = setBatchRenameSegmentParameter(varargin)
%
%
% USAGE::
%
% matlabbatch = setBachRenameSegmentParameter(matlabbatch, opt)
%
% :param matlabbatch: matlabbatch to append to.
% :type matlabbatch: cell
% :param opt: structure or json filename containing the options. See
% ``checkOptions()`` and ``loadAndCheckOptions()``.
% :type opt: structure
%
%
% :returns: - :matlabbatch: (cell) The matlabbatch ready to run the spm job
%
% (C) Copyright 2022 CPP_SPM developers

p = inputParser;

addRequired(p, 'matlabbatch', @iscell);
addRequired(p, 'opt', @isstruct);

parse(p, varargin{:});

matlabbatch = p.Results.matlabbatch;
opt = p.Results.opt;

printBatchName('rename segmentation parameter file', opt);

cfg_fileparts.files(1) = cfg_dep('Segment: Seg Params', ...
returnDependency(opt, 'segment'), ...
substruct('.', 'param', '()', {':'}));

matlabbatch{end + 1}.cfg_basicio.file_dir.cfg_fileparts = cfg_fileparts;

files = cfg_dep('Segment: Seg Params', ...
returnDependency(opt, 'segment'), ...
substruct('.', 'param', '()', {':'}));

moveTo = cfg_dep('Get Pathnames: Directories (unique)', ...
substruct('.', ...
'val', '{}', {numel(matlabbatch)}, '.', ...
'val', '{}', {1}, '.', ...
'val', '{}', {1}), ...
substruct('.', 'up'));

% TODO: adapt in case suffix is not T1w
patternReplace(1).pattern = 'T1w';
patternReplace(1).repl = 'label-T1w';
patternReplace(2).pattern = 'seg8';
patternReplace(2).repl = 'segparam';

matlabbatch = setBachRename(matlabbatch, files, moveTo, patternReplace);

end
41 changes: 41 additions & 0 deletions src/batches/setBachRename.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function matlabbatch = setBachRename(varargin)
%
%
% USAGE::
%
% matlabbatch = setBachRename(matlabbatch, files, moveTo, patternReplace, overwriteDuplicate)
%
%
% :returns: - :matlabbatch: (cell) The matlabbatch ready to run the spm job
%
% (C) Copyright 2022 CPP_SPM developers

p = inputParser;

isPatternReplaceStruct = @(x) isstruct(x) && all(ismember({'pattern', 'repl'}, fieldnames(x)));

addRequired(p, 'matlabbatch', @iscell);
addRequired(p, 'files', @iscell);
addRequired(p, 'moveTo', @iscell);
addRequired(p, 'patternReplace', isPatternReplaceStruct);
addOptional(p, 'overwriteDuplicate', false, @islogical);

parse(p, varargin{:});

matlabbatch = p.Results.matlabbatch;
files = p.Results.files;
moveTo = p.Results.moveTo;
patternReplace = p.Results.patternReplace;
overwriteDuplicate = p.Results.overwriteDuplicate;

file_move.files = files;

file_move.action.moveren.moveto = moveTo;

file_move.action.moveren.patrep = patternReplace;

file_move.action.moveren.unique = overwriteDuplicate;

matlabbatch{end + 1}.cfg_basicio.file_dir.file_ops.file_move = file_move;

end
2 changes: 1 addition & 1 deletion src/batches/stats/setBatchSubjectLevelGLMSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
if ~isfield(BIDS, 'raw')
msg = sprintf(['Provide raw BIDS dataset path in opt.dir.raw .\n' ...
'It is needed to load events.tsv files.\n']);
errorHandling(mfilename(), 'missingRawDir', msg, false, opt.verbosity);
errorHandling(mfilename(), 'missingRawDir', msg, false);
end

getModelType(opt.model.file);
Expand Down
28 changes: 14 additions & 14 deletions src/utils/setDirectories.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
return
end

fields = fieldnames(opt.dir);
for i = 1:numel(fields)
opt.dir.(fields{i}) = canonicalizeIfNonEmpty(opt.dir.(fields{i}));
end

opt = setDerivativesDir(opt);
opt = setDir(opt, 'preproc');
opt = setDir(opt, 'stats');
opt = setInputDir(opt);
opt = setOutputDir(opt);
opt = setJobsDir(opt, opt.dir.output);

fields = fieldnames(opt.dir);
for i = 1:numel(fields)
opt.dir.(fields{i}) = canonicalizeIfNonEmpty(opt.dir.(fields{i}));
end

end

Expand All @@ -36,7 +37,7 @@
end
end

opt.dir.input = spm_file(inputDir, 'cpath');
opt.dir.input = inputDir;

end

Expand Down Expand Up @@ -75,12 +76,11 @@
% to set preproc and stats directory
%

opt.dir.(step) = opt.dir.(step);

if ~strcmp(opt.pipeline.type, step)
return

else

% check that the pth ends with the pipeline type (preproc or stats) or
% is just derivatives
if ~isempty(opt.dir.(step)) && ( ...
Expand All @@ -89,6 +89,7 @@
~bids.internal.ends_with(opt.dir.(step), opt.pipeline.type))
opt.dir.(step) = '';
end

if isempty(opt.dir.(step))
% try to avoid creating folders called "preproc-preproc"
if strcmp(opt.pipeline.name, opt.pipeline.type)
Expand All @@ -100,9 +101,8 @@
return

end
end

opt.dir.(step) = spm_file(opt.dir.(step), 'cpath');
end

end

Expand All @@ -119,19 +119,19 @@
end
end

opt.dir.output = spm_file(outputDir, 'cpath');
opt = setJobsDir(opt, outputDir);
opt.dir.output = outputDir;

end

function opt = setJobsDir(opt, targetDir)

jobDir = fullfile(targetDir, 'jobs');

if isfield(opt, 'taskName') && ~isempty(opt.taskName) && ~isempty(opt.taskName{1})
jobDir = fullfile(targetDir, 'jobs', strjoin(opt.taskName, ''));
end
opt.dir.jobs = jobDir;

opt.dir.jobs = spm_file(jobDir, 'cpath');
opt.dir.jobs = jobDir;

end

Expand Down
7 changes: 4 additions & 3 deletions src/workflows/bidsRename.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,23 @@ function bidsRename(opt)
msg = sprintf('%s --> %s\n', spm_file(data{iFile}, 'filename'), new_filename);
printToScreen(msg, opt);

createdFiles{end + 1, 1} = new_filename;

if ~opt.dryRun && ~strcmp(new_filename, spm_file(data{iFile}, 'filename'))

% TODO write test for this
if exist(new_filename, 'file') || ismember(new_filename, createdFiles)
msg = sprintf('This file already exists. Will not overwrite.\n\t%s\n', ...
new_filename);
error_handling(mfilename(), 'fileAlreadyExist', msg, true, opt.verbosity);
errorHandling(mfilename(), 'fileAlreadyExist', msg, true, opt.verbosity);

else
movefile(data{iFile}, spm_file(data{iFile}, 'filename', new_filename));

end

end

createdFiles{end + 1, 1} = new_filename;

end

end
Expand Down
11 changes: 6 additions & 5 deletions src/workflows/stats/bidsFFX.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function matlabbatch = bidsFFX(action, opt)
function [matlabbatch, opt] = bidsFFX(action, opt)
%
% - specify the subject level fMRI model
% - estimates it
Expand Down Expand Up @@ -36,7 +36,9 @@
% (C) Copyright 2020 CPP_SPM developers

opt.pipeline.type = 'stats';

opt.dir.input = opt.dir.preproc;
opt.dir.output = opt.dir.stats;

description = 'subject level GLM';

Expand Down Expand Up @@ -164,10 +166,9 @@ function checks(opt, action)
end

function batchName = createBatchName(opt, action)
batchName = ...
[action '_ffx_task-', strjoin(opt.taskName, ''), ...
'_space-', char(opt.space), ...
'_FWHM-', num2str(opt.fwhm.func)];
batchName = [action '_ffx_task-', strjoin(opt.taskName, ''), ...
'_space-', char(opt.space), ...
'_FWHM-', num2str(opt.fwhm.func)];
end

function matlabbatch = setAction(action, matlabbatch, BIDS, opt, subLabel)
Expand Down
2 changes: 2 additions & 0 deletions src/workflows/stats/bidsRFX.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

description = 'group level GLM';

opt.dir.output = opt.dir.stats;

[~, opt] = setUpWorkflow(opt, description);

checks(opt, action);
Expand Down
2 changes: 2 additions & 0 deletions src/workflows/stats/bidsResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@

opt.pipeline.type = 'stats';

opt.dir.output = opt.dir.stats;

[~, opt] = setUpWorkflow(opt, 'computing GLM results');

% loop trough the steps and more results to compute for each contrast
Expand Down
Loading