예제 #1
0
def test_primes2smv():
    primes = {
        "vB": [[{}], []],
        "vC": [[{
            "vC": 0
        }], [{
            "vC": 1
        }]],
        "vA": [[{
            "vB": 0,
            "vC": 1
        }], [{
            "vC": 0
        }, {
            "vB": 1
        }]]
    }
    fname = get_tests_path_out(fname="fileexchange_primes2smv_syn.smv")
    primes2smv(primes=primes,
               fname_smv=fname,
               update="synchronous",
               initial_states="INIT TRUE",
               specification="CTLSPEC TRUE")
    fname = get_tests_path_out(fname="fileexchange_primes2smv_async.smv")
    primes2smv(primes=primes,
               fname_smv=fname,
               update="asynchronous",
               initial_states="INIT TRUE",
               specification="CTLSPEC TRUE")
    fname = get_tests_path_out(fname="fileexchange_primes2smv_mixed.smv")
    primes2smv(primes=primes,
               fname_smv=fname,
               update="mixed",
               initial_states="INIT TRUE",
               specification="CTLSPEC TRUE")
예제 #2
0
def test_dot2image():
    fname_in = get_tests_path_in(fname="interactiongraphs_topology.dot")
    fname_out1 = get_tests_path_out(fname="interactiongraphs_dot2image1.png")
    fname_out2 = get_tests_path_out(fname="interactiongraphs_dot2image2.svg")
    fname_out3 = get_tests_path_out(fname="interactiongraphs_dot2image3.eps")
    dot2image(fname_dot=fname_in, fname_image=fname_out1)
    dot2image(fname_dot=fname_in, fname_image=fname_out2)
    dot2image(fname_dot=fname_in, fname_image=fname_out3)
def test_compute_commitment_diagram(attractors, edge_data):
    fname_image = get_tests_path_out(fname="compute_commitment_diagram.pdf")
    fname_json = get_tests_path_out(fname="compute_commitment_diagram.json")

    diagram = compute_commitment_diagram(attractors,
                                         fname_image=fname_image,
                                         fname_json=fname_json,
                                         edge_data=edge_data)
    diagram_from_file = open_commitment_diagram(fname_json=fname_json)

    assert sorted(diagram.edges(data=True)) == sorted(
        diagram_from_file.edges(data=True))
    assert sorted(diagram.nodes(data=True)) == sorted(
        diagram_from_file.nodes(data=True))
예제 #4
0
def test_bnet2primes_empty():
    fname_in = get_tests_path_in(fname="fileexchange_empty.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_empty.primes")
    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    primes_expected = {}

    assert primes_are_equal(primes, primes_expected), str(primes)
예제 #5
0
def test_bnet2primes_missing_inputs():
    fname_in = get_tests_path_in(fname="fileexchange_missing_inputs.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_missing_inputs.primes")
    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    primes_expected = {
        "B": [[{
            "B": 0
        }], [{
            "B": 1
        }]],
        "C": [[{
            "C": 0
        }], [{
            "C": 1
        }]],
        "A": [[{
            "B": 0,
            "C": 1
        }], [{
            "C": 0
        }, {
            "B": 1
        }]]
    }

    assert primes_are_equal(primes, primes_expected), str(primes)
예제 #6
0
def test_trap_spaces_positive_feedback_bounds2():
    fname_in = get_tests_path_in(fname="trapspaces_posfeedback.primes")
    fname_out = get_tests_path_out(fname="trapspaces_posfeedback_bounds2.asp")
    primes = read_primes(fname_json=fname_in)
    tspaces = compute_trap_spaces_bounded(primes=primes, type_="max", bounds=(0, 100), fname_asp=fname_out)
    tspaces.sort(key=lambda x: tuple(sorted(x.items())))

    assert tspaces == [{}]
예제 #7
0
def test_trap_spaces_positive_feedback_all():
    fname_in = get_tests_path_in(fname="trapspaces_posfeedback.primes")
    fname_out = get_tests_path_out(fname="trapspaces_posfeedback_all.asp")
    primes = read_primes(fname_json=fname_in)
    tspaces = compute_trap_spaces(primes=primes, type_="all", fname_asp=fname_out)
    tspaces.sort(key=lambda x: tuple(sorted(x.items())))

    assert tspaces == [{}, {"v1": 0, "v2": 0, "v3": 0}, {"v1": 1, "v2": 1, "v3": 1}]
