def test_positive(self): for x, y in [("001", "000"), ("000", "010"), ("000", "110"), ("000", "100")]: bo = bonesis.BoNesis(self.bn1, self.data) bo.set_constant("bounded_nonreach", 0) +bo.obs(x) / +bo.obs(y) self.assertTrue(bo.is_satisfiable(), f"nonreach({x},{y})")
def source_marker_reprogramming(f, z, M, k, **some_opts): bo = bonesis.BoNesis(f) bad_control = bo.Some(max_size=k, **some_opts) with bo.mutant(bad_control): x = bo.cfg() ~bo.obs(z) >= bo.in_attractor(x) != bo.obs(M) return bad_control.complementary_assignments()
def marker_reprogramming_fixpoints(f, M, k, at_least_one=True, **some_opts): bo = bonesis.BoNesis(f) control = bo.Some(max_size=k, **some_opts) with bo.mutant(control): if at_least_one: bo.fixed(~bo.obs(M)) bo.all_fixpoints(bo.obs(M)) return control.assignments()
def test_all_fixpoints(self): bo = bonesis.BoNesis(self.dom1, self.data1) bo.fixed(bo.obs("0")) bo.all_fixpoints({bo.obs("0")}) self.assertEqual(bo.boolean_networks().count(), 355) bo.all_fixpoints({bo.obs("0"), bo.obs("1")}) self.assertEqual(bo.boolean_networks().count(), 355) bo.all_fixpoints({bo.obs("1")}) self.assertEqual(bo.boolean_networks().count(), 0)
def test_all_fixpoints_mutant(self): bo = bonesis.BoNesis(self.dom1, self.data1) with bo.mutant({"a": 1}) as m: m.fixed(~m.obs("1")) m.all_fixpoints({m.obs("1")}) self.assertEqual(bo.boolean_networks().count(), 2640) bo.fixed(~bo.obs("0")) bo.all_fixpoints({bo.obs("0")}) self.assertEqual(bo.boolean_networks().count(), 25)
def test_final(self): for bn, x, y, t in [ ("bn1", "000", "111", self.assertFalse), ("bn2", "001", "111", self.assertFalse), ("bn2", "110", "000", self.assertFalse), ("bn2", "001", "000", self.assertTrue), ("bn2", "110", "111", self.assertTrue), ]: bo = bonesis.BoNesis(getattr(self, bn), self.data) +bo.obs(x) // bo.fixed(~bo.obs(y)) t(bo.is_satisfiable(), f"final_nonreach({x},{y}) [{bn}]")
def test_bounded(self): for x, y, b, t in [ ("001", "000", 1, self.assertTrue), ("000", "010", 2, self.assertTrue), ("000", "100", 1, self.assertFalse), ("000", "100", 2, self.assertTrue), ]: bo = bonesis.BoNesis(self.bn1, self.data) bo.set_constant("bounded_nonreach", b) +bo.obs(x) / +bo.obs(y) t(bo.is_satisfiable(), f"nonreach({x},{y},{b})")
def source_marker_reprogramming_fixpoints(f, z, M, k, at_least_one=True, **some_opts): bo = bonesis.BoNesis(f) control = bo.Some(max_size=k, **some_opts) with bo.mutant(control): if at_least_one: ~bo.obs(z) >= bo.fixed(~bo.obs(M)) ~bo.obs(z) >> "fixpoints" ^ {bo.obs(M)} return control.assignments()
def main_attractors(): ap = ArgumentParser() ap.add_argument("bnet_file", help="file specifying the Boolean network in bnet format") ap.add_argument("--fixpoints-only", action="store_true", help="Enumerate only fixed points") args = ap.parse_args() dom = bonesis.BooleanNetwork(args.bnet_file) bo = bonesis.BoNesis(dom) x = bo.cfg() if args.fixpoints_only else bo.hypercube() bo.fixed(x) publish = print for sol in x.assignments(): publish(sol)
def setUp(self): pkn = bonesis.InfluenceGraph.complete("abc", sign=1, loops=False, allow_skipping_nodes=False) data = { "x": { "a": 0, "b": 0 }, "y": { "a": 1, "b": 1 }, } bo = bonesis.BoNesis(pkn, data) ~bo.obs("x") >= ~bo.obs("y") self.bo1 = bo
def test_node_equal1(self): pkn = bonesis.InfluenceGraph.complete("abc", sign=1, loops=False, allow_skipping_nodes=False) data = { "x": { "a": 0 }, "y": { "a": 1 }, } bo = bonesis.BoNesis(pkn, data) x = ~bo.obs("x") y = ~bo.obs("y") x >= y x["c"] = y["c"] for _, cfgs in bo.boolean_networks(limit=15, extra="configurations"): self.assertEqual(cfgs["x"]["c"], cfgs["y"]["c"])
import pandas as pd from bonesis.language import * pkn = bonesis.InfluenceGraph.complete("abc", 1) data = { "x": { "a": 0, "b": 0 }, "y": { "a": 1, "b": 1 }, } bo = bonesis.BoNesis(pkn, data) fixed(~bo.obs("x")) all_fixpoints({bo.obs("x")}) with bo.mutant({"c": 1}) as mc: y = mc.obs("y") for cfg in bonesis.matching_configurations(mc.obs("x")): cfg >= mc.fixed(+y) cfg >> "fixpoints" ^ {y} def validate(bn): print("# all fixpoints") fps = [a for a in bn.attractors() if '*' not in a.values()] print(pd.DataFrame(fps)) print("# reachable from x with mutation")
from tqdm import tqdm import bonesis dom1 = bonesis.InfluenceGraph.complete("abc", 1) #dom1 = bonesis.InfluenceGraph.complete("ab", 0) bo = bonesis.BoNesis(dom1) bns = bo.boolean_networks() def count_matching(m): print(m, len([bn for bn in tqdm(bns) if m(bn)])) def all_fixpoints_0(bn): A = list(bn.attractors()) return A == [{"a": 0, "b": 0, "c": 0}] #count_matching(all_fixpoints_0) def all_fixpoints_0_mutant(bn): if all_fixpoints_0(bn): bn["a"] = True A = list(bn.attractors()) return A == [{"a": 1, "b": 1, "c": 1}] return False #count_matching(all_fixpoints_0_mutant)
def test_complete(self): dom = bonesis.InfluenceGraph.complete(3, 1, loops=False, exact=True) bo = bonesis.BoNesis(dom) bns = bo.boolean_networks() self.assertEqual(bns.count(), 8)
def test_nocyclic(self): bo = bonesis.BoNesis(self.dom1) view = bo.boolean_networks(no_cyclic_attractors=True) self.assertEqual(view.count(), 115) # over 196 view = bo.boolean_networks(limit=10, no_cyclic_attractors=True) self.assertEqual(view.count(), 10)
import bonesis f = bonesis.BooleanNetwork({ "a": "c & (!a | !b)", "b": "c & a", "c": "a|b|c", }) bo = bonesis.BoNesis(f) x = bo.cfg() ~bo.obs({ "a": 1, "b": 0, "c": 0 }) >= bo.in_attractor(x) != bo.obs({ "a": 1, "b": 1 }) for v in x.assignments(): print(v)
def _fresh_bo(self): return bonesis.BoNesis(self.dom, self.data)
import bonesis dom = bonesis.BooleanNetwork({"a": "c", "b": "a", "c": "b"}) M = {a: 1 for a in dom} bo = bonesis.BoNesis(dom) with bo.mutant(bo.Some("Ensure111", max_size=2)) as m: m.all_fixpoints(bo.obs(M)) view = bo.assignments() print(view.standalone()) for res in view: print(res) for res in bo.assignments(solutions="all"): print(res) bo = bonesis.BoNesis(dom) control = bo.Some() with bo.mutant(control) as m: m.all_fixpoints(bo.obs(M)) for res in control.assignments(): print(res)
def test_irreflexive(self): bo = bonesis.BoNesis(self.bn1, self.data) bo.set_constant("bounded_nonreach", 0) +bo.obs("000") / +bo.obs("000") self.assertFalse(bo.is_satisfiable())
import bonesis dom = bonesis.InfluenceGraph.complete("abc") data = {"A": {"a": 1}} bo1 = bonesis.BoNesis(dom, data) print(id(bo1)) bo2 = bo1.fork() print(id(bo2)) print(id(bo2.manager.bo))
def test_trapspace(self): bo = bonesis.BoNesis(self.dom1, self.data1) bo.fixed(bo.obs("000")) self.assertEqual(bo.boolean_networks().count(), 6859)