[BioPython] Biopython added to course syllabus

Brad Chapman chapmanb@arches.uga.edu
Thu, 6 Dec 2001 12:01:43 -0500


Hi Scott;


> gets the same error trying to parse different genbank files so I think it
> a very general problem with the new Bio/Genbank/__init__.py
[...]
> self.Intron_data[feature.qualifiers["gene"]] = intron_data
[...]
> (beagle)[2:16pm]myexamples>>python gb_int_ex_gc_content.py
> short_test_file.gb
> filename: short_test_file.gb
> Traceback (most recent call last):
>   File "gb_int_ex_gc_content.py", line 27, in ?
>     intron_sequences = gb_parser.get_introns(filename)
>   File "GenBank_Parser.py", line 106, in get_introns
>     self.Intron_data[feature.qualifiers["gene"]] = intron_data
> TypeError: unhashable type

Yup, now I know the problem. I recently changed
feature.qualifiers["whatever"] to be a list instead of a single item. I
did this because the keys in a qualifier table are not necessarily
unique (ie. you may have "gene" or something else twice). So, the
unhashable type error comes from the fact that
feature.qualifiers["gene"] returns a list, which can't be used as a
dictionary key (because it is mutable). 

If you change the code to 

self.Intron_data[feature.qualifiers["gene"][0]] = intron_data
                                           ^^^    
everything should work fine.

This is a relatively new change (since the last release), 
and I hashed it out in detail here:

http://www.biopython.org/pipermail/biopython-dev/2001-September/000579.html

Oops, this also means the code I posted before was wrong. The diff is:

mrna_name = feature.qualifiers["gene"][0]
for:
mrna_name = feature.qualifiers["gene"]

That's what I get for not runnign it :-)

> 1)  I only changed the __init__.py file, but not
> the genbank_formater.py (I guess you meant genbank_format.py) file. Do I
> have to change the genbank_format.py also? The file that gives error is
> attached. The code used here works with the earlier version of __init__.py

You may see other errors with different versions of __init__.py and
genbank_format.py; you should probably update them both at once.

> [He also wanted to know if you know of any way to directly
> reverse_complement sequences uing the seq objects with Biopython. It is
> easy to write a script but if it is available...]

Thomas' newish Bio/sequtils.py package has both complement() and reverse()
functions, which should do it.

> Thanks for any help you can send my way! -Scott

Hope this helps!

> P.S. I love the idea of a generic application framework - I really wanted
> something like this for python and biopython.

Glad you are excited. Now I just have to get my act together and submit
this :-).

Brad