예제 #8
0
def test_bnet2primes_constants():
    fname_in = get_tests_path_in(fname="fileexchange_constants.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_constants.primes")

    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    primes_expected = {"A": [[{}], []], "B": [[], [{}]]}

    assert primes_are_equal(primes, primes_expected), str(primes)
예제 #9
0
def test_compute_json():
    primes = get_primes("n5s3")
    fname = get_tests_path_out(fname="n5s3_attrs.json")
    attractors = compute_attractors(primes=primes,
                                    update="asynchronous",
                                    fname_json=fname,
                                    max_output=2)

    assert attractors
def test_create_basins_piechart():
    try:
        primes = get_primes("n5s3")
        attractors = compute_attractors(primes, update="asynchronous")
        compute_basins(attractors)
        fname_image = get_tests_path_out(fname="basins_piechart")
        create_basins_piechart(attractors, fname_image=fname_image)
    except NameError:
        pass
def test_create_piechart(attractors):
    try:
        diagram = compute_commitment_diagram(attractors)
        fname_image = get_tests_path_out(
            fname="compute_commitment_diagram.pdf")
        create_commitment_piechart(diagram=diagram,
                                   fname_image=fname_image,
                                   title="A commitment pie chart")
    except NameError:
        pass
def test_best_first_reachability():
    primes = bnet2primes(
        bnet=get_tests_path_in(fname="randomnet.bnet"),
        fname_primes=get_tests_path_out(fname="randomnet.primes"))
    initial_space = dict([("Gene%i" % (i + 1), i % 2) for i in range(20)])
    goal_space = {"Gene2": 0, "Gene4": 0, "Gene6": 0, "Gene8": 0}
    memory = 10000
    path = best_first_reachability(primes, initial_space, goal_space, memory)

    assert path is not None
예제 #13
0
def test_trap_spaces_tsfree():
    fname_in = get_tests_path_in(fname="trapspaces_tsfree.primes")
    fname_out = get_tests_path_out(fname="trapspaces_tsfree_min.asp")
    primes = read_primes(fname_json=fname_in)
    tspaces = compute_trap_spaces(primes=primes, type_="min", fname_asp=fname_out)

    assert tspaces == [{}]

    fname_in = get_tests_path_in(fname="trapspaces_tsfree.primes")
    fname_out = get_tests_path_out(fname="trapspaces_tsfree_all.asp")
    primes = read_primes(fname_json=fname_in)
    tspaces = compute_trap_spaces(primes=primes, type_="all", fname_asp=fname_out)

    assert tspaces == [{}]

    fname_in = get_tests_path_in(fname="trapspaces_tsfree.primes")
    fname_out = get_tests_path_out(fname="trapspaces_tsfree_max.asp")
    primes = read_primes(fname_json=fname_in)
    tspaces = compute_trap_spaces(primes=primes, type_="max", fname_asp=fname_out)

    assert tspaces == []
예제 #14
0
def test_bnet2primes_operatorbinding():
    fname_in = get_tests_path_in(fname="fileexchange_operatorbinding.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_operatorbinding.primes")

    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    names = "abcde"
    results = []
    for x in names:
        for y in names:
            name = x
            results.append(
                primes_are_equal({name: primes[x]}, {name: primes[y]}))

    assert all(results)
예제 #15
0
def test_bnet2primes_a():
    fname_in = get_tests_path_in(fname="fileexchange_constants.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_stdout1.primes")
    file_in = "A, 0\nB, 1"

    expected = {"A": [[{}], []], "B": [[], [{}]]}

    primes = bnet2primes(bnet=fname_in)
    assert primes_are_equal(primes, expected)

    primes = bnet2primes(bnet=file_in)
    assert primes_are_equal(primes, expected)

    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    assert primes_are_equal(primes, expected)
