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

allpy

changeset 764:d16e8559b6dd

allpy.fileio: switched to using iterator-based read methods everywhere. Python prohibits mixing iterator and file.read methods. This caused problem in "mixin" format IO.
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Tue, 12 Jul 2011 14:37:05 +0400
parents 682c272e6e84
children c76ccff11df5
files allpy/fileio.py
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/allpy/fileio.py	Tue Jul 12 01:50:56 2011 +0400
     1.2 +++ b/allpy/fileio.py	Tue Jul 12 14:37:05 2011 +0400
     1.3 @@ -67,8 +67,24 @@
     1.4          for string, name, description in sequences:
     1.5              self.write_string(string, name, description)
     1.6  
     1.7 +    def read_parts(self):
     1.8 +        """Read parts beginning with > in FASTA file.
     1.9 +
    1.10 +        This is a drop-in replacement for self.file.read().split("\n>")
    1.11 +        It is required for markup format, which combines parts read with
    1.12 +        different parsers. Python prohibits combining iterators and file.read
    1.13 +        methods on the same file.
    1.14 +        """
    1.15 +        part = None
    1.16 +        for line in self.file:
    1.17 +            if line.startswith(">"):
    1.18 +                if part: yield part
    1.19 +                part = ""
    1.20 +            part += line
    1.21 +        if part: yield part
    1.22 +
    1.23      def read_strings(self):
    1.24 -        for part in self.file.read().split("\n>"):
    1.25 +        for part in self.read_parts():
    1.26              header, _, body = part.partition("\n")
    1.27              header = header.lstrip(">")
    1.28              name, _, description = header.partition(" ")