[Biopython-dev] Biopython specific warning classes

Peter Cock p.j.a.cock at googlemail.com
Thu May 26 08:38:15 UTC 2011


On Wed, May 25, 2011 at 10:03 PM, Eric Talevich <eric.talevich at gmail.com> wrote:
> 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.

The warning in the GenBank file are also for clearly non-compliant files.

> 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.

Once we have the base classes of BiopythonWarning and ParserWarning
in place, you could introduce more subclasses - but it seems less and less
useful.

>> 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.

There are a couple of existing warnings of this kind, but I agree
they should be used sparingly.

>> 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.

Yes, to ignore any Biopython warnings you do:

from Bio import BiopythonWarning
warnings.simplefilter('ignore', BiopythonWarning)

or, to ignore just our parser warnings:

from Bio import ParserWarning
warnings.simplefilter('ignore', ParserWarning)

That seems easy to me ;)

>> 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.

OK then - I'll work on this.

Peter



More information about the Biopython-dev mailing list