Back to index

python-biopython  1.60
test_raxml_tool.py
Go to the documentation of this file.
00001 # Copyright (C) 2012 by Eric Talevich.
00002 # This code is part of the Biopython distribution and governed by its
00003 # license. Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 """Unit tests for Bio.Phylo.Applications wrappers."""
00007 
00008 import sys
00009 import os
00010 import unittest
00011 
00012 from Bio import Phylo
00013 from Bio.Phylo.Applications import RaxmlCommandline
00014 from Bio import MissingExternalDependencyError
00015 
00016 raxml_exe = None
00017 if sys.platform=="win32":
00018     raise MissingExternalDependencyError(\
00019           "Testing RAxML on Windows not supported yet")
00020 else:
00021     import commands
00022     output = commands.getoutput("raxmlHPC -v")
00023     if "not found" not in output and "This is RAxML" in output:
00024         raxml_exe = "raxmlHPC"
00025 if not raxml_exe:
00026     raise MissingExternalDependencyError(\
00027         "Install RAxML (binary raxmlHPC) if you want to test the Bio.Phylo.Applications wrapper.")
00028 
00029                                 
00030 # Example Phylip file with 4 aligned protein sequences
00031 EX_PHYLIP = 'Phylip/interlaced2.phy'
00032 
00033 class AppTests(unittest.TestCase):
00034     """Tests for application wrappers."""
00035 
00036     def test_raxml(self):
00037         """Run RAxML using the wrapper."""
00038         cmd = RaxmlCommandline(raxml_exe,
00039                                sequences=EX_PHYLIP, model="PROTCATWAG",
00040                                name="test")
00041         # The parsimony seed should be set automatically
00042         self.assert_('-p' in str(cmd))
00043         # Smoke test
00044         try:
00045             out, err = cmd()
00046             self.assert_(len(out) > 0)
00047             self.assert_(len(err) == 0)
00048             # Check the output tree
00049             tree = Phylo.read('RAxML_result.test', 'newick')
00050             self.assertEqual(tree.count_terminals(), 4)
00051         finally:
00052             # Remove RAxML-generated files, or RAxML will complain bitterly
00053             # during the next run
00054             for fname in ['RAxML_info.test',
00055                           'RAxML_log.test',
00056                           'RAxML_parsimonyTree.test',
00057                           'RAxML_result.test',
00058                           # Present in 7.2.X+  but not 7.0.4:
00059                           'RAxML_bestTree.test',
00060                          ]:
00061                 if os.path.isfile(fname):
00062                     os.remove(fname)
00063 
00064 
00065 # ---------------------------------------------------------
00066 
00067 if __name__ == '__main__':
00068     runner = unittest.TextTestRunner(verbosity=2)
00069     unittest.main(testRunner=runner)