diff --git a/fgpyo/io/__init__.py b/fgpyo/io/__init__.py index 837bd55a..0ba6e011 100644 --- a/fgpyo/io/__init__.py +++ b/fgpyo/io/__init__.py @@ -265,37 +265,37 @@ def suppress_stderr() -> Generator[None, None, None]: yield -def assert_fasta_is_indexed( +def assert_fasta_indexed( fasta: Path, - faidx: bool = True, - dictionary: bool = True, - bwa: bool = True, + /, + dictionary: bool = False, + bwa: bool = False, ) -> None: """ Verify that a FASTA is readable and has the expected index files. + The existence of the FASTA index generated by `samtools faidx` will always be verified. The + existence of the index files generated by `samtools dict` and `bwa index` may be optionally + verified. + Args: fasta: Path to the FASTA file. - faidx: If True, check for the index file generated by `samtools faidx` (`{fasta}.fai`). dictionary: If True, check for the index file generated by `samtools dict` (`{fasta}.dict`). bwa: If True, check for the index files generated by `bwa index` (`{fasta}.{suffix}`, for - all suffixes in [".amb", ".ann", ".bwt", ".pac", ".sa"]). + all suffixes in ["amb", "ann", "bwt", "pac", "sa"]). Raises: AssertionError: If the FASTA or any of the expected index files are missing or not readable. """ - assert_path_is_readable(fasta) - - if faidx: - fai_index = Path(f"{fasta}.fai") - assert_path_is_readable(fai_index) + fai_index = Path(f"{fasta}.fai") + assert_path_is_readable(fai_index) if dictionary: dict_index = Path(f"{fasta}.dict") assert_path_is_readable(dict_index) if bwa: - suffixes = [".amb", ".ann", ".bwt", ".pac", ".sa"] + suffixes = ["amb", "ann", "bwt", "pac", "sa"] for suffix in suffixes: bwa_index = Path(f"{fasta}.{suffix}") assert_path_is_readable(bwa_index) diff --git a/tests/fgpyo/io/test_io.py b/tests/fgpyo/io/test_io.py index abc98a47..f3856a1a 100644 --- a/tests/fgpyo/io/test_io.py +++ b/tests/fgpyo/io/test_io.py @@ -11,7 +11,7 @@ import pytest import fgpyo.io as fio -from fgpyo.io import assert_fasta_is_indexed +from fgpyo.io import assert_fasta_indexed from fgpyo.io import assert_path_is_writable from fgpyo.io import assert_path_is_writeable @@ -144,20 +144,22 @@ def test_read_and_write_lines( assert int(next(read_back)) == list_to_write[1] -@pytest.mark.parametrize("faidx", [True, False]) @pytest.mark.parametrize("dictionary", [True, False]) @pytest.mark.parametrize("bwa", [True, False]) -def test_assert_fasta_is_indexed(tmp_path: Path, faidx: bool, dictionary: bool, bwa: bool) -> None: - """assert_fasta_is_indexed should verify the presence of the expected index files.""" +def test_assert_fasta_indexed(tmp_path: Path, dictionary: bool, bwa: bool) -> None: + """assert_fasta_indexed should verify the presence of the expected index files.""" fasta = tmp_path / "test.fa" fasta.touch() - if faidx: - (tmp_path / "test.fa.fai").touch() + (tmp_path / "test.fa.fai").touch() + if dictionary: (tmp_path / "test.fa.dict").touch() if bwa: - for suffix in [".amb", ".ann", ".bwt", ".pac", ".sa"]: - (tmp_path / f"test.fa.{suffix}").touch() + (tmp_path / "test.fa.amb").touch() + (tmp_path / "test.fa.ann").touch() + (tmp_path / "test.fa.bwt").touch() + (tmp_path / "test.fa.pac").touch() + (tmp_path / "test.fa.sa").touch() - assert_fasta_is_indexed(fasta, faidx=faidx, dictionary=dictionary, bwa=bwa) + assert_fasta_indexed(fasta, dictionary=dictionary, bwa=bwa)