diff --git a/fgpyo/io/__init__.py b/fgpyo/io/__init__.py index 837bd55..fa6b612 100644 --- a/fgpyo/io/__init__.py +++ b/fgpyo/io/__init__.py @@ -267,35 +267,36 @@ def suppress_stderr() -> Generator[None, None, None]: def assert_fasta_is_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 abc98a4..dafbc4d 100644 --- a/tests/fgpyo/io/test_io.py +++ b/tests/fgpyo/io/test_io.py @@ -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: +def test_assert_fasta_is_indexed(tmp_path: Path, dictionary: bool, bwa: bool) -> None: """assert_fasta_is_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_is_indexed(fasta, dictionary=dictionary, bwa=bwa)