Skip to content

Commit

Permalink
Merge pull request #96 from mopichalova/30-bidirectional-rules
Browse files Browse the repository at this point in the history
Bidirectional rules
  • Loading branch information
xtrojak authored Mar 11, 2024
2 parents 52f30b5 + dffaea0 commit 8f6600a
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 54 deletions.
66 changes: 66 additions & 0 deletions Testing/objects_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
side_parser = Parser("side")
rate_complex_parser = Parser("rate_complex")
rule_parser = Parser("rule")
rules_parser = Parser("rules")
model_parser = Parser("model")

# atomic
Expand Down Expand Up @@ -246,13 +247,75 @@
r3 = Rule(sequence_3, mid_3, compartments_3, complexes_3, pairs_3, rate_3)

sequence_4 = (s34, s35, s36, s37)
reversed_sequence_4 = (s36, s37, s34, s35)
mid_4 = 2
compartments_4 = ["cyt"] * 4
complexes_4 = [(0, 1), (2, 2), (3, 3)]
reversed_complexes_4 = [(0, 0), (1, 1), (2, 3)]
pairs_4 = [(0, 2), (1, 3)]
rate_4 = Rate("3.0*[K()::cyt]/2.0*v_1")
reversed_rate_4 = Rate("2.0*[K()::cyt]/3.0*v_1")

r4 = Rule(sequence_4, mid_4, compartments_4, complexes_4, pairs_4, rate_4)
reversed_r4a = Rule(
reversed_sequence_4, mid_4, compartments_4, reversed_complexes_4, pairs_4, rate_4
)
reversed_r4b = Rule(
reversed_sequence_4,
mid_4,
compartments_4,
reversed_complexes_4,
pairs_4,
reversed_rate_4,
)
sequence_one_side_bidirectional = (s36, s37)
mid_one_side_bidirectional_a = 2
mid_one_side_bidirectional_b = 0
compartments_one_side_bidirectional = ["cyt"] * 2
complexes_one_side_bidirectional = [(0, 0), (1, 1)]
pairs_one_side_bidirectional_a = [(0, None), (1, None)]
pairs_one_side_bidirectional_b = [(None, 0), (None, 1)]
one_side_bidirectional_a = Rule(
sequence_one_side_bidirectional,
mid_one_side_bidirectional_a,
compartments_one_side_bidirectional,
complexes_one_side_bidirectional,
pairs_one_side_bidirectional_a,
rate_4,
)
one_side_bidirectional_b = Rule(
sequence_one_side_bidirectional,
mid_one_side_bidirectional_b,
compartments_one_side_bidirectional,
complexes_one_side_bidirectional,
pairs_one_side_bidirectional_b,
rate_4,
)
one_side_bidirectional_b_reversed_rate = Rule(
sequence_one_side_bidirectional,
mid_one_side_bidirectional_b,
compartments_one_side_bidirectional,
complexes_one_side_bidirectional,
pairs_one_side_bidirectional_b,
reversed_rate_4,
)
one_side_bidirectional_a_no_rate = Rule(
sequence_one_side_bidirectional,
mid_one_side_bidirectional_a,
compartments_one_side_bidirectional,
complexes_one_side_bidirectional,
pairs_one_side_bidirectional_a,
None,
)
one_side_bidirectional_b_no_rate = Rule(
sequence_one_side_bidirectional,
mid_one_side_bidirectional_b,
compartments_one_side_bidirectional,
complexes_one_side_bidirectional,
pairs_one_side_bidirectional_b,
None,
)


sequence_5 = (s34, s35, s36, s37, s38)
mid_5 = 2
Expand All @@ -272,6 +335,9 @@

r6 = Rule(sequence_6, mid_6, compartments_6, complexes_6, pairs_6, rate_6)
rule_no_rate = Rule(sequence_4, mid_4, compartments_4, complexes_4, pairs_4, None)
reversed_no_rate = Rule(
reversed_sequence_4, mid_4, compartments_4, reversed_complexes_4, pairs_4, None
)

