-
Notifications
You must be signed in to change notification settings - Fork 0
/
gillispie_CGE.m
60 lines (49 loc) · 1.62 KB
/
gillispie_CGE.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function stateMat = gillispie_CGE(numSteps,totalTime)
%gillespie algorithm for Constitutuve Gene Experssion (page294 of Ingalls)
% R1: null -> M ; propensity = kr
% R2: null -> P ; propensity = kp * nM
% R3: M -> null ; propensity = dr * nM
% R4: P -> null ; propensity = dp * nP
nC = 2 ; % number of chemical components
nR = 4 ; % number of chemical reactions
kr = 10; kp = 6; dr = 1; dp = 1;
% starting condition
nM = 0; nP = 0;
% state vector = [nM; nP] (with nM = RNA and nP = Protein)
state = [nM nP];
sMatrix = [ 1 0 ; 0 1 ; -1 0 ; 0 -1];
time = 0;
step = 0;
for step = 1:1:numSteps
%while (time < totalTime)
% calculate propensities
nM = state(1);
nP = state(2);
propensitiesVec = [kr kp*nM dr*nM dp*nP]
% calculate totalPropensity
totalPropensity = sum(propensitiesVec);
% calculate waitTime
waitTime = - log( rand(1,1) ) / totalPropensity
% calculate nextReaction
%prob = rand(1,1);
%rxn = 0;
%p1 = 0;
%while (prob > 0.0 )
% rxn = rxn + 1 ;
% prob = prob - propensitiesVec(rxn);
%end
%nextReaction = rxn;
prob = rand(1,1)*totalPropensity ;
cumulativePropensity = cumsum(propensitiesVec) ;
rxn = 1 ;
while ( prob > cumulativePropensity(rxn))
rxn = rxn + 1 ;
end
nextReaction = rxn ;
% perform nextReaction on state vector
state = state + sMatrix(nextReaction,:);
time = time + waitTime;
step = step +1;
%propensitiesVec
stateMat(step,:) = [time, state, nextReaction];
end