[Biopython-dev] Biopython specific warning classes

Eric Talevich eric.talevich at gmail.com
Wed May 25 21:03:23 UTC 2011


On Wed, May 18, 2011 at 3:42 PM, Peter Cock <p.j.a.cock at googlemail.com>wrote:

> Hi all,
>
> I've been thinking we should introduce some specific warning
> classes to Biopython, in particular:
>
> ParserWarning, for any "dodgy" input files, such as invalid
> GenBank LOCUS lines, and so on. The existing PDB parser
> warning should become a subclass of this.
>

This would fit well with what PDB and Phylo already do. My docstring for
PhyloXMLWarning says it's for non-compliance with the format's
specification.

An alternate way to do this (but less easily scaled for SeqIO) is to have
warnings for each format, triggered whenever the spec for that format is
violated.


WriterWarning, for things like "data loss", e.g. record IDs
> getting truncated in PHYLIP output.
>

I'm not sure whether this would be handy or tedious -- a lot of formats
could conceivably lose some data in a SeqRecord, and adding checks to each
writer might be too much. Maybe just document these things well somewhere.


Perhaps even a base class BiopythonWarning, which would
> be useful for people wanting to ignore all the Biopython issued
> warnings - it might be helpful in our unit tests too.
>

We should make sure these are very easy to use, to avoid making the scheme
complicated, like:

>>> from Bio import BiopythonWarning

or

>>> from Bio.Warnings import BiopythonWarning, ParserWarning, WriterWarning
>>> warnings.simplefilter('ignore', ParserWarning)

I guess it's not so bad.


 Currently (apart from the PDB module), we tend to use
> the default UserWarning which makes filtering the warnings
> as an end user (or a unit test writer) quite hard.
>

Yeah, I think it would be better to reserve UserWarning for the user's
application code, rather than emitting them from the Biopython library.

-Eric



More information about the Biopython-dev mailing list