Пример #1
0
def test_newick__parse__subnode__two_taxa():
    child_node_1 = Newick(name="A")
    child_node_2a = Newick(name="B")
    child_node_2b = Newick(name="C")
    child_node_2 = Newick(children=[child_node_2a, child_node_2b])
    top_node = Newick(children=[child_node_1, child_node_2])
    assert_equal(Newick.from_string("(A,(B,C));"), top_node)
Пример #2
0
def test_newick__get_leaf_nodes__complex_case():
    node_a = Newick(name="Leaf A")
    node_b = Newick(name="Leaf B")
    node_c = Newick(name="Leaf C")
    sub_a = Newick(children=[node_b, node_c])
    top_node = Newick(children=[node_a, sub_a])
    assert_list_equal(top_node.get_leaf_nodes(), [node_a, node_b, node_c])
Пример #3
0
def test_newick__hash__not_identical():
    def _not_identical(node_b):
        node_a = Newick(name="A", length=13, children=[Newick(name="B")])
        assert_not_equal(hash(node_a), hash(node_b))

    yield _not_identical, Newick(name="B",
                                 length=13,
                                 children=[Newick(name="B")])
    yield _not_identical, Newick(name="A",
                                 length=14,
                                 children=[Newick(name="B")])
    yield _not_identical, Newick(name="A", length=13, children=[])
    yield _not_identical, Newick(name="A",
                                 length=13,
                                 children=[Newick(name="C")])
    yield _not_identical, Newick(name="B",
                                 length=14,
                                 children=[Newick(name="C")])
Пример #4
0
def test_newick__wikipedia_example_4():
    # all but root node have a distance to parent
    taxa_d = Newick(length="0.4")
    taxa_c = Newick(length="0.3")
    taxa_sub = Newick(children=[taxa_c, taxa_d], length="0.5")
    taxa_b = Newick(length="0.2")
    taxa_a = Newick(length="0.1")
    top_node = Newick(children=[taxa_a, taxa_b, taxa_sub])
    assert_equal(Newick.from_string("(:0.1,:0.2,(:0.3,:0.4):0.5);"), top_node)
Пример #5
0
def test_newick__wikipedia_example_2():
    # leaf nodes are named
    taxa_d = Newick(name="D")
    taxa_c = Newick(name="C")
    taxa_sub = Newick(children=[taxa_c, taxa_d])
    taxa_b = Newick(name="B")
    taxa_a = Newick(name="A")
    top_node = Newick(children=[taxa_a, taxa_b, taxa_sub])
    assert_equal(Newick.from_string("(A,B,(C,D));"), top_node)
Пример #6
0
def test_newick__wikipedia_example_3():
    # all nodes are named
    taxa_d = Newick(name="D")
    taxa_c = Newick(name="C")
    taxa_sub = Newick(children=[taxa_c, taxa_d], name="E")
    taxa_b = Newick(name="B")
    taxa_a = Newick(name="A")
    top_node = Newick(children=[taxa_a, taxa_b, taxa_sub], name="F")
    assert_equal(Newick.from_string("(A,B,(C,D)E)F;"), top_node)
Пример #7
0
def test_newick__wikipedia_example_6():
    # distances and leaf names (popular)
    taxa_d = Newick(length="0.4", name="D")
    taxa_c = Newick(length="0.3", name="C")
    taxa_sub = Newick(children=[taxa_c, taxa_d], length="0.5")
    taxa_b = Newick(length="0.2", name="B")
    taxa_a = Newick(length="0.1", name="A")
    top_node = Newick(children=[taxa_a, taxa_b, taxa_sub])
    assert_equal(Newick.from_string("(A:0.1,B:0.2,(C:0.3,D:0.4):0.5);"),
                 top_node)
Пример #8
0
def test_newick__wikipedia_example_7():
    # distances and all names
    taxa_d = Newick(length="0.4", name="D")
    taxa_c = Newick(length="0.3", name="C")
    taxa_sub = Newick(children=[taxa_c, taxa_d], length="0.5", name="E")
    taxa_b = Newick(length="0.2", name="B")
    taxa_a = Newick(length="0.1", name="A")
    top_node = Newick(children=[taxa_a, taxa_b, taxa_sub], name="F")
    assert_equal(Newick.from_string("(A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5)F;"),
                 top_node)
Пример #9
0
def test_newick__wikipedia_example_8():
    # a tree rooted on a leaf node (rare)
    taxa_b = Newick(length="0.2", name="B")
    taxa_c = Newick(length="0.3", name="C")
    taxa_d = Newick(length="0.4", name="D")
    node_e = Newick(length="0.5", name="E", children=[taxa_c, taxa_d])
    node_f = Newick(length="0.1", name="F", children=[taxa_b, node_e])
    node_a = Newick(name="A", children=[node_f])
    assert_equal(Newick.from_string("((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;"),
                 node_a)
