Skip to content

Commit

Permalink
merged sd import methods and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrozum committed Mar 1, 2024
1 parent 1e4fa78 commit 70431e7
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 43 deletions.
6 changes: 3 additions & 3 deletions balm/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
Example
-------
>>> import balm
>>> sd = balm.SuccessionDiagram.from_bnet(
>>> sd = balm.SuccessionDiagram.from_rules(
... \"\"\"
... A, B & C
... B, A & C
Expand Down Expand Up @@ -198,7 +198,7 @@ def succession_control(
-------
>>> import balm
>>> from balm.control import succession_control
>>> sd = balm.SuccessionDiagram.from_bnet(
>>> sd = balm.SuccessionDiagram.from_rules(
... \"\"\"
... S, S
... A, S | B
Expand Down Expand Up @@ -237,7 +237,7 @@ def succession_control(
-------
>>> import balm
>>> from balm.control import succession_control
>>> sd = balm.SuccessionDiagram.from_bnet(
>>> sd = balm.SuccessionDiagram.from_rules(
... \"\"\"
... S, S
... A, S | B
Expand Down
4 changes: 2 additions & 2 deletions balm/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def find_single_node_LDOIs(
Example
_______
>>> import balm
>>> sd = balm.SuccessionDiagram.from_bnet('A, A\\nB, A')
>>> sd = balm.SuccessionDiagram.from_rules('A, A\\nB, A')
>>> ldois = balm.drivers.find_single_node_LDOIs(sd.network)
>>> for k in sorted(ldois):
... print(f'{k} ==> {sorted(ldois[k].items())}')
Expand Down Expand Up @@ -107,7 +107,7 @@ def find_single_drivers(
Example
-------
>>> import balm
>>> sd = balm.SuccessionDiagram.from_bnet('A, A\\nB, A')
>>> sd = balm.SuccessionDiagram.from_rules('A, A\\nB, A')
>>> drivers = balm.drivers.find_single_drivers({'B': 0}, sd.network)
>>> sorted(list(drivers))
[('A', 0), ('B', 0)]
Expand Down
2 changes: 1 addition & 1 deletion balm/interaction_graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def feedback_vertex_set(
--------
>>> import balm
>>> from balm.interaction_graph_utils import feedback_vertex_set
>>> sd = balm.SuccessionDiagram.from_bnet(\"\"\"
>>> sd = balm.SuccessionDiagram.from_rules(\"\"\"
... A, B
... B, A
... C, D
Expand Down
46 changes: 28 additions & 18 deletions balm/succession_diagram.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, cast
from typing import TYPE_CHECKING, Any, Literal, cast

if TYPE_CHECKING:
from typing import Iterator
Expand Down Expand Up @@ -44,7 +44,7 @@ class SuccessionDiagram:
Examples
--------
>>> import balm
>>> sd = balm.SuccessionDiagram.from_bnet(\"""
>>> sd = balm.SuccessionDiagram.from_rules(\"""
... A, B
... B, A & C
... C, !A | B
Expand Down Expand Up @@ -158,25 +158,35 @@ def __len__(self) -> int:
return self.dag.number_of_nodes()

@staticmethod
def from_aeon(model: str) -> SuccessionDiagram:
def from_rules(
rules: str,
format: Literal["bnet", "aeon", "sbml"] = "bnet",
) -> SuccessionDiagram:
"""
Read a `BooleanNetwork` from the string contents of an `.aeon` model.
"""
return SuccessionDiagram(BooleanNetwork.from_aeon(model))
Generate a succession diagram from the given string.
@staticmethod
def from_bnet(model: str) -> SuccessionDiagram:
"""
Read a `BooleanNetwork` from the string contents of a `.bnet` model.
"""
return SuccessionDiagram(BooleanNetwork.from_bnet(model))
Parameters
----------
rules : str
The string representation of the network rules.
format : Literal['bnet', 'aeon', 'sbml']
The format of the string. One of `"bnet"`, `"aeon"`, or `"sbml"`.
Defaults to `"bnet"`.
@staticmethod
def from_sbml(model: str) -> SuccessionDiagram:
"""
Read a `BooleanNetwork` from the string contents of an `.sbml` model.
Returns
-------
SuccessionDiagram
The generated succession diagram. Initially unexpanded.
"""
return SuccessionDiagram(BooleanNetwork.from_sbml(model))

if format == "bnet":
return SuccessionDiagram(BooleanNetwork.from_bnet(rules))
elif format == "aeon":
return SuccessionDiagram(BooleanNetwork.from_aeon(rules))
elif format == "sbml":
return SuccessionDiagram(BooleanNetwork.from_sbml(rules))
else:
raise ValueError(f"Unknown format: {format}")

@staticmethod
def from_file(path: str) -> SuccessionDiagram:
Expand Down Expand Up @@ -207,7 +217,7 @@ def expanded_attractor_seeds(self) -> dict[int, list[BooleanSpace]]:
Example
-------
>>> import balm
>>> sd = balm.SuccessionDiagram.from_bnet(\"""
>>> sd = balm.SuccessionDiagram.from_rules(\"""
... A, B
... B, A & C
... C, !A | B
Expand Down
8 changes: 4 additions & 4 deletions tests/control_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_basic_succession_finding():


def test_internal_succession_control():
sd = SuccessionDiagram.from_bnet(
sd = SuccessionDiagram.from_rules(
"""
S, S
A, S | B
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_internal_succession_control():


def test_all_succession_control():
sd = SuccessionDiagram.from_bnet(
sd = SuccessionDiagram.from_rules(
"""
S, S
A, S | B
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_all_succession_control():


def test_forbidden_drivers():
sd = SuccessionDiagram.from_bnet(
sd = SuccessionDiagram.from_rules(
"""
A, B & C
B, A & C
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_forbidden_drivers():


def test_size_restriction():
sd = SuccessionDiagram.from_bnet(
sd = SuccessionDiagram.from_rules(
"""
A, B & C
B, A & C
Expand Down
3 changes: 2 additions & 1 deletion tests/drivers_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from balm.drivers import find_single_drivers, find_single_node_LDOIs
from biodivine_aeon import BooleanNetwork

from balm.drivers import find_single_drivers, find_single_node_LDOIs


def test_find_single_node_LDOIs():
bn = BooleanNetwork.from_bnet(
Expand Down
2 changes: 1 addition & 1 deletion tests/motif_avoidant_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from biodivine_aeon import BooleanNetwork, AsynchronousGraph
from biodivine_aeon import AsynchronousGraph, BooleanNetwork

from balm.motif_avoidant import _filter_candidates # type: ignore
from balm.motif_avoidant import _Pint_reachability # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/petri_net_translation_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# type: ignore
import pytest
from biodivine_aeon import BooleanNetwork, RegulatoryGraph
from biodivine_aeon import BooleanNetwork
from networkx import DiGraph, is_isomorphic # type: ignore

from balm.petri_net_translation import (
Expand Down
6 changes: 3 additions & 3 deletions tests/space_utils_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from biodivine_aeon import BooleanNetwork, BooleanExpression, AsynchronousGraph
from biodivine_aeon import AsynchronousGraph, BooleanExpression, BooleanNetwork

from balm.space_utils import (
expression_to_space_list,
is_subspace,
percolate_network,
percolation_conflicts,
percolate_expression,
percolate_network,
percolate_space,
percolate_space_strict,
percolation_conflicts,
space_unique_key,
)

Expand Down
6 changes: 3 additions & 3 deletions tests/succession_diagram_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def test_succession_diagram_structure(self):


def test_state():
sd1 = SuccessionDiagram.from_bnet("A, B\nB, A")
sd2 = SuccessionDiagram.from_bnet("A, B\nB, A\nC, C & B")
sd1 = SuccessionDiagram.from_rules("A, B\nB, A")
sd2 = SuccessionDiagram.from_rules("A, B\nB, A\nC, C & B")
sd1.build()
sd2.__setstate__(sd1.__getstate__())
slots1 = [x + str(sd1.__getattribute__(x)) for x in sd1.__slots__]
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_attractor_expansion(network_file: str):


def test_attractor_extraction():
sd = balm.SuccessionDiagram.from_bnet(
sd = balm.SuccessionDiagram.from_rules(
"""
A, B
B, A & C
Expand Down
8 changes: 2 additions & 6 deletions tests/trappist_core_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from biodivine_aeon import (
BooleanNetwork,
FixedPoints,
AsynchronousGraph,
)
from biodivine_aeon import AsynchronousGraph, BooleanNetwork, FixedPoints

from balm.interaction_graph_utils import cleanup_network
from balm.petri_net_translation import network_to_petrinet
from balm.trappist_core import compute_fixed_point_reduced_STG, trappist
from balm.interaction_graph_utils import cleanup_network
from balm.types import BooleanSpace


Expand Down

1 comment on commit 70431e7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
balm
   control.py1141488%102, 114, 120, 124, 129, 138–154, 472, 475, 488
   interaction_graph_utils.py30487%6–8, 145–146
   motif_avoidant.py152299%25, 121
   petri_net_translation.py1481193%18–22, 58, 94, 207–208, 232–233, 242, 346
   space_utils.py129497%25–27, 252, 278
   succession_diagram.py2571694%6, 184–189, 197, 257–258, 268, 274, 390, 601, 804, 842, 879
   symbolic_utils.py26388%10–12, 44
   trappist_core.py1833084%11–15, 45, 47, 82, 129, 195, 197, 199, 227–230, 234–236, 256–262, 320, 322, 352, 392, 394, 425, 454
balm/_sd_algorithms
   compute_attractor_seeds.py30197%8
   expand_attractor_seeds.py51590%6, 42, 97–102
   expand_bfs.py28196%6
   expand_dfs.py30197%6
   expand_minimal_spaces.py37295%6, 31
   expand_source_SCCs.py164696%19–21, 91, 101, 143, 287
   expand_to_target.py31390%6, 38, 43
TOTAL147110393% 

Tests Skipped Failures Errors Time
361 0 💤 0 ❌ 0 🔥 52.324s ⏱️

Please sign in to comment.