Back to index

python-biopython  1.60
test_phyml_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 PhymlCommandline
00014 from Bio import MissingExternalDependencyError
00015 
00016 #Try to avoid problems when the OS is in another language
00017 os.environ['LANG'] = 'C'
00018 
00019 phyml_exe = None
00020 if sys.platform=="win32":
00021     raise MissingExternalDependencyError(\
00022         "Testing PhyML on Windows not supported yet")
00023 else:
00024     import commands
00025     output = commands.getoutput("phyml -version")
00026     if "not found" not in output and "PhyML v3.0" in output:
00027         phyml_exe = "phyml"
00028 
00029 if not phyml_exe:
00030     raise MissingExternalDependencyError(\
00031         "Install PhyML 3.0 if you want to use the Bio.Phylo.Applications wrapper.")
00032 
00033 
00034 # Example Phylip file with 4 aligned protein sequences
00035 EX_PHYLIP = 'Phylip/interlaced2.phy'
00036 
00037 class AppTests(unittest.TestCase):
00038     """Tests for application wrappers."""
00039 
00040     def test_phyml(self):
00041         """Run PhyML using the wrapper."""
00042         cmd = PhymlCommandline(phyml_exe, input=EX_PHYLIP, datatype='aa')
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(EX_PHYLIP + '_phyml_tree.txt', 'newick')
00050             self.assertEqual(tree.count_terminals(), 4)
00051         finally:
00052             # Clean up generated files
00053             for suffix in ['_phyml_tree.txt', '_phyml_stats.txt']:
00054                 fname = EX_PHYLIP + suffix
00055                 if os.path.isfile(fname):
00056                     os.remove(fname)
00057 
00058 
00059 # ---------------------------------------------------------
00060 
00061 if __name__ == '__main__':
00062     runner = unittest.TextTestRunner(verbosity=2)
00063     unittest.main(testRunner=runner)