Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/166806efc570
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:09:40 2012
Кодировка:

# HG changeset patch
# User Daniil Alexeyevsky
# Date 1296490325 -10800
# Node ID 166806efc570ff8e0765397e295fe46ce153c5de
# Parent 670ae384aa37f0b85006b42b3148153ca249f7e3
base.Alignment.process: added parameters to control what to copy

also, cleaned up code

diff -r 670ae384aa37 -r 166806efc570 allpy/base.py
--- a/allpy/base.py Mon Jan 31 18:44:23 2011 +0300
+++ b/allpy/base.py Mon Jan 31 19:12:05 2011 +0300
@@ -318,7 +318,7 @@
del column[sequence]

def _merge(self, dst, new, merge):
- """Replace contents of dst with those of new.
+ """Replace contents of `dst` with those of `new`.

Replace contents of elements using function `merge(dst_el, new_le)`.
"""
@@ -327,23 +327,24 @@
dst[len(dst):] = new[len(dst):]
del dst[len(new):]

- def _replace_sequence_contents(self, new):
- """Replace contents of sequences with those of new alignment."""
+ def _replace_sequence_contents(self, new, copy_descriptions):
+ """Replace contents of sequences with those of `new` alignment."""
# XXX: we manually copy sequence contents here
# XXX: we only copy, overlapping parts and link to the rest
def merge_monomers(dst, new):
dst.__class__ = new.__class__
def merge_sequences(dst, new):
- vars(dst).update(vars(new))
+ if copy_descriptions:
+ vars(dst).update(vars(new))
self._merge(dst, new, merge_monomers)
self._merge(self.sequences, new.sequences, merge_sequences)

def _replace_column_contents(self, new):
- """Replace column contents with those of new alignment.
+ """Replace column contents with those of `new` alignment.

- Synonym: copy gap patterns from new to self.
+ Synonym: copy gap patterns from `new` to `self`.

- self.sequences and new.sequences should have the same contents.
+ `self.sequences` and `new.sequences` should have the same contents.
"""
self._wipe()
not_gap = lambda (a,b): a != None
@@ -353,18 +354,21 @@
for monomer, (i, _) in zipped:
self._column_at(i)[sequence] = monomer

- def _replace_contents(self, new):
+ def _replace_contents(self, new, copy_descriptions, copy_contents):
"""Replace alignment contents with those of other alignment."""
- self._replace_sequence_contents(new)
+ if copy_contents:
+ self._replace_sequence_contents(new, copy_descriptions)
self._replace_column_conents(new)

- def process(self, function):
+ def process(self, function, copy_descriptions=True, copy_contents=True):
"""Apply function to the alignment (or block); inject results back.

- function(block) must return block with same line order.
+ - `function(block)` must return block with same line order.
+ - if `copy_descriptions` is False, ignore new sequence names.
+ - if `copy_contents` is False, don't copy sequence contents too.
"""
new = function(self)
- self._replace_contents(new)
+ self._replace_contents(new, copy_descriptions, copy_contents)

class Column(dict):
"""Column of alignment.