@@ -21,7 +21,6 @@ export prob_jump_dnarepressor, prob_jump_constproduct, prob_jump_nonlinrxs,
21
21
the JumpProblem constructor requires the algorithm, so we
22
22
don't create the JumpProblem here.
23
23
"""
24
-
25
24
struct JumpProblemNetwork
26
25
network:: Any # Catalyst network
27
26
rates:: Any # vector of rate constants or nothing
@@ -39,9 +38,14 @@ dna_rs = @reaction_network begin
39
38
k5, DNA + P --> DNAR
40
39
k6, DNAR --> DNA + P
41
40
end
42
- rates = [0.5 , (20 * log (2.0 ) / 120.0 ), (log (2.0 ) / 120.0 ), (log (2.0 ) / 600.0 ), 0.025 , 1.0 ]
41
+ rates = [:k1 => 0.5 ,
42
+ :k2 => (20 * log (2.0 ) / 120.0 ),
43
+ :k3 => (log (2.0 ) / 120.0 ),
44
+ :k4 => (log (2.0 ) / 600.0 ),
45
+ :k5 => 0.025 ,
46
+ :k6 => 1.0 ]
43
47
tf = 1000.0
44
- u0 = [1 , 0 , 0 , 0 ]
48
+ u0 = [:DNA => 1 , :mRNA => 0 , :P => 0 , :DNAR => 0 ]
45
49
prob = DiscreteProblem (dna_rs, u0, (0.0 , tf), rates, eval_module = @__MODULE__ )
46
50
Nsims = 8000
47
51
expected_avg = 5.926553750000000e+02
@@ -55,9 +59,9 @@ bd_rs = @reaction_network begin
55
59
k1, 0 --> A
56
60
k2, A --> 0
57
61
end
58
- rates = [1000.0 , 10.0 ]
62
+ rates = [:k1 => 1000.0 , :k2 => 10.0 ]
59
63
tf = 1.0
60
- u0 = [0 ]
64
+ u0 = [:A => 0 ]
61
65
prob = DiscreteProblem (bd_rs, u0, (0.0 , tf), rates, eval_module = @__MODULE__ )
62
66
Nsims = 16000
63
67
expected_avg = t -> rates[1 ] / rates[2 ] .* (1.0 - exp .(- rates[2 ] * t))
@@ -74,9 +78,9 @@ nonlin_rs = @reaction_network begin
74
78
k4, C --> A + B
75
79
k5, 3 C --> 3 A
76
80
end
77
- rates = [1.0 , 2.0 , 0.5 , 0.75 , 0.25 ]
81
+ rates = [:k1 => 1.0 , :k2 => 2.0 , :k3 => 0.5 , :k4 => 0.75 , :k5 => 0.25 ]
78
82
tf = 0.01
79
- u0 = [200 , 100 , 150 ]
83
+ u0 = [:A => 200 , :B => 100 , :C => 150 ]
80
84
prob = DiscreteProblem (nonlin_rs, u0, (0.0 , tf), rates, eval_module = @__MODULE__ )
81
85
Nsims = 32000
82
86
expected_avg = 84.876015624999994
@@ -98,7 +102,8 @@ oscil_rs = @reaction_network begin
98
102
0.01 , SP + SP --> SP2
99
103
0.05 , SP2 --> 0
100
104
end
101
- u0 = [200.0 , 60.0 , 120.0 , 100.0 , 50.0 , 50.0 , 50.0 ] # Hill equations force use of floats!
105
+ u0 = [:X => 200.0 , :Y => 60.0 , :Z => 120.0 , :R => 100.0 , :S => 50.0 , :SP => 50.0 ,
106
+ :SP2 => 50.0 ] # Hill equations force use of floats!
102
107
tf = 4000.0
103
108
prob = DiscreteProblem (oscil_rs, u0, (0.0 , tf), eval_module = @__MODULE__ )
104
109
"""
@@ -115,9 +120,9 @@ specs_sym_to_name = Dict(:S1 => "R(a,l)",
115
120
:S7 => " A(Y~P,r!1).L(r!2).R(a!1,l!2)" ,
116
121
:S8 => " A(Y~P,r!1).R(a!1,l)" ,
117
122
:S9 => " A(Y~P,r)" )
118
- rates_sym_to_idx = Dict (:R0 => 1 , :L0 => 2 , :A0 => 3 , :kon => 4 , :koff => 5 ,
119
- :kAon => 6 , :kAoff => 7 , :kAp => 8 , :kAdp => 9 )
120
- params = [ 5360 , 1160 , 5360 , 0.01 , 0.1 , 0.01 , 0.1 , 0.01 , 0.1 ]
123
+ rsi = Dict (:R0 => 1 , :L0 => 2 , :A0 => 3 , :kon => 4 , :koff => 5 ,
124
+ :kAon => 6 , :kAoff => 7 , :kAp => 8 , :kAdp => 9 )
125
+ params = ( 5360 , 1160 , 5360 , 0.01 , 0.1 , 0.01 , 0.1 , 0.01 , 0.1 )
121
126
rs = @reaction_network begin
122
127
kon, S1 + S2 --> S4
123
128
kAon, S1 + S3 --> S5
@@ -138,13 +143,10 @@ rs = @reaction_network begin
138
143
kAdp, S8 --> S5
139
144
kAdp, S9 --> S3
140
145
end
141
- rsi = rates_sym_to_idx
142
- rates = params[[rsi[:kon ], rsi[:kAon ], rsi[:koff ], rsi[:kAoff ], rsi[:kAp ], rsi[:kAdp ]]]
143
- u0 = zeros (Int, 9 )
144
- statesyms = ModelingToolkit. tosymbol .(ModelingToolkit. operation .(unknowns (rs)))
145
- u0[findfirst (isequal (:S1 ), statesyms)] = params[1 ]
146
- u0[findfirst (isequal (:S2 ), statesyms)] = params[2 ]
147
- u0[findfirst (isequal (:S3 ), statesyms)] = params[3 ]
146
+ rates = [:kon , :kAon , :koff , :kAoff , :kAp , :kAdp ] .=>
147
+ params[[rsi[:kon ], rsi[:kAon ], rsi[:koff ], rsi[:kAoff ], rsi[:kAp ], rsi[:kAdp ]]]
148
+ u0 = [:S1 => params[1 ], :S2 => params[2 ], :S3 => params[3 ], :S4 => 0 , :S5 => 0 ,
149
+ :S6 => 0 , :S7 => 0 , :S8 => 0 , :S9 => 0 ]
148
150
tf = 100.0
149
151
prob = DiscreteProblem (rs, u0, (0.0 , tf), rates, eval_module = @__MODULE__ )
150
152
"""
@@ -155,57 +157,47 @@ prob = DiscreteProblem(rs, u0, (0.0, tf), rates, eval_module = @__MODULE__)
155
157
"""
156
158
prob_jump_multistate = JumpProblemNetwork (rs, rates, tf, u0, prob,
157
159
Dict (" specs_to_sym_name" => specs_sym_to_name,
158
- " rates_sym_to_idx" => rates_sym_to_idx,
159
- " params" => params))
160
+ " rates_sym_to_idx" => rsi, " params" => params))
160
161
161
162
# generate the network
162
163
N = 10 # number of genes
163
- @variables t
164
+ t = Catalyst . default_t ()
164
165
@species (G (t))[1 : (2 N)] (M (t))[1 : (2 N)] (P (t))[1 : (2 N)] (G_ind (t))[1 : (2 N)]
165
166
166
167
function construct_genenetwork (N)
167
- genenetwork = make_empty_network ()
168
+ rxs = Reaction[]
168
169
for i in 1 : N
169
- addspecies! (genenetwork, G[2 * i - 1 ])
170
- addspecies! (genenetwork, M[2 * i - i])
171
- addspecies! (genenetwork, P[2 * i - i])
172
- addreaction! (genenetwork,
173
- Reaction (10.0 , [G[2 * i - i]], [G[2 * i - i], M[2 * i - i]]))
174
- addreaction! (genenetwork,
175
- Reaction (10.0 , [M[2 * i - i]], [M[2 * i - i], P[2 * i - i]]))
176
- addreaction! (genenetwork, Reaction (1.0 , [M[2 * i - i]], nothing ))
177
- addreaction! (genenetwork, Reaction (1.0 , [P[2 * i - i]], nothing ))
170
+ push! (rxs, Reaction (10.0 , [G[2 * i - i]], [G[2 * i - i], M[2 * i - i]]))
171
+ push! (rxs, Reaction (10.0 , [M[2 * i - i]], [M[2 * i - i], P[2 * i - i]]))
172
+ push! (rxs, Reaction (1.0 , [M[2 * i - i]], nothing ))
173
+ push! (rxs, Reaction (1.0 , [P[2 * i - i]], nothing ))
178
174
# genenetwork *= "\t 10.0, G$(2*i-1) --> G$(2*i-1) + M$(2*i-1)\n"
179
175
# genenetwork *= "\t 10.0, M$(2*i-1) --> M$(2*i-1) + P$(2*i-1)\n"
180
176
# genenetwork *= "\t 1.0, M$(2*i-1) --> 0\n"
181
177
# genenetwork *= "\t 1.0, P$(2*i-1) --> 0\n"
182
178
183
- addspecies! (genenetwork, G[2 * i])
184
- addspecies! (genenetwork, M[2 * i])
185
- addspecies! (genenetwork, P[2 * i])
186
- addreaction! (genenetwork, Reaction (5.0 , [G[2 * i]], [G[2 * i], M[2 * i]]))
187
- addreaction! (genenetwork, Reaction (5.0 , [M[2 * i]], [M[2 * i], P[2 * i]]))
188
- addreaction! (genenetwork, Reaction (1.0 , [M[2 * i]], nothing ))
189
- addreaction! (genenetwork, Reaction (1.0 , [P[2 * i]], nothing ))
179
+ push! (rxs, Reaction (5.0 , [G[2 * i]], [G[2 * i], M[2 * i]]))
180
+ push! (rxs, Reaction (5.0 , [M[2 * i]], [M[2 * i], P[2 * i]]))
181
+ push! (rxs, Reaction (1.0 , [M[2 * i]], nothing ))
182
+ push! (rxs, Reaction (1.0 , [P[2 * i]], nothing ))
190
183
# genenetwork *= "\t 5.0, G$(2*i) --> G$(2*i) + M$(2*i)\n"
191
184
# genenetwork *= "\t 5.0, M$(2*i) --> M$(2*i) + P$(2*i)\n"
192
185
# genenetwork *= "\t 1.0, M$(2*i) --> 0\n"
193
186
# genenetwork *= "\t 1.0, P$(2*i) --> 0\n"
194
187
195
- addspecies! (genenetwork, G_ind[2 * i])
196
- addreaction! (genenetwork,
197
- Reaction (0.0001 , [G[2 * i], P[2 * i - i]], [G_ind[2 * i]]))
198
- addreaction! (genenetwork, Reaction (100.0 , [G_ind[2 * i]], [G_ind[2 * i], M[2 * i]]))
188
+ push! (rxs, Reaction (0.0001 , [G[2 * i], P[2 * i - i]], [G_ind[2 * i]]))
189
+ push! (rxs, Reaction (100.0 , [G_ind[2 * i]], [G_ind[2 * i], M[2 * i]]))
199
190
# genenetwork *= "\t 0.0001, G$(2*i) + P$(2*i-1) --> G$(2*i)_ind \n"
200
191
# genenetwork *= "\t 100., G$(2*i)_ind --> G$(2*i)_ind + M$(2*i)\n"
201
192
end
202
- genenetwork
193
+ spcs = reduce (vcat, collect .((G, M, P, G_ind)))
194
+ @named genenetwork = ReactionSystem (rxs, t, spcs, [])
195
+ complete (genenetwork)
203
196
end
204
197
rs = construct_genenetwork (N)
205
- u0 = zeros (Int, length (unknowns (rs)))
206
- statesyms = ModelingToolkit. tosymbol .(ModelingToolkit. operation .(unknowns (rs)))
198
+ u0 = Num .(unknowns (rs)) .=> zeros (Int, length (unknowns (rs)))
207
199
for i in 1 : (2 * N)
208
- u0[findfirst (isequal (G[i]), unknowns (rs))] = 1
200
+ u0[findfirst (isequal (G[i]), unknowns (rs))] = (G[i] => 1 )
209
201
end
210
202
tf = 2000.0
211
203
prob = DiscreteProblem (rs, u0, (0.0 , tf), eval_module = @__MODULE__ )
@@ -227,9 +219,10 @@ rn = @reaction_network begin
227
219
c7, P2 + G --> P2G
228
220
c8, P2G --> P2 + G
229
221
end
230
- rnpar = [0.09 , 0.05 , 0.001 , 0.0009 , 0.00001 , 0.0005 , 0.005 , 0.9 ]
222
+ rnpar = [:c1 => 0.09 , :c2 => 0.05 , :c3 => 0.001 , :c4 => 0.0009 , :c5 => 0.00001 ,
223
+ :c6 => 0.0005 , :c7 => 0.005 , :c8 => 0.9 ]
231
224
varlabels = [" G" , " M" , " P" , " P2" , " P2G" ]
232
- u0 = [1000 , 0 , 0 , 0 , 0 ]
225
+ u0 = [:G => 1000 , :M => 0 , :P => 0 , :P2 => 0 , :P2G => 0 ]
233
226
tf = 4000.0
234
227
prob = DiscreteProblem (rn, u0, (0.0 , tf), rnpar, eval_module = @__MODULE__ )
235
228
"""
@@ -245,21 +238,19 @@ prob_jump_dnadimer_repressor = JumpProblemNetwork(rn, rnpar, tf, u0, prob,
245
238
function getDiffNetwork (N)
246
239
diffnetwork = make_empty_network ()
247
240
@parameters K
248
- @variables t
241
+ t = default_t ()
249
242
@species (X (t))[1 : N]
250
- for i in 1 : N
251
- addspecies! (diffnetwork, X[i])
252
- end
253
- addparam! (diffnetwork, K)
243
+ rxs = Reaction[]
254
244
for i in 1 : (N - 1 )
255
- addreaction! (diffnetwork , Reaction (K, [X[i]], [X[i + 1 ]]))
256
- addreaction! (diffnetwork , Reaction (K, [X[i + 1 ]], [X[i]]))
245
+ push! (rxs , Reaction (K, [X[i]], [X[i + 1 ]]))
246
+ push! (rxs , Reaction (K, [X[i + 1 ]], [X[i]]))
257
247
end
258
- diffnetwork
248
+ @named diffnetwork = ReactionSystem (rxs, t, collect (X), [K])
249
+ complete (diffnetwork)
259
250
end
260
- params = ( 1.0 ,)
261
- function getDiffu0 (N)
262
- 10 * ones (Int64, N)
251
+ params = [ :K => 1.0 ]
252
+ function getDiffu0 (diffnetwork, N)
253
+ species (diffnetwork) .=> ( 10 * ones (Int64, N) )
263
254
end
264
255
tf = 10.0
265
256
"""
0 commit comments