Package Bio :: Package KEGG :: Package Enzyme
[hide private]
[frames] | no frames]

Source Code for Package Bio.KEGG.Enzyme

  1  # Copyright 2001 by Tarjei Mikkelsen.  All rights reserved. 
  2  # Copyright 2007 by Michiel de Hoon.  All rights reserved. 
  3  # This code is part of the Biopython distribution and governed by its 
  4  # license.  Please see the LICENSE file that should have been included 
  5  # as part of this package. 
  6   
  7  """Code to work with the KEGG Enzyme database. 
  8   
  9  Functions: 
 10  parse - Returns an iterator giving Record objects. 
 11   
 12  Classes: 
 13  Record               -- Holds the information from a KEGG Enzyme record. 
 14  """ 
 15   
 16  from __future__ import print_function 
 17   
 18  from Bio.KEGG import _write_kegg 
 19  from Bio.KEGG import _wrap_kegg 
 20   
 21   
 22  # Set up line wrapping rules (see Bio.KEGG._wrap_kegg) 
 23  rxn_wrap = [0, "", 
 24              (" + ", "", 1, 1), 
 25              (" = ", "", 1, 1), 
 26              (" ", "$", 1, 1), 
 27              ("-", "$", 1, 1)] 
 28  name_wrap = [0, "", 
 29               (" ", "$", 1, 1), 
 30               ("-", "$", 1, 1)] 
 31  id_wrap = lambda indent: [indent, "", (" ", "", 1, 0)] 
 32  struct_wrap = lambda indent: [indent, "", ("  ", "", 1, 1)] 
 33   
 34   
