1
2
3
4
5
6 """ Handle the SCOP CLAssification file, which describes SCOP domains.
7
8 The file format is described in the scop
9 "release notes.":http://scop.berkeley.edu/release-notes-1.55.html
10 The latest CLA file can be found
11 "elsewhere at SCOP.":http://scop.mrc-lmb.cam.ac.uk/scop/parse/
12
13 "Release 1.55":http://scop.berkeley.edu/parse/dir.cla.scop.txt_1.55 (July 2001)
14
15 """
16
17
18 from types import *
19
20 from Residues import *
21 from FileIndex import FileIndex
22
23
25 """Holds information for one SCOP domain
26
27 sid -- SCOP identifier. e.g. d1danl2
28
29 residues -- The domain definition as a Residues object
30
31 sccs -- SCOP concise classification strings. e.g. b.1.2.1
32
33 sunid -- SCOP unique identifier for this domain
34
35 hierarchy -- A sequence of tuples (nodetype, sunid) describing the
36 location of this domain in the SCOP hierarchy.
37 See the Scop module for a description of nodetypes.
38 """
40 self.sid = ''
41 self.residues = None
42 self.sccs = ''
43 self.sunid =''
44 self.hierarchy = []
45
47 s = []
48 s.append(self.sid)
49 s += str(self.residues).split(" ")
50 s.append(self.sccs)
51 s.append(self.sunid)
52
53 h=[]
54 for ht in self.hierarchy:
55 h.append("=".join(map(str,ht)))
56 s.append(",".join(h))
57
58 return "\t".join(map(str,s)) + "\n"
59
61 """Iterates over a CLA file.
62 """
63 - def __init__(self, handle, parser=None):
64 """Create an object that iterates over a DES file.
65
66 handle -- file-like object.
67
68 parser -- an optional Parser object to chang the results into
69 another form. If set to None, then the raw contents
70 of the file will be returned.
71
72 """
73 if type(handle) is not FileType and type(handle) is not InstanceType:
74 raise TypeError, "I expected a file handle or file-like object"
75 self._handle = handle
76 self._parser = parser
77
79 """Retrieve the next CLA record."""
80 while 1:
81 line = self._handle.readline()
82 if not line: return None
83 if line[0] !='#': break
84 if self._parser is not None :
85 return self._parser.parse(line)
86 return line
87
89 return iter(self.next, None)
90
91
93 """Parses tab-deliminated CLA records.
94 """
96 """Returns a Cla Record """
97 entry = entry.rstrip()
98 columns = entry.split('\t')
99 if len(columns) != 6:
100 raise SyntaxError, "I don't understand the format of %s" % entry
101
102 rec = Record()
103 rec.sid, pdbid, residues, rec.sccs, rec.sunid, hierarchy = columns
104 rec.residues = Residues(residues)
105 rec.residues.pdbid = pdbid
106 rec.sunid = int(rec.sunid)
107
108 h = []
109 for ht in hierarchy.split(",") :
110 h.append( ht.split('='))
111 for ht in h:
112 ht[1] = int(ht[1])
113 rec.hierarchy = h
114
115
116 return rec
117
118
120 """A CLA file indexed by SCOP identifiers."""
126