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

allpy

changeset 147:db9d116e979f

documentation improvements
author boris <bnagaev@gmail.com>
date Sun, 24 Oct 2010 23:12:15 +0400
parents 8f1d8ece31af
children bc4c291cc2b0
files geometrical_core/geometrical_core.py lib/allpy_pdb.py lib/block.py lib/graph.py lib/monomer.py lib/project.py lib/sequence.py
diffstat 7 files changed, 56 insertions(+), 74 deletions(-) [+]
line diff
     1.1 --- a/geometrical_core/geometrical_core.py	Sun Oct 24 22:25:36 2010 +0400
     1.2 +++ b/geometrical_core/geometrical_core.py	Sun Oct 24 23:12:15 2010 +0400
     1.3 @@ -15,9 +15,7 @@
     1.4  c = config
     1.5  
     1.6  def f_nng(string):
     1.7 -    """
     1.8 -    Validates nonnegative (>=0) float
     1.9 -    """
    1.10 +    """ Validates nonnegative (>=0) float """
    1.11      try:
    1.12          value = float(string)
    1.13      except:
    1.14 @@ -29,9 +27,7 @@
    1.15      return value
    1.16  
    1.17  def part(string):
    1.18 -    """
    1.19 -    Validates 0.0 <= float <= 1.0
    1.20 -    """
    1.21 +    """ Validates 0.0 <= float <= 1.0 """
    1.22      try:
    1.23          value = float(string)
    1.24      except:
    1.25 @@ -43,9 +39,7 @@
    1.26      return value
    1.27  
    1.28  def timeout(string):
    1.29 -    """
    1.30 -    Validates int >= -1
    1.31 -    """
    1.32 +    """ Validates int >= -1 """
    1.33      try:
    1.34          value = int(string)
    1.35      except:
    1.36 @@ -57,9 +51,7 @@
    1.37      return value
    1.38  
    1.39  def pos(string):
    1.40 -    """
    1.41 -    Validates positive integer
    1.42 -    """
    1.43 +    """ Validates positive integer """
    1.44      try:
    1.45          value = int(string)
    1.46      except:
    1.47 @@ -71,9 +63,7 @@
    1.48      return value
    1.49  
    1.50  def i_nng(string):
    1.51 -    """
    1.52 -    Validates int >= 0
    1.53 -    """
    1.54 +    """ Validates int >= 0 """
    1.55      try:
    1.56          value = int(string)
    1.57      except:
     2.1 --- a/lib/allpy_pdb.py	Sun Oct 24 22:25:36 2010 +0400
     2.2 +++ b/lib/allpy_pdb.py	Sun Oct 24 23:12:15 2010 +0400
     2.3 @@ -1,8 +1,7 @@
     2.4  
     2.5  import re
     2.6  
     2.7 -"""
     2.8 -Functions to get pdb information from fasta id
     2.9 +""" Functions to get pdb information from fasta id
    2.10  and to generate fasta id from pdb information
    2.11  
    2.12  pdb information: code, chain, model
     3.1 --- a/lib/block.py	Sun Oct 24 22:25:36 2010 +0400
     3.2 +++ b/lib/block.py	Sun Oct 24 23:12:15 2010 +0400
     3.3 @@ -10,7 +10,8 @@
     3.4  from Bio.PDB import Superimposer
     3.5  
     3.6  class Block(object):
     3.7 -    """
     3.8 +    """ Block of alignment
     3.9 +    
    3.10      Mandatory data:
    3.11      *   self.project -- project object, which the block belongs to
    3.12      *   self.sequences - set of sequence objects that contain monomers
    3.13 @@ -28,8 +29,8 @@
    3.14      """
    3.15      
    3.16      def __init__(self, project, sequences=None, positions=None):
    3.17 -        """
    3.18 -        Builds new block from project
    3.19 +        """ Builds new block from project
    3.20 +        
    3.21          if sequences==None, all sequences are used
    3.22          if positions==None, all positions are used
    3.23          """
     4.1 --- a/lib/graph.py	Sun Oct 24 22:25:36 2010 +0400
     4.2 +++ b/lib/graph.py	Sun Oct 24 23:12:15 2010 +0400
     4.3 @@ -9,7 +9,8 @@
     4.4  
     4.5  
     4.6  class Graph(object):
     4.7 -    """
     4.8 +    """ Undirected weighted graph
     4.9 +    
    4.10      Data:
    4.11      nodes -- set of elements
    4.12      lines -- {line: cost}. 
    4.13 @@ -56,22 +57,16 @@
    4.14          return k1 == k2 or Graph.line(k1, k2) in self.lines
    4.15      
    4.16      def count_one(self, node):
    4.17 -        """
    4.18 -        Returns number of connections of this node
    4.19 -        """
    4.20 +        """ Returns number of connections of this node """
    4.21          return len([node1 for node1 in self.nodes if self.bounded(node, node1)]) - 1
    4.22      
    4.23      def cost_one(self, node):
    4.24 -        """
    4.25 -        Returns sum of costs of all connections of this node
    4.26 -        """
    4.27 +        """ Returns sum of costs of all connections of this node """
    4.28          return sum([self.lines.get(Graph.line(node, node1), 0) 
    4.29          for node1 in self.nodes if node != node1])
    4.30      
    4.31      def count_all(self):
    4.32 -        """
    4.33 -        Returns {node: number of connections of this node}
    4.34 -        """
    4.35 +        """ Returns {node: number of connections of this node} """
    4.36          c = dict([(node, 0) for node in self.nodes])
    4.37          for line in self.lines:
    4.38              for node in line:
    4.39 @@ -80,16 +75,14 @@
    4.40      
    4.41      
    4.42      def drop_node(self, node):
    4.43 -        """
    4.44 -        Remove node and all involved lines
    4.45 -        """
    4.46 +        """ Remove node and all involved lines """
    4.47          for node1 in self.nodes:
    4.48              self.lines.pop(Graph.line(node, node1), None)
    4.49          self.nodes.discard(node)
    4.50      
    4.51      def add_node(self, node, parent_graph):
    4.52 -        """
    4.53 -        Add node and corresponding lines from parent_graph
    4.54 +        """ Add node and corresponding lines from parent_graph
    4.55 +        
    4.56          Added lines should be contained in self graph
    4.57          (takes care of hanging lines)
    4.58          """
    4.59 @@ -100,8 +93,7 @@
    4.60                  self.lines[line] = parent_graph.lines[line]
    4.61      
    4.62      def drop_nodes(self, nodes):
    4.63 -        """
    4.64 -        Run drop_node for each of given nodes
    4.65 +        """ Run drop_node for each of given nodes
    4.66          Returns if nodes was not empty (ugly beauty)
    4.67          """
    4.68          for node in nodes:
    4.69 @@ -109,16 +101,15 @@
    4.70          return bool(nodes)
    4.71      
    4.72      def drop_if_count(self, minsize):
    4.73 -        """
    4.74 -        Run drop_node for each node, that has less than minsize lines
    4.75 -        """
    4.76 +        """ Run drop_node for each node, that has less than minsize lines """
    4.77          while True:
    4.78              if not self.drop_nodes([node for (node, count) 
    4.79              in self.count_all().items() if count < minsize]):
    4.80                  break
    4.81       
    4.82      def bron_kerbosh(self, timeout=-1, minsize=1):
    4.83 -        """
    4.84 +        """ Bron and Kerboch algorithm implementation
    4.85 +        
    4.86          returns list of cliques
    4.87          clique is frozenset
    4.88          if timeout=-1, it means infinity
    4.89 @@ -217,8 +208,8 @@
    4.90  
    4.91      
    4.92      def fast_cliques(self, minsize=1):
    4.93 -        """
    4.94 -        returns list of cliques
    4.95 +        """ returns list of cliques
    4.96 +        
    4.97          clique is frozenset
    4.98          """
    4.99          print 'Fast algorithm started'
   4.100 @@ -270,8 +261,8 @@
   4.101          
   4.102      
   4.103      def cliques(self, timeout=-1, minsize=1):
   4.104 -        """
   4.105 -        returns length-sorted list of cliques
   4.106 +        """ returns length-sorted list of cliques
   4.107 +        
   4.108          clique is frozenset
   4.109          
   4.110          can change self!
     5.1 --- a/lib/monomer.py	Sun Oct 24 22:25:36 2010 +0400
     5.2 +++ b/lib/monomer.py	Sun Oct 24 23:12:15 2010 +0400
     5.3 @@ -9,8 +9,8 @@
     5.4  
     5.5  
     5.6  class MonomerType(object):
     5.7 -    """
     5.8 -    Monomer type
     5.9 +    """ Monomer type
    5.10 +    
    5.11      name -- string like "Valine" 
    5.12      code1 -- one-letter code (in upper case)
    5.13      code3 -- three-letter code (in upper case)
    5.14 @@ -45,7 +45,8 @@
    5.15  
    5.16  
    5.17  class Monomer(object):
    5.18 -    """
    5.19 +    """ Monomer 
    5.20 +    
    5.21      type -- link to MonomerType object
    5.22      pdb_residues -- dictionary like {Bio.PDB.Chain: Bio.PDB.Residue}
    5.23      """
    5.24 @@ -76,9 +77,7 @@
    5.25  
    5.26  
    5.27  class AminoAcid(Monomer):
    5.28 -    """
    5.29 -    Amino acid
    5.30 -    """
    5.31 +    """  Amino acid """
    5.32      pass
    5.33      
    5.34  
     6.1 --- a/lib/project.py	Sun Oct 24 22:25:36 2010 +0400
     6.2 +++ b/lib/project.py	Sun Oct 24 23:12:15 2010 +0400
     6.3 @@ -18,7 +18,8 @@
     6.4  Block = block.Block
     6.5  
     6.6  class Project(object):
     6.7 -    """
     6.8 +    """ Alignment representing class
     6.9 +    
    6.10      Mandatory data:
    6.11      *   sequences -- list of Sequence objects. Sequences don't contain gaps
    6.12           - see sequence.py module
    6.13 @@ -53,8 +54,7 @@
    6.14          return max([len(line) for line in self.alignment.values()])
    6.15  
    6.16      def thickness(self):
    6.17 -        """ The number of sequences in alignment (it's thickness).
    6.18 -        """
    6.19 +        """ The number of sequences in alignment (it's thickness). """
    6.20          return len(self.alignment)
    6.21         
    6.22      def calc_identity(self):
    6.23 @@ -98,7 +98,10 @@
    6.24  
    6.25      @staticmethod
    6.26      def from_fasta(file, monomer_kind=AminoAcidType):
    6.27 -        """
    6.28 +        """ Import data from fasta file
    6.29 +        
    6.30 +        monomer_kind is class, inherited from MonomerType
    6.31 +        
    6.32          >>> import project
    6.33          >>> sequences,alignment=project.Project.from_fasta(open("test.fasta"))       
    6.34          """
    6.35 @@ -150,9 +153,9 @@
    6.36      
    6.37      @staticmethod
    6.38      def from_sequences(*sequences):
    6.39 -        """
    6.40 -        Constructs new alignment from sequences
    6.41 -        Add gaps to right end to make equal lengthes of alignment sequences 
    6.42 +        """  Constructs new alignment from sequences
    6.43 +        
    6.44 +        Add None's to right end to make equal lengthes of alignment sequences 
    6.45          """
    6.46          project = Project()
    6.47          project.sequences = sequences
    6.48 @@ -163,16 +166,16 @@
    6.49          return project
    6.50      
    6.51      def save_fasta(self, out_file, long_line=60, gap='-'):
    6.52 -        """
    6.53 -        Saves alignment to given file
    6.54 +        """ Saves alignment to given file
    6.55 +        
    6.56          Splits long lines to substrings of length=long_line
    6.57          To prevent this, set long_line=None 
    6.58          """
    6.59          Block(self).save_fasta(out_file, long_line=long_line, gap=gap)
    6.60          
    6.61      def muscle_align(self):
    6.62 -        """
    6.63 -        Simple align ths alignment using sequences (muscle)
    6.64 +        """ Simple align ths alignment using sequences (muscle)
    6.65 +        
    6.66          uses old Monomers and Sequences objects
    6.67          """
    6.68          tmp_file, tmp_filename = mkstemp()
    6.69 @@ -200,8 +203,8 @@
    6.70                      self.alignment[sequence].append(old_monomer)
    6.71      
    6.72      def column(self, sequence=None, sequences=None, original=None):
    6.73 -        """
    6.74 -        returns list of columns of alignment
    6.75 +        """ returns list of columns of alignment
    6.76 +        
    6.77          sequence or sequences:
    6.78              if sequence is given, then column is (original_monomer, monomer)
    6.79              if sequences is given, then column is (original_monomer, {sequence: monomer}) 
    6.80 @@ -224,8 +227,7 @@
    6.81                      dict([(s, column[indexes[s]]) for s in sequences]))
    6.82          
    6.83      def pdb_auto_add(self, conformity_file=None):
    6.84 -        """
    6.85 -        Adds pdb information to each sequence
    6.86 +        """ Adds pdb information to each sequence
    6.87          
    6.88          TODO: conformity_file
    6.89          """
     7.1 --- a/lib/sequence.py	Sun Oct 24 22:25:36 2010 +0400
     7.2 +++ b/lib/sequence.py	Sun Oct 24 23:12:15 2010 +0400
     7.3 @@ -11,7 +11,8 @@
     7.4  cappbuilder = CaPPBuilder()
     7.5  
     7.6  class Sequence(object):
     7.7 -    """
     7.8 +    """ Sequence of Monomers
     7.9 +    
    7.10      Mandatory data:
    7.11      *   name -- str with the name of sequence
    7.12      *   description -- str with description of the sequence
    7.13 @@ -42,8 +43,8 @@
    7.14          return not (self == other)
    7.15      
    7.16      def pdb_chain_add(self, pdb_file, pdb_id, pdb_chain, pdb_model=0):
    7.17 -        """
    7.18 -        Reads Pdb chain from file 
    7.19 +        """ Reads Pdb chain from file 
    7.20 +        
    7.21          and align each Monomer with PDB.Residue (TODO)
    7.22          """
    7.23          name = std_id(pdb_id, pdb_chain, pdb_model)
    7.24 @@ -65,9 +66,9 @@
    7.25  
    7.26      @staticmethod
    7.27      def from_pdb_chain(chain):
    7.28 -        """
    7.29 +        """ returns Sequence with Monomers with link to Bio.PDB.Residue
    7.30 +        
    7.31          chain is Bio.PDB.Chain
    7.32 -        returns Sequence with Monomers with link to Bio.PDB.Residue
    7.33          """
    7.34          peptide = cappbuilder.build_peptides(chain)[0]        
    7.35          sequence = Sequence()
    7.36 @@ -80,10 +81,9 @@
    7.37          return sequence
    7.38      
    7.39      def pdb_auto_add(self, conformity_info=None):
    7.40 -        """
    7.41 -        Adds pdb information to each monomer
    7.42 +        """ Adds pdb information to each monomer
    7.43 +        
    7.44          Returns if information has been successfully added
    7.45 -        
    7.46          TODO: conformity_file
    7.47          """
    7.48          if not conformity_info: