def test_treefile_source(self):
     """
     Test PhyTrees.from_treefile() and PhyTrees.write() methods.
     """
     infile = 'Newick/f002.trees.newick'
     self.assertTrue(os.path.isfile(infile))
     tree_db = PhyTrees.from_treefile(infile, 'newick')
     outfile = 'tmp_test.newick'
     outrepfile = 'tmp_test.rep'
     self.files_to_clean.add(outfile)
     self.files_to_clean.add(outrepfile)
     tree_db.write(outfile)
     self.assertTrue(os.path.isfile(outfile))
     # Check the content of both sequence files
     self.assertEqual(len(list(Phylo.parse(infile, 'newick'))),
                      len(list(Phylo.parse(outfile, 'newick'))))
     # Check the content of the report file
     with open(outrepfile, 'r') as repfile:
         for line in repfile.readlines():
             self.assertTrue(
                 ('Num. trees: 9' in line) or ('History:' in line) or (bool(
                     re.match(
                         r"""\d\d\d\d/\d\d/\d\d\ \d\d:\d\d:\d\d[ ]+
                                    [ ]+.*Tests/Newick/f002\.trees\.newick
                                    \ +newick""", line, re.VERBOSE))))
 def test_join ( self ) :
     """
     Test PhyTrees.join() method.
     """
     infile1 = 'Newick/f002.trees.newick'
     infile2 = 'Nexus/f005.trees.nexus'
     self.assertTrue(os.path.isfile(infile1))
     self.assertTrue(os.path.isfile(infile2))
     tree_db = PhyTrees.from_treefile(infile1, 'newick')
     extra_db = PhyTrees.from_treefile(infile2, 'nexus')
     tree_db.join(extra_db)
     # Check the sequence data
     inlist1 = [tree  for tree in Phylo.parse(infile1, 'newick')]
     inlist2 = [tree  for tree in Phylo.parse(infile2, 'nexus')]
     self.assertEqual(len(inlist1) + len(inlist2), len(tree_db))
     # Check the report information
     self.assertIn('Tests/Newick/f002.trees.newick', tree_db._report[0][1])
     self.assertIn('newick', tree_db._report[0][2])
     self.assertIn('Tests/Nexus/f005.trees.nexus', tree_db._report[1][1])
     self.assertIn('nexus', tree_db._report[1][2])
 def test_join(self):
     """
     Test PhyTrees.join() method.
     """
     infile1 = 'Newick/f002.trees.newick'
     infile2 = 'Nexus/f005.trees.nexus'
     self.assertTrue(os.path.isfile(infile1))
     self.assertTrue(os.path.isfile(infile2))
     tree_db = PhyTrees.from_treefile(infile1, 'newick')
     extra_db = PhyTrees.from_treefile(infile2, 'nexus')
     tree_db.join(extra_db)
     # Check the sequence data
     inlist1 = [tree for tree in Phylo.parse(infile1, 'newick')]
     inlist2 = [tree for tree in Phylo.parse(infile2, 'nexus')]
     self.assertEqual(len(inlist1) + len(inlist2), len(tree_db))
     # Check the report information
     self.assertIn('Tests/Newick/f002.trees.newick', tree_db._report[0][1])
     self.assertIn('newick', tree_db._report[0][2])
     self.assertIn('Tests/Nexus/f005.trees.nexus', tree_db._report[1][1])
     self.assertIn('nexus', tree_db._report[1][2])
 def test_statistics ( self ) :
     """
     Test PhyTrees.statistics() method.
     """
     infile = 'Newick/f002.trees.newick'
     self.assertTrue(os.path.isfile(infile))
     tree_db = PhyTrees.from_treefile(infile, 'newick')
     nseqs, mean, minimum, maximum = tree_db.statistics()
     # Check the resultant values
     self.assertEqual(nseqs, len(tree_db))
     self.assertEqual(mean, 10.0)
     self.assertEqual(minimum, 10)
     self.assertEqual(maximum, 10)
 def test_statistics(self):
     """
     Test PhyTrees.statistics() method.
     """
     infile = 'Newick/f002.trees.newick'
     self.assertTrue(os.path.isfile(infile))
     tree_db = PhyTrees.from_treefile(infile, 'newick')
     nseqs, mean, minimum, maximum = tree_db.statistics()
     # Check the resultant values
     self.assertEqual(nseqs, len(tree_db))
     self.assertEqual(mean, 10.0)
     self.assertEqual(minimum, 10)
     self.assertEqual(maximum, 10)
 def test_str ( self ) :
     """
     Test str() property.
     """
     infile = 'Newick/f002.trees.newick'
     self.assertTrue(os.path.isfile(infile))
     tree_db = PhyTrees.from_treefile(infile, 'newick')
     outstr = str(tree_db)
     # Check the output string
     lines = outstr.split('\n')
     self.assertEqual(lines[0], 'Num. trees: 9')
     self.assertEqual(lines[1], 'History:')
     self.assertTrue(bool(re.match(r"""\d\d\d\d/\d\d/\d\d\ \d\d:\d\d:\d\d[ ]+
         [ ]+.*Tests/Newick/f002\.trees\.newick[ ]+newick""", lines[2],
         re.VERBOSE)))
 def test_str(self):
     """
     Test str() property.
     """
     infile = 'Newick/f002.trees.newick'
     self.assertTrue(os.path.isfile(infile))
     tree_db = PhyTrees.from_treefile(infile, 'newick')
     outstr = str(tree_db)
     # Check the output string
     lines = outstr.split('\n')
     self.assertEqual(lines[0], 'Num. trees: 9')
     self.assertEqual(lines[1], 'History:')
     self.assertTrue(
         bool(
             re.match(
                 r"""\d\d\d\d/\d\d/\d\d\ \d\d:\d\d:\d\d[ ]+
         [ ]+.*Tests/Newick/f002\.trees\.newick[ ]+newick""", lines[2],
                 re.VERBOSE)))
 def test_treefile_source ( self ) :
     """
     Test PhyTrees.from_treefile() and PhyTrees.write() methods.
     """
     infile = 'Newick/f002.trees.newick'
     self.assertTrue(os.path.isfile(infile))
     tree_db = PhyTrees.from_treefile(infile, 'newick')
     outfile = 'tmp_test.newick'
     outrepfile = 'tmp_test.rep'
     self.files_to_clean.add(outfile)
     self.files_to_clean.add(outrepfile)
     tree_db.write(outfile)
     self.assertTrue(os.path.isfile(outfile))
     # Check the content of both sequence files
     self.assertEqual(len(list(Phylo.parse(infile, 'newick'))),
                      len(list(Phylo.parse(outfile, 'newick'))))
     # Check the content of the report file
     with open(outrepfile, 'r') as repfile :
         for line in repfile.readlines() :
             self.assertTrue(('Num. trees: 9' in line) or
                 ('History:' in line) or
                 (bool(re.match(r"""\d\d\d\d/\d\d/\d\d\ \d\d:\d\d:\d\d[ ]+
                                    [ ]+.*Tests/Newick/f002\.trees\.newick
                                    \ +newick""", line, re.VERBOSE))))