def test_simple_pattern_layout():
    ag = AssemblyGraph("metagenomescope/tests/input/bubble_test.gml")
    ag.scale_nodes()
    ag.compute_node_dimensions()
    ag.scale_edges()
    ag.hierarchically_identify_patterns()

    # This graph should contain just a single bubble. We're going to verify
    # that laying it out works as expected.
    assert len(ag.bubbles) == 1
    p = ag.bubbles[0]
    p.layout(ag)
Пример #2
0
def test_compute_node_dimensions_all_lengths_equal():
    ag = AssemblyGraph("metagenomescope/tests/input/loop.gfa")
    ag.scale_nodes()
    ag.compute_node_dimensions()
    default_area = config.MIN_NODE_AREA + (
        0.5 * (config.MAX_NODE_AREA - config.MIN_NODE_AREA)
    )
    default_height = default_area ** config.MID_LONGSIDE_PROPORTION
    default_width = default_area / default_height

    # This double-checks that the defaults we expect here are computed
    # properly. If the config values are updated that may break this, so feel
    # free to comment this out if that happens to you.
    assert default_area == 5.5
    assert default_height == approx(3.115839)
    assert default_width == approx(1.765174)

    for node in ag.digraph.nodes:
        assert ag.digraph.nodes[node]["height"] == default_height
        assert ag.digraph.nodes[node]["width"] == default_width
Пример #3
0
def test_compute_node_dimensions():
    ag = AssemblyGraph("metagenomescope/tests/input/sample1.gfa")
    ag.scale_nodes()
    ag.compute_node_dimensions()

    def get_dims(rl, lp):
        area = config.MIN_NODE_AREA + (
            rl * (config.MAX_NODE_AREA - config.MIN_NODE_AREA)
        )
        hgt = area ** lp
        wid = area / hgt
        return (wid, hgt)

    # Relative length and longside proportions reused from test_scale_nodes()
    nodename2dims = {
        "1": get_dims(0.4180047, config.MID_LONGSIDE_PROPORTION),
        "2": get_dims(0.5525722, config.HIGH_LONGSIDE_PROPORTION),
        "3": get_dims(1, config.HIGH_LONGSIDE_PROPORTION),
        "4": get_dims(0.3374782, config.MID_LONGSIDE_PROPORTION),
        "5": get_dims(0.4180047, config.MID_LONGSIDE_PROPORTION),
        "6": get_dims(0, config.LOW_LONGSIDE_PROPORTION),
    }

    seen_nodenames = []
    for node in ag.digraph.nodes:
        name = ag.digraph.nodes[node]["name"]
        w = ag.digraph.nodes[node]["width"]
        h = ag.digraph.nodes[node]["height"]
        exp_data = ()
        if name in nodename2dims:
            exp_data = nodename2dims[name]
        else:
            exp_data = nodename2dims[negate_node_id(name)]
        assert w == approx(exp_data[0])
        assert h == approx(exp_data[1])
        seen_nodenames.append(name)
    assert len(seen_nodenames) == 12
Пример #4
0
def test_compute_node_dimensions_fails_if_scale_nodes_not_called_first():
    # (Since relative_length and longside_proportion data won't be available.)
    ag = AssemblyGraph("metagenomescope/tests/input/loop.gfa")
    with raises(KeyError):
        ag.compute_node_dimensions()