Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/fc9e2b8e84b3
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 00:50:46 2012
Кодировка:
allpy: fc9e2b8e84b3

allpy

changeset 622:fc9e2b8e84b3

Added base.Alignment.rows_as_strings
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Tue, 03 May 2011 21:04:29 +0400
parents 4bc2075d338a
children 6e87dcc73d8b
files allpy/base.py
diffstat 1 files changed, 22 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/allpy/base.py	Tue May 03 21:04:08 2011 +0400
     1.2 +++ b/allpy/base.py	Tue May 03 21:04:29 2011 +0400
     1.3 @@ -208,15 +208,8 @@
     1.4  
     1.5      def to_file(self, file, format='fasta', gap='-'):
     1.6          """Write alignment in FASTA file as sequences with gaps."""
     1.7 -        def char(monomer):
     1.8 -            if monomer:
     1.9 -                return monomer.code1
    1.10 -            return gap
    1.11 -        def as_string(row):
    1.12 -            seq = row.sequence
    1.13 -            line = "".join(map(char, row))
    1.14 -            return line, seq.name, seq.description
    1.15 -        strings = map(as_string, self.rows_as_lists())
    1.16 +        strings = [(s, s.sequence.name, s.sequence.description)
    1.17 +            for s in self.rows_as_strings()]
    1.18          fileio.File(file, format).write_strings(strings)
    1.19  
    1.20      # Data access methods for alignment
    1.21 @@ -265,6 +258,26 @@
    1.22              rows.append(row)
    1.23          return rows
    1.24  
    1.25 +    def rows_as_strings(self, gap='-'):
    1.26 +        """Return list of string representation of rows in alignment.
    1.27 +
    1.28 +        Each row has attribute `sequence` pointing to the sequence of row.
    1.29 +
    1.30 +        `gap` is the symbol to use for gap.
    1.31 +        """
    1.32 +        rows = []
    1.33 +        for sequence in self.sequences:
    1.34 +            string = ""
    1.35 +            for column in self.columns:
    1.36 +                if sequence in column:
    1.37 +                    string += column[sequence].code1
    1.38 +                else:
    1.39 +                    string += gap
    1.40 +            string = util.UserString(string)
    1.41 +            string.sequence = sequence
    1.42 +            rows.append(string)
    1.43 +        return rows
    1.44 +
    1.45      def columns_as_lists(self):
    1.46          """Return list of columns (temorary objects) in alignment.
    1.47