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