From 27ae413e094b915b95abaf490f63fee2f3722e78 Mon Sep 17 00:00:00 2001 From: Juan Carlos Farah Date: Tue, 17 Aug 2021 21:16:49 +0200 Subject: [PATCH] feat: allow to set starting step --- .../BuildSegmentationConfiguration.m | 6 ++- .../pipelines/BuildSegmentationPipeline.m | 2 +- .../sequences/BuildSegmentationSequence.m | 2 +- src/matlab/classes/Sequence.m | 50 +++++++++++++++---- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/matlab/builders/configurations/BuildSegmentationConfiguration.m b/src/matlab/builders/configurations/BuildSegmentationConfiguration.m index 4dcd996..13ae09f 100644 --- a/src/matlab/builders/configurations/BuildSegmentationConfiguration.m +++ b/src/matlab/builders/configurations/BuildSegmentationConfiguration.m @@ -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; @@ -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; diff --git a/src/matlab/builders/pipelines/BuildSegmentationPipeline.m b/src/matlab/builders/pipelines/BuildSegmentationPipeline.m index fc9a630..33063d4 100644 --- a/src/matlab/builders/pipelines/BuildSegmentationPipeline.m +++ b/src/matlab/builders/pipelines/BuildSegmentationPipeline.m @@ -24,7 +24,7 @@ pathToIntermediaryOutputs char = '.' pathToOutput char = '.' numSubjects int8 {mustBeNonnegative} = 0 - config = {} + config = struct() end % names of inputs needed to start the sequence diff --git a/src/matlab/builders/sequences/BuildSegmentationSequence.m b/src/matlab/builders/sequences/BuildSegmentationSequence.m index cc3abdf..11476c6 100644 --- a/src/matlab/builders/sequences/BuildSegmentationSequence.m +++ b/src/matlab/builders/sequences/BuildSegmentationSequence.m @@ -398,7 +398,7 @@ outputs, ... pathToWorkspace, ... pathToOutput, ... - true); + config.sequence); end diff --git a/src/matlab/classes/Sequence.m b/src/matlab/classes/Sequence.m index acaf621..b2ba304 100644 --- a/src/matlab/classes/Sequence.m +++ b/src/matlab/classes/Sequence.m @@ -8,9 +8,9 @@ Outputs WorkspacePath OutputPath - NoCleanUp Results Ready + Configuration end methods @@ -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) @@ -86,7 +111,7 @@ function [obj, success] = cleanUp(obj) success = true; - if obj.NoCleanUp + if obj.Configuration.noCleanUp return end % remove the workspace @@ -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; @@ -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); @@ -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;