|
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
|
@@ -409,3 +430,114 @@ let
|
409 | 430 | @test issubset([[1,2], [3,4], [5,6,7]], slcs)
|
410 | 431 | @test issubset([[3,4], [5,6,7]], tslcs)
|
411 | 432 | end
|
| 433 | + |
| 434 | +### Other Network Properties Tests ### |
| 435 | + |
| 436 | +# Tests outgoing complexes matrices (1). |
| 437 | +# Checks using dense and sparse representation. |
| 438 | +let |
| 439 | + # Declares network. |
| 440 | + rs = @reaction_network begin |
| 441 | + k1, X1 + X2 --> X3 + X4 |
| 442 | + (k2,k2), X3 + X4 <--> X1 |
| 443 | + k3, X1 --> X2 |
| 444 | + k4, X1 + X2 --> X2 |
| 445 | + end |
| 446 | + |
| 447 | + # Compares to manually computed matrix. |
| 448 | + cmplx_out_mat = [ |
| 449 | + -1 0 0 0 -1; |
| 450 | + 0 -1 0 0 0; |
| 451 | + 0 0 -1 -1 0; |
| 452 | + 0 0 0 0 0; |
| 453 | + ] |
| 454 | + complexoutgoingmat(rs) == cmplx_out_mat |
| 455 | + complexoutgoingmat(rs; sparse = true) == sparse(cmplx_out_mat) |
| 456 | +end |
| 457 | + |
| 458 | +# Tests outgoing complexes matrices (2). |
| 459 | +# Checks using dense and sparse representation. |
| 460 | +let |
| 461 | + # Declares network. |
| 462 | + rs = @reaction_network begin |
| 463 | + k1, X1 --> X2 |
| 464 | + k2, X2 --> X3 |
| 465 | + k3, X3 --> X4 |
| 466 | + k4, X3 --> X5 |
| 467 | + k5, X2 --> X1 |
| 468 | + k6, X1 --> X2 |
| 469 | + end |
| 470 | + |
| 471 | + # Compares to manually computed matrix. |
| 472 | + cmplx_out_mat = [ |
| 473 | + -1 0 0 0 0 -1; |
| 474 | + 0 -1 0 0 -1 0; |
| 475 | + 0 0 -1 -1 0 0; |
| 476 | + 0 0 0 0 0 0; |
| 477 | + 0 0 0 0 0 0; |
| 478 | + ] |
| 479 | + complexoutgoingmat(rs) |
| 480 | + complexoutgoingmat(rs; sparse = true) == sparse(cmplx_out_mat) |
| 481 | +end |
| 482 | + |
| 483 | +# Tests that `iscomplexbalanced` works for different rate inputs. |
| 484 | +# Tests that non-valid rate input yields and error |
| 485 | +let |
| 486 | + # Declares network. |
| 487 | + rn = @reaction_network begin |
| 488 | + k1, 3A + 2B --> 3C |
| 489 | + k2, B + 4D --> 2E |
| 490 | + k3, 2E --> 3C |
| 491 | + (k4, k5), B + 4D <--> 3A + 2B |
| 492 | + k6, F --> B + 4D |
| 493 | + k7, 3C --> F |
| 494 | + end |
| 495 | + |
| 496 | + # Declares rate alternatives. |
| 497 | + k = rand(rng, numparams(rn)) |
| 498 | + rates_vec = Pair.(parameters(rn), k) |
| 499 | + rates_tup = Tuple(rates_vec) |
| 500 | + rates_dict = Dict(rates_vec) |
| 501 | + rates_invalid = k |
| 502 | + |
| 503 | + # Tests that inputs are handled correctly. |
| 504 | + @test Catalyst.iscomplexbalanced(rn, rates_vec) == Catalyst.iscomplexbalanced(rn, rates_tup) |
| 505 | + @test Catalyst.iscomplexbalanced(rn, rates_tup) == Catalyst.iscomplexbalanced(rn, rates_dict) |
| 506 | + @test_throws Exception Catalyst.iscomplexbalanced(rn, k) |
| 507 | +end |
| 508 | + |
| 509 | +# Tests rate matrix computation for various input types. |
| 510 | +let |
| 511 | + # Declares network and its known rate matrix. |
| 512 | + rn = @reaction_network begin |
| 513 | + (k2, k1), A1 <--> A2 + A3 |
| 514 | + k3, A2 + A3 --> A4 |
| 515 | + k4, A4 --> A5 |
| 516 | + (k6, k5), A5 <--> 2A6 |
| 517 | + k7, 2A6 --> A4 |
| 518 | + k8, A4 + A5 --> A7 |
| 519 | + end |
| 520 | + rate_mat = [ |
| 521 | + 0.0 1.0 0.0 0.0 0.0 0.0 0.0; |
| 522 | + 2.0 0.0 3.0 0.0 0.0 0.0 0.0; |
| 523 | + 0.0 0.0 0.0 4.0 0.0 0.0 0.0; |
| 524 | + 0.0 0.0 0.0 0.0 5.0 0.0 0.0; |
| 525 | + 0.0 0.0 7.0 6.0 0.0 0.0 0.0; |
| 526 | + 0.0 0.0 0.0 0.0 0.0 0.0 8.0; |
| 527 | + 0.0 0.0 0.0 0.0 0.0 0.0 0.0; |
| 528 | + ] |
| 529 | + |
| 530 | + # Declares rate alternatives. |
| 531 | + rate_vals = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] |
| 532 | + rates_vec = Pair.(parameters(rn), rate_vals) |
| 533 | + rates_tup = Tuple(rates_vec) |
| 534 | + rates_dict = Dict(rates_vec) |
| 535 | + rates_invalid = reshape(rate_vals, 1, 8) |
| 536 | + |
| 537 | + # Tests that all input types generates the correct rate matrix. |
| 538 | + Catalyst.ratematrix(rn, rate_vals) == rate_mat |
| 539 | + Catalyst.ratematrix(rn, rates_vec) == rate_mat |
| 540 | + Catalyst.ratematrix(rn, rates_tup) == rate_mat |
| 541 | + Catalyst.ratematrix(rn, rates_dict) == rate_mat |
| 542 | + @test_throws Exception Catalyst.iscomplexbalanced(rn, rates_invalid) |
| 543 | +end |
0 commit comments