def test_stg2image():
    fname_in = get_tests_path_in(fname="irma.primes")
    fname_out1 = get_tests_path_out(fname="irma_stg_async.pdf")
    fname_out2 = get_tests_path_out(fname="irma_stg_tendencies_async.pdf")
    fname_out3 = get_tests_path_out(fname="irma_stg_sccs_async.pdf")

    primes = read_primes(fname_json=fname_in)
    stg = primes2stg(primes=primes, update="asynchronous")
    stg2image(stg, fname_out1)

    add_style_tendencies(stg)
    stg2image(stg, fname_out2)

    stg = primes2stg(primes=primes, update="asynchronous")
    add_style_sccs(stg)
    stg2image(stg, fname_out3)

    fname_out1 = get_tests_path_out(fname="irma_stg_sync.pdf")
    fname_out2 = get_tests_path_out(fname="irma_stg_tendencies_sync.pdf")
    fname_out3 = get_tests_path_out(fname="irma_stg_sccs_sync.pdf")
    fname_out4 = get_tests_path_out(fname="irma_stg_path.pdf")

    primes = read_primes(fname_json=fname_in)
    stg = primes2stg(primes=primes, update="synchronous")
    stg2image(stg, fname_out1)

    stg = primes2stg(primes=primes, update="asynchronous")
    add_style_tendencies(stg)
    stg2image(stg, fname_out2)

    stg = primes2stg(primes=primes, update="synchronous")
    add_style_sccs(stg)
    stg2image(stg, fname_out3)

    init = random_state(primes=primes)
    walk = random_walk(primes=primes,
                       update="asynchronous",
                       initial_state=init,
                       length=5)
    stg = primes2stg(primes=primes, update="asynchronous")
    add_style_path(stg, walk, "red")
    init = pyboolnet.state_space.random_state(primes=primes)
    walk = random_walk(primes=primes,
                       update="asynchronous",
                       initial_state=init,
                       length=5)
    add_style_path(stg, walk, "blue")
    stg2image(stg, fname_out4)
예제 #17
0
def test_find_attractor_state_by_randomwalk_and_ctl():
    fname_in = get_tests_path_in(fname="randomnet.bnet")
    fname_out = get_tests_path_out(fname="randomnet.primes")
    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)

    subspace = {"Gene1": 0, "Gene3": 0, "Gene5": 0, "Gene7": 0, "Gene9": 0}
    length = 200
    attempts = 10

    min_trap_spaces = {
        "Gene1": 1,
        "Gene11": 0,
        "Gene12": 1,
        "Gene13": 0,
        "Gene14": 1,
        "Gene15": 0,
        "Gene16": 1,
        "Gene17": 1,
        "Gene18": 1,
        "Gene19": 0,
        "Gene2": 1,
        "Gene20": 1,
        "Gene3": 0,
        "Gene4": 1,
        "Gene5": 0,
        "Gene6": 0,
        "Gene8": 0,
        "Gene9": 0
    }

    x = find_attractor_state_by_randomwalk_and_ctl(primes, "asynchronous",
                                                   subspace, length, attempts)
    assert state_is_in_subspace(primes, x, min_trap_spaces)

    y = find_attractor_state_by_randomwalk_and_ctl(primes, "synchronous",
                                                   subspace, length, attempts)
    reachable = list_reachable_states(primes, "synchronous", y, 100)

    assert state2str(y) in reachable

    z = find_attractor_state_by_randomwalk_and_ctl(primes, "mixed", subspace,
                                                   length, attempts)
    assert state_is_in_subspace(primes, z, min_trap_spaces)
예제 #18
0
def test_primes2bns():
    fname = get_tests_path_out(fname="fileexchange_primes2bns.bns")
    primes = {
        "B": [[{}], []],
        "C": [[{
            "C": 0
        }], [{
            "C": 1
        }]],
        "A": [[{
            "B": 0,
            "C": 1
        }], [{
            "C": 0
        }, {
            "B": 1
        }]]
    }
    primes2bns(primes=primes, fname_bns=fname)
예제 #19
0
def test_primes2bnet_b():
    fname = get_tests_path_out(fname="fileexchange_primes2bnet.primes")
    primes = {
        "B": [[{}], []],
        "C": [[{
            "C": 0
        }], [{
            "C": 1
        }]],
        "A": [[{
            "B": 0,
            "C": 1
        }], [{
            "C": 0
        }, {
            "B": 1
        }]]
    }
    primes2bnet(primes=primes, fname_bnet=fname)
    primes2bnet(primes=primes, fname_bnet=fname, minimize=True)
