| Trees | Indices | Help |
|---|
|
|
1 # This is a Python module.
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 # Standard Bioformats definitions
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 # pre- Python 2.2 functions didn't allow attributes
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": # XXX FIXME
89 return
90 assert NS + f.func_name == text, (NS + ":" + f.func_name, text)
91
93 for name in attrs.keys():
94 if name not in names:
95 raise TypeError("attr %r is not allowed here (valid terms: %s)" % \
96 (name, names))
97 d = attrs.copy()
98 for name in names:
99 if not d.has_key(name):
100 d[name] = None
101 return d
102
103 if not _use_hack:
107 else:
108 # Convert the functions into callable objects
114
119
120 ################ identifier, description, and cross-references
122 attrs = _check_attrs(attrs, ("format",))
123 d = {"xmlns:bioformat": XMLNS}
124 _set_if_given(attrs, "format", d)
125 return Group("record", expr, d) # XXX FIXME
126 _settag(record, "record") # XXX AND FIXME
127
128
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
160 attrs = _check_attrs(attrs, ("style",))
161 _must_have(expr, dbxref_dbid)
162 d = {}
163 _complain_if_given(attrs, "style")
164 return Group(NS + "dbxref", expr, d)
165 _settag(dbxref, NS + "dbxref")
166
168 attrs = _check_attrs(attrs, ("style",))
169 d = {}
170 _set_if_given(attrs, "style", d)
171 return Group(NS + "dbxref_dbname", expr, d)
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 ##################### sequences
191
193 if not ( ord(" ") <= ord(s) <= 126 ):
194 raise TypeError("%r not allowed as a gap character" % (s,))
195 return s
196
197 # What about three letter codes?
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 ############################## features
233
234 # In PIR
235
236 # FEATURE
237 # 1-25 #domain signal sequence #status predicted #label SIG\
238 # 26-737 #product procollagen-lysine 5-dioxygenase 2 #status
239 # predicted #label MAT\
240 # 63,209,297,365,522,
241 # 725 #binding_site carbohydrate (Asn) (covalent) #status
242 # predicted
243
244 # The whole thing is a 'feature_block'
245
246 # One 'feature' is
247 # 26-737 #product procollagen-lysine 5-dioxygenase 2 #status
248 # predicted #label MAT\
249
250 # One 'feature_name' is "binding_site".
251
252 # An example of the feature_location_block and feature_block, which I
253 # will abbreviate as 'flb' and 'fl', is:
254 # <flb> <fl>63,209,297,365,522,</fl>
255 # <fl>725</fl> #binding_site carbohydrate ...
256
257 # PIR doesn't have a 'feature_description'
258
259 # Let:
260 # fq = feature_qualifier
261 # fqb = feature_qualifier
262 # fqn = feature_qualifier_name
263 # fqd = feature_qualifier_description
264 # then the text
265 #
266 # 26-737 #product procollagen-lysine 5-dioxygenase 2 #status
267 # predicted #label MAT\
268 #
269 # can be represented as (the rather tedious)
270 #
271 # 26-737 <fqb><fq>#<fqn>product</fqn> <fqd>procollagen-\
272 # lysine 5-dioxygenase 2</fqd></fq> #<fq><fqn>status</fqn>
273 # <fqd>predicted</fqd> #<fq><fqn>label\
274 # </fqn> <fqd>MAT</fqd></fq>\</fqb>
275 #
276
277 # 'style' determines the namespace for the feature name
279 attrs = _check_attrs(attrs, ("style", "location-style"))
280 d = {}
281 _set_if_given(attrs, "style", d)
282 _set_if_given(attrs, "location-style", d)
283 _must_have(expr, feature)
284 return Group(NS + "feature_block", expr, d)
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 ##def feature_qualifier_block(expr, attrs = {}):
324 ## attrs = _check_attrs(attrs, ())
325 ## _must_have(expr, feature_qualifier)
326 ## return Group(NS + "feature_qualifier_block", expr)
327 ##_settag(feature_qualifier_block, NS + "feature_qualifier_block")
328
330 attrs = _check_attrs(attrs, ())
331 _must_have(expr, feature_qualifier_name)
332 return Group(NS + "feature_qualifier", expr)
333 _settag(feature_qualifier, NS + "feature_qualifier")
334
338 _settag(feature_qualifier_name, NS + "feature_qualifier_name")
339
343 _settag(feature_qualifier_description, NS + "feature_qualifier_description")
344
345
346 ############ For homology searches
347
348 # "BLASTN", "BLASTP"
350 attrs = _check_attrs(attrs, ("app",))
351 return Group("bioformat:application_name", expr, attrs)
352
353 # "2.0.11", "2.0a19MP-WashU"
357
361
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
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
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
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
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
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
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
491 attrs = _check_attrs(attrs, ("name", "bioformat:decode"))
492 d = {}
493 _set_if_given(attrs, "name", d)
494 _set_if_given(attrs, "bioformat:decode", d)
495 return Group("bioformat:search_parameter", expr, d)
496
498 attrs = _check_attrs(attrs, ("name", "bioformat:decode"))
499 d = {}
500 _set_if_given(attrs, "name", d)
501 _set_if_given(attrs, "bioformat:decode", d)
502 return Group("bioformat:search_statistic", expr, d)
503
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sun May 3 17:14:56 2009 | http://epydoc.sourceforge.net |