% Author: Elsa W. Birch, ewbirch@stanford.edu, Covert Lab - Stanford Bioengineering
% Date: 4/24/2011
% Version: associated with production of the figures for Birch et al. 2012 
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
%
% Summary: Run function to call all functions to complete simulations for paper figures
% 
%
% Inputs: none, but requires flat files and functions
%
% Outputs: saved simulations and text version output for use in R
%
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
%
% Notes: 
%
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

clear all
clc

% switch on/off (true/fale) the display of status durring running
outputProgress = true;

origPath = path; 
try
    % add folders to path
    addpath( fullfile(pwd,'modelsFunctionsAndFlatFiles') )
    addpath( fullfile(pwd,'functionsMatlab') )
    addpath( fullfile(pwd,'utilitiesMatlab','glpkmex') )
     
    % load in a setup the models
    FBA_EB_organismSetupAndSave( {'modelsFunctionsAndFlatFiles','Ecoli_EB_'}, {'modelsFunctionsAndFlatFiles','T7_37Growth_EB_'} )
    FBA_EB_organismSetupAndSave( {'modelsFunctionsAndFlatFiles','Ecoli_EB_'}, {} )
   
    % This will take a couple hours to run
    FBA_EB_batchRun( outputProgress )

    % This may take a day or two to run, unless a parallelization pool is opened
    % % Note that this is only necessary for figure 7 (limiting by mechinery or
    %       metabolism) and will not overwrite but add to total simulations
    %       avalible for figure productoin by R.  Thus if any changes are made
    %       to the model, parameters, sor even just when re-running the folders
    %       should be cleaned out so that the resutls of old simulations d not 
    %       get included in fig 8 (or if no paraemter change so that excessr
    %       edundant simulations do not make code to slow)
     FBA_EB_batchRun_fluxBoundSet( outputProgress )


    % This whole next section should only take a few minutes to run
    FORMAT_EB_parseFilesInFolderTo('simulationsMatlab', 'simulationsText',outputProgress)
    
    FORMAT_EB_parseFilesInFolderTo(fullfile('simulationsMatlab','fluxBoundsSet_mechineryLimit')...
                                    ,fullfile('simulationsText','fluxBoundsSet_mechineryLimit'),outputProgress)
    
    FORMAT_EB_parseFilesInFolderTo(fullfile('simulationsMatlab','fluxBoundsSet_metabolicLimit')...
                                    ,fullfile('simulationsText','fluxBoundsSet_metabolicLimit'),outputProgress)
    
    FORMAT_EB_mat2textMetClass( 'simulationsMatlab', 'tryptoneInfectedSimulation', 'simulationsText')

catch erOut 
    
    path(origPath)
    throw(erOut)
    
end % catch

% reset path
path(origPath)