예제 #20
0
def test_bnet2primes_results():
    fname_in = get_tests_path_in(fname="fileexchange_feedback.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_feedback.primes")
    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    primes_expected = {
        "v1": [[{
            "v2": 0
        }], [{
            "v2": 1
        }]],
        "v2": [[{
            "v2": 0
        }, {
            "v1": 1
        }], [{
            "v1": 0,
            "v2": 1
        }]]
    }

    assert primes_are_equal(primes, primes_expected)
예제 #21
0
def test_read_write_primes():
    fname = get_tests_path_out(fname="fileexchange_read_write.primes")
    primes_write = {
        "B": [[{}], []],
        "C": [[{
            "C": 0
        }], [{
            "C": 1
        }]],
        "A": [[{
            "B": 0,
            "C": 1
        }], [{
            "C": 0
        }, {
            "B": 1
        }]]
    }
    write_primes(primes=primes_write, fname_json=fname)
    primes_read = read_primes(fname_json=fname)

    assert primes_are_equal(primes_read, primes_write)
예제 #22
0
def test_primes2asp(bounds, projection, type_):
    primes = {
        "B": [[{}], []],
        "C": [[{
            "C": 0
        }], [{
            "C": 1
        }]],
        "A": [[{
            "B": 0,
            "C": 1
        }], [{
            "C": 0
        }, {
            "B": 1
        }]]
    }
    fname = get_tests_path_out(fname="fileexchange_primes2asp_case.asp")
    primes2asp(primes=primes,
               fname_asp=fname,
               bounds=bounds,
               project=projection,
               type_=type_)
예제 #23
0
def test_activities2animation():
    fname_in = get_tests_path_in(fname="irma.primes")
    fname_out1 = get_tests_path_out(fname="irma*.png")
    fname_out2 = get_tests_path_out(fname="irma.gif")
    primes = read_primes(fname_json=fname_in)
    igraph = primes2igraph(primes)
    activities = [
        {
            "gal": 0,
            "Cbf1": 1,
            "Gal80": 1,
            "Ash1": 0,
            "Gal4": 0,
            "Swi5": 1
        },
        {
            "gal": 1,
            "Cbf1": 1,
            "Gal80": 1,
            "Ash1": 0,
            "Gal4": 0,
            "Swi5": 1
        },
        {
            "gal": 1,
            "Cbf1": 0,
            "Gal80": 1,
            "Ash1": 0,
            "Gal4": 0,
            "Swi5": 1
        },
        {
            "gal": 1,
            "Cbf1": 0,
            "Gal80": 0,
            "Ash1": 0,
            "Gal4": 0,
            "Swi5": 1
        },
        {
            "gal": 1,
            "Cbf1": 0,
            "Gal80": 0,
            "Ash1": 1,
            "Gal4": 0,
            "Swi5": 1
        },
        {
            "gal": 1,
            "Cbf1": 0,
            "Gal80": 0,
            "Ash1": 1,
            "Gal4": 1,
            "Swi5": 1
        },
        {
            "gal": 1,
            "Cbf1": 0,
            "Gal80": 0,
            "Ash1": 1,
            "Gal4": 1,
            "Swi5": 0
        },
    ]

    activities2animation(igraph=igraph,
                         activities=activities,
                         fname_tmp=fname_out1,
                         fname_gif=fname_out2)
예제 #24
0
def test_create_image():
    fname = get_tests_path_out(fname="interactiongraphs_create_image.pdf")
    primes = get_primes("raf")
    create_image(primes, fname)
