[Biopython-dev] [Bug 1718] New: Fasta.Dictionary should support
"in" (the __contains__ method)
bugzilla-daemon at portal.open-bio.org
bugzilla-daemon at portal.open-bio.org
Wed Dec 8 19:00:15 EST 2004
http://bugzilla.open-bio.org/show_bug.cgi?id=1718
Summary: Fasta.Dictionary should support "in" (the __contains__
method)
Product: Biopython
Version: Not Applicable
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Main Distribution
AssignedTo: biopython-dev at biopython.org
ReportedBy: biopython-bugzilla at maubp.freeserve.co.uk
With a real Python dictionary you can do this:
dictionary = {'A' : 'Apple', 'B' : 'Bananna', 'C' : 'Cherry'}
print 'A' in dictionary
print 'D' in dictionary
The Fasta.Dictionary does not support this. It fails with a TypeError exception
from Mindy which is very confusing to a novice (full traceback below).
Possible implementation in Bio/Fasta/__init__.py is as follows:
def __contains__(self, key) :
"""key in D -> True if D has a key k, else False
"""
return key in self._index['id'].keys()
A Mindy expert may have a more efficient way of doing this.
----------------------------------------------------------------
Traceback (most recent call last):
File "C:\Temp\fasta_dict_bug\test.py", line 33, in ?
print 'Alpha' in fasta_dict
File "C:\Python23\lib\site-packages\Bio\Fasta\__init__.py", line 187, in
__getitem__
seqs = self._index.lookup(id = key)
File "c:\python23\Lib\site-packages\Bio\Mindy\BaseDB.py", line 118, in lookup
return self[namespace][name]
File "c:\python23\Lib\site-packages\Bio\Mindy\FlatDB.py", line 329, in __getitem__
loc = _lookup_location(self.db.key_filename, name)
File "c:\python23\Lib\site-packages\Bio\Mindy\FlatDB.py", line 258, in
_lookup_location
line = _find_entry(key_filename, word)
File "c:\python23\Lib\site-packages\Bio\Mindy\FlatDB.py", line 235, in _find_entry
if not line.startswith(wantword):
TypeError: expected a character buffer object
----------------------------------------------------------------
See also the related:
Bug 1716 - Fasta.Dictionary should throw KeyError for invalid keys
Bug 1717 - Fasta.Dictionary should support has_key
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
More information about the Biopython-dev
mailing list