1- using DiffEqBase, DiffEqBiological
1+ using DiffEqBase, Catalyst
22# Jump Example Problems
33export prob_jump_dnarepressor, prob_jump_constproduct, prob_jump_nonlinrxs,
44# examples mixing mass action and constant rate jumps
@@ -13,8 +13,9 @@ export prob_jump_dnarepressor, prob_jump_constproduct, prob_jump_nonlinrxs,
1313 the JumpProblem constructor requires the algorithm, so we
1414 don't create the JumpProblem here.
1515"""
16+
1617struct JumpProblemNetwork
17- network # DiffEqBiological network
18+ network # Catalyst network
1819 rates # vector of rate constants or nothing
1920 tstop # time to end simulation
2021 u0 # initial values
@@ -33,7 +34,7 @@ end k1 k2 k3 k4 k5 k6
3334rates = [.5 , (20 * log (2. )/ 120. ), (log (2. )/ 120. ), (log (2. )/ 600. ), .025 , 1. ]
3435tf = 1000.0
3536u0 = [1 ,0 ,0 ,0 ]
36- prob = DiscreteProblem (u0, (0.0 , tf), rates)
37+ prob = DiscreteProblem (dna_rs, u0, (0.0 , tf), rates)
3738Nsims = 8000
3839expected_avg = 5.926553750000000e+02
3940prob_data = Dict (" num_sims_for_mean" => Nsims, " expected_mean" => expected_avg)
@@ -49,7 +50,7 @@ end k1 k2
4950rates = [1000. , 10. ]
5051tf = 1.0
5152u0 = [0 ]
52- prob = DiscreteProblem (u0, (0. , tf), rates)
53+ prob = DiscreteProblem (bd_rs, u0, (0. , tf), rates)
5354Nsims = 16000
5455expected_avg = t -> rates[1 ] / rates[2 ] .* ( 1. - exp .(- rates[2 ] * t))
5556prob_data = Dict (" num_sims_for_mean" => Nsims, " expected_mean_at_t" => expected_avg)
@@ -68,7 +69,7 @@ end k1 k2 k3 k4 k5
6869rates = [1. , 2. , .5 , .75 , .25 ]
6970tf = .01
7071u0 = [200 , 100 , 150 ]
71- prob = DiscreteProblem (u0, (0. , tf), rates)
72+ prob = DiscreteProblem (nonlin_rs, u0, (0. , tf), rates)
7273Nsims = 32000
7374expected_avg = 84.876015624999994
7475prob_data = Dict (" num_sims_for_mean" => Nsims, " expected_mean" => expected_avg)
@@ -92,7 +93,7 @@ oscil_rs = @reaction_network begin
9293end
9394u0 = [200. ,60. ,120. ,100. ,50. ,50. ,50. ] # Hill equations force use of floats!
9495tf = 4000.
95- prob = DiscreteProblem (u0, (0. ,tf))
96+ prob = DiscreteProblem (oscil_rs, u0, (0. ,tf))
9697"""
9798 Oscillatory system, uses a mixture of jump types.
9899"""
@@ -136,11 +137,11 @@ end kon kAon koff kAoff kAp kAdp
136137rsi = rates_sym_to_idx
137138rates = params[[rsi[:kon ], rsi[:kAon ], rsi[:koff ], rsi[:kAoff ], rsi[:kAp ], rsi[:kAdp ]]]
138139u0 = zeros (Int,9 )
139- u0[ something ( findfirst (isequal (:S1 ), rs. syms), 0 )] = params[1 ]
140- u0[ something ( findfirst (isequal (:S2 ), rs. syms), 0 )] = params[2 ]
141- u0[ something ( findfirst (isequal (:S3 ), rs. syms), 0 )] = params[3 ]
140+ u0[ findfirst (isequal (Variable ( :S1 )) , rs. states )] = params[1 ]
141+ u0[ findfirst (isequal (Variable ( :S2 )) , rs. states )] = params[2 ]
142+ u0[ findfirst (isequal (Variable ( :S3 )) , rs. states )] = params[3 ]
142143tf = 100.
143- prob = DiscreteProblem (u0, (0. , tf), rates)
144+ prob = DiscreteProblem (rs, u0, (0. , tf), rates)
144145"""
145146 Multistate model from Gupta and Mendes,
146147 "An Overview of Network-Based and -Free Approaches for Stochastic Simulation of Biochemical Systems",
@@ -154,39 +155,62 @@ prob_jump_multistate = JumpProblemNetwork(rs, rates, tf, u0, prob,
154155# generate the network
155156N = 10 # number of genes
156157function construct_genenetwork (N)
157- genenetwork = " @reaction_network begin\n "
158- for i in 1 : N
159- genenetwork *= " \t 10.0, G$(2 * i- 1 ) --> G$(2 * i- 1 ) + M$(2 * i- 1 ) \n "
160- genenetwork *= " \t 10.0, M$(2 * i- 1 ) --> M$(2 * i- 1 ) + P$(2 * i- 1 ) \n "
161- genenetwork *= " \t 1.0, M$(2 * i- 1 ) --> 0\n "
162- genenetwork *= " \t 1.0, P$(2 * i- 1 ) --> 0\n "
163-
164- genenetwork *= " \t 5.0, G$(2 * i) --> G$(2 * i) + M$(2 * i) \n "
165- genenetwork *= " \t 5.0, M$(2 * i) --> M$(2 * i) + P$(2 * i) \n "
166- genenetwork *= " \t 1.0, M$(2 * i) --> 0\n "
167- genenetwork *= " \t 1.0, P$(2 * i) --> 0\n "
168-
169- genenetwork *= " \t 0.0001, G$(2 * i) + P$(2 * i- 1 ) --> G$(2 * i) _ind \n "
170- genenetwork *= " \t 100., G$(2 * i) _ind --> G$(2 * i) _ind + M$(2 * i) \n "
171- end
172- genenetwork *= " end"
158+ genenetwork = make_empty_network ()
159+ @parameters t
160+ for i in 1 : N
161+ G₂ᵢ₋₁ = Variable (Symbol (" G" ,2 * i- 1 ))(t)
162+ M₂ᵢ₋₁ = Variable (Symbol (" M" ,2 * i- 1 ))(t)
163+ P₂ᵢ₋₁ = Variable (Symbol (" P" ,2 * i- 1 ))(t)
164+ addspecies! (genenetwork,G₂ᵢ₋₁)
165+ addspecies! (genenetwork,M₂ᵢ₋₁)
166+ addspecies! (genenetwork,P₂ᵢ₋₁)
167+ addreaction! (genenetwork, Reaction (10.0 , [G₂ᵢ₋₁], [G₂ᵢ₋₁,M₂ᵢ₋₁]))
168+ addreaction! (genenetwork, Reaction (10.0 , [M₂ᵢ₋₁], [M₂ᵢ₋₁,P₂ᵢ₋₁]))
169+ addreaction! (genenetwork, Reaction (1.0 , [M₂ᵢ₋₁], nothing ))
170+ addreaction! (genenetwork, Reaction (1.0 , [P₂ᵢ₋₁], nothing ))
171+ # genenetwork *= "\t 10.0, G$(2*i-1) --> G$(2*i-1) + M$(2*i-1)\n"
172+ # genenetwork *= "\t 10.0, M$(2*i-1) --> M$(2*i-1) + P$(2*i-1)\n"
173+ # genenetwork *= "\t 1.0, M$(2*i-1) --> 0\n"
174+ # genenetwork *= "\t 1.0, P$(2*i-1) --> 0\n"
175+
176+ G₂ᵢ = Variable (Symbol (" G" ,2 * i))(t)
177+ M₂ᵢ = Variable (Symbol (" M" ,2 * i))(t)
178+ P₂ᵢ = Variable (Symbol (" P" ,2 * i))(t)
179+ addspecies! (genenetwork,G₂ᵢ)
180+ addspecies! (genenetwork,M₂ᵢ)
181+ addspecies! (genenetwork,P₂ᵢ)
182+ addreaction! (genenetwork, Reaction (5.0 , [G₂ᵢ], [G₂ᵢ,M₂ᵢ]))
183+ addreaction! (genenetwork, Reaction (5.0 , [M₂ᵢ], [M₂ᵢ,P₂ᵢ]))
184+ addreaction! (genenetwork, Reaction (1.0 , [M₂ᵢ], nothing ))
185+ addreaction! (genenetwork, Reaction (1.0 , [P₂ᵢ], nothing ))
186+ # genenetwork *= "\t 5.0, G$(2*i) --> G$(2*i) + M$(2*i)\n"
187+ # genenetwork *= "\t 5.0, M$(2*i) --> M$(2*i) + P$(2*i)\n"
188+ # genenetwork *= "\t 1.0, M$(2*i) --> 0\n"
189+ # genenetwork *= "\t 1.0, P$(2*i) --> 0\n"
190+
191+ G₂ᵢ_ind = Variable (Symbol (" G" ,2 * i," _ind" ))(t)
192+ addspecies! (genenetwork, G₂ᵢ_ind)
193+ addreaction! (genenetwork, Reaction (0.0001 , [G₂ᵢ,P₂ᵢ₋₁], [G₂ᵢ_ind]))
194+ addreaction! (genenetwork, Reaction (100.0 , [G₂ᵢ_ind], [G₂ᵢ_ind,M₂ᵢ]))
195+ # genenetwork *= "\t 0.0001, G$(2*i) + P$(2*i-1) --> G$(2*i)_ind \n"
196+ # genenetwork *= "\t 100., G$(2*i)_ind --> G$(2*i)_ind + M$(2*i)\n"
197+ end
198+ genenetwork
173199end
174- genenetwork = construct_genenetwork (N)
175- rs = eval ( Meta. parse (genenetwork) )
176- u0 = zeros (Int, length (rs. syms))
200+ rs = construct_genenetwork (N)
201+ u0 = zeros (Int, length (rs. states))
177202for i = 1 : (2 * N)
178- u0[something ( findfirst (isequal (Symbol (" G$(i) " )),rs. syms), 0 )] = 1
203+ u0[findfirst (isequal (Variable ( Symbol (" G$(i) " ))) ,rs. states )] = 1
179204end
180205tf = 2000.0
181- prob = DiscreteProblem (u0, (0.0 , tf))
206+ prob = DiscreteProblem (rs, u0, (0.0 , tf))
182207"""
183208 Twenty-gene model from McCollum et al,
184209 "The sorting direct method for stochastic simulation of biochemical systems with varying reaction execution behavior"
185210 Comp. Bio. and Chem., 30, pg. 39-49 (2006).
186211"""
187212prob_jump_twentygenes = JumpProblemNetwork (rs, nothing , tf, u0, prob, nothing )
188213
189-
190214rn = @reaction_network begin
191215 c1, G --> G + M
192216 c2, M --> M + P
@@ -201,7 +225,7 @@ rnpar = [.09, .05, .001, .0009, .00001, .0005, .005, .9]
201225varlabels = [" G" , " M" , " P" , " P2" ," P2G" ]
202226u0 = [1000 , 0 , 0 , 0 ,0 ]
203227tf = 4000.
204- prob = DiscreteProblem (u0, (0.0 , tf), rnpar)
228+ prob = DiscreteProblem (rn, u0, (0.0 , tf), rnpar)
205229"""
206230 Negative feedback autoregulatory gene expression model. Dimer is the repressor.
207231 Taken from Marchetti, Priami and Thanh,
@@ -214,14 +238,18 @@ prob_jump_dnadimer_repressor = JumpProblemNetwork(rn, rnpar, tf, u0, prob,
214238
215239# diffusion model
216240function getDiffNetwork (N)
217- diffnetwork = " @reaction_network begin\n "
241+ diffnetwork = make_empty_network ()
242+ @parameters t K
243+ for i = 1 : N
244+ addspecies! (diffnetwork, Variable (" X" ,i)(t))
245+ end
218246 for i in 1 : (N- 1 )
219- diffnetwork *= " \t K, X$(i) --> X$(i+ 1 ) \n "
220- diffnetwork *= " \t K, X$(i+ 1 ) --> X$(i) \n "
247+ Xᵢ = Variable (" X" ,i)(t)
248+ Xᵢ₊₁ = Variable (" X" ,i+ 1 )(t)
249+ addreaction! (diffnetwork, Reaction (K, [Xᵢ], [Xᵢ₊₁]))
250+ addreaction! (diffnetwork, Reaction (K, [Xᵢ₊₁], [Xᵢ]))
221251 end
222- diffnetwork *= " end K"
223- rs = eval ( Meta. parse (diffnetwork) )
224- rs
252+ diffnetwork
225253end
226254params = (1. ,)
227255function getDiffu0 (N)
0 commit comments