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
19 from Residues import *
20
21
23 """Holds information for one SCOP domain
24
25 sid -- SCOP identifier. e.g. d1danl2
26
27 residues -- The domain definition as a Residues object
28
29 sccs -- SCOP concise classification strings. e.g. b.1.2.1
30
31 sunid -- SCOP unique identifier for this domain
32
33 hierarchy -- A sequence of tuples (nodetype, sunid) describing the
34 location of this domain in the SCOP hierarchy.
35 See the Scop module for a description of nodetypes.
36 """
38 self.sid = ''
39 self.residues = None
40 self.sccs = ''
41 self.sunid =''
42 self.hierarchy = []
43 if line:
44 self._process(line)
45
47 line = line.rstrip()
48 columns = line.split('\t')
49 if len(columns) != 6:
50 raise ValueError, "I don't understand the format of %s" % line
51
52 self.sid, pdbid, residues, self.sccs, self.sunid, hierarchy = columns
53 self.residues = Residues(residues)
54 self.residues.pdbid = pdbid
55 self.sunid = int(self.sunid)
56
57 for ht in hierarchy.split(",") :
58 key, value = ht.split('=')
59 value = int(value)
60 self.hierarchy.append([key, value])
61
63 s = []
64 s.append(self.sid)
65 s += str(self.residues).split(" ")
66 s.append(self.sccs)
67 s.append(self.sunid)
68
69 h=[]
70 for ht in self.hierarchy:
71 h.append("=".join(map(str,ht)))
72 s.append(",".join(h))
73
74 return "\t".join(map(str,s)) + "\n"
75
77 """Iterates over a CLA file.
78 """
79 - def __init__(self, handle, parser=None):
80 """Create an object that iterates over a CLA file.
81
82 handle -- file-like object.
83
84 parser -- an optional Parser object to chang the results into
85 another form. If set to None, then the raw contents
86 of the file will be returned.
87
88 """
89 import warnings
90 warnings.warn("Bio.SCOP.Cla.Iterator is deprecated. Please use Bio.SCOP.Cla.parse() instead.", DeprecationWarning)
91 from types import FileType, InstanceType
92 if type(handle) is not FileType and type(handle) is not InstanceType:
93 raise TypeError, "I expected a file handle or file-like object"
94 self._handle = handle
95 self._parser = parser
96
98 """Retrieve the next CLA record."""
99 while 1:
100 line = self._handle.readline()
101 if not line: return None
102 if line[0] !='#': break
103 if self._parser is not None :
104 return self._parser.parse(line)
105 return line
106
108 return iter(self.next, None)
109
110
112 """Parses tab-deliminated CLA records.
113 """
115 import warnings
116 warnings.warn("""Bio.SCOP.Cla.Parser is deprecated.
117 Instead of
118
119 parser = Cla.Parser()
120 record = parser.parse(entry)
121
122 please use
123
124 record = Cla.Record(entry)
125 """, DeprecationWarning)
126
128 """Returns a Cla Record """
129 return Record(entry)
130
131
133 """Iterates over a CLA file, returning a Cla record for each line
134 in the file.
135
136 Arguments:
137
138 handle -- file-like object.
139 """
140 for line in handle:
141 yield Record(line)
142
143
145 """A CLA file indexed by SCOP identifiers, allowing rapid
146 random access into a file."""
148 """
149 Arguments:
150
151 filename -- The file to index
152 """
153 dict.__init__(self)
154 self.filename = filename
155 f = open(self.filename)
156 try:
157 position = 0
158 while True:
159 line = f.readline()
160 if not line: break
161 record = Record(line)
162 key = record.sid
163 if key != None :
164 self[key] = position
165 position = f.tell()
166 finally:
167 f.close()
168
181