Esempio n. 1
0
 def test_majority_consensus(self):
     ref_trees = Phylo.parse('./TreeConstruction/majority_ref.tre', 'newick')
     ref_tree = next(ref_trees)
     consensus_tree = Consensus.majority_consensus(self.trees)
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_tree))
     ref_tree = next(ref_trees)
     consensus_tree = Consensus.majority_consensus(self.trees, 1)
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_tree))
 def test_majority_consensus(self):
     ref_trees = Phylo.parse('./TreeConstruction/majority_ref.tre', 'newick')
     ref_tree = next(ref_trees)
     consensus_tree = Consensus.majority_consensus(self.trees)
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_tree))
     ref_tree = next(ref_trees)
     consensus_tree = Consensus.majority_consensus(self.trees, 1)
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_tree))
Esempio n. 3
0
 def test_majority_consensus(self):
     # three trees
     # ref_tree = open('./TreeConstruction/majority_ref.tre')
     ref_tree = list(Phylo.parse("./TreeConstruction/majority_ref.tre", "newick"))
     consensus_tree = Consensus.majority_consensus(self.trees)
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_tree[0]))
     consensus_tree = Consensus.majority_consensus(self.trees, 1)
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_tree[1]))
Esempio n. 4
0
 def test_majority_consensus(self):
     ref_trees = Phylo.parse("./TreeConstruction/majority_ref.tre", "newick")
     ref_tree = next(ref_trees)
     consensus_tree = Consensus.majority_consensus(self.trees)
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_tree))
     # ref_tree = next(ref_trees)
     # consensus_tree_mcmc = Consensus.majority_consensus(self.mcmc_trees, mcmc=True)
     # self.assertTrue(Consensus._equal_topology(consensus_tree_mcmc, ref_tree))
     ref_tree = next(ref_trees)
     consensus_tree = Consensus.majority_consensus(self.trees, 1)
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_tree))
     consensus_tree_mcmc = Consensus.majority_consensus(self.mcmc_trees, 1, mcmc=True)
     self.assertTrue(Consensus._equal_topology(consensus_tree_mcmc, ref_tree))
Esempio n. 5
0
 def test_built_tree(self):
     tree = self.constructor.build_tree(self.aln)
     self.assertTrue(isinstance(tree, BaseTree.Tree))
     # tree_file = StringIO()
     # Phylo.write(tree, tree_file, 'newick')
     ref_tree = Phylo.read('./TreeConstruction/nj.tre', 'newick')
     self.assertTrue(Consensus._equal_topology(tree, ref_tree))
 def test_built_tree(self):
     tree = self.constructor.build_tree(self.aln)
     self.assertTrue(isinstance(tree, BaseTree.Tree))
     # tree_file = StringIO()
     # Phylo.write(tree, tree_file, 'newick')
     ref_tree = Phylo.read('./TreeConstruction/nj.tre', 'newick')
     self.assertTrue(Consensus._equal_topology(tree, ref_tree))
Esempio n. 7
0
 def test_upgma(self):
     tree = self.constructor.upgma(self.dm)
     self.assertTrue(isinstance(tree, BaseTree.Tree))
     # tree_file = StringIO()
     # Phylo.write(tree, tree_file, 'newick')
     ref_tree = Phylo.read("./TreeConstruction/upgma.tre", "newick")
     self.assertTrue(Consensus._equal_topology(tree, ref_tree))
Esempio n. 8
0
 def test_strict_consensus(self):
     ref_trees = list(Phylo.parse('./TreeConstruction/strict_refs.tre', 'newick'))
     # three trees
     consensus_tree = Consensus.strict_consensus(self.trees)
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[0]))
     # tree 1 and tree 2
     consensus_tree = Consensus.strict_consensus(self.trees[:2])
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[1]))
     # tree 1 and tree 3
     consensus_tree = Consensus.strict_consensus(self.trees[::2])
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[2]))
 def test_strict_consensus(self):
     ref_trees = list(Phylo.parse('./TreeConstruction/strict_refs.tre', 'newick'))
     # three trees
     consensus_tree = Consensus.strict_consensus(self.trees)
     #tree_file = StringIO()
     #Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[0]))
     # tree 1 and tree 2
     consensus_tree = Consensus.strict_consensus(self.trees[:2])
     #tree_file = StringIO()
     #Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[1]))
     # tree 1 and tree 3
     consensus_tree = Consensus.strict_consensus(self.trees[::2])
     #tree_file = StringIO()
     #Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[2]))
