Beispiel #1
0
def test_roundtrip(basictrees):
    """Make sure scaling by x and then 1/x changes nothing."""
    heights = Height().consume(basictrees)
    scaled_heights = build_pipeline("scale -s 2.0 | scale -s 0.5 | height",
                                    basictrees)
    for x, y in zip(heights, scaled_heights):
        assert x == y

    lengths = Length().consume(basictrees)
    scaled_lengths = build_pipeline("scale -s 2.0 | scale -s 0.5 | length",
                                    basictrees)
    for x, y in zip(lengths, scaled_lengths):
        assert x == y
Beispiel #2
0
def test_annotation_subtree(basictrees):
    subtrees = build_pipeline(
        "annotate -f tests/argfiles/annotation.csv -k taxon | subtree --attribute f1 --values 0",
        basictrees)
    expected_taxa = (3, 3, 3, 3, 3, 6)
    for t, n in zip(subtrees, expected_taxa):
        assert len(t.get_leaves()) == n

    subtrees = build_pipeline(
        "annotate -f tests/argfiles/annotation.csv -k taxon | subtree --attribute f1 --values 1",
        basictrees)
    taxa = extracted_taxa(subtrees)
    subtrees = build_pipeline(
        "annotate -f tests/argfiles/annotation.csv -k taxon | subtree D E F",
        basictrees)
    assert taxa == extracted_taxa(subtrees)
Beispiel #3
0
def test_categorical_annotation(treefilenewick):
    # This is just to make sure the clade probability calculator doesnt't
    # erroneously try to calculate means etc. of categorical annotations
    list(
        build_pipeline(
            "annotate -f tests/argfiles/categorical_annotation.csv -k taxon | clades",
            treefilenewick('basic.trees')))
Beispiel #4
0
def test_plot_annotated(tmpdir, basictrees, with_ete3):
    annotated_trees = build_pipeline(
        "annotate --f tests/argfiles/annotation.csv -k taxon",
        source=basictrees)
    plot = Plot(output=str(tmpdir.join('test')),
                attribute="f1",
                dummy=not with_ete3)
    list(plot.consume(annotated_trees))
Beispiel #5
0
def test_implicit_source(treefilepath, argfilepath):
    output = build_pipeline(
        "cat -s 2 | rename -f {0} --from old --to new | prune X B | dedupe | uniq | support --sort | stat"
        .format(argfilepath('rename.txt')),
        source=treefilepath("basic.trees"))
    for t in output:
        leaves = t.get_leaf_names()
        assert all((leaves.count(x) == 1 for x in leaves))
        assert "A" not in leaves
        assert "X" not in leaves
        assert "B" not in leaves
        assert all((x in leaves for x in ("C", "D", "E", "F")))
Beispiel #6
0
def test_pipeline(basictrees, argfilepath):
    """Silly long pipeline to stress test build_pipeline."""
    output = build_pipeline(
        "cat -s 2 | rename -f {0} --from old --to new | prune X B | dedupe | uniq | support --sort | stat"
        .format(argfilepath('rename.txt')),
        source=basictrees)
    for t in output:
        leaves = t.get_leaf_names()
        assert all((leaves.count(x) == 1 for x in leaves))
        assert "A" not in leaves
        assert "X" not in leaves
        assert "B" not in leaves
        assert all((x in leaves for x in ("C", "D", "E", "F")))
Beispiel #7
0
def test_extract_annotations(treefile, argfilepath):
    trees = list(NewickParser().consume(treefile('basic.trees')))
    with tempfile.NamedTemporaryFile(mode="r") as fp:
        list(
            build_pipeline(
                "annotate -f {0} -k taxon | annotate --extract -f {1}".format(
                    argfilepath('annotation.csv'), fp.name), trees))
        fp.seek(0)
        reader = csv.DictReader(fp)
        assert all(
            (field in reader.fieldnames for field in ("f1", "f2", "f3")))
        assert "tree_number" not in reader.fieldnames
        for row in reader:
            if row["name"] == "A":
                assert row["f1"] == "0"
                assert row["f2"] == "1"
                assert row["f3"] == "1"
Beispiel #8
0
def test_pretty_compressed_mid_signal(treefilenewick):
    for x in build_pipeline("support | pretty --compress",
                            treefilenewick('mid_signal.trees')):
        assert type(x) == str
Beispiel #9
0
def test_non_leaf_sibling(basictrees):
    siblings = list(build_pipeline("sibling C", source=basictrees))
    assert siblings == ["(A,B)", "A", "(A,B)", "(A,B)", "A", "E"]
Beispiel #10
0
def test_attribute_singleton_collapse(treefilenewick, argfilepath):
    collapsed = build_pipeline(
        "annotate -f {0} -k taxon | collapse --attribute f3".format(argfilepath('annotation.csv')),
        treefilenewick('basic.trees'))
    for t in collapsed:
        assert len(t.get_leaves()) == 6