File: test_KEGG.py

package info (click to toggle)
python-biopython 1.78%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 65,756 kB
  • sloc: python: 221,141; xml: 178,777; ansic: 13,369; sql: 1,208; makefile: 131; sh: 70
file content (195 lines) | stat: -rw-r--r-- 7,730 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# Copyright 2001 by Tarjei Mikkelsen.  All rights reserved.
# Revisions copyright 2007 by Michiel de Hoon. All rights reserved.
# Revisions copyright 2017 by Peter Cock. All rights reserved.
# 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.
"""Tests the basic functionality of the KEGG parsers."""

import unittest

from Bio.KEGG import Enzyme
from Bio.KEGG import Compound
from Bio.KEGG import Map
from Bio.Pathway import System


class EnzymeTests(unittest.TestCase):
    """Tests for Bio.KEGG.Enzyme."""

    def test_sample(self):
        """enzyme.sample tests."""
        with open("KEGG/enzyme.sample") as handle:
            records = list(Enzyme.parse(handle))
        self.assertEqual(len(records), 8)
        self.assertEqual(records[0].entry, "1.1.1.1")
        self.assertEqual(
            records[0].name,
            [
                "alcohol dehydrogenase",
                "aldehyde reductase",
                "ADH",
                "alcohol dehydrogenase (NAD)",
                "aliphatic alcohol dehydrogenase",
                "ethanol dehydrogenase",
                "NAD-dependent alcohol dehydrogenase",
                "NAD-specific aromatic alcohol dehydrogenase",
                "NADH-alcohol dehydrogenase",
                "NADH-aldehyde dehydrogenase",
                "primary alcohol dehydrogenase",
                "yeast alcohol dehydrogenase",
            ],
        )
        self.assertEqual(
            records[0].pathway,
            [
                ("PATH", "ec00010", "Glycolysis / Gluconeogenesis"),
                ("PATH", "ec00071", "Fatty acid degradation"),
                ("PATH", "ec00260", "Glycine, serine and threonine metabolism"),
                ("PATH", "ec00350", "Tyrosine metabolism"),
                ("PATH", "ec00592", "alpha-Linolenic acid metabolism"),
                ("PATH", "ec00625", "Chloroalkane and chloroalkene degradation"),
                ("PATH", "ec00626", "Naphthalene degradation"),
                ("PATH", "ec00830", "Retinol metabolism"),
                ("PATH", "ec00980", "Metabolism of xenobiotics by cytochrome P450"),
                ("PATH", "ec00982", "Drug metabolism - cytochrome P450"),
                ("PATH", "ec01100", "Metabolic pathways"),
                ("PATH", "ec01110", "Biosynthesis of secondary metabolites"),
                ("PATH", "ec01120", "Microbial metabolism in diverse environments"),
                ("PATH", "ec01130", "Biosynthesis of antibiotics"),
            ],
        )
        self.assertEqual(
            records[0].dblinks,
            [
                ("ExplorEnz - The Enzyme Database", ["1.1.1.1"]),
                ("IUBMB Enzyme Nomenclature", ["1.1.1.1"]),
                ("ExPASy - ENZYME nomenclature database", ["1.1.1.1"]),
                ("UM-BBD (Biocatalysis/Biodegradation Database)", ["1.1.1.1"]),
                ("BRENDA, the Enzyme Database", ["1.1.1.1"]),
                ("CAS", ["9031-72-5"]),
            ],
        )
        self.assertEqual(records[-1].entry, "2.7.2.1")
        self.assertEqual(
            str(records[-1]).replace(" ", "").split("\n")[:10],
            [
                "ENTRYEC2.7.2.1",
                "NAMEacetatekinase",
                "acetokinase",
                "AckA",
                "AK",
                "acetickinase",
                "acetatekinase(phosphorylating)",
                "CLASSTransferases;",
                "Transferringphosphorus-containinggroups;",
                "Phosphotransferaseswithacarboxygroupasacceptor",
            ],
        )

    def test_irregular(self):
        """enzyme.irregular tests."""
        with open("KEGG/enzyme.irregular") as handle:
            records = list(Enzyme.parse(handle))
        self.assertEqual(len(records), 2)
        self.assertEqual(records[0].entry, "1.14.18.1")
        self.assertEqual(records[-1].entry, "3.4.21.50")

    def test_new(self):
        """enzyme.new tests."""
        with open("KEGG/enzyme.new") as handle:
            records = list(Enzyme.parse(handle))
        self.assertEqual(len(records), 1)
        self.assertEqual(records[0].entry, "6.2.1.25")

    def test_4letter(self):
        """enzyme.4letter tests."""
        with open("KEGG/enzyme.4letter") as handle:
            records = list(Enzyme.parse(handle))
            self.assertEqual(len(records), 1)
        self.assertEqual(records[0].entry, "5.4.2.2")
        self.assertEqual(records[0].genes[0], ("HSA", ["5236", "55276"]))
        self.assertEqual(records[0].genes[8], ("CSAB", ["103224690", "103246223"]))

    def test_exceptions(self):
        """enzyme.exceptions tests."""
        with open("KEGG/enzyme.sample") as handle:
            with self.assertRaises(ValueError) as context:
                list(Enzyme.read(handle))
            self.assertIn(
                "More than one record found in handle", str(context.exception)
            )
            records = Enzyme.parse(handle)
            for i in range(0, 6):
                next(records)
            self.assertRaises(StopIteration, next, records)


