Generated Code

The following is matlab code generated by the CellML API from this CellML file. (Back to language selection)

The raw code is available.

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = mainFunction()
    % This is the "main function".  In Matlab, things work best if you rename this function to match the filename.
   [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel();
end

function [algebraicVariableCount] = getAlgebraicVariableCount() 
    % Used later when setting a global variable with the number of algebraic variables.
    % Note: This is not the "main method".  
    algebraicVariableCount =3;
end
% There are a total of 11 entries in each of the rate and state variable arrays.
% There are a total of 21 entries in the constant variable array.
%

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel()
    % Create ALGEBRAIC of correct size
    global algebraicVariableCount;  algebraicVariableCount = getAlgebraicVariableCount();
    % Initialise constants and state variables
    [INIT_STATES, CONSTANTS] = initConsts;

    % Set timespan to solve over 
    tspan = [0, 10];

    % Set numerical accuracy options for ODE solver
    options = odeset('RelTol', 1e-06, 'AbsTol', 1e-06, 'MaxStep', 1);

    % Solve model with ODE solver
    [VOI, STATES] = ode15s(@(VOI, STATES)computeRates(VOI, STATES, CONSTANTS), tspan, INIT_STATES, options);

    % Compute algebraic variables
    [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS);
    ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI);

    % Plot state variables against variable of integration
    [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends();
    figure();
    plot(VOI, STATES);
    xlabel(LEGEND_VOI);
    l = legend(LEGEND_STATES);
    set(l,'Interpreter','none');
end

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (second)');
    LEGEND_CONSTANTS(:,1) = strpad('EGF in component EGF (dimensionless)');
    LEGEND_CONSTANTS(:,2) = strpad('inhibitor in component inhibitor (dimensionless)');
    LEGEND_CONSTANTS(:,3) = strpad('pro_EGFR in component pro_EGFR (dimensionless)');
    LEGEND_STATES(:,1) = strpad('EGFR in component EGFR (dimensionless)');
    LEGEND_STATES(:,2) = strpad('EGF_EGFR in component EGF_EGFR (dimensionless)');
    LEGEND_STATES(:,3) = strpad('EGFR_i in component EGFR_i (dimensionless)');
    LEGEND_CONSTANTS(:,4) = strpad('EGF_binding_kb in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,5) = strpad('EGF_binding_kf in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,6) = strpad('inhibitor_binding_kb in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,7) = strpad('inhibitor_binding_kf in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,8) = strpad('EGFR_turnover in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,4) = strpad('EGF_EGFR_i in component EGF_EGFR_i (dimensionless)');
    LEGEND_CONSTANTS(:,9) = strpad('k1_EGFR_phosphorylation in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,5) = strpad('pEGFR in component pEGFR (dimensionless)');
    LEGEND_STATES(:,6) = strpad('pEGFR_Akt in component pEGFR_Akt (dimensionless)');
    LEGEND_STATES(:,7) = strpad('Akt in component Akt (dimensionless)');
    LEGEND_CONSTANTS(:,10) = strpad('k1_pEGFR_degradation in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,11) = strpad('k1_Akt_phosphorylation in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,12) = strpad('k1_pEGFR_Akt in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,13) = strpad('k2_pEGFR_Akt in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,8) = strpad('pAkt in component pAkt (dimensionless)');
    LEGEND_CONSTANTS(:,14) = strpad('k1_pAkt_dephosphorylation in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,9) = strpad('S6 in component S6 (dimensionless)');
    LEGEND_STATES(:,10) = strpad('pAkt_S6 in component pAkt_S6 (dimensionless)');
    LEGEND_CONSTANTS(:,15) = strpad('k1_pAkt_S6 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,16) = strpad('k2_pAkt_S6 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,17) = strpad('k1_S6_phosphorylation in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,11) = strpad('pS6 in component pS6 (dimensionless)');
    LEGEND_CONSTANTS(:,18) = strpad('k1_pS6_dephosphorylation in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,1) = strpad('pEGFR_total in component pEGFR_total (dimensionless)');
    LEGEND_CONSTANTS(:,19) = strpad('pEGFR_scalefactor in component pEGFR_total (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('pAkt_total in component pAkt_total (dimensionless)');
    LEGEND_CONSTANTS(:,20) = strpad('pAkt_scalefactor in component pAkt_total (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('pS6_total in component pS6_total (dimensionless)');
    LEGEND_CONSTANTS(:,21) = strpad('pS6_scalefactor in component pS6_total (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt EGFR in component EGFR (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt EGF_EGFR in component EGF_EGFR (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt EGFR_i in component EGFR_i (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt EGF_EGFR_i in component EGF_EGFR_i (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt pEGFR in component pEGFR (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt pEGFR_Akt in component pEGFR_Akt (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt Akt in component Akt (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt pAkt in component pAkt (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt pAkt_S6 in component pAkt_S6 (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt S6 in component S6 (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt pS6 in component pS6 (dimensionless)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    CONSTANTS(:,1) = 30.0;
    CONSTANTS(:,2) = 15.0;
    CONSTANTS(:,3) = 6.81902e-4;
    STATES(:,1) = 68190.000000002;
    STATES(:,2) = 0.0;
    STATES(:,3) = 0.0;
    CONSTANTS(:,4) = 4.07490e-2;
    CONSTANTS(:,5) = 6.73816e-3;
    CONSTANTS(:,6) = 5.25097e-5;
    CONSTANTS(:,7) = 2.434663e-5;
    CONSTANTS(:,8) = 1.06386129269658e-4;
    STATES(:,4) = 0.0;
    CONSTANTS(:,9) = 1.92391e-2;
    STATES(:,5) = 0.0;
    STATES(:,6) = 0.0;
    STATES(:,7) = 4.33090e-2;
    CONSTANTS(:,10) = 9.97194e-2;
    CONSTANTS(:,11) = 3.05684e-2;
    CONSTANTS(:,12) = 1.55430e-5;
    CONSTANTS(:,13) = 5.17473e-3;
    STATES(:,8) = 0.0;
    CONSTANTS(:,14) = 3.27962e-2;
    STATES(:,9) = 3.54317e0;
    STATES(:,10) = 0.0;
    CONSTANTS(:,15) = 2.10189e-6;
    CONSTANTS(:,16) = 5.17940e-15;
    CONSTANTS(:,17) = 1.21498e-3;
    STATES(:,11) = 0.0;
    CONSTANTS(:,18) = 1.13102e-3;
    CONSTANTS(:,19) = 1.81735e-4;
    CONSTANTS(:,20) = 6.00588e1;
    CONSTANTS(:,21) = 4.98862e4;
    if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
    global algebraicVariableCount;
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        ALGEBRAIC = zeros(1, algebraicVariableCount);
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
        utilOnes = ones(statesRowCount, 1);
    end
    RATES(:,1) = ( CONSTANTS(:,4).*STATES(:,2)+ CONSTANTS(:,6).*STATES(:,3)+ CONSTANTS(:,8).*(CONSTANTS(:,3) - STATES(:,1))) - ( CONSTANTS(:,5).*CONSTANTS(:,1).*STATES(:,1)+ CONSTANTS(:,7).*CONSTANTS(:,2).*STATES(:,1));
    RATES(:,2) = ( CONSTANTS(:,5).*CONSTANTS(:,1).*STATES(:,1)+ CONSTANTS(:,6).*STATES(:,4)) - ( CONSTANTS(:,4).*STATES(:,2)+ CONSTANTS(:,7).*CONSTANTS(:,2).*STATES(:,2)+ CONSTANTS(:,9).*STATES(:,2));
    RATES(:,3) = ( CONSTANTS(:,4).*STATES(:,4)+ CONSTANTS(:,7).*CONSTANTS(:,2).*STATES(:,1)) - ( CONSTANTS(:,5).*CONSTANTS(:,1).*STATES(:,3)+ CONSTANTS(:,6).*STATES(:,3)+ CONSTANTS(:,8).*STATES(:,3));
    RATES(:,4) = ( CONSTANTS(:,5).*CONSTANTS(:,1).*STATES(:,3)+ CONSTANTS(:,7).*CONSTANTS(:,2).*STATES(:,2)) - ( CONSTANTS(:,4).*STATES(:,4)+ CONSTANTS(:,6).*STATES(:,4));
    RATES(:,5) = ( CONSTANTS(:,9).*STATES(:,2)+ CONSTANTS(:,11).*STATES(:,6)+ CONSTANTS(:,13).*STATES(:,6)) - ( CONSTANTS(:,10).*STATES(:,5)+ CONSTANTS(:,12).*STATES(:,5).*STATES(:,7));
    RATES(:,6) =  CONSTANTS(:,12).*STATES(:,5).*STATES(:,7) - ( CONSTANTS(:,13).*STATES(:,6)+ CONSTANTS(:,11).*STATES(:,6));
    RATES(:,7) = ( CONSTANTS(:,13).*STATES(:,6)+ CONSTANTS(:,14).*STATES(:,8)) -  CONSTANTS(:,12).*STATES(:,5).*STATES(:,7);
    RATES(:,8) = ( CONSTANTS(:,11).*STATES(:,6)+ CONSTANTS(:,16).*STATES(:,10)+ CONSTANTS(:,17).*STATES(:,10)) - ( CONSTANTS(:,14).*STATES(:,8)+ CONSTANTS(:,15).*STATES(:,8).*STATES(:,9));
    RATES(:,10) =  CONSTANTS(:,15).*STATES(:,8).*STATES(:,9) - ( CONSTANTS(:,16).*STATES(:,10)+ CONSTANTS(:,17).*STATES(:,10));
    RATES(:,9) = ( CONSTANTS(:,16).*STATES(:,10)+ CONSTANTS(:,18).*STATES(:,11)) -  CONSTANTS(:,15).*STATES(:,8).*STATES(:,9);
    RATES(:,11) =  CONSTANTS(:,17).*STATES(:,10) -  CONSTANTS(:,18).*STATES(:,11);
   RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        utilOnes = ones(statesRowCount, 1);
    end
    ALGEBRAIC(:,1) =  (STATES(:,5)+STATES(:,6)).*CONSTANTS(:,19);
    ALGEBRAIC(:,2) =  (STATES(:,8)+STATES(:,10)).*CONSTANTS(:,20);
    ALGEBRAIC(:,3) =  STATES(:,11).*CONSTANTS(:,21);
end

% Pad out or shorten strings to a set length
function strout = strpad(strin)
    req_length = 160;
    insize = size(strin,2);
    if insize > req_length
        strout = strin(1:req_length);
    else
        strout = [strin, blanks(req_length - insize)];
    end
end