Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing BCBio.GFF suppresses Biopython warnings in external code #140

Closed
victorlin opened this issue Dec 26, 2023 · 4 comments
Closed

Comments

@victorlin
Copy link

victorlin commented Dec 26, 2023

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.
@corneliusroemer
Copy link

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

@victorlin
Copy link
Author

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

@victorlin
Copy link
Author

Closed by 03e96ca.

@corneliusroemer
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants