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  #TODO: factor out this module with SeqIO's _index to stay DRY 
 8   
 9  """Custom indexing for Bio.SearchIO objects.""" 
10   
11  from StringIO import StringIO 
12  from Bio._py3k import _bytes_to_string 
13  from Bio import bgzf 
14  from Bio.File import _IndexedSeqFileProxy, _open_for_random_access 
15   
16   
17 -class SearchIndexer(_IndexedSeqFileProxy):
18 """Base class for file format specific random access. 19 20 Subclasses for each file format should define '_parser' and optionally 21 'get_raw' methods. 22 """ 23
24 - def __init__(self, filename, **kwargs):
25 self._handle = _open_for_random_access(filename) 26 self._kwargs = kwargs
27
28 - def _parse(self, handle):
29 return iter(self._parser(handle, **self._kwargs)).next()
30
31 - def get(self, offset):
32 return self._parse(StringIO(_bytes_to_string(self.get_raw(offset))))
33