allpy
view allpy/markup.py @ 822:d87129162eb4
Implemented & tested new markup API. See #95
1) Sequences, Alignment and Blocks now have two new methods:
- add_markup(name, markup_class=optional, **kwargs=optional)
- remove_markup(name)
name refers to the same name as in aln.markups[name] or sequence[i].name
It is now explicitly denied to create markups any other way.
2) Markups now have `remove()` method that means 'release all memory that would
not be released otherwised, if we just remove markup from the dictionary'. For
sequences markups it removes markup attribute from each monomer.
3) Added necessary del sequence_markup[monomer] method.
4) Many base classes have attribute `kind`; for Alignments and Blocks it is
'alignment', for Sequences it is 'sequence' for AlignmentMarkups it is
'alignment_markup' for SequenceMarkups it is 'sequence_markup'. This attribute
is crucial for new alignment construction API.
5) Common stuff for MarkupContainers (Alignments and Sequences) is in
MarkupContainerMixin.
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Fri, 15 Jul 2011 16:43:03 +0400 |
parents | 3566d253c994 |
children |
line source
4 """ object for use as key for default value """
7 """ Markup for Sequence or Alignment
9 container is iterable collection of items.
10 item is object getting markup data (new attribute).
12 container: Alignment, item: Column
13 container: Sequence, item: Monomer
15 Markup stored in attributes of item is internal value.
16 When export or import, it is mapped to or from external value.
17 Internal value could be of any type.
18 External value should be single character.
20 Data:
21 * name -- name (str) of attribute of object
22 * container
23 * map_out -- dict, mapping internal values to external
24 * map_in -- dict, mapping external values to internal
26 map_in and map_out can have key markup.default, which used when
27 input key is not in map. To drop this defaults, drop this key
28 from map_out and map_in dicts. In this case to_string() and
29 from_string() methods can raise KeyError
30 """
33 """ Note: add convenient defaults to maps """
55 """ return internal value for given item
57 markup[monomer] <==> monomer.name, where name is markup.name
58 """
62 """ set attribute of item to value """
66 """ return item has attribute
68 usage: if item in markup
69 """
73 """ delete all attributes from items """
78 """ return string representing markup """
87 @classmethod
89 """ return new markup
91 add (or replaces) attributes to items
92 """
104 """ return list of tuples (item, self[item]) for items with attribute """
110 """ return list of items for with attribute is determined """