1
2
3
4
5
6 """
7 This module provides code to work with the enzyme.dat file from
8 Enzyme.
9 http://www.expasy.ch/enzyme/
10
11
12 Classes:
13 _Scanner Scans Enzyme data.
14
15 """
16
17 from Bio import File
18 from Bio.ParserSupport import *
19
21 """Scans Enzyme data.
22
23 Tested with:
24 Release 33
25 """
26
27 - def feed(self, handle, consumer):
28 """feed(self, handle, consumer)
29
30 Feed in Enzyme data for scanning. handle is a file-like object
31 that contains keyword information. consumer is a Consumer
32 object that will receive events as the report is scanned.
33
34 """
35 if isinstance(handle, File.UndoHandle):
36 uhandle = handle
37 else:
38 uhandle = File.UndoHandle(handle)
39
40 while not is_blank_line(uhandle.peekline()):
41 self._scan_record(uhandle, consumer)
42
56
57 - def _scan_line(self, line_type, uhandle, event_fn,
58 exactly_one=None, one_or_more=None, any_number=None,
59 up_to_one=None):
77
80
83
86
90
93
96
99
103
107
110
111 _scan_fns = [
112 _scan_id,
113 _scan_de,
114 _scan_an,
115 _scan_ca,
116 _scan_cf,
117 _scan_cc,
118 _scan_di,
119 _scan_pr,
120 _scan_dr,
121 _scan_terminator
122 ]
124 - def __init__(self,tr_code='',sw_code=''):
125 self.tr_code = tr_code
126 self.sw_code = sw_code
127
129 return self.tr_code + ", " + self.sw_code
130
133 self.ID = ''
134 self.DE = []
135 self.AN = []
136 self.CA = ''
137 self.CF = []
138 self.CC = []
139 self.DI = []
140 self.PR = []
141 self.DR = []
142
144 if self.ID:
145 if self.DE:
146 return "%s (%s, %s)" % (self.__class__.__name__,
147 self.ID, self.DE[0])
148 else:
149 return "%s (%s)" % (self.__class__.__name__,
150 self.ID)
151 else:
152 return "%s ( )" % (self.__class__.__name__)
153
155 output = "ID: " + self.ID
156 output += " DE: " + repr(self.DE)
157 output += " AN: " + repr(self.AN)
158 output += " CA: '" + self.CA + "'"
159 output += " CF: " + repr(self.CF)
160 output += " CC: " + repr(self.CC)
161 output += " DI: " + repr(self.DI)
162 output += " PR: " + repr(self.PR)
163 output += " DR: %d Records" % len(self.DR)
164
165 return output
166
171
172 - def parse(self, handle):
179
181 - def __init__(self, handle, parser=None):
183
185 self._parser = RecordParser()
186 lines = []
187 while 1:
188 line = self._uhandle.readline()
189 if not line: break
190 if line[:2] == '//':
191 break
192 lines.append(line)
193 if not lines:
194 return None
195 lines.append('//')
196 data = string.join(lines,'')
197 if self._parser is not None:
198 return self._parser.parse(File.StringHandle(data))
199 return data
200
202 return iter(self.next, None)
203
208 self.enzyme_record.ID = id_info.split()[1]
214 self.enzyme_record.CA = string.join([self.enzyme_record.CA,ca_info[2:].strip()],'')
231
234
236 good_data = dr_info[2:].strip()
237 pair_data = good_data.split(';')
238 for pair in pair_data:
239 if not pair: continue
240 data_record = DataRecord()
241 t1, t2 = pair.split(',')
242 data_record.tr_code, data_record.sw_code = \
243 t1.strip(), t2.strip()
244 self.enzyme_record.DR.append(data_record)
245
246 def terminator(self,schwarzenegger):
247 pass
248