class CompoundTests(unittest.TestCase):
    """Bio.KEGG.Compound tests."""

    def test_sample(self):
        """compound.sample tests."""
        with open("KEGG/compound.sample") as handle:
            records = list(Compound.parse(handle))
        self.assertEqual(len(records), 8)
        self.assertEqual(records[1].entry, "C00017")
        self.assertEqual(records[1].mass, "")  # Why?
        self.assertEqual(records[1].formula, "C2H4NO2R(C2H2NOR)n")
        self.assertEqual(records[1].name, ["Protein"])
        self.assertEqual(
            records[1].pathway, [("PATH", "map00450", "Selenocompound metabolism")]
        )
        self.assertEqual(len(records[1].enzyme), 21)
        self.assertEqual(records[1].enzyme[0], ("2.3.2.6"))
        self.assertEqual(records[1].structures, [])
        self.assertEqual(records[1].dblinks[0], ("PubChem", ["3319"]))
        self.assertEqual(
            str(records[-1]).replace(" ", "").split("\n")[:10],
            [
                "ENTRYC01386",
                "NAMENH2Mec",
                "7-Amino-4-methylcoumarin",
                "FORMULAC10H9NO2",
                "DBLINKSCAS:26093-31-2",
                "PubChem:4580",
                "ChEBI:51771",
                "ChEMBL:CHEMBL270672",
                "KNApSAcK:C00048593",
                "PDB-CCD:MCM",
            ],
        )

    def test_irregular(self):
        """compound.irregular tests."""
        with open("KEGG/compound.irregular") as handle:
            records = list(Compound.parse(handle))
        self.assertEqual(len(records), 2)
        self.assertEqual(records[0].entry, "C01454")


class MapTests(unittest.TestCase):
    """Bio.KEGG.Map tests."""

    def test_map00950(self):
        """map00950.rea tests."""
        system = System()
        with open("KEGG/map00950.rea") as handle:
            for reaction in Map.parse(handle):
                system.add_reaction(reaction)
        rxs = system.reactions()
        self.assertEqual(len(rxs), 56)
        # sort the reaction output by the string names, so that the
        # output will be consistent between python versions
        rxs.sort(key=lambda x: str(x))  # noqa: E731
        self.assertEqual(
            str(rxs[0]),
            "(R)-N-Methylcoclaurine + (S)-Coclaurine + NADPH + O2 "
            "<=> 2'-Norberbamunine + 2 H2O + NADP",
        )
        self.assertEqual(str(rxs[-1]), "Tyramine <=> Dopamine")


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