chapmanb / bcbb

Incubator for useful bioinformatics code, primarily in Python and R
http://bcbio.wordpress.com
603 stars 243 forks source link

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

Closed victorlin closed 6 months ago

victorlin commented 7 months ago

https://github.com/chapmanb/bcbb/blob/81442c07173aaa59cbc1be33dd4a6e0eee87c5f6/gff/BCBio/GFF/GFFParser.py#L46-L47

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 commented 6 months ago

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 commented 6 months ago

@corneliusroemer yes, I've added that in https://github.com/nextstrain/augur/pull/1379/commits/05bff35272299986885d37d962d3e8daaaed94ad. Note that it has to come not just after importing BCBio.GFF, but all usages of it that emit Biopython deprecation warnings.

victorlin commented 6 months ago

Closed by 03e96caa2b91cce22b6d05cf5d5f473cccbb7eb2.

corneliusroemer commented 6 months ago

@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