Example #1
0
def test_file_collapse():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = list(NewickParser().consume(lines))
    collapsed = Collapse(filename="tests/argfiles/collapse.txt").consume(trees)
    # These groups are monophyletic in the first 5 of the 6 basic trees, so...
    for n, t in enumerate(collapsed):
        assert len(t.get_leaves()) == (2 if n < 5 else 6)
Example #2
0
def test_collapse():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = list(NewickParser().consume(lines))
    collapsed = Collapse({"left":("A","B","C"), "right":("D","E","F")}).consume(trees)
    # These groups are monophyletic in the first 5 of the 6 basic trees, so...
    for n, t in enumerate(collapsed):
        assert len(t.get_leaves()) == (2 if n < 5 else 6)
Example #3
0
def test_attribute_collapse(basictrees):
    annotated = Annotate(
        filename="tests/argfiles/annotation.csv", key="taxon").consume(basictrees)
    # f1 in the annotations applied above corresponds to the same left/right
    # split as the other tests above
    collapsed = Collapse(attribute="f1").consume(annotated)
    # These groups are monophyletic in the first 5 of the 6 basic trees, so...
    for n, t in enumerate(collapsed):
        assert len(t.get_leaves()) == (2 if n < 5 else 6)
Example #4
0
def test_attribute_collapse():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = list(NewickParser().consume(lines))
    annotated = Annotate("tests/argfiles/annotation.csv", "taxon").consume(trees)
    # f1 in the annotations applied above corresponds to the same left/right
    # split as the other tests above
    collapsed = Collapse(attribute="f1").consume(annotated)
    # These groups are monophyletic in the first 5 of the 6 basic trees, so...
    for n, t in enumerate(collapsed):
        assert len(t.get_leaves()) == (2 if n < 5 else 6)
Example #5
0
def test_init():
    collapse = Collapse.init_from_args("--translate tests/argfiles/collapse.txt")
    assert collapse.filename == "tests/argfiles/collapse.txt"

    collapse = Collapse.init_from_args("--attribute collapsibility")
    assert collapse.attribute == "collapsibility"
Example #6
0
def test_attribute_non_collapse():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = list(NewickParser().consume(lines))
    collapsed = Collapse(attribute="foo").consume(trees)
    for t1, t2 in zip(trees, collapsed):
        assert t1.write() == t2.write()
Example #7
0
def test_non_collapse():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = list(NewickParser().consume(lines))
    collapsed = Collapse({"non-existent":("X","Y","Z")}).consume(trees)
    for t1, t2 in zip(trees, collapsed):
        assert t1.write() == t2.write()
Example #8
0
def test_bad_init_no_args():
    Collapse()
Example #9
0
def test_init(argfilepath):
    collapse = Collapse.init_from_args("--translate {0}".format(argfilepath('collapse.txt')))
    assert collapse.opts.filename == argfilepath('collapse.txt')

    collapse = Collapse.init_from_args("--attribute collapsibility")
    assert collapse.opts.attribute == "collapsibility"
Example #10
0
def test_attribute_non_collapse(basictrees):
    trees = list(basictrees)
    collapsed = Collapse(attribute="foo").consume(trees)
    for t1, t2 in zip(trees, collapsed):
        assert t1.write() == t2.write()
Example #11
0
def test_non_collapse(basictrees):
    trees = list(basictrees)
    collapsed = Collapse({"non-existent":("X","Y","Z")}).consume(trees)
    for t1, t2 in zip(trees, collapsed):
        assert t1.write() == t2.write()
Example #12
0
def test_file_collapse(basictrees, argfilepath):
    collapsed = Collapse(filename=argfilepath("collapse.txt")).consume(basictrees)
    # These groups are monophyletic in the first 5 of the 6 basic trees, so...
    for n, t in enumerate(collapsed):
        assert len(t.get_leaves()) == (2 if n < 5 else 6)
Example #13
0
def test_collapse(basictrees):
    collapsed = Collapse(
        clades={"left":("A","B","C"), "right":("D","E","F")}).consume(basictrees)
    # These groups are monophyletic in the first 5 of the 6 basic trees, so...
    for n, t in enumerate(collapsed):
        assert len(t.get_leaves()) == (2 if n < 5 else 6)
Example #14
0
def test_bad_init_no_args():
    with pytest.raises(ValueError):
        Collapse()