File: test_raxml_tool.py

package info (click to toggle)
python-biopython 1.68%2Bdfsg-3~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 46,856 kB
  • sloc: python: 160,306; xml: 93,216; ansic: 9,118; sql: 1,208; makefile: 155; sh: 63
file content (70 lines) | stat: -rw-r--r-- 2,366 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright (C) 2012 by Eric Talevich.
# This code is part of the Biopython distribution and governed by its
# license. Please see the LICENSE file that should have been included
# as part of this package.

"""Unit tests for Bio.Phylo.Applications wrappers."""

import sys
import os
import unittest

from Bio import Phylo
from Bio.Phylo.Applications import RaxmlCommandline
from Bio import MissingExternalDependencyError

raxml_exe = None
try:
    from Bio._py3k import getoutput
    output = getoutput("raxmlHPC -v")
    if "not found" not in output and "This is RAxML" in output:
        raxml_exe = "raxmlHPC"
except OSError:
    # TODO: Use FileNotFoundError once we drop Python 2
    pass

if not raxml_exe:
    raise MissingExternalDependencyError(
        "Install RAxML (binary raxmlHPC) if you want to test the Bio.Phylo.Applications wrapper.")

# Example Phylip file with 4 aligned protein sequences
EX_PHYLIP = 'Phylip/interlaced2.phy'


class AppTests(unittest.TestCase):
    """Tests for application wrappers."""

    def test_raxml(self):
        """Run RAxML using the wrapper."""
        cmd = RaxmlCommandline(raxml_exe,
                               sequences=EX_PHYLIP, model="PROTCATWAG",
                               name="test")
        # The parsimony seed should be set automatically
        self.assertTrue('-p' in str(cmd))
        # Smoke test
        try:
            out, err = cmd()
            self.assertTrue(len(out) > 0)
            self.assertEqual(len(err), 0)
            # Check the output tree
            tree = Phylo.read('RAxML_result.test', 'newick')
            self.assertEqual(tree.count_terminals(), 4)
        finally:
            # Remove RAxML-generated files, or RAxML will complain bitterly
            # during the next run
            for fname in ['RAxML_info.test',
                          'RAxML_log.test',
                          'RAxML_parsimonyTree.test',
                          'RAxML_result.test',
                          # Present in 7.2.X+  but not 7.0.4:
                          'RAxML_bestTree.test',
                          ]:
                if os.path.isfile(fname):
                    os.remove(fname)


# ---------------------------------------------------------

if __name__ == '__main__':
    runner = unittest.TextTestRunner(verbosity=2)
    unittest.main(testRunner=runner)