Example #1
0
    def test_consensus_from_scored_trees_collection_ii(self):
        """strict consensus should handle conflicting trees"""
        sct = ScoredTreeCollection(zip([1]*3, self.unrooted_conflicting_trees))
        ct = sct.getConsensusTrees()[0]
        self.assertTrue(ct.sameTopology(Tree("(a,b,c,d);")))

        sct = ScoredTreeCollection(zip([1]*3, self.rooted_conflicting_trees))
        #cts = sct.getConsensusTrees(method='rooted')
        ct = sct.getConsensusTrees(method='rooted')[0]
        self.assertTrue(ct.sameTopology(Tree("(a,b,c,d);")))
Example #2
0
    def test_consensus_tree_branch_lengths(self):
        """consensus trees should average branch lengths properly"""
        def get_ac(tree):
            for edge in tree.getEdgeVector(include_root=False):
                if set('ac') == set([c.Name for c in edge.Children]):
                    return edge

        sct = ScoredTreeCollection(self.unrooted_trees_lengths)
        ct = sct.getConsensusTree()
        maj_tree = self.unrooted_trees_lengths[0][1]
        self.assertTrue(abs(get_ac(ct).Length-get_ac(maj_tree).Length) < 1e-9)

        sct = ScoredTreeCollection(self.rooted_trees_lengths)
        ct = sct.getConsensusTree(method='rooted')
        maj_tree = self.rooted_trees_lengths[0][1]
        self.assertTrue(abs(get_ac(ct).Length-get_ac(maj_tree).Length) < 1e-9)