[BioPython] Weird biopython bug

Gavin Crooks gec at compbio.berkeley.edu
Tue Jun 1 15:49:16 EDT 2004


I've run into the following weird error; I can't import Bio.Fasta


> >>> from Bio import Fasta
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/Users/gec/CVSWork/biopython/Bio/Fasta/__init__.py", line 19, 
> in ?
>     from Bio import SeqRecord
>   File "/Users/gec/CVSWork/biopython/Bio/SeqRecord.py", line 11, in ?
>     default_output_format = "fasta")
>   File "/Users/gec/CVSWork/biopython/Bio/Bio/FormatIO.py", line 55, in 
> __init__
>     registery = Bio.formats
> AttributeError: 'module' object has no attribute 'formats'


This also fails with the same error..
	cd Tests
	python test_Fasta.py

But this works and the Fasta unit test passes!
	python run_tests.py test_Fasta.py

There appear to be two problems. The first is in this code from the 
start of SeqRecord (which is imported in Fasta.py).

> import sys
> if getattr(sys, "version_info", (1, 5))[:2] >= (2,1):
>   from Bio import FormatIO
>   # Should this be in the module namespace or the record namespace?
>   io = FormatIO.FormatIO("SeqRecord",
>                          default_input_format = "sequence",
>                          default_output_format = "fasta")

This code is meant to run when SeqRecord is imported. But run_tests 
uses the __import__ hook which bypasses this code. Thus the unit test 
works, but a direct
import does not. Removing the 'if' statement entirely appears to fix 
this problem.

The other problem is in FormatIO.FormatIO

> class FormatIO:
>     def __init__(self, name,
>                  default_input_format = None,
>                  default_output_format = None,
>                  abbrev = None,
>                  registery = None):
>         if abbrev is None:
>             abbrev = name
>         if registery is None:
>             import Bio
>             registery = Bio.formats
>         ...

This fails whenever 'registery' is None since Bio.formats does not 
appear to exist.

FormatIO.FormatIO is never called in any unit test so removing 
FormatIO.py altogether seems like an easy fix. However, I don't know 
what FormatIO is meant to do, nor do I understand the chunk of code in 
SeqRecord. What is going here?


Gavin




--
Gavin E. Crooks
Postdoctoral Fellow                  tel:  (510) 642-9614
461 Koshland Hall                    aim:notastring
University of California             http://threeplusone.com/
Berkeley, CA 94720-3102, USA         gec at compbio.berkeley.edu



More information about the BioPython mailing list