From 82c3c04311dead2611f26818a1104496268746a8 Mon Sep 17 00:00:00 2001 From: matthewfallan <31744230+matthewfallan@users.noreply.github.com> Date: Sun, 25 Feb 2024 12:20:46 -0500 Subject: [PATCH] Validate excluded positions and ignore those outside the section --- src/seismicrna/mask/write.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/seismicrna/mask/write.py b/src/seismicrna/mask/write.py index 1e42d086..6f4d94e9 100644 --- a/src/seismicrna/mask/write.py +++ b/src/seismicrna/mask/write.py @@ -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)