35 -class Record(object):
36 """Holds info from a KEGG Enzyme record. 37 38 Members: 39 entry The EC number (withou the 'EC '). 40 name A list of the enzyme names. 41 classname A list of the classification terms. 42 sysname The systematic name of the enzyme. 43 reaction A list of the reaction description strings. 44 substrate A list of the substrates. 45 product A list of the products. 46 inhibitor A list of the inhibitors. 47 cofactor A list of the cofactors. 48 effector A list of the effectors. 49 comment A list of the comment strings. 50 pathway A list of 3-tuples: (database, id, pathway) 51 genes A list of 2-tuples: (organism, list of gene ids) 52 disease A list of 3-tuples: (database, id, disease) 53 structures A list of 2-tuples: (database, list of struct ids) 54 dblinks A list of 2-tuples: (database, list of db ids) 55 """
56 - def __init__(self):
57 """__init___(self) 58 59 Create a new Record. 60 """ 61 self.entry = "" 62 self.name = [] 63 self.classname = [] 64 self.sysname = [] 65 self.reaction = [] 66 self.substrate = [] 67 self.product = [] 68 self.inhibitor = [] 69 self.cofactor = [] 70 self.effector = [] 71 self.comment = [] 72 self.pathway = [] 73 self.genes = [] 74 self.disease = [] 75 self.structures = [] 76 self.dblinks = []
77
78 - def __str__(self):
79 """__str__(self) 80 81 Returns a string representation of this Record. 82 """ 83 return self._entry() + \ 84 self._name() + \ 85 self._classname() + \ 86 self._sysname() + \ 87 self._reaction() + \ 88 self._substrate() + \ 89 self._product() + \ 90 self._inhibitor() + \ 91 self._cofactor() + \ 92 self._effector() + \ 93 self._comment() + \ 94 self._pathway() + \ 95 self._genes() + \ 96 self._disease() + \ 97 self._structures() + \ 98 self._dblinks() + \ 99 "///"
100
101 - def _entry(self):
102 return _write_kegg("ENTRY", 103 ["EC " + self.entry])
104
105 - def _name(self):
106 return _write_kegg("NAME", 107 [_wrap_kegg(l, wrap_rule=name_wrap) 108 for l in self.name])
109
110 - def _classname(self):
111 return _write_kegg("CLASS", 112 self.classname)
113
114 - def _sysname(self):
115 return _write_kegg("SYSNAME", 116 [_wrap_kegg(l, wrap_rule=name_wrap) 117 for l in self.sysname])
118
119 - def _reaction(self):
120 return _write_kegg("REACTION", 121 [_wrap_kegg(l, wrap_rule=rxn_wrap) 122 for l in self.reaction])
123
124 - def _substrate(self):
125 return _write_kegg("SUBSTRATE", 126 [_wrap_kegg(l, wrap_rule=name_wrap) 127 for l in self.substrate])
128
129 - def _product(self):
130 return _write_kegg("PRODUCT", 131 [_wrap_kegg(l, wrap_rule=name_wrap) 132 for l in self.product])
133
134 - def _inhibitor(self):
135 return _write_kegg("INHIBITOR", 136 [_wrap_kegg(l, wrap_rule=name_wrap) 137 for l in self.inhibitor])
138
139 - def _cofactor(self):
140 return _write_kegg("COFACTOR", 141 [_wrap_kegg(l, wrap_rule=name_wrap) 142 for l in self.cofactor])
143
144 - def _effector(self):
145 return _write_kegg("EFFECTOR", 146 [_wrap_kegg(l, wrap_rule=name_wrap) 147 for l in self.effector])
148
149 - def _comment(self):
150 return _write_kegg("COMMENT", 151 [_wrap_kegg(l, wrap_rule=id_wrap(0)) 152 for l in self.comment])
153
154 - def _pathway(self):
155 s = [] 156 for entry in self.pathway: 157 s.append(entry[0] + ": " + entry[1] + " " + entry[2]) 158 return _write_kegg("PATHWAY", 159 [_wrap_kegg(l, wrap_rule=id_wrap(16)) 160 for l in s])
161
162 - def _genes(self):
163 s = [] 164 for entry in self.genes: 165 s.append(entry[0] + ": " + " ".join(entry[1])) 166 return _write_kegg("GENES", 167 [_wrap_kegg(l, wrap_rule=id_wrap(5)) 168 for l in s])
169
170 - def _disease(self):
171 s = [] 172 for entry in self.disease: 173 s.append(entry[0] + ": " + entry[1] + " " + entry[2]) 174 return _write_kegg("DISEASE", 175 [_wrap_kegg(l, wrap_rule=id_wrap(13)) 176 for l in s])
177
178 - def _structures(self):
179 s = [] 180 for entry in self.structures: 181 s.append(entry[0] + ": " + " ".join(entry[1]) + " ") 182 return _write_kegg("STRUCTURES", 183 [_wrap_kegg(l, wrap_rule=struct_wrap(5)) 184 for l in s])
185
195 196
197 -def parse(handle):
198 """Parse a KEGG Enzyme file, returning Record objects. 199 200 This is an iterator function, typically used in a for loop. For 201 example, using one of the example KEGG files in the Biopython 202 test suite, 203 204 >>> with open("KEGG/enzyme.sample") as handle: 205 ... for record in parse(handle): 206 ... print("%s %s" % (record.entry, record.name[0])) 207 ... 208 1.1.1.1 Alcohol dehydrogenase 209 1.1.1.62 Estradiol 17beta-dehydrogenase 210 1.1.1.68 Transferred to EC 1.7.99.5 211 1.6.5.3 NADH dehydrogenase (ubiquinone) 212 1.14.13.28 3,9-Dihydroxypterocarpan 6a-monooxygenase 213 2.4.1.68 Glycoprotein 6-alpha-L-fucosyltransferase 214 3.1.1.6 Acetylesterase 215 2.7.2.1 Acetate kinase 216 217 """ 218 record = Record() 219 for line in handle: 220 if line[:3]=="///": 221 yield record 222 record = Record() 223 continue 224 if line[:12]!=" ": 225 keyword = line[:12] 226 data = line[12:].strip() 227 if keyword=="ENTRY ": 228 words = data.split() 229 record.entry = words[1] 230 elif keyword=="CLASS ": 231 record.classname.append(data) 232 elif keyword=="COFACTOR ": 233 record.cofactor.append(data) 234 elif keyword=="COMMENT ": 235 record.comment.append(data) 236 elif keyword=="DBLINKS ": 237 if ":" in data: 238 key, values = data.split(":") 239 values = values.split() 240 row = (key, values) 241 record.dblinks.append(row) 242 else: 243 row = record.dblinks[-1] 244 key, values = row 245 values.extend(data.split()) 246 row = key, values 247 record.dblinks[-1] = row 248 elif keyword=="DISEASE ": 249 if ":" in data: 250 database, data = data.split(":") 251 number, name = data.split(None, 1) 252 row = (database, number, name) 253 record.disease.append(row) 254 else: 255 row = record.disease[-1] 256 database, number, name = row 257 name = name + " " + data 258 row = database, number, name 259 record.disease[-1] = row 260 elif keyword=="EFFECTOR ": 261 record.effector.append(data.strip(";")) 262 elif keyword=="GENES ": 263 if data[3:5]==': ': 264 key, values = data.split(":", 1) 265 values = [value.split("(")[0] for value in values.split()] 266 row = (key, values) 267 record.genes.append(row) 268 else: 269 row = record.genes[-1] 270 key, values = row 271 for value in data.split(): 272 value = value.split("(")[0] 273 values.append(value) 274 row = key, values 275 record.genes[-1] = row 276 elif keyword=="INHIBITOR ": 277 record.inhibitor.append(data.strip(";")) 278 elif keyword=="NAME ": 279 record.name.append(data.strip(";")) 280 elif keyword=="PATHWAY ": 281 if data[:5]=='PATH:': 282 _, map_num, name = data.split(None, 2) 283 pathway = ('PATH', map_num, name) 284 record.pathway.append(pathway) 285 else: 286 ec_num, name = data.split(None, 1) 287 pathway = 'PATH', ec_num, name 288 record.pathway.append(pathway) 289 elif keyword=="PRODUCT ": 290 record.product.append(data.strip(";")) 291 elif keyword=="REACTION ": 292 record.reaction.append(data.strip(";")) 293 elif keyword=="STRUCTURES ": 294 if data[:4]=='PDB:': 295 database = data[:3] 296 accessions = data[4:].split() 297 row = (database, accessions) 298 record.structures.append(row) 299 else: 300 row = record.structures[-1] 301 database, accessions = row 302 accessions.extend(data.split()) 303 row = (database, accessions) 304 record.structures[-1] = row 305 elif keyword=="SUBSTRATE ": 306 record.substrate.append(data.strip(";")) 307 elif keyword=="SYSNAME ": 308 record.sysname.append(data.strip(";"))
309 310 311 if __name__ == "__main__": 312 from Bio._utils import run_doctest 313 run_doctest() 314