Example #1
0
 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))))
Example #2
0
 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])
Example #3
0
 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])
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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)))
Example #7
0
 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)))
Example #8
0
 def test_bioseqs_source ( self ) :
     """
     Test PhyTrees.from_bioseqs() method and len() property.
     """
     infile = 'PhyTrees/f002.trees.newick'
     inrepfile = 'PhyTrees/f002.trees.rep'
     self.assertTrue(os.path.isfile(infile))
     self.assertTrue(os.path.isfile(inrepfile))
     tree_db = PhyTrees.from_phytrees(infile)
     # Check the content of the PhyTrees' object
     self.assertEqual(len(tree_db), len(list(Phylo.parse(infile, 'newick'))))
     # Check the content of the PhyTrees' report
     with open(inrepfile, 'r') as repfile :
         line = repfile.readline().strip() # Num. trees: 9
         self.assertEqual(len(tree_db), int(line[-2:]))
         line = repfile.readline() # History:
         line = repfile.readline().strip() # [First source information]
         source_info = line.split('    ')
         self.assertEqual(tree_db._report[0], tuple(source_info))
Example #9
0
 def test_bioseqs_source(self):
     """
     Test PhyTrees.from_bioseqs() method and len() property.
     """
     infile = 'PhyTrees/f002.trees.newick'
     inrepfile = 'PhyTrees/f002.trees.rep'
     self.assertTrue(os.path.isfile(infile))
     self.assertTrue(os.path.isfile(inrepfile))
     tree_db = PhyTrees.from_phytrees(infile)
     # Check the content of the PhyTrees' object
     self.assertEqual(len(tree_db), len(list(Phylo.parse(infile,
                                                         'newick'))))
     # Check the content of the PhyTrees' report
     with open(inrepfile, 'r') as repfile:
         line = repfile.readline().strip()  # Num. trees: 9
         self.assertEqual(len(tree_db), int(line[-2:]))
         line = repfile.readline()  # History:
         line = repfile.readline().strip()  # [First source information]
         source_info = line.split('    ')
         self.assertEqual(tree_db._report[0], tuple(source_info))
Example #10
0
 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))))