| Trees | Indices | Help |
|---|
|
|
1 # Copyright 1999 by Jeffrey Chang. All rights reserved.
2 # This code is part of the Biopython distribution and governed by its
3 # license. Please see the LICENSE file that should have been included
4 # as part of this package.
5
6 """Module to work with enzyme.dat file (DEPRECATED).
7
8 This module provides code to work with the enzyme.dat file from
9 Enzyme (OBSOLETE as of Biopython version 1.50).
10 http://www.expasy.ch/enzyme/
11
12 The functionality of Bio.Enzyme has moved to Bio.ExPASy.ExPASy;
13 please use that module instead of Bio.Enzyme. Bio.Enzyme is now
14 deprecated and will be removed in a future release of Biopython.
15 """
16
17 import warnings
18 import Bio
19 warnings.warn("Bio.Enzyme is deprecated, and will be removed in a"\
20 " future release of Biopython. Most of the functionality "
21 " is now provided by Bio.ExPASy.Enzyme. If you want to "
22 " continue to use Bio.Enzyme, please get in contact "
23 " via the mailing lists to avoid its permanent removal from"\
24 " Biopython.", Bio.BiopythonDeprecationWarning)
25
26 from Bio import File
27 from Bio.ParserSupport import *
28
30 """Scans Enzyme data (PRIVATE).
31
32 Tested with:
33 Release 33
34 """
35
37 """feed(self, handle, consumer)
38
39 Feed in Enzyme data for scanning. handle is a file-like object
40 that contains keyword information. consumer is a Consumer
41 object that will receive events as the report is scanned.
42
43 """
44 if isinstance(handle, File.UndoHandle):
45 uhandle = handle
46 else:
47 uhandle = File.UndoHandle(handle)
48
49 while not is_blank_line(uhandle.peekline()): # Am I done yet?
50 self._scan_record(uhandle, consumer)
51
53 # The first record is just copyright information embedded in
54 # comments. Check to see if I'm at the first record. If so,
55 # then just scan the comments and the terminator.
56 consumer.start_record()
57 line = uhandle.peekline()
58 if line[:2] == 'CC':
59 self._scan_cc(uhandle, consumer)
60 self._scan_terminator(uhandle, consumer)
61 else:
62 for fn in self._scan_fns:
63 fn(self, uhandle, consumer)
64 consumer.end_record()
65
66 - def _scan_line(self, line_type, uhandle, event_fn,
67 exactly_one=None, one_or_more=None, any_number=None,
68 up_to_one=None):
69 # Callers must set exactly one of exactly_one, one_or_more, or
70 # any_number to a true value. I do not explicitly check to
71 # make sure this function is called correctly.
72
73 # This does not guarantee any parameter safety, but I
74 # like the readability. The other strategy I tried was have
75 # parameters min_lines, max_lines.
76
77 if exactly_one or one_or_more:
78 read_and_call(uhandle, event_fn, start=line_type)
79 if one_or_more or any_number:
80 while 1:
81 if not attempt_read_and_call(uhandle, event_fn,
82 start=line_type):
83 break
84 if up_to_one:
85 attempt_read_and_call(uhandle, event_fn, start=line_type)
86
89
92
95
99
102
105
108
112
116
119
120 _scan_fns = [
121 _scan_id,
122 _scan_de,
123 _scan_an,
124 _scan_ca,
125 _scan_cf,
126 _scan_cc,
127 _scan_di,
128 _scan_pr,
129 _scan_dr,
130 _scan_terminator
131 ]
139
142 self.ID = ''
143 self.DE = []
144 self.AN = []
145 self.CA = ''
146 self.CF = []
147 self.CC = [] # one comment per line
148 self.DI = []
149 self.PR = []
150 self.DR = []
151
153 if self.ID:
154 if self.DE:
155 return "%s (%s, %s)" % (self.__class__.__name__,
156 self.ID, self.DE[0])
157 else:
158 return "%s (%s)" % (self.__class__.__name__,
159 self.ID)
160 else:
161 return "%s ( )" % (self.__class__.__name__)
162
164 output = "ID: " + self.ID
165 output += " DE: " + repr(self.DE)
166 output += " AN: " + repr(self.AN)
167 output += " CA: '" + self.CA + "'"
168 output += " CF: " + repr(self.CF)
169 output += " CC: " + repr(self.CC)
170 output += " DI: " + repr(self.DI)
171 output += " PR: " + repr(self.PR)
172 output += " DR: %d Records" % len(self.DR)
173
174 return output
175
180
182 if isinstance(handle, File.UndoHandle):
183 uhandle = handle
184 else:
185 uhandle = File.UndoHandle(handle)
186 self._scanner.feed(uhandle, self._consumer)
187 return self._consumer.enzyme_record
188
192
194 self._parser = RecordParser()
195 lines = []
196 while True:
197 line = self._uhandle.readline()
198 if not line: break
199 if line[:2] == '//':
200 break
201 lines.append(line)
202 if not lines:
203 return None
204 lines.append('//')
205 data = ''.join(lines)
206 if self._parser is not None:
207 return self._parser.parse(File.StringHandle(data))
208 return data
209
211 return iter(self.next, None)
212
215 self.enzyme_record = EnzymeRecord()
223 self.enzyme_record.CA = ''.join([self.enzyme_record.CA, ca_info[2:].strip()])
227 cc = cc_info[2:].strip()
228 if cc.startswith("-!-"):
229 self.enzyme_record.CC.append(cc[len("-!-"):].strip())
230 else:
231 # The header is all CC, but doesn't start with -!-
232 if self.enzyme_record.CC:
233 pre_cc = self.enzyme_record.CC.pop()
234 else:
235 pre_cc = ""
236 new_cc = pre_cc + " " + cc
237 self.enzyme_record.CC.append(new_cc)
240
243
245 good_data = dr_info[2:].strip()
246 pair_data = good_data.split(';')
247 for pair in pair_data:
248 if not pair: continue
249 data_record = DataRecord()
250 t1, t2 = pair.split(',')
251 data_record.tr_code, data_record.sw_code = \
252 t1.strip(), t2.strip()
253 self.enzyme_record.DR.append(data_record)
254
257
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Fri Nov 26 16:20:24 2010 | http://epydoc.sourceforge.net |