1
2
3
4
5
6
7 """
8 This module provides code to work with the KEGG Enzyme database.
9
10
11 Classes:
12 Record -- Holds the information from a KEGG Enzyme record.
13 """
14
15 from Bio.KEGG import _write_kegg
16 from Bio.KEGG import _wrap_kegg
17
18
19
20 rxn_wrap = [0, "",
21 (" + ","",1,1),
22 (" = ","",1,1),
23 (" ","$",1,1),
24 ("-","$",1,1)]
25 name_wrap = [0, "",
26 (" ","$",1,1),
27 ("-","$",1,1)]
28 id_wrap = lambda indent : [indent, "",
29 (" ","",1,0)]
30 struct_wrap = lambda indent : [indent, "",
31 (" ","",1,1)]
32
34 """Holds info from a KEGG Enzyme record.
35
36 Members:
37 entry The EC number (withou the 'EC ').
38 name A list of the enzyme names.
39 classname A list of the classification terms.
40 sysname The systematic name of the enzyme.
41 reaction A list of the reaction description strings.
42 substrate A list of the substrates.
43 product A list of the products.
44 inhibitor A list of the inhibitors.
45 cofactor A list of the cofactors.
46 effector A list of the effectors.
47 comment A list of the comment strings.
48 pathway A list of 3-tuples: (database, id, pathway)
49 genes A list of 2-tuples: (organism, list of gene ids)
50 disease A list of 3-tuples: (database, id, disease)
51 structures A list of 2-tuples: (database, list of struct ids)
52 dblinks A list of 2-tuples: (database, list of db ids)
53 """
55 """__init___(self)
56
57 Create a new Record.
58 """
59 self.entry = ""
60 self.name = []
61 self.classname = []
62 self.sysname = []
63 self.reaction = []
64 self.substrate = []
65 self.product = []
66 self.inhibitor = []
67 self.cofactor = []
68 self.effector = []
69 self.comment = []
70 self.pathway = []
71 self.genes = []
72 self.disease = []
73 self.structures = []
74 self.dblinks = []
98 return _write_kegg("ENTRY",
99 ["EC " + self.entry])
141 s = []
142 for entry in self.pathway:
143 s.append(entry[0] + ": " + entry[1] + " " + entry[2])
144 return _write_kegg("PATHWAY",
145 [_wrap_kegg(l, wrap_rule = id_wrap(16)) \
146 for l in s])
169
170
171
172
173 s = []
174 for entry in self.dblinks:
175 s.append(entry[0] + ": " + " ".join(entry[1]))
176 return _write_kegg("DBLINKS", s)
177
178
179
181 record = Record()
182 for line in handle:
183 if line[:3]=="///":
184 yield record
185 record = Record()
186 continue
187 if line[:12]!=" ":
188 keyword = line[:12]
189 data = line[12:].strip()
190 if keyword=="ENTRY ":
191 words = data.split()
192 record.entry = words[1]
193 elif keyword=="CLASS ":
194 record.classname.append(data)
195 elif keyword=="COFACTOR ":
196 record.cofactor.append(data)
197 elif keyword=="COMMENT ":
198 record.comment.append(data)
199 elif keyword=="DBLINKS ":
200 if ":" in data:
201 key, values = data.split(":")
202 values = values.split()
203 row = (key, values)
204 record.dblinks.append(row)
205 else:
206 row = record.dblinks[-1]
207 key, values = row
208 values.extend(data.split())
209 row = key, values
210 record.dblinks[-1] = row
211 elif keyword=="DISEASE ":
212 if ":" in data:
213 database, data = data.split(":")
214 number, name = data.split(None, 1)
215 row = (database, number, name)
216 record.disease.append(row)
217 else:
218 row = record.disease[-1]
219 database, number, name = row
220 name = name + " " + data
221 row = database, number, name
222 record.disease[-1] = row
223 elif keyword=="EFFECTOR ":
224 record.effector.append(data.strip(";"))
225 elif keyword=="GENES ":
226 if data[3:5]==': ':
227 key, values = data.split(":")
228 values = [value.split("(")[0] for value in values.split()]
229 row = (key, values)
230 record.genes.append(row)
231 else:
232 row = record.genes[-1]
233 key, values = row
234 for value in data.split():
235 value = value.split("(")[0]
236 values.append(value)
237 row = key, values
238 record.genes[-1] = row
239 elif keyword=="INHIBITOR ":
240 record.inhibitor.append(data.strip(";"))
241 elif keyword=="NAME ":
242 record.name.append(data.strip(";"))
243 elif keyword=="PATHWAY ":
244 if data[:5]=='PATH:':
245 path, map, name = data.split(None,2)
246 pathway = (path[:-1], map, name)
247 record.pathway.append(pathway)
248 else:
249 pathway = record.pathway[-1]
250 path, map, name = pathway
251 name = name + " " + data
252 pathway = path, map, name
253 record.pathway[-1] = pathway
254 elif keyword=="PRODUCT ":
255 record.product.append(data.strip(";"))
256 elif keyword=="REACTION ":
257 record.reaction.append(data.strip(";"))
258 elif keyword=="STRUCTURES ":
259 if data[:4]=='PDB:':
260 database = data[:3]
261 accessions = data[4:].split()
262 row = (database, accessions)
263 record.structures.append(row)
264 else:
265 row = record.structures[-1]
266 database, accessions = row
267 accessions.extend(data.split())
268 row = (database, accessions)
269 record.structures[-1] = row
270 elif keyword=="SUBSTRATE ":
271 record.substrate.append(data.strip(";"))
272 elif keyword=="SYSNAME ":
273 record.sysname.append(data.strip(";"))
274
276 """Iterator to read a file of KEGG Enzyme entries one at a time.
277 """
278 - def __init__(self, handle, parser = None):
279 """Initialize the iterator.
280
281 Arguments:
282 o handle - A handle with Enzyme entries to iterate through.
283 o parser - An optional parser to pass the entries through before
284 returning them. If None, then the raw entry will be returned.
285 """
286 import warnings
287 warnings.warn("Bio.KEGG.Compound.Iterator(handle, parser) is deprecated. Please use Bio.KEGG.Compound.parse(handle) instead. It also returns an iterator.",
288 DeprecationWarning)
289 self.records = parse(handle)
290
292 """Return the next KEGG Enzyme record from the handle.
293
294 Will return None if we ran out of records.
295 """
296 return self.records.next()
297
299 return iter(self.next, None)
300