Skip to content

Commit

Permalink
feat: allow to set starting step
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlosfarah committed Aug 17, 2021
1 parent 6e9298d commit 27ae413
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
config.parcellation = 'schaefer_2018_400_subc';
config.parallel = false;

% sequence level configurations
config.sequence.startStep = 6;
config.sequence.noCleanUp = true;


% step 1: fast
config.step1.H = 0.25;
Expand All @@ -56,7 +60,7 @@

% step 4: binarize
config.step4.skip = false;
config.step4.optional = true;
config.step4.optional = false;
config.step4.clobber = config.clobber;
config.step4.verbose = config.verbose;

Expand Down
2 changes: 1 addition & 1 deletion src/matlab/builders/pipelines/BuildSegmentationPipeline.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
pathToIntermediaryOutputs char = '.'
pathToOutput char = '.'
numSubjects int8 {mustBeNonnegative} = 0
config = {}
config = struct()
end

% names of inputs needed to start the sequence
Expand Down
2 changes: 1 addition & 1 deletion src/matlab/builders/sequences/BuildSegmentationSequence.m
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
outputs, ...
pathToWorkspace, ...
pathToOutput, ...
true);
config.sequence);

end

50 changes: 41 additions & 9 deletions src/matlab/classes/Sequence.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
Outputs
WorkspacePath
OutputPath
NoCleanUp
Results
Ready
Configuration
end

methods
Expand All @@ -19,17 +19,42 @@
outputs, ...
workspacePath, ...
outputPath, ...
noCleanUp)
config)
%SEQUENCE Construct an instance of this class
% Detailed explanation goes here
arguments
steps
inputs
outputs
workspacePath
outputPath
config
end

% default to empty struct if empty cell array is passed
if isempty(config)
obj.Configuration = struct();
else
obj.Configuration = config;
end

% add default config options
if ~isfield(obj.Configuration, 'noCleanUp')
obj.Configuration.noCleanUp = false;
end
if ~isfield(obj.Configuration, 'startStep')
obj.Configuration.startStep = 1;
end


obj.Steps = steps;
obj.Inputs = inputs;
obj.Outputs = outputs;
obj.WorkspacePath = workspacePath;
obj.OutputPath = outputPath;
obj.NoCleanUp = noCleanUp;
obj.Results = cell(1, length(steps));
obj.Ready = false;
obj.Configuration = config;
end

function isValid = validate(obj)
Expand Down Expand Up @@ -86,7 +111,7 @@

function [obj, success] = cleanUp(obj)
success = true;
if obj.NoCleanUp
if obj.Configuration.noCleanUp
return
end
% remove the workspace
Expand Down Expand Up @@ -174,14 +199,21 @@
for i = 1 : length(obj.Steps)
step = obj.Steps{i};

% check if we are skipping this step
% check if we are skipping this step using start step
startStep = obj.Configuration.startStep;
if i < obj.Configuration.startStep
warning('start step is %d, skipping step %d', startStep, i);
continue;
end

% check if we are skipping this step manually
skip = isfield(step.Configuration, 'skip') && ...
step.Configuration.skip == true;
if skip
warning('skipping step %d', i)
continue;
end

% check if step is optional
optional = isfield(step.Configuration, 'optional') && ...
step.Configuration.optional == true;
Expand Down Expand Up @@ -230,7 +262,7 @@
return
else
warning('ignoring optional step %d after caught error: step %d failed with status %d and message "%s"\n', ...
i, ...
i, ...
i, ...
status, ...
result);
Expand All @@ -242,13 +274,13 @@

% extract outputs
extractOutputsSuccess = obj.extractOutputs();

if ~extractOutputsSuccess
success = false;
end

% clean up
if ~obj.NoCleanUp
if ~obj.Configuration.noCleanUp
[~, cleanUpSuccess] = obj.cleanUp();
if ~cleanUpSuccess
success = false;
Expand Down

0 comments on commit 27ae413

Please sign in to comment.