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

allpy

changeset 285:99798ebaedc2

Automated merge with ssh://kodomo/allpy
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Wed, 15 Dec 2010 23:44:25 +0300
parents 0f17438fafb7 bee4d155f526
children cf6cdc3b7ec5
files
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/allpy/base.py	Wed Dec 15 21:51:01 2010 +0300
     1.2 +++ b/allpy/base.py	Wed Dec 15 23:44:25 2010 +0300
     1.3 @@ -5,9 +5,9 @@
     1.4  import urllib2
     1.5  
     1.6  import config
     1.7 +import fasta
     1.8  from graph import Graph
     1.9  from Bio.PDB.DSSP import make_dssp_dict
    1.10 -from fasta import save_fasta
    1.11  import data.codes
    1.12  
    1.13  class MonomerType(object):
    1.14 @@ -173,6 +173,18 @@
    1.15          monomers = [monomer(letter) for letter in string]
    1.16          return cls(monomers, name, description)
    1.17  
    1.18 +    @classmethod
    1.19 +    def from_fasta(cls, file):
    1.20 +        """Read sequence from FASTA file.
    1.21 +        
    1.22 +        File must contain exactly one sequence.
    1.23 +        """
    1.24 +        sequences = fasta.parse_file(file)
    1.25 +        assert len(sequences) == 1
    1.26 +        header = sequences.keys()[0]
    1.27 +        name, _, description = header.partition(" ")
    1.28 +        return cls(sequences[header], name, description, file.name)
    1.29 +
    1.30  class Alignment(dict):
    1.31      """Alignment.
    1.32  
     2.1 --- a/allpy/fasta.py	Wed Dec 15 21:51:01 2010 +0300
     2.2 +++ b/allpy/fasta.py	Wed Dec 15 23:44:25 2010 +0300
     2.3 @@ -1,3 +1,16 @@
     2.4 +def parse_fasta(file):
     2.5 +    """Parse fasta file, remove spaces and newlines from sequence bodies.
     2.6 +
     2.7 +    Return a dict of { sequence header: sequence body }.
     2.8 +    """
     2.9 +    sequences = {}
    2.10 +    for part in file.read().split(">"):
    2.11 +        header, _, body = part.partition("\n")
    2.12 +        header = header.lstrip(">").strip()
    2.13 +        body = body.replace(" ", "").replace("\n", "")
    2.14 +        sequences[header] = body
    2.15 +    return sequences
    2.16 +
    2.17  def save_fasta(out_file, string, name, description='', long_line=70):
    2.18      """ Saves given string to out_file in fasta_format
    2.19  
    2.20 @@ -19,3 +32,5 @@
    2.21          if len(lines) >= 2:
    2.22              return len(lines[0].strip())
    2.23      return 70
    2.24 +
    2.25 +# vim: set ts=4 sts=4 sw=4 et: