1
2
3
4
5
6 """Code used for parsing GenBank/EMBL feature location strings (DEPRECATED)."""
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 from Bio.Parsers.spark import GenericScanner, GenericParser
26
33 return "Tokens(%r)" % (self.type,)
34
35
37 type = "integer"
45 return "Integer(%s)" % self.val
46
47
48
50 type = "unsigned_integer"
52 return "UnsignedInteger(%s)" % self.val
53
55 type = "symbol"
63 return "Symbol(%s)" % repr(self.name)
64
65
70 return "LowBound(%r)" % self.base
71
72
77 return "HighBound(%r)" % self.base
78
79
82 self.low = low
83 self.high = high
85 return "TwoBound(%r, %r)" % (self.low, self.high)
86
87
90 self.low = low
91 self.high = high
93 return "Between(%r, %r)" % (self.low, self.high)
94
95
98 self.low = low
99 self.high = high
101 return "Range(%r, %r)" % (self.low, self.high)
102
105 self.name = name
106 self.args = args
108 return "Function(%r, %r)" % (self.name, self.args)
109
111 - def __init__(self, path, local_location):
112 self.path = path
113 self.local_location = local_location
115 return "AbsoluteLocation(%r, %r)" % (self.path, self.local_location)
116
118 - def __init__(self, database, accession):
123
126 self.path = path
127 self.label = label
129 return "FeatureName(%r, %r)" % (self.path, self.label)
130
134
139
171 r" [A-Za-z0-9_'*-][A-Za-z0-9_'*.-]* "
172
173 self.rv.append(Symbol(input))
180
181
182
183
188
190 """
191 location ::= absolute_location
192 location ::= feature_name
193 location ::= function
194 """
195 return args[0]
196
198 """
199 function ::= functional_operator open_paren location_list close_paren
200 """
201 return Function(args[0].name, args[2])
202
204 """
205 absolute_location ::= local_location
206 absolute_location ::= path colon local_location
207 """
208 if len(args) == 1:
209 return AbsoluteLocation(None, args[-1])
210 return AbsoluteLocation(args[0], args[-1])
211
213 """
214 path ::= database double_colon primary_accession
215 path ::= primary_accession
216 """
217 if len(args) == 3:
218 return Path(args[0], args[2])
219 return Path(None, args[0])
220
222 """
223 feature_name ::= path colon feature_label
224 feature_name ::= feature_label
225 """
226 if len(args) == 3:
227 return FeatureName(args[0], args[2])
228 return FeatureName(None, args[0])
229
231 """
232 label ::= symbol
233 """
234 return args[0].name
235
237 """
238 local_location ::= base_position
239 local_location ::= between_position
240 local_location ::= base_range
241 """
242 return args[0]
244 """
245 location_list ::= location
246 location_list ::= location_list comma location
247 """
248 if len(args) == 1:
249 return args
250 return args[0] + [args[2]]
251
253 """
254 functional_operator ::= symbol
255 """
256 return args[0]
257
259 """
260 base_position ::= integer
261 base_position ::= low_base_bound
262 base_position ::= high_base_bound
263 base_position ::= two_base_bound
264 """
265 return args[0]
266
268 """
269 low_base_bound ::= greater_than integer
270 """
271 return LowBound(args[1])
272
274 """
275 high_base_bound ::= less_than integer
276 """
277 return HighBound(args[1])
278
280 """
281 two_base_bound ::= open_paren base_position dot base_position close_paren
282 """
283
284 return TwoBound(args[1], args[3])
285
287 """
288 two_base_bound ::= base_position dot base_position
289 """
290
291 return TwoBound(args[0], args[2])
292
294 """
295 between_position ::= base_position caret base_position
296 """
297 return Between(args[0], args[2])
298
300 """
301 base_range ::= base_position double_dot base_position
302 base_range ::= function double_dot base_position
303 base_range ::= base_position double_dot function
304 base_range ::= function double_dot function
305 """
306 return Range(args[0], args[2])
307
309 """
310 database ::= symbol
311 """
312 return args[0].name
313
315 """
316 primary_accession ::= symbol
317 """
318 return args[0].name
319
320
321 _cached_scanner = LocationScanner()
327
328 _cached_parser = LocationParser()
330 """Go from a set of tokens to an object representation"""
331
332
333
334 return _cached_parser.parse(tokens)
335