Пример #1
0
def test_file_prune():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = NewickParser().consume(lines)
    pruned = Prune(filename="tests/argfiles/taxa_abc.txt").consume(trees)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert not any((x in leaves for x in ("A", "B", "C")))
Пример #2
0
def test_inverse_annotation_prune(basictrees):
    annotated = Annotate(filename="tests/argfiles/annotation.csv", key="taxon").consume(basictrees)
    pruned = Prune(attribute="f1", values="0", inverse=True).consume(annotated)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert all((x in leaves for x in ("A", "B", "C")))
        assert not any ((x in leaves for x in ("D", "E", "F")))
Пример #3
0
def test_prune():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = NewickParser().consume(lines)
    pruned = Prune(["A"]).consume(trees)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert "A" not in leaves
        assert all((x in leaves for x in ("B", "C", "D", "E", "F")))
Пример #4
0
def test_inverse_prune():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = NewickParser().consume(lines)
    pruned = Prune(["A", "B"], inverse=True).consume(trees)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert all((x in leaves for x in ("A", "B")))
        assert not any((x in leaves for x in ("C", "D", "E", "F")))
Пример #5
0
def test_annotation_prune():
    lines = fileinput.input("tests/treefiles/basic.trees")
    trees = NewickParser().consume(lines)
    annotated = Annotate(filename="tests/argfiles/annotation.csv", key="taxon").consume(trees)
    pruned = Prune(attribute="f1", value="0").consume(annotated)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert not any((x in leaves for x in ("A", "B", "C")))
Пример #6
0
def test_init_from_args(argfilepath):
    prune = Prune.init_from_args("A,B,C")
    assert prune.opts.filename == None
    assert prune.opts.attribute == None
    assert prune.opts.values == None
    assert prune.opts.inverse == False

    prune = Prune.init_from_args("A,B,C --inverse")
    assert prune.opts.inverse == True

    taxa_abc = argfilepath('taxa_abc.txt')
    prune = Prune.init_from_args("--file {0}".format(taxa_abc))
    assert prune.opts.filename == taxa_abc
    assert prune.opts.attribute == None
    assert prune.opts.values == None

    prune = Prune.init_from_args("--attribute foo --values bar")
    assert prune.opts.filename == None
    assert prune.opts.attribute == "foo"
    assert prune.opts.values == ["bar"]
Пример #7
0
def test_init_from_args():
    prune = Prune.init_from_args("A,B,C")
    assert prune.taxa == set(("A","B","C"))
    assert prune.filename == None
    assert prune.attribute == None
    assert prune.value == None
    assert prune.inverse == False

    prune = Prune.init_from_args("A,B,C --inverse")
    assert prune.inverse == True

    prune = Prune.init_from_args("--file tests/argfiles/taxa_abc.txt")
    assert prune.taxa == set(("A","B","C"))
    assert prune.filename == "tests/argfiles/taxa_abc.txt"
    assert prune.attribute == None
    assert prune.value == None

    prune = Prune.init_from_args("--attribute foo --value bar")
    assert prune.taxa == []
    assert prune.filename == None
    assert prune.attribute == "foo"
    assert prune.value == "bar"
Пример #8
0
def test_bad_init_no_args():
    with pytest.raises(ValueError):
        Prune()
Пример #9
0
def test_bad_init_empty_file(emptyargs):
    with pytest.raises(ValueError):
        Prune(filename=emptyargs)
Пример #10
0
def test_bad_init_no_value_only():
    with pytest.raises(ValueError):
        Prune(value="bar")
Пример #11
0
def test_inverse_prune(basictrees):
    pruned = Prune(taxa=["A", "B"], inverse=True).consume(basictrees)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert all((x in leaves for x in ("A", "B")))
        assert not any((x in leaves for x in ("C", "D", "E", "F")))
Пример #12
0
def test_prune(basictrees):
    pruned = Prune(taxa=["A"]).consume(basictrees)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert "A" not in leaves
        assert all((x in leaves for x in ("B", "C", "D", "E", "F")))
Пример #13
0
def test_bad_init_no_value_only():
    Prune(value="bar")
Пример #14
0
def test_bad_init_empty_file():
    Prune(filename="tests/argfiles/empty.txt")
Пример #15
0
def test_bad_init_no_attribute_only():
    Prune(attribute="foo")
Пример #16
0
def test_bad_init_no_args():
    Prune()
Пример #17
0
def test_bad_init_no_attribute_only():
    with pytest.raises(ValueError):
        Prune(attribute="foo")
Пример #18
0
def test_annotation_prune(basictrees, argfilepath):
    annotated = Annotate(filename=argfilepath("annotation.csv"), key="taxon").consume(basictrees)
    pruned = Prune(attribute="f1", values="0").consume(annotated)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert not any((x in leaves for x in ("A", "B", "C")))
Пример #19
0
def test_file_prune(basictrees):
    pruned = Prune(filename="tests/argfiles/taxa_abc.txt").consume(basictrees)
    for t in pruned:
        leaves = t.get_leaf_names()
        assert not any((x in leaves for x in ("A", "B", "C")))