[Biopython-dev] Trie with_prefix doesn't work as expected

Kevin Wu kjwu at ucsd.edu
Tue Jan 29 21:09:42 EST 2013


Hi All,

I'm attempting to use the trie implementation in biopython to develop a
suffix trie. I'm using the with_prefix function to find all keys which
start with a sequence, however, the function doesn't return values that I
expect. I tested it with the canonical example "banana" and am a bit
confused.

from Bio.trie import trie
t = trie()
s = "BANANA"
for i in range(len(s)):  # insert all suffixes into trie
    t[s[i:]] = i

t.with_prefix("NA")  # this works as expected
>> ['NA', 'NANA']

t.with_prefix("AN")
>> ['AN', 'ANNA']  # this doesn't work as expected
                           # expected output: ["ANANA", "ANA"]

Can anyone clarify my confusion or confirm this bug? I'm on Biopython 1.60,
Linux Mint 64-bit.

Thanks!
Kevin


More information about the Biopython-dev mailing list