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

Source Code for Module Bio.SearchIO._index

 1  # Copyright 2012 by Wibowo Arindrarto.  All rights reserved. 
 2  # All rights reserved. 
 3  # This code is part of the Biopython distribution and governed by its 
 4  # license.  Please see the LICENSE file that should have been included 
 5  # as part of this package. 
 6   
 7  """Custom indexing for Bio.SearchIO objects.""" 
 8   
 9  from Bio._py3k import StringIO 
10  from Bio._py3k import _bytes_to_string 
11  from Bio import bgzf 
12  from Bio.File import _IndexedSeqFileProxy, _open_for_random_access 
13   
14   
15  __docformat__ = "restructuredtext en" 
16   
17   
18 -class SearchIndexer(_IndexedSeqFileProxy):
19 """Base class for file format specific random access. 20 21 Subclasses for each file format should define '_parser' and optionally 22 'get_raw' methods. 23 """ 24
25 - def __init__(self, filename, **kwargs):
26 self._handle = _open_for_random_access(filename) 27 self._kwargs = kwargs
28
29 - def _parse(self, handle):
30 return next(iter(self._parser(handle, **self._kwargs)))
31
32 - def get(self, offset):
33 return self._parse(StringIO(_bytes_to_string(self.get_raw(offset))))
34