示例#1
0
def test_deep_iteration():
    root = t = Tree(0)
    for i in range(1, sys.getrecursionlimit() + 2):
        child = Tree(i)
        t.add_child(child)
        t = child
    list(ipreorder(root))
    list(ipostorder(root))
    list(iupstream(t))
示例#2
0
def test_deep_iteration():
    root = t = Tree(0)
    for i in range(1, sys.getrecursionlimit() + 2):
        child = Tree(i)
        t.add_child(child)
        t = child
    list(ipreorder(root))
    list(ipostorder(root))
    list(iupstream(t))
示例#3
0
def _check_trees(trees):
    for t in trees:
        nt.ok_(len(list(tree.ileaf(t))) == 11)
        nt.ok_(len(list(tree.iforking_point(t))) == 10)
        nt.ok_(len(list(tree.ipreorder(t))) == 211)
        nt.ok_(len(list(tree.ipostorder(t))) == 211)
        nt.ok_(len(list(tree.isegment(t))) == 210)
        leaves = [l for l in tree.ileaf(t)]
        # path length from each leaf to root node.
        branch_order = [21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 111]
        for i, l in enumerate(leaves):
            nt.ok_(len(list(tree.iupstream(l))) == branch_order[i])
示例#4
0
def test_upstream_iteration():

    nt.ok_(list(val_iter(iupstream(REF_TREE))) == [0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[0]))) == [11, 0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[0].children[0]))) == [111, 11, 0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[0].children[1]))) == [112, 11, 0])

    nt.ok_(list(val_iter(iupstream(REF_TREE.children[1]))) == [12, 0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[1].children[0]))) == [121, 12, 0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[1].children[1]))) == [122, 12, 0])
示例#5
0
def _check_trees(trees):
    for t in trees:
        nt.ok_(len(list(tree.ileaf(t))) == 11)
        nt.ok_(len(list(tree.iforking_point(t))) == 10)
        nt.ok_(len(list(tree.ipreorder(t))) == 211)
        nt.ok_(len(list(tree.ipostorder(t))) == 211)
        nt.ok_(len(list(tree.isegment(t))) == 210)
        leaves = [l for l in tree.ileaf(t)]
        # path length from each leaf to root node.
        branch_order = [21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 111]
        for i, l in enumerate(leaves):
            nt.ok_(len(list(tree.iupstream(l))) == branch_order[i])
示例#6
0
def compare_trees(tree1, tree2):
    '''
    Comparison between all the nodes and their respective radii between two trees.
    Ids are do not have to be identical between the trees, and swapping is allowed

    Returns:

        False if the trees are not identical. True otherwise.
    '''
    leaves1 = list(tr.ileaf(tree1))
    leaves2 = list(tr.ileaf(tree2))

    if len(leaves1) != len(leaves2):

        return False

    else:

        nleaves = len(leaves1)

        for leaf1, leaf2 in product(leaves1, leaves2):

            is_equal = True

            for node1, node2 in izip(tr.val_iter(tr.iupstream(leaf1)),
                                     tr.val_iter(tr.iupstream(leaf2))):

                if any(node1[0:5] != node2[0:5]):

                    is_equal = False
                    continue

            if is_equal:
                nleaves -= 1

    return nleaves == 0
示例#7
0
def test_upstream_iteration():

    nt.ok_(list(val_iter(iupstream(REF_TREE))) == [0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[0]))) == [11, 0])
    nt.ok_(
        list(val_iter(iupstream(REF_TREE.children[0].children[0]))) ==
        [111, 11, 0])
    nt.ok_(
        list(val_iter(iupstream(REF_TREE.children[0].children[1]))) ==
        [112, 11, 0])

    nt.ok_(list(val_iter(iupstream(REF_TREE.children[1]))) == [12, 0])
    nt.ok_(
        list(val_iter(iupstream(REF_TREE.children[1].children[0]))) ==
        [121, 12, 0])
    nt.ok_(
        list(val_iter(iupstream(REF_TREE.children[1].children[1]))) ==
        [122, 12, 0])