Пример #10
0
def test_newick__str__non_string_length():
    node = Newick(children=[Newick(name="Foo", length=1.3)])
    assert_equal(str(node), "(Foo:1.3);")
Пример #11
0
def test_newick__str__non_string_name():
    node = Newick(children=[Newick(name=17, length="1.3")])
    assert_equal(str(node), "(17:1.3);")
Пример #12
0
def test_newick__get_leaf_nodes__internal_node_returns_leaf_nodes():
    node_a = Newick(name="Leaf A")
    node_b = Newick(name="Leaf B")
    top_node = Newick(children=[node_a, node_b])
    assert_list_equal(top_node.get_leaf_nodes(), [node_a, node_b])
Пример #13
0
def test_newick__cmp__identical_for_empty_string_name():
    node_a = Newick(name="", length=13, children=[Newick(name="B")])
    node_b = Newick(name=None, length=13, children=[Newick(name="B")])
    assert_equal(node_a, node_b)
Пример #14
0
def test_newick__str__single_leaf_should_not_be_followed_by_comma():
    node = Newick(name="A")
    top_node = Newick(children=[node])
    assert_equal(str(top_node), "(A);")
Пример #15
0
def test_newick__parse__three_taxa():
    child_node_1 = Newick(name="A")
    child_node_2 = Newick(name="Bc")
    child_node_3 = Newick(name="DeF")
    top_node = Newick(children=[child_node_1, child_node_2, child_node_3])
    assert_equal(Newick.from_string("(A,Bc,DeF);"), top_node)
Пример #16
0
def test_newick__constructor__children_not_set_in_leaf_nodes():
    node = Newick(name="Leaf")
    assert_equal(node.children, ())
Пример #17
0
def test_newick__constructor__name():
    node = Newick(name="AbC")
    assert_equal(node.name, "AbC")
Пример #18
0
def test_newick__constructor__children_set_in_internal_nodes():
    node = Newick(name="Leaf")
    top_node = Newick(children=[node])
    assert_equal(top_node.children, (node, ))
Пример #19
0
def test_newick__hash__hashable():
    key_a = Newick(name="A", length=13.7, children=[Newick(name="F")])
    key_b = Newick(name="A", length=13.7, children=[Newick(name="F")])
    assert key_b in {key_a: True}
Пример #20
0
 def _not_identical(node_b):
     node_a = Newick(name="A", length=13, children=[Newick(name="B")])
     assert_not_equal(hash(node_a), hash(node_b))
Пример #21
0
def test_newick__constructor__is_leaf_false_for_internal_nodes():
    node = Newick(name="Leaf")
    top_node = Newick(children=[node])
    assert not top_node.is_leaf
Пример #22
0
 def _test_newick__properties_cannot_be_deleted(name):
     node = Newick(name="A", length=3, children=[Newick(name="B")])
     assert_raises(NotImplementedError, delattr, node, name)
Пример #23
0
def test_newick__str__repr_equal_to_str():
    node_a = Newick(name="A", length="123")
    node_b = Newick(name="B", length="4567")
    top_node = Newick(children=[node_a, node_b])
    assert_equal(str(top_node), "(A:123,B:4567);")
Пример #24
0
def test_newick__hash__identical():
    node_a = Newick(name="A", length=13, children=[Newick(name="B")])
    node_b = Newick(name="A", length=13, children=[Newick(name="B")])
    assert_equal(hash(node_a), hash(node_b))
Пример #25
0
 def _test_newick__properties_are_immutable(name, value):
     node = Newick(name="A", length=3, children=[Newick(name="B")])
     assert_raises(NotImplementedError, setattr, node, name, value)
Пример #26
0
def test_newick__parse__two_taxa():
    child_node_1 = Newick(name="A")
    child_node_2 = Newick(name="Bc")
    top_node = Newick(children=[child_node_1, child_node_2])
    assert_equal(Newick.from_string("(A,Bc);"), top_node)
Пример #27
0
def test_newick__get_leaf_nodes__leaf_returns_self():
    node = Newick(name="Leaf")
    assert_list_equal(node.get_leaf_nodes(), [node])
Пример #28
0
def test_newick__constructor__is_leaf_true_for_leaf_nodes():
    node = Newick(name="Another Leaf")
    assert node.is_leaf
Пример #29
0
def test_newick__parse__single_taxa():
    child_node = Newick(name="Ab")
    top_node = Newick(children=[child_node])
    assert_equal(Newick.from_string("(Ab);"), top_node)
Пример #30
0
def test_newick__cmp__identical():
    node_a = Newick(name="A", length=13, children=[Newick(name="B")])
    node_b = Newick(name="A", length=13, children=[Newick(name="B")])
    assert_equal(node_a, node_b)