File: test_SCOP_Cla.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 (90 lines) | stat: -rw-r--r-- 3,408 bytes parent folder | download | duplicates (3)
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
# Copyright 2001 by Gavin E. Crooks.  All rights reserved.
# Modifications Copyright 2010 Jeffrey Finkelstein. 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.

"""Unit test for Cla."""

import unittest

from Bio.SCOP import Cla


class ClaTests(unittest.TestCase):
    def setUp(self):
        self.filename = "./SCOP/dir.cla.scop.txt_test"

    def testParse(self):
        """Test if all records in a CLA file are being read."""
        count = 0
        with open(self.filename) as f:
            records = Cla.parse(f)
            for record in records:
                count += 1
        self.assertEqual(count, 14)

    def testStr(self):
        """Test if we can convert each record to a string correctly."""
        with open(self.filename) as f:
            for line in f:
                record = Cla.Record(line)
                # The SCOP Classification file format which can be found at
                # http://scop.mrc-lmb.cam.ac.uk/scop/release-notes.html states
                # that the list of classification hierarchy key-value pairs is
                # unordered, therefore we need only check that they are all
                # there, NOT that they are in the same order.
                # End of line is platform dependent. Strip it off
                expected_hierarchy = line.rstrip().split("\t")[5].split(",")
                expected_hierarchy = dict(
                    pair.split("=") for pair in expected_hierarchy
                )
                actual_hierarchy = str(record).rstrip().split("\t")[5].split(",")
                actual_hierarchy = dict(pair.split("=") for pair in actual_hierarchy)
                self.assertEqual(len(actual_hierarchy), len(expected_hierarchy))
                for key, actual_value in actual_hierarchy.items():
                    self.assertEqual(actual_value, expected_hierarchy[key])

    def testError(self):
        """Test if a corrupt record raises the appropriate exception."""
        corruptRec = "49268\tsp\tb.1.2.1\t-\n"
        self.assertRaises(ValueError, Cla.Record, corruptRec)

    def testRecord(self):
        """Test one record in detail."""
        recLine = "d1dan.1\t1dan\tT:,U:91-106\tb.1.2.1\t21953\tcl=48724,cf=48725,sf=49265,fa=49266,dm=49267,sp=49268,px=21953"

        record = Cla.Record(recLine)
        self.assertEqual(record.sid, "d1dan.1")
        self.assertEqual(record.residues.pdbid, "1dan")
        self.assertEqual(record.residues.fragments, (("T", "", ""), ("U", "91", "106")))
        self.assertEqual(record.sccs, "b.1.2.1")
        self.assertEqual(record.sunid, 21953)
        self.assertEqual(
            record.hierarchy,
            {
                "cl": 48724,
                "cf": 48725,
                "sf": 49265,
                "fa": 49266,
                "dm": 49267,
                "sp": 49268,
                "px": 21953,
            },
        )

    def testIndex(self):
        """Test CLA file indexing."""
        index = Cla.Index(self.filename)

        self.assertEqual(len(index), 14)
        self.assertIn("d4hbia_", index)

        rec = index["d1hbia_"]
        self.assertEqual(rec.sunid, 14996)


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