Triggering Events In SimBiology toolbox

I am wondering if it's possible to define time delay as an event for a trigger in simbiology. I want to define a duration of 2 hours for one stage of the system. For example, when species_1 gets a certain value (like species_1 == 5), I need the system to stay in this state for 2 hours and afterwards species_1 =0 and species_2 = 1 (while some other species are interacting with each other independent of this process). I defined a function as event and used "tic toc" to make a delay after trigger, but even though this provides a delay, the amount of corresponding species are changed at the beginning of delay not at the end! Can somebody help me with this? thanks

 Réponse acceptée

Ingrid Tigges
Ingrid Tigges le 2 Sep 2014

1 vote

I have attached a .zip file which contains a .sbproj file with a small example. In this example species_1 is created with constant rate, than you have reversible reaction which creates species_2 and species_2 degenerated with constant rate. I have then also created a copy of this whole set. This copy should not be effected by stages while the species_1 and species_2 are.
The two stages are modelled using two events: The first event gets triggered if species_1 gets above a certain threshold. During a simulation it is unlikely that for example 5 is exactly hit, hence one uses >5. Then you have several event functions:
  • stage is used to ensure that the second event triggers at the correct time
  • stage_start_time stores the time the event is triggered. This is needed to calculate the time the second event should be started at the stage_start_time + the time the first stage takes
  • In order to keep species_1 and species_2 on there values you have to set the generating and removing kinetics to 0
  • The trigger for the second event is that stage=1 (meaning the first stage took place) and that the time is past stage_start_time+the time the first stage takes
Is this explanation understandable?

4 commentaires

al
al le 3 Sep 2014
Thank you very much for your answer. That is a very good explanation. Having seen the model you made, I want to ask few other questions:
1:Changing the reaction rates causes the system dynamic to have some discontinuities at some time points. In the user guide, it is mentioned that we need to construct events that are triggered at the Time of Discontinuities. And they used a repeated assignment rule to define different modes that I didn't get the point of using it (model.addrule('rate2 = discontSimBiologyRateFunction(time, mode)', 'repeatedAssignment')). Do we need to do the same thing here in the model you made?
2: For the time duration, you created a parameter named stage1_duration with the value of 2 second. I am wondering if it is possible to create a time duration with a fixed value (like 2 second) and a small random value (for example created from a normal distribution with a mean of 1) added to it (to create a kind of stochastisity in the model).
3: The last question is related to analysis we can do with this model that has events. Based on Simbiology user guide, when a model has events, we cannot do sensitivity analysis! But what if I had a model like this with some proteins interacting with each other continuously as well as some parameters that show the stage or state of the system not the reaction rate constants (for example a parameter shows that we are in the growth phase of the cell when it is 1, and another parameter demonstrate DNA replication when it gets the value of one). Imagine I want to do some sensitivity analysis to see if i change the rate constants within a particular range (like +- 10%), what happen to the system respond (in this case I don't want the toolbox to change the other parameters like the ones showing the system phases). So, my question is that what can I do at this situation? If it is not possible to do such analysis inside the toolbox, is it possible to make a bridge from toolbox to Matlab coding environment in order to do these type of analysis? IF so, how?
Thanks a million,
You are welcome.
Let me answer your questions now: 1) Are you refering to this example with discontinuity? When a repeated assignment introduces a discontinuity, you should add an event to the model that "fires" at the same time as the discontinuity. Otherwise, the integration may not behave correctly. In your case you are not using repeated assignments and hence the issue does not apply here. The approach for setting the value of the species I have used is the same that is described here: How do I set an upper or lower limit for a species?
2) In order to introduce stochasticity you can use the following approach
m1.addparameter('eventTime');
m1.addrule('nextEventTime = randn');
m1.addevent('time > nextEventTime', {'nextEventTime = nextEventTime + randn', 'x = …'});
You can also accomplish the same kind of behaviour by addition randomness to the inital value:
durationObj.InitialValue = 10 + randn;
If you want to perform things like sensitivity analysis than better do not use the randomness in the initial assignment because it will lead to the values used for sbiosimulate changing every time.
3) Yes, it is true that you cannot use the sensitivity analysis that is build into SimBiology when using events. However you can do a kind of manual sensitivity analysis, meaning that you perform a simulation, change a parameter, simulate again and so on.
al
al le 5 Sep 2014
Thank you so much again for your help and precise answers.
A: Regarding the question 2, I didn't get the point exactly. you added a parameter (eventTime) but never used it in the event! If you remember, in the model you made, there was a stage 1, which was triggered if species_1 crosses a certain threshold. And there was a fixed duration of 2 seconds. Now, I want this duration to be "2+ a small random number". But how?
B: Another question is that since you used 'randn", i am wondering if it is possible to change the type and the parameters of distribution we want (like normal distribution with mean of zero and the standard deviation of 0.1 or an exponential distribution with our interested parameters).
C: The last point is related to possibility of defining expressions like sig(t) and deg(t) in the following model (there is a model that has some ODEs and also, it has two strange equations which are not differential equations but they are used inside some other ODEs):
>>d(species_1)/dt = k1*species_2 - deg(t) *species_2*species_1
>> sig(t) = k2*exp(-k3*time)
>> deg(t) = k4 - k5*(sig(t) - k2*exp(-k6*k2*time))
>>k1=7e-2, k2=2e-3, k3=1e-8, k4=5.56e-2, k5=7.72e-1, k6=2e-2
species_1 and species_2 are two species in the system. the main thing here is that there is a signal, sig(t), which decays and another one, deg(t), that shows a sort of strange degradation that itself depends on sig(t). How can we write such a thing in Simbiology?
Thanks Again
Ingrid Tigges
Ingrid Tigges le 8 Sep 2014
Modifié(e) : Ingrid Tigges le 8 Sep 2014
Like before, let me answer your points separately:
A: Sorry, I made a typing mistake. It should have been nextEventTime rather than eventTime. After this small change you can use the code I have posted in my previous comment.
B: Yes, it is. You can use another MATLAB expression there as well
C: What you would like to have is something called rate rules, which is described here Rate rules
The following shows the example from the above mentioned page of the documentation and once the same example but with time as parameter, note how the slope changed
m = sbiomodel('m');
c = addcompartment(m,'comp');
s = addspecies(m,'x','InitialAmount',2);
p = addparameter(m,'k','Value',1);
r = addrule(m,'x = -k * x*time','RuleType','rate');
output=sbiosimulate(m);
m2=sbiomodel('m2');
c2 = addcompartment(m2,'comp');
s2 = addspecies(m2,'x','InitialAmount',2);
p2 = addparameter(m2,'k','Value',1);
r2 = addrule(m2,'x = -k * x','RuleType','rate');
m2output=sbiosimulate(m2);
figure(2) subplot(1,2,1) plot(output.Time,output.Data) ylim([0 2]) title('Time in rule') subplot(1,2,2) ylim([0 2]) title('Time not in rule') plot(m2output.Time,m2output.Data)
As a side note, if you have a completely new question, it helps the readability if you create a new post :-).

Connectez-vous pour commenter.

Plus de réponses (0)

Communautés

Plus de réponses dans  SimBiology Community

Catégories

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by