Esempio n. 10
0
 def test_adam_consensus(self):
     # ref_trees = open('./TreeConstruction/adam_refs.tre')
     ref_trees = list(Phylo.parse("./TreeConstruction/adam_refs.tre", "newick"))
     # three trees
     consensus_tree = Consensus.adam_consensus(self.trees)
     # tree_file = '/home/yeyanbo/adam.tres'
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[0]))
     # tree 1 and tree 2
     consensus_tree = Consensus.adam_consensus(self.trees[:2])
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[1]))
     # tree 1 and tree 3
     consensus_tree = Consensus.adam_consensus(self.trees[::2])
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[2]))
Esempio n. 11
0
    def test_nj(self):
        tree = self.constructor.nj(self.dm)
        self.assertTrue(isinstance(tree, BaseTree.Tree))
        # tree_file = StringIO()
        # Phylo.write(tree, tree_file, 'newick')
        ref_tree = Phylo.read("./TreeConstruction/nj.tre", "newick")
        self.assertTrue(Consensus._equal_topology(tree, ref_tree))
        # ref_tree.close()

        # create a matrix of length 2
        calculator = DistanceCalculator("blosum62")
        self.min_dm = calculator.get_distance(self.aln)
        for i in range(len(self.min_dm) - 2):
            del self.min_dm[len(self.min_dm) - 1]

        min_tree = self.constructor.nj(self.min_dm)
        self.assertTrue(isinstance(min_tree, BaseTree.Tree))

        ref_min_tree = Phylo.read("./TreeConstruction/nj_min.tre", "newick")
        self.assertTrue(Consensus._equal_topology(min_tree, ref_min_tree))
Esempio n. 12
0
    def test_nj(self):
        tree = self.constructor.nj(self.dm)
        self.assertTrue(isinstance(tree, BaseTree.Tree))
        # tree_file = StringIO()
        # Phylo.write(tree, tree_file, 'newick')
        ref_tree = Phylo.read('./TreeConstruction/nj.tre', 'newick')
        self.assertTrue(Consensus._equal_topology(tree, ref_tree))
        # ref_tree.close()

        # create a matrix of length 2
        calculator = DistanceCalculator('blosum62')
        self.min_dm = calculator.get_distance(self.aln)
        for i in range(len(self.min_dm) - 2):
            del self.min_dm[len(self.min_dm) - 1]

        min_tree = self.constructor.nj(self.min_dm)
        self.assertTrue(isinstance(min_tree, BaseTree.Tree))

        ref_min_tree = Phylo.read('./TreeConstruction/nj_min.tre', 'newick')
        self.assertTrue(Consensus._equal_topology(min_tree, ref_min_tree))
Esempio n. 13
0
 def test_adam_consensus(self):
     ref_trees = list(Phylo.parse("./TreeConstruction/adam_refs.tre", "newick"))
     # three trees
     consensus_tree = Consensus.adam_consensus(self.trees)
     # tree_file = '/home/yeyanbo/adam.tres'
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[0]))
     consensus_tree_mcmc = Consensus.adam_consensus(self.mcmc_trees, mcmc=True)
     self.assertTrue(Consensus._equal_topology(consensus_tree_mcmc, ref_trees[0]))
     # tree 1 and tree 2
     consensus_tree = Consensus.adam_consensus(self.trees[:2])
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[1]))
     consensus_tree_mcmc = Consensus.adam_consensus(self.mcmc_trees[:2], mcmc=True)
     # tree 1 and tree 3
     consensus_tree = Consensus.adam_consensus(self.trees[::2])
     # tree_file = StringIO()
     # Phylo.write(consensus_tree, tree_file, 'newick')
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[2]))
Esempio n. 14
0
 def test_maximum_clade_probability_consensus(self):
     ref_trees = list(Phylo.parse("./TreeConstruction/maximum_clade_probability_ref.tre", "newick"))
     consensus_tree = Consensus.maximum_clade_probability_consensus(self.trees)[0]
     self.assertTrue(Consensus._equal_topology(consensus_tree, ref_trees[0]))
     consensus_tree_mcmc = Consensus.maximum_clade_probability_consensus(self.mcmc_trees, mcmc=True)[0]
     self.assertTrue(Consensus._equal_topology(consensus_tree_mcmc, ref_trees[0]))