allpy
view allpy/base.py @ 374:bdbea6d93dad
Rebuilt documentation indexes for Sphinx (re-run sphinx-autopackage)
author | Daniil Alexeyevsky <me.dendik@gmail.com> |
---|---|
date | Mon, 31 Jan 2011 19:28:33 +0300 |
parents | 670ae384aa37 |
children | dd94230c6f08 |
line source
8 """Set of characters to recoginze as gaps when parsing alignment."""
11 """Monomer object."""
14 """Either of 'dna', 'rna', 'protein'."""
17 """A mapping from 1-letter code to Monomer subclass."""
20 """A mapping from 3-letter code to Monomer subclass."""
23 """A mapping from full monomer name to Monomer subclass."""
25 @classmethod
27 """Create new subclass of Monomer for given monomer type."""
29 pass
42 # We duplicate distinguished long names into Monomer itself, so that we
43 # can use Monomer.from_code3 to create the relevant type of monomer.
47 @classmethod
49 """Create all relevant subclasses of Monomer."""
50 # NB. The table uses letters d, r, p for types,
51 # while we use full words; hence, we compare by first letter
56 @classmethod
58 """Create new monomer from 1-letter code."""
61 @classmethod
63 """Create new monomer from 3-letter code."""
66 @classmethod
68 """Create new monomer from full name."""
75 """Returns one-letter code"""
79 """Monomers within same monomer type are compared by code1."""
84 """Sequence of Monomers.
86 This behaves like list of monomer objects. In addition to standard list
87 behaviour, Sequence has the following attributes:
89 * name -- str with the name of the sequence
90 * description -- str with description of the sequence
91 * source -- str denoting source of the sequence
93 Any of them may be empty (i.e. hold empty string)
95 Class attributes:
97 * monomer_type -- type of monomers in sequence, must be redefined when
98 subclassing
99 """
107 @classmethod
109 """Create sequence from a list of monomer objecst."""
119 @classmethod
121 """Create sequences from string of one-letter codes."""
130 """Returns sequence of one-letter codes."""
134 """Hash sequence by identity."""
138 """Alignment. It is a list of Columns."""
141 """Type of sequences in alignment. SHOULD be redefined when subclassing."""
144 """Ordered list of sequences in alignment. Read, but DO NOT FIDDLE!"""
147 """Initialize empty alignment."""
151 # Alignment grow & IO methods
152 # ==============================
155 """Add sequence to alignment. Return self.
157 If sequence is too short, pad it with gaps on the right.
158 """
166 """Add row from a string of one-letter codes and gaps. Return self."""
171 # The following line has some simple magic:
172 # 1. attach natural numbers to monomers
173 # 2. delete gaps
174 # 3. attach numbers again
175 # This way we have a pair of numbers attached to monomer:
176 # - it's position in alignment (the first attached number, j)
177 # - it's position in sequence (the second attached number, i)
184 """Return column by index. Create new columns if required."""
190 """Append sequences from file to alignment. Return self.
192 If sequences in file have gaps (detected as characters belonging to
193 `gaps` set), treat them accordingly.
194 """
201 """Write alignment in FASTA file as sequences with gaps."""
212 # Data access methods for alignment
213 # =================================
216 """Return list of rows (temporary objects) in alignment.
218 Each row is a dictionary of { column : monomer }.
220 For gap positions there is no key for the column in row.
222 Each row has attribute `sequence` pointing to the sequence the row is
223 describing.
225 Modifications of row have no effect on the alignment.
226 """
227 # For now, the function returns a list rather than iterator.
228 # It is yet to see, whether memory performance here becomes critical,
229 # or is random access useful.
241 """Return list of rows (temporary objects) in alignment.
243 Each row here is a list of either monomer or None (for gaps).
245 Each row has attribute `sequence` pointing to the sequence of row.
247 Modifications of row have no effect on the alignment.
248 """
259 """Return list of columns (temorary objects) in alignment.
261 Each column here is a list of either monomer or None (for gaps).
263 Items of column are sorted in the same way as alignment.sequences.
265 Modifications of column have no effect on the alignment.
266 """
275 # Alignment / Block editing methods
276 # =================================
279 """Helper for `flush`: flush to one side all monomers in one row."""
288 # vvv fix padding for case when length is odd: better have more
295 """Remove all gaps from alignment and flush results to one side.
297 `whence` must be one of 'left', 'right' or 'center'
298 """
309 """Remove all empty columns."""
315 """Make all positions gaps (but keep sequences intact)."""
321 """Replace contents of `dst` with those of `new`.
323 Replace contents of elements using function `merge(dst_el, new_le)`.
324 """
331 """Replace contents of sequences with those of `new` alignment."""
332 # XXX: we manually copy sequence contents here
333 # XXX: we only copy, overlapping parts and link to the rest
343 """Replace column contents with those of `new` alignment.
345 Synonym: copy gap patterns from `new` to `self`.
347 `self.sequences` and `new.sequences` should have the same contents.
348 """
358 """Replace alignment contents with those of other alignment."""
364 """Apply function to the alignment (or block); inject results back.
366 - `function(block)` must return block with same line order.
367 - if `copy_descriptions` is False, ignore new sequence names.
368 - if `copy_contents` is False, don't copy sequence contents too.
369 """
374 """Column of alignment.
376 Column is a dict of { sequence : monomer }.
378 For sequences that have gaps in current row, given key is not present in
379 the column.
380 """
383 """Return hash by identity."""
387 """Block of alignment.
389 Block is intersection of a set of columns & a set of rows. Most of blocks
390 look like rectangular part of alignment if you shuffle alignment rows the
391 right way.
392 """
395 """Alignment the block belongs to."""
398 """List of sequences in block."""
401 """List of columns in block."""
403 @classmethod
405 """Build new block from alignment.
407 If sequences are not given, the block uses all sequences in alignment.
409 If columns are not given, the block uses all columns in alignment.
411 In both cases we use exactly the list used in alignment, thus, if new
412 sequences or columns are added to alignment, the block tracks this too.
413 """
424 # vim: set ts=4 sts=4 sw=4 et: