Scripts

This is the entry point for our code, it calls all other relevant functions.

Run_main

Code

  1function [settings,sb,results,model_folders,plots] = Run_main(Folder,Analysis,settings)
  2% Main function to perform various analyses on a selected model
  3% using a given settings file.
  4%
  5% Syntax: [stg, sb, rst, mmf, plots] = Run_main(Folder, Analysis, settings)
  6%
  7% Inputs:
  8%   - Folder: Name of the model folder located at
  9%       "Repository_name"/Matlab/Model/
 10%   - Analysis: Integer code representing the desired analysis to run:
 11%       1 = Diagnostics
 12%       2 = Parameter Estimation
 13%       3 = Local Sensitivity Analysis
 14%       4 = Global Sensitivity Analysis
 15%       5 = Profile Likelihood Analysis
 16%       6 = Reproduce a previous analysis
 17%       7 = Reproduce the plots of a previous analysis
 18%       8 = Import model files
 19%   - Settings: Name of the settings file located at
 20%       "Repository_name"/Matlab/Model/"Folder"/Matlab/Settings
 21%
 22% Outputs:
 23%   - stg: Structure containing the settings used for the analysis
 24%   - sb: Structure containing the sbtab data
 25%   - rst: Structure containing the results of the analysis
 26%   - mmf: Structure containing folder paths
 27%   - plots: Structure containing plot data (if applicable)
 28%
 29% This function performs the following steps:
 30%   1. Collect user inputs and create a timestamp
 31%   2. Get the main MATLAB folder and add it to the path if needed
 32%   3. Load settings and data based on user choices
 33%   4. Create the folder structure for model files
 34%   5. Import or generate sbtab data if needed
 35%   6. Re-Run the selected analysis
 36%   7. Plot results (if applicable)
 37%   ?? 8. Save analysis results and plots (if specified in settings)
 38
 39user_choices = {Folder,Analysis,settings};
 40
 41%Get the date and time
 42date_stamp = string(year(datetime)) + "_" + ...
 43    string(month(datetime)) + "_" + string(day(datetime))...
 44    + "__" + string(hour(datetime)) + "_" + string(minute(datetime))...
 45    + "_" + string(round(second(datetime)));
 46
 47% Get the folder where the MATLAB code and models are located
 48Matlab_main_folder = fileparts(mfilename('fullpath')) + "/";
 49Matlab_main_folder = strrep(Matlab_main_folder,"\","/");
 50
 51if ~contains(strrep(path,"\","/"),...
 52        extractAfter(Matlab_main_folder,strlength(Matlab_main_folder)-1))
 53    % If the folder is not in the path, add it
 54    addpath(genpath(Matlab_main_folder));
 55end
 56
 57model_folders.main = Matlab_main_folder;
 58
 59% Name of the various analysis that can be run with this code
 60analysis_options = ["Diagnostics","Parameter Estimation",...
 61    "Local Sensitivity Analysis","Global Sensitivity Analysis",...
 62    "Profile Likelihood Analysis","Reproduce a previous analysis",...
 63    "Reproduce the plots of a previous analysis","Import model files"];
 64
 65% Code for choosing the model and loading the settings files
 66[settings,results,sb] = f_user_input(model_folders,analysis_options,user_choices);
 67
 68% Get the folder structure used for the model files
 69[model_folders] = default_folders(settings,model_folders,date_stamp);
 70
 71% Runs the import scripts if chosen in settings
 72if settings.import
 73    [settings,sb] = f_import(settings,model_folders);
 74else
 75    % Creates a struct based on the sbtab that is used elswhere in the code
 76    % and also adds the number of experiments and outputs to the settings
 77    % variable
 78    if isempty(sb)% check needed for plot reproduction
 79        [settings,sb] = f_generate_sbtab_struct(settings,model_folders);
 80    end
 81end
 82
 83% Runs the Analysis chosen by the user input
 84     [results,settings] = f_analysis(settings,settings.analysis,model_folders,analysis_options,results);
 85
 86% Plots the results of the analysis, this can be done independently after
 87% loading the results of a previously run analysis
 88plots = [];
 89if settings.plot
 90     % plots = f_plot(results,settings,model_folders);
 91    % Save plots results if chosen in settings
 92%     if stg.save_results
 93%          f_save_plots(mmf)
 94%     end
 95end
 96
 97% Save Analysis results if chosen in settings
 98if settings.save_results
 99    % try
100    % f_save_analysis(settings,sb,results,model_folders,plots)
101    % catch
102    % end
103end
104
105end

This is the main script from the MATLAB® portion of the workflow. Depending on the configurations on the settings file and choices on the user facing prompts it can call functions to:

It can also reproduce a the calculations of a previous analysis or just its plots.