File: test_nexus.py

package info (click to toggle)
python-weblogo 3.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,700 kB
  • sloc: xml: 14,455; python: 10,384; sh: 140; makefile: 58
file content (68 lines) | stat: -rwxr-xr-x 1,659 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
#!/usr/bin/env python

import unittest

from weblogo.seq_io._nexus import Nexus

from . import data_stream


class test_nexus(unittest.TestCase):
    def test_create(self) -> None:
        n = Nexus()
        self.assertNotEqual(n, None)

    def test_parse_f0(self) -> None:
        f = data_stream("nexus/test_Nexus_input.nex")
        n = Nexus(f)
        # self.output_basics(n)

        expected = [
            "t1",
            "t2 the name",
            "isn'that [a] strange name?",
            "one should be punished, for (that)!",
            "t5",
            "t6",
            "t7",
            "t8",
            "t9",
        ]
        taxa = n.taxlabels
        self.assertEqual(taxa, expected)
        f.close()

    def test_parse_protein(self) -> None:
        f = data_stream("nexus/protein.nex")
        Nexus(f)
        f.close()

    def test_parse_dna(self) -> None:
        f = data_stream("nexus/dna.nex")
        n = Nexus(f)

        taxa = n.taxlabels
        taxa.sort()
        self.assertEqual(len(taxa), 10)
        self.assertEqual(taxa[0], "Carp")
        self.assertEqual(taxa[-1], "Whale")
        f.close()

    def test_TreeTest1(self) -> None:
        """Test Tree module."""
        f = data_stream("nexus/test_Nexus_input.nex")
        n = Nexus(f)
        t3 = n.trees[2]
        n.trees[2]
        t3.root_with_outgroup(["t1", "t5"])

        # Return node_id of common ancestor if
        # taxon_list is monophyletic, -1 otherwise.
        self.assertEqual(t3.is_monophyletic(["t1", "t5"]), 13)

        t3.split(parent_id=t3.search_taxon("t9"))
        f.close()


if __name__ == "__main__":
    unittest.main()