Package Bio :: Package SeqIO :: Module _index :: Class _IndexedSeqFileDict
[hide private]
[frames] | no frames]

Class _IndexedSeqFileDict

source code

object --+    
         |    
      dict --+
             |
            _IndexedSeqFileDict
Known Subclasses:

Read only dictionary interface to a sequential sequence file.

Keeps the keys in memory, reads the file to access entries as SeqRecord objects using Bio.SeqIO for parsing them. This approach is memory limited, but will work even with millions of sequences.

Note - as with the Bio.SeqIO.to_dict() function, duplicate keys (record identifiers by default) are not allowed. If this happens, a ValueError exception is raised.

By default the SeqRecord's id string is used as the dictionary key. This can be changed by suppling an optional key_function, a callback function which will be given the record id and must return the desired key. For example, this allows you to parse NCBI style FASTA identifiers, and extract the GI number to use as the dictionary key.

Note that this dictionary is essentially read only. You cannot add or change values, pop values, nor clear the dictionary.

Instance Methods [hide private]
new empty dictionary

__init__(self, filename, alphabet, key_function, mode='rU')
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
 
_record_key(self, identifier, seek_position)
Used by subclasses to record file offsets for identifiers (PRIVATE).
source code
list of D's values
values(self)
Would be a list of the SeqRecord objects, but not implemented.
source code
list of D's (key, value) pairs, as 2-tuples
items(self)
Would be a list of the (key, SeqRecord) tuples, but not implemented.
source code
an iterator over the (key, value) items of D
iteritems(self)
Iterate over the (key, SeqRecord) items.
source code
 
__getitem__(x, y)
x[y]
source code
D[k] if k in D, else d
get(D, k, d=...)
d defaults to None.
source code
 
get_raw(self, key)
Similar to the get method, but returns the record as a raw string.
source code
 
__setitem__(self, key, value)
Would allow setting or replacing records, but not implemented.
source code
None
update(self, **kwargs)
Would allow adding more values, but not implemented.
source code
v, remove specified key and return the corresponding value
pop(self, key, default=None)
Would remove specified record, but not implemented.
source code
(k, v), remove and return some (key, value) pair as a
popitem(self)
Would remove and return a SeqRecord, but not implemented.
source code
None
clear(self)
Would clear dictionary, but not implemented.
source code
New dict with keys from S and values equal to v
fromkeys(self, keys, value=None)
A dictionary method which we don't implement.
source code
a shallow copy of D
copy(self)
A dictionary method which we don't implement.
source code

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __gt__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __sizeof__, has_key, iterkeys, itervalues, keys, setdefault

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __subclasshook__

Class Variables [hide private]

Inherited from dict: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, filename, alphabet, key_function, mode='rU')
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Returns:
new empty dictionary

Overrides: object.__init__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

_record_key(self, identifier, seek_position)

source code 

Used by subclasses to record file offsets for identifiers (PRIVATE).

This will apply the key_function (if given) to map the record id string to the desired key.

This will raise a ValueError if a key (record id string) occurs more than once.

values(self)

source code 

Would be a list of the SeqRecord objects, but not implemented.

In general you can be indexing very very large files, with millions of sequences. Loading all these into memory at once as SeqRecord objects would (probably) use up all the RAM. Therefore we simply don't support this dictionary method.

Returns: list of D's values
Overrides: dict.values

items(self)

source code 

Would be a list of the (key, SeqRecord) tuples, but not implemented.

In general you can be indexing very very large files, with millions of sequences. Loading all these into memory at once as SeqRecord objects would (probably) use up all the RAM. Therefore we simply don't support this dictionary method.

Returns: list of D's (key, value) pairs, as 2-tuples
Overrides: dict.items

iteritems(self)

source code 

Iterate over the (key, SeqRecord) items.

Returns: an iterator over the (key, value) items of D
Overrides: dict.iteritems

__getitem__(x, y)
(Indexing operator)

source code 

x[y]

Overrides: dict.__getitem__

get(D, k, d=...)

source code 

d defaults to None.

Returns: D[k] if k in D, else d
Overrides: dict.get

get_raw(self, key)

source code 

Similar to the get method, but returns the record as a raw string.

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

NOTE - This functionality is not supported for every file format.

__setitem__(self, key, value)
(Index assignment operator)

source code 

Would allow setting or replacing records, but not implemented.

Overrides: dict.__setitem__

update(self, **kwargs)

source code 

Would allow adding more values, but not implemented.

Returns: None
Overrides: dict.update

pop(self, key, default=None)

source code 

Would remove specified record, but not implemented.

Returns: v, remove specified key and return the corresponding value
Overrides: dict.pop

popitem(self)

source code 

Would remove and return a SeqRecord, but not implemented.

Returns: (k, v), remove and return some (key, value) pair as a
Overrides: dict.popitem

clear(self)

source code 

Would clear dictionary, but not implemented.

Returns: None
Overrides: dict.clear

fromkeys(self, keys, value=None)

source code 

A dictionary method which we don't implement.

Returns: New dict with keys from S and values equal to v
Overrides: dict.fromkeys

copy(self)

source code 

A dictionary method which we don't implement.

Returns: a shallow copy of D
Overrides: dict.copy