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  # Revisions copyright 2012-2016 by Peter Cock.  All rights reserved. 
 3  # 
 4  # This file is part of the Biopython distribution and governed by your 
 5  # choice of the "Biopython License Agreement" or the "BSD 3-Clause License". 
 6  # Please see the LICENSE file that should have been included as part of this 
 7  # package. 
 8   
 9  """Custom indexing for Bio.SearchIO objects.""" 
10   
11  from Bio._py3k 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 next(iter(self._parser(handle, **self._kwargs)))
30
31 - def get(self, offset):
32 return self._parse(StringIO(_bytes_to_string(self.get_raw(offset))))
33