Package Bio :: Package SearchIO :: Package HmmerIO :: Module _base
[hide private]
[frames] | no frames]

Source Code for Module Bio.SearchIO.HmmerIO._base

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