예제 #25
0
def test_styles():
    fname_in = get_tests_path_in(fname="interactiongraphs_topology.primes")
    fname_out_dot = get_tests_path_out(
        fname="interactiongraphs_style_interactionsigns.dot")
    fname_out_pdf = get_tests_path_out(
        fname="interactiongraphs_style_interactionsigns.pdf")
    primes = read_primes(fname_json=fname_in)
    igraph = primes2igraph(primes=primes)
    add_style_interactionsigns(igraph=igraph)
    igraph2dot(igraph=igraph, fname_dot=fname_out_dot)
    dot2image(fname_dot=fname_out_dot, fname_image=fname_out_pdf)
    igraph2image(igraph=igraph, fname_image=fname_out_pdf)

    fname_out_dot = get_tests_path_out(
        fname="interactiongraphs_style_activities.dot")
    fname_out_pdf = get_tests_path_out(
        fname="interactiongraphs_style_activities.pdf")

    add_style_interactionsigns(igraph=igraph)
    igraph2dot(igraph=igraph, fname_dot=fname_out_dot)
    dot2image(fname_dot=fname_out_dot, fname_image=fname_out_pdf)
    igraph2image(igraph=igraph, fname_image=fname_out_pdf)

    igraph = primes2igraph(primes=primes)
    activities = {"v1": 1, "v2": 0, "v3": 1, "v4": 1, "v5": 1, "v6": 0}
    add_style_activities(igraph=igraph, activities=activities)
    igraph2dot(igraph=igraph, fname_dot=fname_out_dot)
    dot2image(fname_dot=fname_out_dot, fname_image=fname_out_pdf)

    fname_in = get_tests_path_in(fname="interactiongraphs_topology.primes")
    fname_out_dot = get_tests_path_out(
        fname="interactiongraphs_style_sccs.dot")
    fname_out_pdf = get_tests_path_out(
        fname="interactiongraphs_style_sccs.pdf")
    primes = read_primes(fname_json=fname_in)

    igraph = primes2igraph(primes=primes)
    add_style_sccs(igraph=igraph)
    igraph2dot(igraph=igraph, fname_dot=fname_out_dot)
    dot2image(fname_dot=fname_out_dot, fname_image=fname_out_pdf)

    fname_in = get_tests_path_in(fname="interactiongraphs_topology.primes")
    fname_out_pdf = get_tests_path_out(fname="interactiongraphs_style_ioc.pdf")
    primes = read_primes(fname_json=fname_in)

    igraph = primes2igraph(primes=primes)
    add_style_inputs(igraph=igraph)
    add_style_constants(igraph=igraph)
    add_style_outputs(igraph=igraph)
    igraph2image(igraph=igraph, fname_image=fname_out_pdf)

    fname_in = get_tests_path_in(fname="interactiongraphs_topology.primes")
    fname_out_pdf = get_tests_path_out(
        fname="interactiongraphs_style_subgrapghs.pdf")
    fname_out_dot = get_tests_path_out(
        fname="interactiongraphs_style_subgrapghs.dot")
    primes = read_primes(fname_json=fname_in)

    igraph = primes2igraph(primes=primes)
    subgraphs = [(["v1", "v2"], {}), (["v3", "v4"], {"label": "jo"})]
    add_style_subgraphs(igraph=igraph, subgraphs=subgraphs)
    igraph2dot(igraph=igraph, fname_dot=fname_out_dot)
    dot2image(fname_dot=fname_out_dot, fname_image=fname_out_pdf)
예제 #26
0
def test_igraph2image():
    fname_in = get_tests_path_in(fname="interactiongraphs_irma.primes")
    primes = read_primes(fname_json=fname_in)
    igraph = primes2igraph(primes=primes)
    fname_out = get_tests_path_out(fname="interactiongraphs_igraph2image.png")
    igraph2image(igraph=igraph, fname_image=fname_out)
예제 #27
0
def test_igraph2dot():
    fname_in = get_tests_path_in(fname="interactiongraphs_irma.primes")
    fname_out = get_tests_path_out(fname="interactiongraphs_igraph2dot.dot")
    primes = read_primes(fname_json=fname_in)
    igraph = primes2igraph(primes=primes)
    igraph2dot(igraph=igraph, fname_dot=fname_out)
def test_successor_synchronous():
    primes = bnet2primes(
        bnet=get_tests_path_in(fname="randomnet.bnet"),
        fname_primes=get_tests_path_out(fname="randomnet.primes"))
    state = dict([("Gene%i" % (i + 1), i % 2) for i in range(20)])
    successor_synchronous(primes, state)
def test_random_mixed_transition():
    primes = bnet2primes(
        bnet=get_tests_path_in(fname="randomnet.bnet"),
        fname_primes=get_tests_path_out(fname="randomnet.primes"))
    state = dict([("Gene%i" % (i + 1), i % 2) for i in range(20)])
    random_successor_mixed(primes, state)
def test_stg2htg():
    fname_out = get_tests_path_out(fname="raf_htg.pdf")
    primes = get_primes("raf")
    stg = primes2stg(primes, "asynchronous")
    htg = stg2htg(stg)
    htg2image(htg, fname_out)