Package Bio :: Module File :: Class _SQLiteManySeqFilesDict
[hide private]
[frames] | no frames]

Class _SQLiteManySeqFilesDict

source code

UserDict.DictMixin --+    
                     |    
   _IndexedSeqFileDict --+
                         |
                        _SQLiteManySeqFilesDict

Read only dictionary interface to many sequential record files.

This code is used in both Bio.SeqIO for indexing as SeqRecord objects, and in Bio.SearchIO for indexing QueryResult objects.

Keeps the keys, file-numbers and offsets in an SQLite database. To access a record by key, reads from the offset in the appropriate file and then parses the record into an object.

There are OS limits on the number of files that can be open at once, so a pool are kept. If a record is required from a closed file, then one of the open handles is closed first.

Instance Methods [hide private]
 
__init__(self, index_filename, filenames, proxy_factory, format, key_function, repr, max_open=10)
Initialize the class.
source code
 
_load_index(self)
Call from __init__ to re-use an existing index (PRIVATE).
source code
 
_build_index(self)
Call from __init__ to create a new index (PRIVATE).
source code
 
__repr__(self)
Return a string representation of the File object.
source code
 
__contains__(self, key)
Return key if contained in the offsets dictionary.
source code
 
__len__(self)
Return the number of records indexed.
source code
 
__iter__(self)
Iterate over the keys.
source code
 
keys(self)
Iterate over the keys.
source code
 
__getitem__(self, key)
Return record for the specified key.
source code
 
get(self, k, d=None)
Return the value in the dictionary.
source code
 
get_raw(self, key)
Return the raw record from the file as a bytes string.
source code
 
close(self)
Close any open file handles.
source code

Inherited from _IndexedSeqFileDict: __setitem__, __str__, clear, copy, fromkeys, items, iteritems, iterkeys, itervalues, pop, popitem, update, values

Inherited from UserDict.DictMixin: __cmp__, has_key, setdefault

Method Details [hide private]

__init__(self, index_filename, filenames, proxy_factory, format, key_function, repr, max_open=10)
(Constructor)

source code 
Initialize the class.
Overrides: _IndexedSeqFileDict.__init__

__repr__(self)
(Representation operator)

source code 
Return a string representation of the File object.
Overrides: UserDict.DictMixin.__repr__

__contains__(self, key)
(In operator)

source code 
Return key if contained in the offsets dictionary.
Overrides: UserDict.DictMixin.__contains__

__len__(self)
(Length operator)

source code 
Return the number of records indexed.
Overrides: UserDict.DictMixin.__len__

__iter__(self)

source code 
Iterate over the keys.
Overrides: UserDict.DictMixin.__iter__

keys(self)

source code 

Iterate over the keys.

This tries to act like a Python 3 dictionary, and does not return a list of keys due to memory concerns.

Overrides: _IndexedSeqFileDict.keys

__getitem__(self, key)
(Indexing operator)

source code 
Return record for the specified key.
Overrides: _IndexedSeqFileDict.__getitem__

get(self, k, d=None)

source code 

Return the value in the dictionary.

If the key (k) is not found, this returns None unless a default (d) is specified.

Overrides: UserDict.DictMixin.get

get_raw(self, key)

source code 

Return the raw record from the file as a bytes string.

If the key is not found, a KeyError exception is raised.

Overrides: _IndexedSeqFileDict.get_raw

close(self)

source code 
Close any open file handles.
Overrides: _IndexedSeqFileDict.close