1
2 """This module is DEPRECATED.
3
4 Andrew Dalke is no longer maintaining Martel or Bio.Mindy, and these modules
5 and associate ones like Bio.Std are now deprecated. They are no longer
6 used in any of the current Biopython parsers, and are likely to be removed
7 in a future release.
8 """
9
10 import warnings
11 warnings.warn("Martel and those parts of Biopython depending on it" \
12 +" directly (such as Bio.Mindy and Bio.Std) are now" \
13 +" deprecated, and will be removed in a future release of"\
14 +" Biopython. If you want to continue to use this code,"\
15 +" please get in contact with the Biopython developers via"\
16 +" the mailing lists to avoid its permanent removal from"\
17 +" Biopython.", \
18 DeprecationWarning)
19
20
21 import Martel
22 Group = Martel.Group
23
24 namespace = "bioformat"
25 NS = namespace + ":"
26 XMLNS = "http://biopython.org/bioformat"
27
29 value = attrs.get(field)
30 if value is not None:
31 if valid is not None:
32 if value not in valid:
33 raise TypeError("%s (%r) must be one of %s" % \
34 (field, value, valid))
35 if convert is None:
36 d[field] = value
37 else:
38 d[field] = convert(value)
39
41 if attrs.has_key(name) and attrs[name] is not None:
42 raise NotImplementedError("Don't yet handle %r" % (name,))
43
45 tag = f.tag
46 if tag not in expr.group_names():
47 raise TypeError(
48 "group %r not present in the expression but is required" % \
49 (tag,))
50
52 names = expr.group_names()
53 for set in sets:
54 for f in set:
55 tag = f.tag
56 if tag not in names:
57 break
58 else:
59 return
60 if len(sets) == 1:
61 raise TypeError("missing required tags (need %s) in expression" %
62 [f.tag for f in sets[0]])
63 lines = ["missing required tags in expression; must have one set from:"]
64 for set in sets:
65 lines.append( str( [t.tag for f in set] ) )
66 s = "\n".join(lines)
67 raise TypeError(s)
68
70 f.tag
71 if tag in expr.group_names():
72 raise TypeError(
73 "group %r present in the expression but is not allowed" % \
74 (tag,))
75
76
77
80 try:
81 _f.x = 1
82 _use_hack = 0
83 except AttributeError:
84 _use_hack = 1
85 del _f
86
88 if text == "record":
89 return
90 assert NS + f.func_name == text, (NS + ":" + f.func_name, text)
91
102
103 if not _use_hack:
107 else:
108
113 return self._func( *args, **kwargs)
114
119
120
126 _settag(record, "record")
127
128
129 -def dbid(expr, attrs = {}):
130 attrs = _check_attrs(attrs, ("type", "style", "dbname"))
131 d = {}
132 _set_if_given(attrs, "type", d, ("primary", "accession", "secondary"))
133 _set_if_given(attrs, "dbname", d)
134 return Group(NS + "dbid", expr, d)
135 _settag(dbid, NS + "dbid")
136
138 attrs = _check_attrs(attrs, ("join",))
139 _must_have(expr, description)
140 d = {}
141 _set_if_given(attrs, "join", d, ("english", "concat", "space", "newline"))
142 return Group(NS + "description_block", expr, d)
143 _settag(description_block, NS + "description_block")
144
148 _settag(description, NS + "description")
149
152
154 attrs = _check_attrs(attrs, ("style",))
155 d = {}
156 _set_if_given(attrs, "style", d, ("sp-general", "sp-prosite", "sp-embl"))
157 return Group(NS + "fast_dbxref", expr, d)
158
165 _settag(dbxref, NS + "dbxref")
166
172 _settag(dbxref_dbname, NS + "dbxref_dbname")
173
175 attrs = _check_attrs(attrs, ("dbname", "type", "style", "negate"))
176 d = {}
177 _set_if_given(attrs, "dbname", d)
178 _set_if_given(attrs, "type", d, ("primary", "accession", "secondary"))
179 _complain_if_given(attrs, "style")
180 _set_if_given(attrs, "negate", d, (0, 1), str)
181
182 return Group(NS + "dbxref_dbid", expr, d)
183 _settag(dbxref_dbid, NS + "dbxref_dbid")
184
188 _settag(dbxref_negate, NS + "dbxref_negate")
189
190
191
193 if not ( ord(" ") <= ord(s) <= 126 ):
194 raise TypeError("%r not allowed as a gap character" % (s,))
195 return s
196
197
199 attrs = _check_attrs(attrs, ("alphabet", "gapchar", "remove_spaces"))
200 _must_have(expr, sequence)
201 d = {}
202 _set_if_given(attrs, "alphabet", d,
203 ("iupac-protein", "iupac-dna", "iupac-rna",
204 "iupac-ambiguous-protein",
205 "iupac-ambiguous-dna",
206 "iupac-ambiguous-rna",
207 "protein", "dna", "rna", "unknown"))
208 _set_if_given(attrs, "gapchar", d, convert = _check_gapchar)
209 _set_if_given(attrs, "remove_spaces", d, (0, 1), str)
210 return Group(NS + "sequence_block", expr, d)
211 _settag(sequence_block, NS + "sequence_block")
212
216 _settag(sequence, NS + "sequence")
217
219 attrs = _check_attrs(attrs, ("alphabet",))
220 d = {}
221 _set_if_given(attrs, "alphabet", d,
222 ("iupac-protein", "iupac-dna", "iupac-rna",
223 "iupac-ambiguous-protein",
224 "iupac-ambiguous-dna",
225 "iupac-ambiguous-rna",
226 "protein", "dna", "rna", "nucleotide", "unknown"))
227 return Group(NS + "alphabet", expr, d)
228 _settag(alphabet, NS + "alphabet")
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
285 _settag(feature_block, NS + "feature_block")
286
288 attrs = _check_attrs(attrs, ("location-style",))
289 d = {}
290 _set_if_given(attrs, "location-style", d)
291 _must_have(expr, feature_name)
292 _must_have_set(expr, [[feature_location],
293 [feature_location_start, feature_location_end]])
294 return Group(NS + "feature", expr, d)
295 _settag(feature, NS + "feature")
296
300 _settag(feature_name, NS + "feature_name")
301
305 _settag(feature_location, NS + "feature_location")
306
310 _settag(feature_location_start, NS + "feature_location_start")
311
315 _settag(feature_location_end, NS + "feature_location_end")
316
320 _settag(feature_description, NS + "feature_description")
321
322
323
324
325
326
327
328
333 _settag(feature_qualifier, NS + "feature_qualifier")
334
338 _settag(feature_qualifier_name, NS + "feature_qualifier_name")
339
341 attrs = _check_attrs(attrs, ())
342 return Group(NS + "feature_qualifier_description", expr)
343 _settag(feature_qualifier_description, NS + "feature_qualifier_description")
344
345
346
347
348
350 attrs = _check_attrs(attrs, ("app",))
351 return Group("bioformat:application_name", expr, attrs)
352
353
355 attrs = _check_attrs(attrs, ())
356 return Group("bioformat:application_version", expr, attrs)
357
359 attrs = _check_attrs(attrs, ())
360 return Group("bioformat:search_header", expr, attrs)
361
363 attrs = _check_attrs(attrs, ())
364 return Group("bioformat:search_table", expr, attrs)
365
367 attrs = _check_attrs(attrs, ("bioformat:decode",))
368 d = {"bioformat:decode": "strip"}
369 _set_if_given(attrs, "bioformat:decode", d)
370 return Group("bioformat:search_table_description", expr, d)
371
373 attrs = _check_attrs(attrs, ("name", "bioformat:decode"))
374 return Group("bioformat:search_table_value", expr, attrs)
375
376 -def search_table_entry(expr, attrs = {}):
377 attrs = _check_attrs(attrs, ())
378 return Group("bioformat:search_table_entry", expr, attrs)
379
381 attrs = _check_attrs(attrs, ("join-query",))
382 d = {"join-query": "join|fixspaces"}
383 _set_if_given(attrs, "join-query", d)
384 return Group("bioformat:query_description_block", expr, d)
385
387 attrs = _check_attrs(attrs, ("bioformat:decode"))
388 d = {}
389 _set_if_given(attrs, "bioformat:decode", d)
390 return Group("bioformat:query_description", expr, d)
391
395
397 attrs = _check_attrs(attrs, ())
398 return Group("bioformat:database_name", expr, attrs)
399
401 attrs = _check_attrs(attrs, ("bioformat:decode",))
402 return Group("bioformat:database_num_sequences", expr, attrs)
403
405 attrs = _check_attrs(attrs, ("bioformat:decode",))
406 return Group("bioformat:database_num_letters", expr, attrs)
407
408 -def hit(expr, attrs = {}):
409 attrs = _check_attrs(attrs, ("join-description",))
410 d = {"join-description": "join|fixspaces"}
411 _set_if_given(attrs, "join-description", d)
412 return Group("bioformat:hit", expr, d)
413
415 attrs = _check_attrs(attrs, ())
416 return Group("bioformat:hit_length", expr, attrs)
417
419 attrs = _check_attrs(attrs, ("bioformat:decode"))
420 d = {}
421 _set_if_given(attrs, "bioformat:decode", d)
422 return Group("bioformat:hit_description", expr, d)
423
424 -def hsp(expr, attrs = {}):
427
429 attrs = _check_attrs(attrs, ("name", "bioformat:decode"))
430 return Group("bioformat:hsp_value", expr, attrs)
431
433 attrs = _check_attrs(attrs, ("which",))
434 d = {}
435 _set_if_given(attrs, "which", d, valid = ("query", "homology", "subject"))
436 return Group("bioformat:hsp_frame", expr, d)
437
439 attrs = _check_attrs(attrs, ("strand", "which"))
440 d = {}
441 _set_if_given(attrs, "which", d, valid = ("query", "homology", "subject"))
442 _set_if_given(attrs, "strand", d, valid = ("+1", "0", "-1", ""))
443 return Group("bioformat:hsp_strand", expr, d)
444
446 attrs = _check_attrs(attrs, ())
447 return Group("bioformat:hsp_seqalign_query_seq", expr, attrs)
448
450 attrs = _check_attrs(attrs, ())
451 return Group("bioformat:hsp_seqalign_homology_seq", expr, attrs)
452
454 attrs = _check_attrs(attrs, ())
455 return Group("bioformat:hsp_seqalign_subject_seq", expr, attrs)
456
458 attrs = _check_attrs(attrs, ())
459 return Group("bioformat:hsp_seqalign_query_leader", expr, attrs)
460
461
463 attrs = _check_attrs(attrs, ())
464 return Group("bioformat:hsp_seqalign_query_name", expr, attrs)
465
467 attrs = _check_attrs(attrs, ())
468 return Group("bioformat:hsp_seqalign_subject_name", expr, attrs)
469
471 attrs = _check_attrs(attrs, ())
472 return Group("bioformat:hsp_seqalign", expr, attrs)
473
475 attrs = _check_attrs(attrs, ())
476 return Group("bioformat:hsp_seqalign_query_start", expr, attrs)
477
479 attrs = _check_attrs(attrs, ())
480 return Group("bioformat:hsp_seqalign_query_end", expr, attrs)
481
483 attrs = _check_attrs(attrs, ())
484 return Group("bioformat:hsp_seqalign_subject_start", expr, attrs)
485
487 attrs = _check_attrs(attrs, ())
488 return Group("bioformat:hsp_seqalign_subject_end", expr, attrs)
489
496
503