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