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)
Beispiel #2
0
def test_primes2igraph2():
    fname_in = get_tests_path_in(fname="interactiongraphs_irma.primes")
    primes = read_primes(fname_json=fname_in)
    igraph = primes2igraph(primes=primes)

    nodes = sorted(igraph.nodes(data=True))
    expected_nodes = [("Ash1", {}), ("Cbf1", {}), ("Gal4", {}), ("Gal80", {}),
                      ("Swi5", {}), ("gal", {})]
    assert nodes == expected_nodes

    edges = sorted(igraph.edges(data=True))
    expected_edges = [("Ash1", "Cbf1", {
        "sign": {1}
    }), ("Cbf1", "Ash1", {
        "sign": {1}
    }), ("Gal4", "Swi5", {
        "sign": {-1}
    }), ("Gal80", "Gal4", {
        "sign": {1}
    }), ("Swi5", "Gal4", {
        "sign": {-1}
    }), ("gal", "Ash1", {
        "sign": {1}
    }), ("gal", "Gal80", {
        "sign": {-1}
    }), ("gal", "gal", {
        "sign": {1}
    })]
    assert edges == expected_edges
def test_primes2stg():
    primes = read_primes(fname_json=get_tests_path_in(fname="irma.primes"))

    def init(x):
        return x["Cbf1"] + x["Ash1"] + x["Gal80"] == 1

    primes2stg(primes=primes, update="asynchronous")
    primes2stg(primes=primes, update="synchronous")
    primes2stg(primes=primes, update="mixed")
    primes2stg(primes=primes, update="asynchronous", initial_states=init)
    primes2stg(primes=primes, update="synchronous", initial_states=init)
    primes2stg(primes=primes, update="mixed", initial_states=init)

    init = []
    stg = primes2stg(primes=primes, update="synchronous", initial_states=init)
    answer = sorted(stg.nodes())
    expected = []

    assert answer == expected

    init = ["000010"]
    stg = primes2stg(primes=primes, update="synchronous", initial_states=init)
    answer = sorted(stg.nodes())

    assert answer == ["000010", "000110"]

    init = [{"Cbf1": 0, "Gal4": 1, "Gal80": 0, "gal": 1, "Swi5": 0, "Ash1": 1}]
    stg = primes2stg(primes=primes, update="synchronous", initial_states=init)
    answer = sorted(stg.nodes())

    assert answer == ["010001", "010011", "100011", "101001"]
def test_read_primes():
    fname = get_tests_path_in(fname="fileexchange_missing_inputs.primes")
    primes = read_primes(fname_json=fname)
    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)
Beispiel #5
0
def test_trap_spaces_piped2():
    fname_in = get_tests_path_in(fname="trapspaces_tsfree.primes")
    primes = read_primes(fname_json=fname_in)
    tspaces = compute_trap_spaces(primes=primes, type_="min")
    tspaces.sort(key=lambda x: tuple(sorted(x.items())))

    assert tspaces == [{}]
Beispiel #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 == [{}]
Beispiel #7
0
def test_trap_spaces_piped1():
    fname_in = get_tests_path_in(fname="trapspaces_posfeedback.primes")
    primes = read_primes(fname_json=fname_in)
    tspaces = compute_trap_spaces(primes=primes, type_="min")
    tspaces.sort(key=lambda x: tuple(sorted(x.items())))
    expected = [{"v1": 0, "v2": 0, "v3": 0}, {"v1": 1, "v2": 1, "v3": 1}]

    assert tspaces == expected
Beispiel #8
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}]
Beispiel #9
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 == []
Beispiel #10
0
def test_primes2igraph1():
    fname_in = get_tests_path_in(fname="interactiongraphs_irma.primes")
    primes = read_primes(fname_json=fname_in)
    igraph = primes2igraph(primes=primes)

    nodes = sorted(igraph.nodes())
    expected_nodes = ["Ash1", "Cbf1", "Gal4", "Gal80", "Swi5", "gal"]
    assert nodes == expected_nodes

    edges = sorted(igraph.edges())
    expected_edges = [("Ash1", "Cbf1"), ("Cbf1", "Ash1"), ("Gal4", "Swi5"),
                      ("Gal80", "Gal4"), ("Swi5", "Gal4"), ("gal", "Ash1"),
                      ("gal", "Gal80"), ("gal", "gal")]
    assert edges == expected_edges
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)
Beispiel #12
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)
Beispiel #13
0
def test_igraph2dot_string():
    fname_in = get_tests_path_in(fname="interactiongraphs_irma.primes")
    primes = read_primes(fname_json=fname_in)
    igraph = primes2igraph(primes=primes)
    igraph2dot(igraph=igraph, fname_dot=None)
Beispiel #14
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_stg2dot():
    fname_in = get_tests_path_in(fname="irma.primes")
    fname_out = get_tests_path_out(fname="irma_stg.dot")
    primes = read_primes(fname_json=fname_in)
    stg = primes2stg(primes=primes, update="asynchronous")
    stg2dot(stg, fname_out)
Beispiel #16
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)
Beispiel #17
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)
def test_random_state():
    fname_in = get_tests_path_in(fname="irma.primes")
    primes = read_primes(fname_json=fname_in)
    pyboolnet.state_space.random_state(primes=primes)
    pyboolnet.state_space.random_state(primes=primes, subspace="111-0-")