chapmanb / bcbb

Incubator for useful bioinformatics code, primarily in Python and R

Home Page:http://bcbio.wordpress.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Importing BCBio.GFF suppresses Biopython warnings in external code

victorlin opened this issue · comments

from Bio import BiopythonDeprecationWarning
warnings.simplefilter("ignore", BiopythonDeprecationWarning)

The above lines may have been added with good intents to reduce unnecessary outputs. In practice, it has hidden important messages from users, causing deprecations to be noticed only when it's too late:

What's worse is that this warning suppression affects everything in the same Python process, even outside of BCBio code. Example with Biopython 1.81:

from Bio.SeqFeature import SeqFeature, SimpleLocation

# Using the deprecated strand parameter shows a useful warning.
f = SeqFeature(SimpleLocation(5, 10), strand=1)

# Output:
# …/site-packages/Bio/SeqFeature.py:257: BiopythonDeprecationWarning: Using the
#     strand argument is deprecated, and will be removed in a future release.
#     Please set it via the location object instead.
#  warnings.warn(

# Import BCBio.GFF and try again.
import BCBio.GFF
f = SeqFeature(SimpleLocation(5, 10), strand=1)

# No warning output.

It's possible this will not get merged for a while given how quiet this repo is. Is there a way to undo the warnings silencing? E.g. after importing BCBio.GFF one runs something like:

warnings.simplefilter("default", BiopythonDeprecationWarning) 

https://docs.python.org/3/library/warnings.html

@corneliusroemer yes, I've added that in nextstrain/augur@05bff35. Note that it has to come not just after importing BCBio.GFF, but all usages of it that emit Biopython deprecation warnings.

Closed by 03e96ca.

@chapmanb thanks so much for releasing 0.7.1 and continuing to maintain bcbio-gff which continues to be widely used in production at e.g. Nextstrain