Skip to content

Commit

Permalink
Hide BiopythonDeprecationWarnings when reading certain sequence files
Browse files Browse the repository at this point in the history
Biopython 1.85 shows a deprecation warning when using format='fasta'
with files that start with anything but '>'.

The warning as-is should not be exposed to Augur users. It is not
triggered when reading files with format='fasta-pearson', so this is the
easiest thing to do continue accepting such files for Biopython
>=1.85.

This way, Augur users get consistent, backwards compatible behavior no
matter the Biopython version they use.
  • Loading branch information
victorlin committed Jan 22, 2025
1 parent 61f7a00 commit 0d81c0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion augur/io/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os

from augur.errors import AugurError
from importlib.metadata import version
from packaging.version import Version
from typing import Iterator, Iterable, Union
from .file import open_file

Expand All @@ -11,8 +13,15 @@ def get_biopython_format(augur_format: str) -> str:
supported_formats = {"fasta", "genbank"}
if augur_format not in supported_formats:
raise AugurError(f"Sequence file format {augur_format!r} is invalid. Must be one of {', '.join(repr(f) for f in sorted(supported_formats))}.")

# Supported formats are valid Biopython formats
return augur_format
biopython_format = augur_format

# Allow comments in FASTA format using fasta-pearson in later biopython versions
if Version(version("biopython")) >= Version("1.85") and biopython_format == "fasta":
biopython_format = "fasta-pearson"

return biopython_format


def read_sequence(
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def genbank_reference():
class TestFormat:
def test_fasta(self):
biopython_format = augur.io.sequences.get_biopython_format("fasta")
assert biopython_format == "fasta"
assert biopython_format == "fasta" or biopython_format == "fasta-pearson"

def test_genbank(self):
biopython_format = augur.io.sequences.get_biopython_format("genbank")
Expand Down

0 comments on commit 0d81c0e

Please sign in to comment.