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

allpy

changeset 275:4a2341bc90b1

base.Sequence major cleanup * moved base.Sequence.secstr_has to pdb (it appears that secondary structure it uses is from PDB, which is not a nice thing to do; secondary structure is an entity in itself and must have same names across different sources) * removed stupid base.Sequence.monomers, since base.Sequence is subclass of list * removed all methods that reimplement list behaviour * fixed headers of base.Sequence.from_slice
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Wed, 15 Dec 2010 20:06:27 +0300
parents 9ea5099309b8
children 4466baf642df
files allpy/base.py allpy/pdb.py
diffstat 2 files changed, 27 insertions(+), 27 deletions(-) [+]
line diff
     1.1 --- a/allpy/base.py	Wed Dec 15 19:19:11 2010 +0300
     1.2 +++ b/allpy/base.py	Wed Dec 15 20:06:27 2010 +0300
     1.3 @@ -135,32 +135,32 @@
     1.4      *   source -- str denoting source of the sequence
     1.5  
     1.6      Any of them may be empty (i.e. hold empty string)
     1.7 +
     1.8 +    Class attributes:
     1.9 +    *   monomer_type -- type of monomers in sequence, must be redefined when
    1.10 +        subclassing
    1.11      """
    1.12  
    1.13 -    def __init__(self, monomers=None, name='', description=""):
    1.14 -        if not monomers:
    1.15 -            monomers = []
    1.16 -        self.name = name
    1.17 -        self.description = description
    1.18 -        self.monomers = monomers
    1.19 +    monomer_type = Monomer
    1.20  
    1.21 -    def __len__(self):
    1.22 -        return len(self.monomers)
    1.23 +    name = ''
    1.24 +    description = ''
    1.25 +    source = ''
    1.26 +
    1.27 +    def __init__(self, sequence=[], name=None, description=None, source=None):
    1.28 +        super(Sequence, self).__init__(sequence)
    1.29 +        if hasattr(sequence, 'name'):
    1.30 +            vars(self).update(vars(sequence))
    1.31 +        if name:
    1.32 +            self.name = name
    1.33 +        if description:
    1.34 +            self.description = description
    1.35 +        if source:
    1.36 +            self.source = source
    1.37  
    1.38      def __str__(self):
    1.39 -        """ Returns sequence in one-letter code """
    1.40 -        return ''.join([monomer.type.code1 for monomer in self.monomers])
    1.41 -
    1.42 -    def __eq__(self, other):
    1.43 -        """ Returns if all corresponding monomers of this sequences are equal
    1.44 -
    1.45 -        If lengths of sequences are not equal, returns False
    1.46 -        """
    1.47 -        return len(self) == len(other) and \
    1.48 -        all([a==b for a, b in zip(self.monomers, other.monomers)])
    1.49 -
    1.50 -    def __ne__(self, other):
    1.51 -        return not (self == other)
    1.52 +        """Returns sequence in one-letter code."""
    1.53 +        return ''.join(monomer.code1 for monomer in self)
    1.54  
    1.55      @classmethod
    1.56      def from_string(cls, string, name='', description=''):
    1.57 @@ -169,11 +169,8 @@
    1.58          monomers = [monomer(letter) for letter in string]
    1.59          return cls(monomers, name, description)
    1.60  
    1.61 -    def secstr_has(self, chain, monomer):
    1.62 -        return chain in self.pdb_secstr and monomer in self.pdb_secstr[chain]
    1.63 -
    1.64 -    @staticmethod
    1.65 -    def file_slice(file, n_from, n_to, fasta_name='', name='', description='', monomer_kind=AminoAcidType):
    1.66 +    @classmethod
    1.67 +    def file_slice(cls, file, n_from, n_to, fasta_name='', name='', description=''):
    1.68          """ Build and return sequence, consisting of part of sequence from file
    1.69  
    1.70          Does not control gaps
    1.71 @@ -189,7 +186,7 @@
    1.72              else:
    1.73                  n = len(line)
    1.74                  s += line[(n_from - number_user):(n_to - number_user)]
    1.75 -        return Sequence.from_str(s, name, description, monomer_kind)
    1.76 +        return cls.from_string(s, name, description)
    1.77  
    1.78  class Alignment(dict):
    1.79      """ Alignment
     2.1 --- a/allpy/pdb.py	Wed Dec 15 19:19:11 2010 +0300
     2.2 +++ b/allpy/pdb.py	Wed Dec 15 20:06:27 2010 +0300
     2.3 @@ -209,4 +209,7 @@
     2.4      def pdb_has(self, chain, monomer):
     2.5          return chain in self.pdb_residues and monomer in self.pdb_residues[chain]
     2.6  
     2.7 +    def secstr_has(self, chain, monomer):
     2.8 +        return chain in self.pdb_secstr and monomer in self.pdb_secstr[chain]
     2.9 +
    2.10  # vim: set ts=4 sts=4 sw=4 et: