Package Bio :: Package ExPASy :: Module Enzyme
[hide private]
[frames] | no frames]

Source Code for Module Bio.ExPASy.Enzyme

  1  # Copyright 1999 by Jeffrey Chang.  All rights reserved. 
  2  # Copyright 2009 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  """Parse the enzyme.dat file from Enzyme at ExPASy. 
  8   
  9  See http://www.expasy.ch/enzyme/ 
 10   
 11  Tested with the release of 03-Mar-2009. 
 12   
 13  Functions: 
 14   - read       Reads a file containing one ENZYME entry 
 15   - parse      Reads a file containing multiple ENZYME entries 
 16   
 17  Classes: 
 18   - Record     Holds ENZYME data. 
 19   
 20  """ 
 21   
 22   
23 -def parse(handle):
24 """Parse ENZYME records. 25 26 This function is for parsing ENZYME files containing multiple 27 records. 28 29 Arguments: 30 - handle - handle to the file. 31 32 """ 33 while True: 34 record = __read(handle) 35 if not record: 36 break 37 yield record
38 39
40 -def read(handle):
41 """Read one ENZYME record. 42 43 This function is for parsing ENZYME files containing 44 exactly one record. 45 46 Arguments: 47 - handle - handle to the file. 48 49 """ 50 record = __read(handle) 51 # We should have reached the end of the record by now 52 remainder = handle.read() 53 if remainder: 54 raise ValueError("More than one ENZYME record found") 55 return record
56 57
58 -class Record(dict):
59 """Holds information from an ExPASy ENZYME record as a Python dictionary. 60 61 Each record contains the following keys: 62 63 - ID: EC number 64 - DE: Recommended name 65 - AN: Alternative names (if any) 66 - CA: Catalytic activity 67 - CF: Cofactors (if any) 68 - PR: Pointers to the Prosite documentation entrie(s) that 69 correspond to the enzyme (if any) 70 - DR: Pointers to the Swiss-Prot protein sequence entrie(s) 71 that correspond to the enzyme (if any) 72 - CC: Comments 73 74 """ 75
76 - def __init__(self):
77 dict.__init__(self) 78 self["ID"] = '' 79 self["DE"] = '' 80 self["AN"] = [] 81 self["CA"] = '' 82 self["CF"] = '' 83 self["CC"] = [] # one comment per line 84 self["PR"] = [] 85 self["DR"] = []
86
87 - def __repr__(self):
88 if self["ID"]: 89 if self["DE"]: 90 return "%s (%s, %s)" % (self.__class__.__name__, 91 self["ID"], self["DE"]) 92 else: 93 return "%s (%s)" % (self.__class__.__name__, 94 self["ID"]) 95 else: 96 return "%s ( )" % (self.__class__.__name__)
97
98 - def __str__(self):
99 output = "ID: " + self["ID"] 100 output += " DE: " + self["DE"] 101 output += " AN: " + repr(self["AN"]) 102 output += " CA: '" + self["CA"] + "'" 103 output += " CF: " + self["CF"] 104 output += " CC: " + repr(self["CC"]) 105 output += " PR: " + repr(self["PR"]) 106 output += " DR: %d Records" % len(self["DR"]) 107 return output
108 109 # Everything below is private 110 111
112 -def __read(handle):
113 record = None 114 for line in handle: 115 key, value = line[:2], line[5:].rstrip() 116 if key == "ID": 117 record = Record() 118 record["ID"] = value 119 elif key == "DE": 120 record["DE"] += value 121 elif key == "AN": 122 if record["AN"] and not record["AN"][-1].endswith("."): 123 record["AN"][-1] += " " + value 124 else: 125 record["AN"].append(value) 126 elif key == "CA": 127 record["CA"] += value 128 elif key == "DR": 129 pair_data = value.rstrip(";").split(';') 130 for pair in pair_data: 131 t1, t2 = pair.split(',') 132 row = [t1.strip(), t2.strip()] 133 record["DR"].append(row) 134 elif key == "CF": 135 if record["CF"]: 136 record["CF"] += " " + value 137 else: 138 record["CF"] = value 139 elif key == "PR": 140 assert value.startswith("PROSITE; ") 141 value = value[9:].rstrip(";") 142 record["PR"].append(value) 143 elif key == 'CC': 144 if value.startswith("-!- "): 145 record["CC"].append(value[4:]) 146 elif value.startswith(" ") and record["CC"]: 147 record["CC"][-1] += value[3:] 148 # copyright notice is silently skipped 149 elif key == "//": 150 if record: 151 return record 152 else: # This was the copyright notice 153 continue 154 if record: 155 raise ValueError("Unexpected end of stream")
156