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

allpy

changeset 968:e461a5529338 1.4.0

Backported fixes to Alignment.realign(), Markup.remove(), processors.Muscle(), *.Column.types from default branch (revs [853],[931],[932],[933],[934],[952],[954])
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Sat, 25 Feb 2012 18:50:58 +0400
parents e71155b99511
children 9f851dfb807b
files allpy/base.py allpy/dna.py allpy/processors.py allpy/protein.py allpy/rna.py
diffstat 5 files changed, 31 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/allpy/base.py	Wed Dec 14 22:15:48 2011 +0400
     1.2 +++ b/allpy/base.py	Sat Feb 25 18:50:58 2012 +0400
     1.3 @@ -259,10 +259,14 @@
     1.4                  column[sequence] = monomer
     1.5          return self
     1.6  
     1.7 +    def _append_columns(self, n, columns):
     1.8 +        """Insert list of `columns` after position `n`."""
     1.9 +        self.columns[n+1:n+1] = columns
    1.10 +
    1.11      def _pad_to_width(self, n):
    1.12          """Pad alignment with empty columns on the right to width n."""
    1.13 -        for i in range(len(self.columns), n):
    1.14 -            self.columns.append(Column())
    1.15 +        columns = [Column() for _ in range(len(self.columns), n)]
    1.16 +        self._append_columns(len(self.columns)-1, columns)
    1.17  
    1.18      def append_file(self, file, format='fasta', gaps=default_gaps):
    1.19          """Append sequences from file to alignment. Return self.
    1.20 @@ -445,6 +449,7 @@
    1.21              monomers = filter(None, row)
    1.22              assert len(monomers) == len(filter(None, new_row))
    1.23              self._wipe_row(sequence)
    1.24 +            self._pad_to_width(len(new_row))
    1.25              non_gap_columns = [column
    1.26                  for column, monomer in zip(self.columns, new_row)
    1.27                  if monomer
    1.28 @@ -546,6 +551,15 @@
    1.29          block.columns = columns
    1.30          return block
    1.31  
    1.32 +    def _append_columns(self, n, columns):
    1.33 +        """Insert list of `columns` after position `n`."""
    1.34 +        target = self.columns[n]
    1.35 +        for k, column in enumerate(self.alignment.columns):
    1.36 +            if column is target:
    1.37 +                me = k
    1.38 +        self.alignment._append_columns(me, columns)
    1.39 +        self.columns[n+1:n+1] = columns
    1.40 +
    1.41  class Markup(object):
    1.42      """Base class for sequence and alignment markups.
    1.43  
    1.44 @@ -562,6 +576,9 @@
    1.45      name = None
    1.46      """Name of markup elements"""
    1.47  
    1.48 +    save = True
    1.49 +    """If set to false, fileio should not save this markup."""
    1.50 +
    1.51      def __init__(self, container, name, **kwargs):
    1.52          """Markup takes mandatory container and name and optional kwargs.
    1.53  
    1.54 @@ -640,7 +657,7 @@
    1.55  
    1.56      def remove(self):
    1.57          """Remove the traces of markup object. Do not call this yourself!"""
    1.58 -        for monomer in self.monomers:
    1.59 +        for monomer in self.sequence:
    1.60              del self[monomer]
    1.61  
    1.62      def sorted_keys(self):
     2.1 --- a/allpy/dna.py	Wed Dec 14 22:15:48 2011 +0400
     2.2 +++ b/allpy/dna.py	Sat Feb 25 18:50:58 2012 +0400
     2.3 @@ -15,6 +15,9 @@
     2.4  class Sequence(base.Sequence):
     2.5      types = dna
     2.6  
     2.7 +class Column(base.Column):
     2.8 +    types = dna
     2.9 +
    2.10  class Alignment(base.Alignment):
    2.11      types = dna
    2.12  
     3.1 --- a/allpy/processors.py	Wed Dec 14 22:15:48 2011 +0400
     3.2 +++ b/allpy/processors.py	Sat Feb 25 18:50:58 2012 +0400
     3.3 @@ -25,7 +25,7 @@
     3.4          block.to_file(infile)
     3.5          infile.close()
     3.6          os.system(self.command % {'infile': infile.name, 'outfile': outfile.name})
     3.7 -        Alignment = block.__class__
     3.8 +        Alignment = block.types.Alignment
     3.9          new_alignment = Alignment().append_file(outfile)
    3.10          os.unlink(infile.name)
    3.11          os.unlink(outfile.name)
    3.12 @@ -45,7 +45,7 @@
    3.13  
    3.14      def __init__(self, remove_gaps=False):
    3.15          self.remove_gaps = remove_gaps
    3.16 -        cmd = 'muscle -stable -in %(infile)s -out %(outfile)s >/dev/null 2>&1'
    3.17 +        cmd = 'muscle -in %(infile)s -out %(outfile)s >/dev/null 2>&1'
    3.18          ExternalCommand.__init__(self, cmd)
    3.19  
    3.20      def __call__(self, block):
     4.1 --- a/allpy/protein.py	Wed Dec 14 22:15:48 2011 +0400
     4.2 +++ b/allpy/protein.py	Sat Feb 25 18:50:58 2012 +0400
     4.3 @@ -19,6 +19,9 @@
     4.4  class Sequence(base.Sequence):
     4.5      types = protein
     4.6  
     4.7 +class Column(base.Column):
     4.8 +    types = protein
     4.9 +
    4.10  class Alignment(base.Alignment):
    4.11      types = protein
    4.12  
     5.1 --- a/allpy/rna.py	Wed Dec 14 22:15:48 2011 +0400
     5.2 +++ b/allpy/rna.py	Sat Feb 25 18:50:58 2012 +0400
     5.3 @@ -15,6 +15,9 @@
     5.4  class Sequence(base.Sequence):
     5.5      types = rna
     5.6  
     5.7 +class Column(base.Column):
     5.8 +    types = rna
     5.9 +
    5.10  class Alignment(base.Alignment):
    5.11      types = rna
    5.12