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 -class SearchIndexer(_IndexedSeqFileProxy):
16 """Base class for file format specific random access. 17 18 Subclasses for each file format should define '_parser' and optionally 19 'get_raw' methods. 20 """ 21
22 - def __init__(self, filename, **kwargs):
23 self._handle = _open_for_random_access(filename) 24 self._kwargs = kwargs
25
26 - def _parse(self, handle):
27 return next(iter(self._parser(handle, **self._kwargs)))
28
29 - def get(self, offset):
30 return self._parse(StringIO(_bytes_to_string(self.get_raw(offset))))
31