1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
# Copyright 2012 by Wibowo Arindrarto. All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license. Please see the LICENSE file that should have been included
# as part of this package.
"""Bio.SearchIO base classes for HMMER-related code."""
from Bio._py3k import _as_bytes
from Bio.SearchIO._index import SearchIndexer
class _BaseHmmerTextIndexer(SearchIndexer):
"""Base indexer class for HMMER plain text output."""
def __init__(self, *args, **kwargs):
super(_BaseHmmerTextIndexer, self).__init__(*args, **kwargs)
self._preamble = _as_bytes('')
def get_raw(self, offset):
"""Return the raw record from the file as a bytes string."""
handle = self._handle
qresult_raw = _as_bytes('')
# read header first
if not self._preamble:
handle.seek(0)
while True:
line = handle.readline()
if line.startswith(self.qresult_start):
break
qresult_raw += line
else:
qresult_raw += self._preamble
# and read the qresult raw string
handle.seek(offset)
while True:
# preserve whitespace, don't use read_forward
line = handle.readline()
qresult_raw += line
# break when we've reached qresult end
if line.startswith(self.qresult_end) or not line:
break
return qresult_raw
|