sequence_c1 = (s34, s35, s36, s37, s2)
mid_c1 = 2
Expand Down
56 changes: 53 additions & 3 deletions Testing/parsing/test_rule.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pytest

from eBCSgen.Core.Rule import Rule
from eBCSgen.Core.Rate import Rate

import Testing.objects_testing as objects


def test_parser():
rule_expr = "K(S{u}).B()::cyt => K(S{p})::cyt + B()::cyt + D(B{_})::cell @ 3*[K()::cyt]/2*v_1"
assert objects.rule_parser.parse(rule_expr).data[1] == objects.r5
Expand All @@ -20,3 +18,55 @@ def test_parser():

rule_expr = "K(S{u}).B()::cyt => K(S{p})::cyt + B()::cyt"
assert objects.rule_parser.parse(rule_expr).data[1] == objects.rule_no_rate


def test_bidirectional():
rule_expr = "#! rules\nK(S{u}).B()::cyt <=> K(S{p})::cyt + B()::cyt"
parsed = objects.rules_parser.parse(rule_expr)
assert parsed.success
assert objects.rule_no_rate in parsed.data["rules"]
assert objects.reversed_no_rate in parsed.data["rules"]

rule_expr = "#! rules\nK(S{u}).B()::cyt <=> K(S{p})::cyt + B()::cyt @ 3*[K()::cyt]/2*v_1 | 3*[K()::cyt]/2*v_1"
parsed = objects.rules_parser.parse(rule_expr)
assert parsed.success
assert objects.r4 in parsed.data["rules"]
assert objects.reversed_r4a in parsed.data["rules"]

rule_expr = "#! rules\nK(S{u}).B()::cyt <=> K(S{p})::cyt + B()::cyt @ 3*[K()::cyt]/2*v_1 | 2*[K()::cyt]/3*v_1"
parsed = objects.rules_parser.parse(rule_expr)
assert parsed.success
assert objects.r4 in parsed.data["rules"]
assert objects.reversed_r4b in parsed.data["rules"]

rule_expr = "#! rules\n <=> K(S{p})::cyt + B()::cyt @ 3*[K()::cyt]/2*v_1 | 3*[K()::cyt]/2*v_1"
parsed = objects.rules_parser.parse(rule_expr)
assert parsed.success
assert objects.one_side_bidirectional_a in parsed.data["rules"]
assert objects.one_side_bidirectional_b in parsed.data["rules"]

rule_expr = "#! rules\n K(S{p})::cyt + B()::cyt <=> @ 3*[K()::cyt]/2*v_1 | 3*[K()::cyt]/2*v_1"
parsed = objects.rules_parser.parse(rule_expr)
assert parsed.success
assert objects.one_side_bidirectional_a in parsed.data["rules"]
assert objects.one_side_bidirectional_b in parsed.data["rules"]

rule_expr = "#! rules\n K(S{p})::cyt + B()::cyt <=> @ 3*[K()::cyt]/2*v_1 | 2*[K()::cyt]/3*v_1"
parsed = objects.rules_parser.parse(rule_expr)
assert parsed.success
assert objects.one_side_bidirectional_a in parsed.data["rules"]
assert objects.one_side_bidirectional_b_reversed_rate in parsed.data["rules"]

rule_expr = "#! rules\n K(S{p})::cyt + B()::cyt <=>"
parsed = objects.rules_parser.parse(rule_expr)
assert parsed.success
assert objects.one_side_bidirectional_a_no_rate in parsed.data["rules"]
assert objects.one_side_bidirectional_b_no_rate in parsed.data["rules"]

rule_expr = (
"#! rules\nK(S{u}).B()::cyt <=> K(S{p})::cyt + B()::cyt @ 3*[K()::cyt]/2*v_1"
)
assert not objects.rules_parser.parse(rule_expr).success

rule_expr = "#! rules\nK(S{u}).B()::cyt => K(S{p})::cyt + B()::cyt @ 3*[K()::cyt]/2*v_1 | 2*[K()::cyt]/3*v_1"
assert not objects.rules_parser.parse(rule_expr).success
Loading

0 comments on commit 8f6600a

Please sign in to comment.