File: test_SCOP_Cla.py

package info (click to toggle)
python-biopython 1.45-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 18,192 kB
  • ctags: 12,310
  • sloc: python: 83,505; xml: 13,834; ansic: 7,015; cpp: 1,855; sql: 1,144; makefile: 179
file content (105 lines) | stat: -rw-r--r-- 2,652 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
# Copyright 2001 by Gavin E. Crooks.  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
from Bio.SCOP.Residues import Residues

import sys

def run_tests(argv):
    test_suite = testing_suite()
    runner = unittest.TextTestRunner(sys.stdout, verbosity = 2)
    runner.run(test_suite)

def testing_suite():
    return test_suite()




class ClaTests(unittest.TestCase):

    def setUp(self) :
        self.filename = './SCOP/dir.cla.scop.txt_test'

    def testParse(self):
        """Can we parse a CLA file?"""
        f=open(self.filename)
        try: 
            count = 0
            i = Cla.Iterator(f, Cla.Parser())
            while 1 :
                rec = i.next() 
                if rec is None : break
                count +=1
            assert count == 14, "Wrong number of records?!"
        finally:
            f.close()
    
    def testStr(self):
        f = open(self.filename)
        try: 
            p = Cla.Parser()
            i = Cla.Iterator(f)
            while 1 :
                line = i.next() 
                if line is None : break
                rec = p.parse(line)
                #End of line is plateform dependant. Strip it off
                assert str(rec).rstrip() == line.rstrip()
        finally:
            f.close()        

    def testError(self) :
        corruptRec = "49268\tsp\tb.1.2.1\t-\n"
        p = Cla.Parser()

        try:
            rec = p.parse(corruptRec)
            assert False, "Should never get here"
        except ValueError, e :
            pass

    def testRecord(self) :
        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'

        rec = Cla.Parser().parse(recLine)
        assert rec.sid =='d1dan.1'
        assert rec.residues.pdbid =='1dan'
        assert rec.residues.fragments ==(('T','',''),('U','91','106'))
        assert rec.sccs == 'b.1.2.1'
        assert rec.sunid == 21953
        assert rec.hierarchy == [['cl',48724],['cf',48725],['sf',49265],
             ['fa',49266],['dm',49267],['sp',49268],
             ['px',21953]], rec.hierarchy

    def testIndex(self) :
        index = Cla.Index(self.filename)
        
        assert len(index)==14
        assert index.has_key('d4hbia_')

        rec = index['d1hbia_']
        assert rec.sunid == 14996


def test_suite():
    return unittest.makeSuite(ClaTests)


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