Skip to Main Content Skip to Search
Product Documentation

Example — Creating and Simulating a Model That Uses a User-Defined Function in an Expression

Overview

Prerequisites for the Example

This example assumes you have a working knowledge of:

About the Example Model

This example uses the model described in Model of the Yeast Heterotrimeric G Protein Cycle.

This table shows the reactions used to model the G protein cycle and the corresponding rate parameters (rate constants) for each reaction. For reversible reactions, the forward rate parameter is listed first.

No.NameReaction1Rate Parameters
1Receptor-ligand interactionL + R <-> RLkRL, kRLm
2Heterotrimeric G protein formationGd + Gbg -> GkG1
3G protein activationRL + G -> Ga + Gbg + RLkGa
4Receptor synthesis and degradationR <-> nullkRdo, kRs
5Receptor-ligand degradationRL -> nullkRD1
6G protein inactivationGa -> GdkGd
1 Legend of species: L = ligand (alpha factor), R = alpha-factor receptor, Gd = inactive G-alpha-GDP, Gbg = free levels of G-beta:G-gamma complex, G = inactive Gbg:Gd complex, Ga = active G-alpha-GTP

Assumptions of the Example

This example assumes that:

About the Example

This example shows how to create and call a custom function in a SimBiology expression. Specifically, it shows how to use a custom function in a rule expression.

About Using Custom Functions in SimBiology Expressions

You can use custom functions in:

The requirements for using custom functions in SimBiology expressions are:

Creating a Custom Function

The following procedure creates a custom function, inhibvalex, which lets you specify how the inhibitor amount changes over time. The inputs are time, the initial amount of inhibitor, and a parameter that governs the amount of inhibitor. The output of the function is the amount of inhibitor.

  1. In the MATLAB desktop, select File > New > Script, to open the MATLAB Editor.

  2. Copy and paste the following function declaration:

    % inhibvalex.m
    function Cp = inhibvalex(t, Cpo, kel)
    
    % This function takes the input arguments t, Cpo, and kel 
    % and returns the value of the inhibitor Cp.
    % You can later specify the input arguments in a 
    % SimBiology rule expression. 
    % For example in the rule expression, specify:
    % t as time (a keyword recognized as simulation time), 
    % Cpo as a parameter that represents the initial amount of inhibitor, 
    % and kel as a parameter that governs the amount of inhibitor.
    
    if  t < 400   
        Cp = Cpo*exp(-kel*(t));
    else
        Cp = Cpo*exp(-kel*(t-400));
    end
  3. Save the file (name the file inhibvalex.m) in a directory that is on the MATLAB search path, or to a directory that you can access.

  4. If the location of the file is not on the MATLAB search path, change the working directory to the file location.

Opening the Example Model

Load the gprotein example project, which includes the variable m1, a model object:

sbioloadproject gprotein

The m1 model object appears in the MATLAB Workspace.

Adding the Custom Function to the Example Model

The following procedure creates a rule expression that calls the custom function, inhibvalex, and specifies the three input values to this function.

  1. Add a repeated assignment rule to the model that specifies the three input values to the custom function, inhibvalex:

    rule1 = addrule(m1, 'Inhib = inhibvalex(time, Cpo, Kel)',...
                    'repeatedAssignment');

    The time input is a SimBiology keyword recognized as simulation time

  2. Create the two parameters used by the rule1 rule and assign values to them:

    p1 = addparameter(m1, 'Cpo', 250);
    p2 = addparameter(m1, 'Kel', 0.01);
    
  3. Create the species used by the rule1 rule:

    s1 = addspecies(m1.Compartments, 'Inhib');

Defining a Rule to Affect Parameter Value

The value of rate parameter kGd is affected by the amount of inhibitor present in the system. Add a rule to the model to describe this action, but first change the ConstantValue property of the parameter kGd so that it can be varied by a rule.

  1. Change the ConstantValue property of the kGd parameter to false.

    p3 = sbioselect(m1, 'Type', 'parameter', 'Name', 'kGd');
    set(p3, 'ConstantValue', false)
    
  2. Add a repeated assignment rule to the model to define how the kGd parameter is affected by the Inhib species.

    rule2 = addrule(m1, 'kGd = 1/Inhib', 'repeatedAssignment');

Adding an Event to Reset the Solver at a Discontinuity

The custom function, inhibvalex, introduces a discontinuity in the model when time = 400. To ensure accurate simulation results, add an event to the model to reset the solver at the time of the discontinuity. Set the event to trigger at the time of the discontinuity (time = 400). The event does not need to modify the model, so create an event function that multiplies a species value by 1:

addevent(m1, 'time>=400', 'G=1*G');

Simulating the Modified Model

  1. Configure the simulation settings (configset object) for the m1 model object to log all states during the simulation:

    cs = getconfigset(m1);
    set(cs.RuntimeOptions, 'StatesToLog', 'all')
    
  2. Simulate the model:

    simDataObj = sbiosimulate(m1);
  3. Plot the results:

    sbioplot(simDataObj)
    

    The plot does not show the species of interest due to the wide range in species amounts/concentrations.

  4. Plot only the species of interest. Ga:

    GaSimDataObj = selectbyname(simDataObj, 'Ga');
    sbioplot(GaSimDataObj)
    

    Notice the change in the profile of species Ga at time = 400 seconds (simulation time). This is the time when the inhibitor amount is changed to reflect the re-addition of inhibitor to the model.

  5. Plot only the inhibitor (Inhib species):

    InhibSimDataObj = selectbyname(simDataObj, 'Inhib');
    sbioplot(InhibSimDataObj)
    

See Also

To learn about...Refer to...
Functionsfunction in the MATLAB Function Reference.
Changing the working directory to the directory containing the function filecd in the MATLAB Function Reference.
Adding the directory containing function files to the MATLAB search pathaddpath in the MATLAB Function Reference or Adding Folders to the Search Path in the MATLAB Desktop Tools and Development Environment.

  


Free Computational Biology Interactive Kit

See how to analyze, visualize, and model biological data and systems using MathWorks products.

Get free kit

Trials Available

Try the latest computational biology products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS