allpy
view allpy/base.py @ 536:1a8ddc6e2eee
mkcodes.py, codes.py: remove entries with 1-letter code longer than 1 letter
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Mon, 28 Feb 2011 19:24:28 +0300 |
parents | 23af8cf15344 |
children | 364232e42888 |
line source
7 # import this very module as means of having all related classes in one place
11 """Set of characters to recoginze as gaps when parsing alignment."""
14 """Monomer object."""
17 """Either of 'dna', 'rna', 'protein'."""
20 """Mapping of related types. SHOULD be redefined in subclasses."""
23 """A mapping from 1-letter code to Monomer subclass."""
26 """A mapping from 3-letter code to Monomer subclass."""
29 """A mapping from full monomer name to Monomer subclass."""
31 @classmethod
33 """Create new subclass of Monomer for given monomer type."""
35 pass
48 # We duplicate distinguished long names into Monomer itself, so that we
49 # can use Monomer.from_code3 to create the relevant type of monomer.
53 @classmethod
55 """Create all relevant subclasses of Monomer."""
59 @classmethod
61 """Create new monomer from 1-letter code."""
64 @classmethod
66 """Create new monomer from 3-letter code."""
69 @classmethod
71 """Create new monomer from full name."""
78 """Returns one-letter code"""
82 """Monomers within same monomer type are compared by code1."""
90 """Sequence of Monomers.
92 This behaves like list of monomer objects. In addition to standard list
93 behaviour, Sequence has the following attributes:
95 * name -- str with the name of the sequence
96 * description -- str with description of the sequence
97 * source -- str denoting source of the sequence
99 Any of them may be empty (i.e. hold empty string)
100 """
103 """Mapping of related types. SHOULD be redefined in subclasses."""
109 @classmethod
111 """Create sequence from a list of monomer objecst."""
121 @classmethod
123 """Create sequences from string of one-letter codes."""
132 """Returns sequence of one-letter codes."""
136 """Hash sequence by identity."""
140 """Alignment. It is a list of Columns."""
143 """Mapping of related types. SHOULD be redefined in subclasses."""
146 """Ordered list of sequences in alignment. Read, but DO NOT FIDDLE!"""
149 """Initialize empty alignment."""
153 # Alignment grow & IO methods
154 # ==============================
157 """Add sequence to alignment. Return self.
159 If sequence is too short, pad it with gaps on the right.
160 """
169 """Add row from a string of one-letter codes and gaps. Return self."""
177 ]
184 """Pad alignment with empty columns on the right to width n."""
189 """Append sequences from file to alignment. Return self.
191 If sequences in file have gaps (detected as characters belonging to
192 `gaps` set), treat them accordingly.
193 """
206 """Write alignment in FASTA file as sequences with gaps."""
222 # Data access methods for alignment
223 # =================================
226 """Return list of rows (temporary objects) in alignment.
228 Each row is a dictionary of { column : monomer }.
230 For gap positions there is no key for the column in row.
232 Each row has attribute `sequence` pointing to the sequence the row is
233 describing.
235 Modifications of row have no effect on the alignment.
236 """
237 # For now, the function returns a list rather than iterator.
238 # It is yet to see, whether memory performance here becomes critical,
239 # or is random access useful.
251 """Return list of rows (temporary objects) in alignment.
253 Each row here is a list of either monomer or None (for gaps).
255 Each row has attribute `sequence` pointing to the sequence of row.
257 Modifications of row have no effect on the alignment.
258 """
269 """Return list of columns (temorary objects) in alignment.
271 Each column here is a list of either monomer or None (for gaps).
273 Items of column are sorted in the same way as alignment.sequences.
275 Modifications of column have no effect on the alignment.
276 """
285 # Alignment / Block editing methods
286 # =================================
289 """Helper for `flush`: flush to one side all monomers in one row."""
298 # vvv fix padding for case when length is odd: better have more
305 """Remove all gaps from alignment and flush results to one side.
307 `whence` must be one of 'left', 'right' or 'center'
308 """
319 """Remove all empty columns."""
325 """Turn all row positions into gaps (but keep sequences intact)."""
331 """Replace contents of `dst` with those of `new`.
333 Replace contents of elements using function `merge(dst_el, new_le)`.
334 """
341 """Replace contents of sequences with those of `new` alignment."""
342 # XXX: we manually copy sequence contents here
343 # XXX: we only copy, overlapping parts and link to the rest
353 """Replace column contents with those of `new` alignment.
355 In other words: copy gap patterns from `new` to `self`.
357 `self.sequences` and `new.sequences` should have the same contents.
358 """
367 ]
372 """Replace alignment contents with those of other alignment."""
378 """Apply function to the alignment (or block); inject results back.
380 - `function(block)` must return block with same line order.
381 - if `copy_descriptions` is False, ignore new sequence names.
382 - if `copy_contents` is False, don't copy sequence contents too.
384 `function` (object) may have attributes `copy_descriptions` and
385 `copy_contents`, which override the same named arguments.
386 """
395 """Column of alignment.
397 Column is a dict of { sequence : monomer }.
399 For sequences that have gaps in current row, given key is not present in
400 the column.
401 """
404 """Mapping of related types. SHOULD be redefined in subclasses."""
407 """Return hash by identity."""
411 """Block of alignment.
413 Block is an intersection of several rows & columns. (The collections of
414 rows and columns are represented as ordered lists, to retain display order
415 of Alignment or add ability to tweak it). Most of blocks look like
416 rectangular part of alignment if you shuffle alignment rows the right way.
417 """
420 """Alignment the block belongs to."""
423 """List of sequences in block."""
426 """List of columns in block."""
428 @classmethod
430 """Build new block from alignment.
432 If sequences are not given, the block uses all sequences in alignment.
434 If columns are not given, the block uses all columns in alignment.
436 In both cases we use exactly the list used in alignment, thus, if new
437 sequences or columns are added to alignment, the block tracks this too.
438 """
449 # vim: set ts=4 sts=4 sw=4 et: