Ejemplo n.º 1
0
class TestTree(TestCase):
    def setUp(self):
        self.tree = Tree('((a,b),(c,d),e)')
        assert sorted(self.tree.taxa) == list('abcde')

    def test_getDistanceToRoot(self):
        assert self.tree.getDistanceToRoot('a') == 2

    def test_get_LCA(self):
        assert str(self.tree.get_LCA('a', 'b')) == '(a,b);'

    def test_get_distance(self):
        tree_a = Tree('((a:1,b:1):1,(c:1,d:1):1)')
        tree_b = Tree('((a:1,c:1):1,(b:1,d:1):1)')

        assert tree_a.get_distance(tree_b, 'grf') == 1.0
        assert tree_a.get_distance(tree_b, 'rf') == 1.0
        assert tree_a.get_distance(tree_b, 'symmetric') == 2
        assert tree_a.get_distance(tree_b, 'grf') == 1.0

    def test_get_distance_unknown(self):
        """test failure with unknown distance"""
        with self.assertRaises(ValueError):
            Tree('(a,b)').get_distance(Tree('(a,b)'), 'xxx')

    def test_init_from_file(self):
        tree = Tree(test_data('phybo.tre'))
        assert len(tree.taxa) == 40, "should have a taxa attribute and 40 tips"

    def test_init_from_list(self):
        tree = Tree(['Simon', 'Mattis', 'Robert'])
        assert len(tree.taxa) == 3, "should have a taxa attribute and 3 tips"
Ejemplo n.º 2
0
class TestTree(object):

    def setup(self):

        self.tree = Tree('((a,b),(c,d),e)')

        assert sorted(self.tree.taxa) == list('abcde')
    
    def test_getDistanceToRoot(self):

        
        assert self.tree.getDistanceToRoot('a') == 2

    def test_get_LCA(self):

        assert str(self.tree.get_LCA('a','b')) == '(a,b);'

    def test_get_distance(self):

        treeA = Tree('((a:1,b:1):1,(c:1,d:1):1)')
        treeB = Tree('((a:1,c:1):1,(b:1,d:1):1)')

        assert treeA.get_distance(treeB,'grf') == 1.0
        assert treeA.get_distance(treeB,'rf') == 1.0
        assert treeA.get_distance(treeB,'symmetric') == 2
        assert treeA.get_distance(treeB,'grf') == 1.0
Ejemplo n.º 3
0
def test_random_tree():
    taxa = list('abcdefg')

    t1 = Tree(random_tree(taxa, branch_lengths=False))
    t2 = Tree(random_tree(taxa, branch_lengths=True))

    assert sorted(t1.taxa) == sorted(t2.taxa)
    assert str(t1) != str(t2)
    assert ':' in str(t2) and ':' not in str(t1)
Ejemplo n.º 4
0
    def test_get_distance(self):
        tree_a = Tree('((a:1,b:1):1,(c:1,d:1):1)')
        tree_b = Tree('((a:1,c:1):1,(b:1,d:1):1)')

        assert tree_a.get_distance(tree_b, 'grf') == 1.0
        assert tree_a.get_distance(tree_b, 'rf') == 1.0
        assert tree_a.get_distance(tree_b, 'symmetric') == 2
        assert tree_a.get_distance(tree_b, 'grf') == 1.0
Ejemplo n.º 5
0
class TestTree(TestCase):
    def setUp(self):
        self.tree = Tree('((a,b),(c,d),e)')
        assert sorted(self.tree.taxa) == list('abcde')

    def test_getDistanceToRoot(self):
        assert self.tree.getDistanceToRoot('a') == 2

    def test_get_LCA(self):
        assert str(self.tree.get_LCA('a', 'b')) == '(a,b);'

    def test_get_distance(self):
        treeA = Tree('((a:1,b:1):1,(c:1,d:1):1)')
        treeB = Tree('((a:1,c:1):1,(b:1,d:1):1)')

        assert treeA.get_distance(treeB, 'grf') == 1.0
        assert treeA.get_distance(treeB, 'rf') == 1.0
        assert treeA.get_distance(treeB, 'symmetric') == 2
        assert treeA.get_distance(treeB, 'grf') == 1.0
Ejemplo n.º 6
0
 def test_init_from_list(self):
     tree = Tree(['Simon', 'Mattis', 'Robert'])
     assert len(tree.taxa) == 3, "should have a taxa attribute and 3 tips"
Ejemplo n.º 7
0
 def test_init_from_file(self):
     tree = Tree(test_data('phybo.tre'))
     assert len(tree.taxa) == 40, "should have a taxa attribute and 40 tips"
Ejemplo n.º 8
0
 def test_get_distance_unknown(self):
     """test failure with unknown distance"""
     with self.assertRaises(ValueError):
         Tree('(a,b)').get_distance(Tree('(a,b)'), 'xxx')
Ejemplo n.º 9
0
 def setUp(self):
     self.tree = Tree('((a,b),(c,d),e)')
     assert sorted(self.tree.taxa) == list('abcde')
Ejemplo n.º 10
0
def test_nwk2tree_matrix():
    newick = '(((a,b),(c,d)),e);'
    matrix, taxa = tree.nwk2tree_matrix(newick)
    assert taxa == Tree(newick).taxa
Ejemplo n.º 11
0
def test_get_distance_unknown():
    """test failure with unknown distance"""
    with pytest.raises(ValueError):
        Tree('(a,b)').get_distance(Tree('(a,b)'), 'xxx')
Ejemplo n.º 12
0
def tree():
    return Tree('((a,b),(c,d),e)')
Ejemplo n.º 13
0
 def setUp(self):
     WithTempDir.setUp(self)
     self.newick = '(((a,b),(c,d)),e);'
     self.tree = Tree(self.newick)