Skip to content

Commit

Permalink
Validate excluded positions and ignore those outside the section
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfallan committed Feb 25, 2024
1 parent 5139a01 commit 82c3c04
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/seismicrna/mask/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ def _get_exclude_pos(self, exclude_file: Path | None):
exclude_file,
index_col=[FIELD_REF, POS_NAME]
).loc[self.dataset.ref].index
# Check if any positions are out of bounds.
if below := exclude_pos[exclude_pos < 1].to_list():
raise ValueError(f"Got excluded positions < 1: {below}")
seqlen = len(self.dataset.refseq)
if above := exclude_pos[exclude_pos > seqlen].to_list():
raise ValueError(f"Got excluded positions < {seqlen}: {above}")
# Retain only the positions in the section.
exclude_pos = exclude_pos[(exclude_pos >= self.section.end5)
& (exclude_pos <= self.section.end3)]
else:
exclude_pos = list()
return np.asarray(exclude_pos, dtype=int)
Expand Down

0 comments on commit 82c3c04

Please sign in to comment.