| 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 warnings.warn("Bio.Enzyme is deprecated, and will be removed in a"\
19 " future release of Biopython. Most of the functionality "
20 " is now provided by Bio.ExPASy.Enzyme. If you want to "
21 " continue to use Bio.Enzyme, please get in contact "
22 " via the mailing lists to avoid its permanent removal from"\
23 " Biopython.", DeprecationWarning)
24
25 from Bio import File
26 from Bio.ParserSupport import *
27
29 """Scans Enzyme data (PRIVATE).
30
31 Tested with:
32 Release 33
33 """
34
36 """feed(self, handle, consumer)
37
38 Feed in Enzyme data for scanning. handle is a file-like object
39 that contains keyword information. consumer is a Consumer
40 object that will receive events as the report is scanned.
41
42 """
43 if isinstance(handle, File.UndoHandle):
44 uhandle = handle
45 else:
46 uhandle = File.UndoHandle(handle)
47
48 while not is_blank_line(uhandle.peekline()): # Am I done yet?
49 self._scan_record(uhandle, consumer)
50
52 # The first record is just copyright information embedded in
53 # comments. Check to see if I'm at the first record. If so,
54 # then just scan the comments and the terminator.
55 consumer.start_record()
56 line = uhandle.peekline()
57 if line[:2] == 'CC':
58 self._scan_cc(uhandle, consumer)
59 self._scan_terminator(uhandle, consumer)
60 else:
61 for fn in self._scan_fns:
62 fn(self, uhandle, consumer)
63 consumer.end_record()
64
65 - def _scan_line(self, line_type, uhandle, event_fn,
66 exactly_one=None, one_or_more=None, any_number=None,
67 up_to_one=None):
68 # Callers must set exactly one of exactly_one, one_or_more, or
69 # any_number to a true value. I do not explicitly check to
70 # make sure this function is called correctly.
71
72 # This does not guarantee any parameter safety, but I
73 # like the readability. The other strategy I tried was have
74 # parameters min_lines, max_lines.
75
76 if exactly_one or one_or_more:
77 read_and_call(uhandle, event_fn, start=line_type)
78 if one_or_more or any_number:
79 while 1:
80 if not attempt_read_and_call(uhandle, event_fn,
81 start=line_type):
82 break
83 if up_to_one:
84 attempt_read_and_call(uhandle, event_fn, start=line_type)
85
88
91
94
98
101
104
107
111
115
118
119 _scan_fns = [
120 _scan_id,
121 _scan_de,
122 _scan_an,
123 _scan_ca,
124 _scan_cf,
125 _scan_cc,
126 _scan_di,
127 _scan_pr,
128 _scan_dr,
129 _scan_terminator
130 ]
138
141 self.ID = ''
142 self.DE = []
143 self.AN = []
144 self.CA = ''
145 self.CF = []
146 self.CC = [] # one comment per line
147 self.DI = []
148 self.PR = []
149 self.DR = []
150
152 if self.ID:
153 if self.DE:
154 return "%s (%s, %s)" % (self.__class__.__name__,
155 self.ID, self.DE[0])
156 else:
157 return "%s (%s)" % (self.__class__.__name__,
158 self.ID)
159 else:
160 return "%s ( )" % (self.__class__.__name__)
161
163 output = "ID: " + self.ID
164 output += " DE: " + repr(self.DE)
165 output += " AN: " + repr(self.AN)
166 output += " CA: '" + self.CA + "'"
167 output += " CF: " + repr(self.CF)
168 output += " CC: " + repr(self.CC)
169 output += " DI: " + repr(self.DI)
170 output += " PR: " + repr(self.PR)
171 output += " DR: %d Records" % len(self.DR)
172
173 return output
174
179
181 if isinstance(handle, File.UndoHandle):
182 uhandle = handle
183 else:
184 uhandle = File.UndoHandle(handle)
185 self._scanner.feed(uhandle, self._consumer)
186 return self._consumer.enzyme_record
187
191
193 self._parser = RecordParser()
194 lines = []
195 while True:
196 line = self._uhandle.readline()
197 if not line: break
198 if line[:2] == '//':
199 break
200 lines.append(line)
201 if not lines:
202 return None
203 lines.append('//')
204 data = string.join(lines,'')
205 if self._parser is not None:
206 return self._parser.parse(File.StringHandle(data))
207 return data
208
210 return iter(self.next, None)
211
214 self.enzyme_record = EnzymeRecord()
222 self.enzyme_record.CA = string.join([self.enzyme_record.CA,ca_info[2:].strip()],'')
226 cc = cc_info[2:].strip()
227 if cc.startswith("-!-"):
228 self.enzyme_record.CC.append(cc[len("-!-"):].strip())
229 else:
230 # The header is all CC, but doesn't start with -!-
231 if self.enzyme_record.CC:
232 pre_cc = self.enzyme_record.CC.pop()
233 else:
234 pre_cc = ""
235 new_cc = pre_cc + " " + cc
236 self.enzyme_record.CC.append(new_cc)
239
242
244 good_data = dr_info[2:].strip()
245 pair_data = good_data.split(';')
246 for pair in pair_data:
247 if not pair: continue
248 data_record = DataRecord()
249 t1, t2 = pair.split(',')
250 data_record.tr_code, data_record.sw_code = \
251 t1.strip(), t2.strip()
252 self.enzyme_record.DR.append(data_record)
253
256
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Wed Dec 16 11:27:53 2009 | http://epydoc.sourceforge.net |