Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/166806efc570
Дата изменения: Unknown
Дата индексирования: Mon Oct 1 23:30:29 2012
Кодировка:
allpy: 166806efc570

allpy

changeset 373:166806efc570

base.Alignment.process: added parameters to control what to copy also, cleaned up code
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Mon, 31 Jan 2011 19:12:05 +0300
parents 670ae384aa37
children bdbea6d93dad
files allpy/base.py
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/allpy/base.py	Mon Jan 31 18:44:23 2011 +0300
     1.2 +++ b/allpy/base.py	Mon Jan 31 19:12:05 2011 +0300
     1.3 @@ -318,7 +318,7 @@
     1.4                  del column[sequence]
     1.5  
     1.6      def _merge(self, dst, new, merge):
     1.7 -        """Replace contents of dst with those of new.
     1.8 +        """Replace contents of `dst` with those of `new`.
     1.9  
    1.10          Replace contents of elements using function `merge(dst_el, new_le)`.
    1.11          """
    1.12 @@ -327,23 +327,24 @@
    1.13          dst[len(dst):] = new[len(dst):]
    1.14          del dst[len(new):]
    1.15  
    1.16 -    def _replace_sequence_contents(self, new):
    1.17 -        """Replace contents of sequences with those of new alignment."""
    1.18 +    def _replace_sequence_contents(self, new, copy_descriptions):
    1.19 +        """Replace contents of sequences with those of `new` alignment."""
    1.20          # XXX: we manually copy sequence contents here
    1.21          # XXX: we only copy, overlapping parts and link to the rest
    1.22          def merge_monomers(dst, new):
    1.23              dst.__class__ = new.__class__
    1.24          def merge_sequences(dst, new):
    1.25 -            vars(dst).update(vars(new))
    1.26 +            if copy_descriptions:
    1.27 +                vars(dst).update(vars(new))
    1.28              self._merge(dst, new, merge_monomers)
    1.29          self._merge(self.sequences, new.sequences, merge_sequences)
    1.30  
    1.31      def _replace_column_contents(self, new):
    1.32 -        """Replace column contents with those of new alignment.
    1.33 +        """Replace column contents with those of `new` alignment.
    1.34  
    1.35 -        Synonym: copy gap patterns from new to self.
    1.36 +        Synonym: copy gap patterns from `new` to `self`.
    1.37  
    1.38 -        self.sequences and new.sequences should have the same contents.
    1.39 +        `self.sequences` and `new.sequences` should have the same contents.
    1.40          """
    1.41          self._wipe()
    1.42          not_gap = lambda (a,b): a != None
    1.43 @@ -353,18 +354,21 @@
    1.44              for monomer, (i, _) in zipped:
    1.45                  self._column_at(i)[sequence] = monomer
    1.46  
    1.47 -    def _replace_contents(self, new):
    1.48 +    def _replace_contents(self, new, copy_descriptions, copy_contents):
    1.49          """Replace alignment contents with those of other alignment."""
    1.50 -        self._replace_sequence_contents(new)
    1.51 +        if copy_contents:
    1.52 +            self._replace_sequence_contents(new, copy_descriptions)
    1.53          self._replace_column_conents(new)
    1.54  
    1.55 -    def process(self, function):
    1.56 +    def process(self, function, copy_descriptions=True, copy_contents=True):
    1.57          """Apply function to the alignment (or block); inject results back.
    1.58  
    1.59 -        function(block) must return block with same line order.
    1.60 +        - `function(block)` must return block with same line order.
    1.61 +        - if `copy_descriptions` is False, ignore new sequence names.
    1.62 +        - if `copy_contents` is False, don't copy sequence contents too.
    1.63          """
    1.64          new = function(self)
    1.65 -        self._replace_contents(new)
    1.66 +        self._replace_contents(new, copy_descriptions, copy_contents)
    1.67  
    1.68  class Column(dict):
    1.69      """Column of alignment.