diff --git a/pybwa/libbwaindex.pxd b/pybwa/libbwaindex.pxd index 92a9857..2cdea2d 100644 --- a/pybwa/libbwaindex.pxd +++ b/pybwa/libbwaindex.pxd @@ -43,7 +43,6 @@ cdef extern from "bntseq.h": void bns_destroy(bntseq_t *bns) cdef bytes force_bytes(object s) -cdef bytes force_bytes_with(object s, encoding: str | None = *, errors: str | None = *) cpdef bint _set_bwa_idx_verbosity(int level) cdef class BwaIndex: diff --git a/pybwa/libbwaindex.pyx b/pybwa/libbwaindex.pyx index 6767487..ced926e 100644 --- a/pybwa/libbwaindex.pyx +++ b/pybwa/libbwaindex.pyx @@ -28,19 +28,13 @@ cdef str TEXT_ENCODING = 'utf-8' cdef bytes force_bytes(object s): - return force_bytes_with(s, None, None) - - -cdef bytes force_bytes_with( - object s, encoding: str | None = None, errors: str | None = None -): # pragma: no cover """convert string or unicode object to bytes, assuming utf8 encoding.""" if s is None: return None elif PyBytes_Check(s): return s elif PyUnicode_Check(s): - return s.encode(encoding or TEXT_ENCODING, errors or ERROR_HANDLER) + return s.encode(TEXT_ENCODING, ERROR_HANDLER) else: raise TypeError("Argument must be a string, bytes or unicode.") diff --git a/pyproject.toml b/pyproject.toml index 86a7644..9cca71c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,7 +95,7 @@ sphinx-rtd-theme = ">=3.0.2" sphinx-autodoc-typehints = "2" [build-system] -requires = ["poetry-core>=2.1.1", "cython>=3.0.11", "setuptools>=75.1.0", "pysam >=0.22.1"] +requires = ["poetry-core>=2.1.1", "cython>=3.0.11", "setuptools>=75.1.0", "pysam ==0.22.1"] build-backend = "poetry.core.masonry.api" [tool.poe] diff --git a/tests/_test_libbwaindex.pyx b/tests/_test_libbwaindex.pyx index dd369ed..f0fa8ae 100644 --- a/tests/_test_libbwaindex.pyx +++ b/tests/_test_libbwaindex.pyx @@ -1,12 +1,12 @@ # cython: language_level=3 -from pybwa.libbwaindex cimport force_bytes_with +from pybwa.libbwaindex cimport force_bytes import pytest -def test_force_bytes_with() -> None: - assert force_bytes_with(None) is None - assert force_bytes_with(b"foo-bar") == b"foo-bar" - assert force_bytes_with("foo-bar") == b"foo-bar" +def test_force_bytes() -> None: + assert force_bytes(None) is None + assert force_bytes(b"foo-bar") == b"foo-bar" + assert force_bytes("foo-bar") == b"foo-bar" with pytest.raises(TypeError, match="Argument must be a string, bytes or unicode"): - force_bytes_with(42) + force_bytes(42) diff --git a/tests/test_libbwaindex.py b/tests/test_libbwaindex.py index d318a9f..e7c966f 100644 --- a/tests/test_libbwaindex.py +++ b/tests/test_libbwaindex.py @@ -11,10 +11,10 @@ import_test_lib(libname="libbwaindex") -def test_force_bytes_with() -> None: +def test_force_bytes() -> None: import _test_libbwaindex - _test_libbwaindex.test_force_bytes_with() + _test_libbwaindex.test_force_bytes() @pytest.mark.parametrize("in_place", [True, False]) diff --git a/tests/test_libbwaln.py b/tests/test_libbwaln.py index dd4d158..f70074c 100644 --- a/tests/test_libbwaln.py +++ b/tests/test_libbwaln.py @@ -373,3 +373,27 @@ def test_bwa_aln_ambiguous_bases(num_amb: int, tmp_path_factory: pytest.TempPath else: assert rec.has_tag("XN"), str(rec) assert rec.get_tag("XN") == num_amb + + +@pytest.mark.parametrize("limit", [1, 32767, 32768, 100000]) +def test_bwa_aln_max_hits(limit: int, tmp_path_factory: pytest.TempPathFactory) -> None: + query = "G" * 25 + target = ("A" * 25) + query + ("T" * 25) + + src_dir = Path(str(tmp_path_factory.mktemp("test_bwa_aln_max_hits"))) + fasta = src_dir / "ref.fasta" + with fasta.open("w") as writer: + writer.write(">ref\n") + for _ in range(limit): + writer.write(f"{target}\n") + BwaIndex.index(fasta=fasta) + + bwa = BwaAln(prefix=fasta) + queries = [FastxRecord(name="NA", sequence=query)] + options = BwaAlnOptions(seed_length=len(query), max_mismatches=0, max_hits=limit) + recs = bwa.align(queries=queries, opt=options) + assert len(recs) == 1 + rec = recs[0] + print(rec) + assert rec.is_unmapped is False + assert rec.get_tag("HN") == limit, f"limit was {limit}"