Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/diff/df571a5233fb/allpy/base.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 20:16:33 2013
Кодировка:
allpy: allpy/base.py diff

allpy

diff allpy/base.py @ 382:df571a5233fb

Changed the way related types are stored for Alignment, Block, Sequence, Monomer Now each of them has attribute 'type', which is an object with four attributes: - Alignment - Block - Sequence - Monomer
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Tue, 01 Feb 2011 23:08:08 +0300
parents d66d470a9c0a
children 01f9e9c3493e 02c4cfd12d4c
line diff
     1.1 --- a/allpy/base.py	Tue Feb 01 18:46:23 2011 +0300
     1.2 +++ b/allpy/base.py	Tue Feb 01 23:08:08 2011 +0300
     1.3 @@ -4,6 +4,9 @@
     1.4  import util
     1.5  import fasta
     1.6  
     1.7 +# import this very module as means of having all related classes in one place
     1.8 +import base
     1.9 +
    1.10  default_gaps = set((".", "-", "~"))
    1.11  """Set of characters to recoginze as gaps when parsing alignment."""
    1.12  
    1.13 @@ -13,6 +16,9 @@
    1.14      type = None
    1.15      """Either of 'dna', 'rna', 'protein'."""
    1.16  
    1.17 +    types = base
    1.18 +    """Mapping of related types. SHOULD be redefined in subclasses."""
    1.19 +
    1.20      by_code1 = {}
    1.21      """A mapping from 1-letter code to Monomer subclass."""
    1.22  
    1.23 @@ -90,14 +96,10 @@
    1.24      *   source -- str denoting source of the sequence
    1.25  
    1.26      Any of them may be empty (i.e. hold empty string)
    1.27 -
    1.28 -    Class attributes:
    1.29 -
    1.30 -    *   monomer_type -- type of monomers in sequence, must be redefined when
    1.31 -        subclassing
    1.32      """
    1.33  
    1.34 -    monomer_type = Monomer
    1.35 +    types = base
    1.36 +    """Mapping of related types. SHOULD be redefined in subclasses."""
    1.37  
    1.38      name = ''
    1.39      description = ''
    1.40 @@ -118,7 +120,7 @@
    1.41      @classmethod
    1.42      def from_string(cls, string, name='', description='', source=''):
    1.43          """Create sequences from string of one-letter codes."""
    1.44 -        monomer = cls.monomer_type.from_code1
    1.45 +        monomer = cls.types.Monomer.from_code1
    1.46          monomers = [monomer(letter) for letter in string]
    1.47          return cls.from_monomers(monomers, name, description, source)
    1.48  
    1.49 @@ -136,16 +138,8 @@
    1.50  class Alignment(object):
    1.51      """Alignment. It is a list of Columns."""
    1.52  
    1.53 -    alignment_type = None
    1.54 -    """Related Alignment class. SHOULD be redefined when subclassing."""
    1.55 -    # Actually given value at EOF, since name Alignment is not yet defined
    1.56 -
    1.57 -    block_type = None
    1.58 -    """Related Block class. SHOULD be redefined when subclassing."""
    1.59 -    # Actually given value at EOF, since name Block is not yet defined
    1.60 -
    1.61 -    sequence_type = Sequence
    1.62 -    """Type of sequences in alignment. SHOULD be redefined when subclassing."""
    1.63 +    types = base
    1.64 +    """Mapping of related types. SHOULD be redefined in subclasses."""
    1.65  
    1.66      sequences = None
    1.67      """Ordered list of sequences in alignment. Read, but DO NOT FIDDLE!"""
    1.68 @@ -171,7 +165,7 @@
    1.69      def append_row_from_string(self, string,
    1.70              name='', description='', source='', gaps=default_gaps):
    1.71          """Add row from a string of one-letter codes and gaps. Return self."""
    1.72 -        Sequence = self.sequence_type
    1.73 +        Sequence = self.types.Sequence
    1.74          not_gap = lambda (i, char): char not in gaps
    1.75          without_gaps = util.remove_each(string, gaps)
    1.76          sequence = Sequence.from_string(without_gaps, name, description, source)
    1.77 @@ -392,6 +386,9 @@
    1.78      the column.
    1.79      """
    1.80  
    1.81 +    types = base
    1.82 +    """Mapping of related types. SHOULD be redefined in subclasses."""
    1.83 +
    1.84      def __hash__(self):
    1.85          """Return hash by identity."""
    1.86          return id(self)
    1.87 @@ -434,7 +431,4 @@
    1.88          block.columns = columns
    1.89          return block
    1.90  
    1.91 -Alignment.alignment_type = Alignment
    1.92 -Alignment.block_type = Block
    1.93 -
    1.94  # vim: set ts=4 sts=4 sw=4 et: