def setUp(self): self.bn1 = bonesis.BooleanNetwork({"a": "b", "b": "c", "c": 1}) self.bn2 = bonesis.BooleanNetwork({"a": "b", "b": "c", "c": "c"}) self.data = {} for a in [0, 1]: for b in [0, 1]: for c in [0, 1]: self.data[f"{a}{b}{c}"] = {"a": a, "b": b, "c": c}
def main_reprogramming(): ap = ArgumentParser() ap.add_argument("bnet_file", help="file specifying the Boolean network in bnet format") ap.add_argument( "marker", help="Marker specification (partial configuration) - JSON format") ap.add_argument("max_size", type=int, help="Maximum number of perturbation") ap.add_argument( "--reachable-from", help= "Initial configuration for source-marker reprogramming - JSON format") ap.add_argument("--fixpoints", action="store_true", help="Reprogram fixed points only") ap.add_argument( "--allow-no-fixpoint", action="store_true", help="When reprogramming fixed points, allow having no fixed points") ap.add_argument("--exclude", help="Perturbation blacklist - JSON format") ap.add_argument("--limit", type=int, help="Maximum number of solutions") ap.add_argument("--verbose", action="store_true") ap.add_argument("--parallel", "-t", default=1, help="Parallel solving") args = ap.parse_args() bonesis.settings["quiet"] = not args.verbose bonesis.settings["parallel"] = args.parallel f = bonesis.BooleanNetwork(args.bnet_file) M = json.loads(args.marker) k = args.max_size meth_prefix = "" meth_suffix = "" meth_args = (f, M, k) meth_kwargs = {} if args.exclude: meth_kwargs["exclude"] = json.loads(args.exclude) if args.reachable_from: z = json.loads(args.reachable_from) meth_prefix = "source_" meth_args = (f, z, M, k) if args.fixpoints: meth_suffix = "_fixpoints" meth_kwargs["at_least_one"] = not args.allow_no_fixpoint from bonesis import reprogramming meth = f"{meth_prefix}marker_reprogramming{meth_suffix}" meth = getattr(reprogramming, meth) it = meth(*meth_args, **meth_kwargs) has_one = False if args.limit: it = islice(it, args.limit) for sol in it: has_one = True print(sol) if not has_one: print("No solution", file=sys.stderr)
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)
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)
import bonesis dom = bonesis.InfluenceGraph.complete("abc", sign=1, exact=True, loops=False) dom2 = bonesis.BooleanNetwork({"a": "c", "b": "a", "c": "b"}) bo = bonesis.BoNesis(dom) """ x = bo.cfg() bo.in_attractor(x) for i, sol in enumerate(x.assignments()): print(i, sol) """ #h = bo.hypercube({"a": 1}) h = bo.hypercube() bo.fixed(h) bo.aspmodel.make() print(str(bo.aspmodel)) assert bo.is_satisfiable() for i, sol in enumerate(h.assignments()): print(i, sol)
import bonesis dom = bonesis.BooleanNetwork({"a": "a", "b": "a & c", "c": "!b"}) data = { "never_b": { "b": 0 }, } bo = bonesis.BoNesis(dom, data) bad_control = bo.Some() with bo.mutant(bad_control) as m: m.fixed(bo.obs("never_b")) for res in bad_control.complementary_assignments(): print(res)