diff --git a/sub-packages/bionemo-noodles/src/bionemo/noodles/nvfaidx.py b/sub-packages/bionemo-noodles/src/bionemo/noodles/nvfaidx.py index d10c2101a7..d4e9af72bb 100644 --- a/sub-packages/bionemo-noodles/src/bionemo/noodles/nvfaidx.py +++ b/sub-packages/bionemo-noodles/src/bionemo/noodles/nvfaidx.py @@ -40,6 +40,7 @@ def __init__(self, reader: PyIndexedMmapFastaReader, seqid: str, length: int) -> - out of bounds indexing is truncated: query[1:999999999] will return a string from position 1 to the terminus. - reversed slices return the empty string: query[999:1] is the empty string. - empty slice returns the full string: query[:] is the full string of the sequence. + - beginning of slice is beyond the range of the contig, the empty string is returned. Additionally there are convenience methods that you may find useful in the class definition. @@ -178,18 +179,6 @@ def __init__(self, fasta_path: str | Path, faidx_path: Optional[str | Path] = No raise ValueError("unreachable condition.") self.records: Dict[str, PyFaidxRecord] = {record.name: record for record in self.reader.records()} - return - if ignore_existing_fai: - self.reader = PyIndexedMmapFastaReader(fasta_path, ignore_existing_fai=ignore_existing_fai) - elif faidx_path is not None: - self.reader = PyIndexedMmapFastaReader.from_fasta_and_faidx(fasta_path, faidx_path) - else: - # No faidx path is passed, ignore_existing is always False in this branch - # if the faidx exists, we use it - # if the faidx does not exist, we dont. - self.reader = PyIndexedMmapFastaReader(fasta_path, ignore_existing_fai=ignore_existing_fai) - - self.records: Dict[str, PyFaidxRecord] = {record.name: record for record in self.reader.records()} def __getitem__(self, seqid: str) -> SequenceAccessor: # noqa: D105 if seqid not in self.records: diff --git a/sub-packages/bionemo-noodles/tests/bionemo/noodles/test_nvfaidx.py b/sub-packages/bionemo-noodles/tests/bionemo/noodles/test_nvfaidx.py index 32da2117e6..c273370efd 100644 --- a/sub-packages/bionemo-noodles/tests/bionemo/noodles/test_nvfaidx.py +++ b/sub-packages/bionemo-noodles/tests/bionemo/noodles/test_nvfaidx.py @@ -263,6 +263,8 @@ def _test_faidx_generic(faidx_obj): # Should see this is out of bounds and return empty or throw an error assert index["chr4"][17:17] == "" + assert index["chr4"][17:] == "" + def test_nvfaidx_python_interface(sample_fasta): nvfaidx_index = NvFaidx(sample_fasta)