|
1 | 1 | ### Prepares Tests ###
|
2 | 2 |
|
3 | 3 | # Fetch packages.
|
4 |
| -using Catalyst, LinearAlgebra, Test, StableRNGs |
| 4 | +using Catalyst, LinearAlgebra, Test, SparseArrays |
5 | 5 |
|
| 6 | +# Sets stable rng number. |
| 7 | +using StableRNGs |
6 | 8 | rng = StableRNG(514)
|
7 | 9 |
|
8 | 10 | ### Basic Tests ###
|
9 | 11 |
|
| 12 | +# Tests basic `ReactionComplex` properties. |
| 13 | +let |
| 14 | + rcs1 = Catalyst.ReactionComplex([1, 2], [1, 3]) |
| 15 | + rcs2 = Catalyst.ReactionComplex([1, 2], [1, 3]) |
| 16 | + rcs3 = Catalyst.ReactionComplex([3], [2]) |
| 17 | + @test rcs1 == rcs2 |
| 18 | + @test rcs2 != rcs3 |
| 19 | + @test length(rcs1) == 2 |
| 20 | + @test length(rcs3) == 1 |
| 21 | +end |
| 22 | + |
10 | 23 | # Tests network analysis functions on MAPK network (by comparing to manually computed outputs).
|
11 | 24 | let
|
12 | 25 | MAPK = @reaction_network MAPK begin
|
|
203 | 216 | rates = Dict(zip(parameters(rn), k))
|
204 | 217 | @test Catalyst.iscomplexbalanced(rn, rates) == false
|
205 | 218 | end
|
| 219 | + |
206 | 220 | let
|
207 | 221 | rn = @reaction_network begin
|
208 | 222 | k1, A --> B
|
|
215 | 229 | rates = Dict(zip(parameters(rn), k))
|
216 | 230 | @test Catalyst.iscomplexbalanced(rn, rates) == false
|
217 | 231 | end
|
| 232 | + |
218 | 233 | let
|
219 | 234 | rn = @reaction_network begin
|
220 | 235 | k1, A --> B
|
|
229 | 244 | rates = Dict(zip(parameters(rn), k))
|
230 | 245 | @test Catalyst.iscomplexbalanced(rn, rates) == false
|
231 | 246 | end
|
| 247 | + |
232 | 248 | let
|
233 | 249 | rn = @reaction_network begin
|
234 | 250 | (k2, k1), A <--> 2B
|
|
244 | 260 | rates = Dict(zip(parameters(rn), k))
|
245 | 261 | @test Catalyst.iscomplexbalanced(rn, rates) == true
|
246 | 262 | end
|
| 263 | + |
247 | 264 | let
|
248 | 265 | rn = @reaction_network begin
|
249 | 266 | (k2, k1), A + E <--> AE
|
|
257 | 274 | rates = Dict(zip(parameters(rn), k))
|
258 | 275 | @test Catalyst.iscomplexbalanced(rn, rates) == false
|
259 | 276 | end
|
| 277 | + |
260 | 278 | let
|
261 | 279 | rn = @reaction_network begin
|
262 | 280 | (k2, k1), A + E <--> AE
|
|
270 | 288 | rates = Dict(zip(parameters(rn), k))
|
271 | 289 | @test Catalyst.iscomplexbalanced(rn, rates) == true
|
272 | 290 | end
|
| 291 | + |
273 | 292 | let
|
274 | 293 | rn = @reaction_network begin (k2, k1), A + B <--> 2A end
|
275 | 294 | rev = true
|
|
280 | 299 | rates = Dict(zip(parameters(rn), k))
|
281 | 300 | @test Catalyst.iscomplexbalanced(rn, rates) == true
|
282 | 301 | end
|
| 302 | + |
283 | 303 | let
|
284 | 304 | rn = @reaction_network begin
|
285 | 305 | k1, A + B --> 3A
|
|
295 | 315 | rates = Dict(zip(parameters(rn), k))
|
296 | 316 | @test Catalyst.iscomplexbalanced(rn, rates) == true
|
297 | 317 | end
|
| 318 | + |
298 | 319 | let
|
299 | 320 | rn = @reaction_network begin
|
300 | 321 | (k2, k1), A + E <--> AE
|
@@ -326,3 +347,113 @@ let
|
326 | 347 | @test Catalyst.iscomplexbalanced(rn, rates) == true
|
327 | 348 | end
|
328 | 349 |
|
| 350 | +### Other Network Properties Tests ### |
| 351 | + |
| 352 | +# Tests outgoing complexes matrices (1). |
| 353 | +# Checks using dense and sparse representation. |
| 354 | +let |
| 355 | + # Declares network. |
| 356 | + rs = @reaction_network begin |
| 357 | + k1, X1 + X2 --> X3 + X4 |
| 358 | + (k2,k2), X3 + X4 <--> X1 |
| 359 | + k3, X1 --> X2 |
| 360 | + k4, X1 + X2 --> X2 |
| 361 | + end |
| 362 | + |
| 363 | + # Compares to manually computed matrix. |
| 364 | + cmplx_out_mat = [ |
| 365 | + -1 0 0 0 -1; |
| 366 | + 0 -1 0 0 0; |
| 367 | + 0 0 -1 -1 0; |
| 368 | + 0 0 0 0 0; |
| 369 | + ] |
| 370 | + complexoutgoingmat(rs) == cmplx_out_mat |
| 371 | + complexoutgoingmat(rs; sparse = true) == sparse(cmplx_out_mat) |
| 372 | +end |
| 373 | + |
| 374 | +# Tests outgoing complexes matrices (2). |
| 375 | +# Checks using dense and sparse representation. |
| 376 | +let |
| 377 | + # Declares network. |
| 378 | + rs = @reaction_network begin |
| 379 | + k1, X1 --> X2 |
| 380 | + k2, X2 --> X3 |
| 381 | + k3, X3 --> X4 |
| 382 | + k4, X3 --> X5 |
| 383 | + k5, X2 --> X1 |
| 384 | + k6, X1 --> X2 |
| 385 | + end |
| 386 | + |
| 387 | + # Compares to manually computed matrix. |
| 388 | + cmplx_out_mat = [ |
| 389 | + -1 0 0 0 0 -1; |
| 390 | + 0 -1 0 0 -1 0; |
| 391 | + 0 0 -1 -1 0 0; |
| 392 | + 0 0 0 0 0 0; |
| 393 | + 0 0 0 0 0 0; |
| 394 | + ] |
| 395 | + complexoutgoingmat(rs) |
| 396 | + complexoutgoingmat(rs; sparse = true) == sparse(cmplx_out_mat) |
| 397 | +end |
| 398 | + |
| 399 | +# Tests that `iscomplexbalanced` works for different rate inputs. |
| 400 | +# Tests that non-valid rate input yields and error |
| 401 | +let |
| 402 | + # Declares network. |
| 403 | + rn = @reaction_network begin |
| 404 | + k1, 3A + 2B --> 3C |
| 405 | + k2, B + 4D --> 2E |
| 406 | + k3, 2E --> 3C |
| 407 | + (k4, k5), B + 4D <--> 3A + 2B |
| 408 | + k6, F --> B + 4D |
| 409 | + k7, 3C --> F |
| 410 | + end |
| 411 | + |
| 412 | + # Declares rate alternatives. |
| 413 | + k = rand(rng, numparams(rn)) |
| 414 | + rates_vec = Pair.(parameters(rn), k) |
| 415 | + rates_tup = Tuple(rates_vec) |
| 416 | + rates_dict = Dict(rates_vec) |
| 417 | + rates_invalid = k |
| 418 | + |
| 419 | + # Tests that inputs are handled correctly. |
| 420 | + @test Catalyst.iscomplexbalanced(rn, rates_vec) == Catalyst.iscomplexbalanced(rn, rates_tup) |
| 421 | + @test Catalyst.iscomplexbalanced(rn, rates_tup) == Catalyst.iscomplexbalanced(rn, rates_dict) |
| 422 | + @test_throws Exception Catalyst.iscomplexbalanced(rn, k) |
| 423 | +end |
| 424 | + |
| 425 | +# Tests rate matrix computation for various input types. |
| 426 | +let |
| 427 | + # Declares network and its known rate matrix. |
| 428 | + rn = @reaction_network begin |
| 429 | + (k2, k1), A1 <--> A2 + A3 |
| 430 | + k3, A2 + A3 --> A4 |
| 431 | + k4, A4 --> A5 |
| 432 | + (k6, k5), A5 <--> 2A6 |
| 433 | + k7, 2A6 --> A4 |
| 434 | + k8, A4 + A5 --> A7 |
| 435 | + end |
| 436 | + rate_mat = [ |
| 437 | + 0.0 1.0 0.0 0.0 0.0 0.0 0.0; |
| 438 | + 2.0 0.0 3.0 0.0 0.0 0.0 0.0; |
| 439 | + 0.0 0.0 0.0 4.0 0.0 0.0 0.0; |
| 440 | + 0.0 0.0 0.0 0.0 5.0 0.0 0.0; |
| 441 | + 0.0 0.0 7.0 6.0 0.0 0.0 0.0; |
| 442 | + 0.0 0.0 0.0 0.0 0.0 0.0 8.0; |
| 443 | + 0.0 0.0 0.0 0.0 0.0 0.0 0.0; |
| 444 | + ] |
| 445 | + |
| 446 | + # Declares rate alternatives. |
| 447 | + rate_vals = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] |
| 448 | + rates_vec = Pair.(parameters(rn), rate_vals) |
| 449 | + rates_tup = Tuple(rates_vec) |
| 450 | + rates_dict = Dict(rates_vec) |
| 451 | + rates_invalid = reshape(rate_vals, 1, 8) |
| 452 | + |
| 453 | + # Tests that all input types generates the correct rate matrix. |
| 454 | + Catalyst.ratematrix(rn, rate_vals) == rate_mat |
| 455 | + Catalyst.ratematrix(rn, rates_vec) == rate_mat |
| 456 | + Catalyst.ratematrix(rn, rates_tup) == rate_mat |
| 457 | + Catalyst.ratematrix(rn, rates_dict) == rate_mat |
| 458 | + @test_throws Exception Catalyst.iscomplexbalanced(rn, rates_invalid) |
| 459 | +end |
0 commit comments