Skip to content

Commit a1ebb6e

Browse files
authored
Merge pull request #1034 from suhaan-24/fix/veff-replace-asserts-with-exceptions
fix: replace bare asserts in veff.py with explicit ValueError exceptions
2 parents 14c2ab5 + f4308ed commit a1ebb6e

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

malariagen_data/veff.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ def get_ref_allele_coords(self, chrom, pos, ref):
9292

9393
# check the reference allele matches the reference sequence
9494
ref_seq = self.get_ref_seq(chrom, ref_start, ref_stop).lower()
95-
assert ref_seq == ref.lower(), (
96-
"reference allele does not match reference sequence, "
97-
f"expected {ref_seq!r}, found {ref.lower()!r}"
98-
)
95+
if ref_seq != ref.lower():
96+
raise ValueError(
97+
f"Reference allele does not match reference sequence at "
98+
f"{chrom}:{ref_start}-{ref_stop}. Expected {ref_seq!r}, "
99+
f"found {ref.lower()!r}."
100+
)
99101

100102
return ref_start, ref_stop
101103

@@ -170,7 +172,12 @@ def get_effects(self, transcript, variants, progress=None):
170172
)
171173

172174
# reference allele falls within current transcript
173-
assert feature_start <= ref_start <= ref_stop <= feature_stop
175+
if not (feature_start <= ref_start <= ref_stop <= feature_stop):
176+
raise ValueError(
177+
f"Variant coordinates ({ref_start}-{ref_stop}) fall outside "
178+
f"transcript boundaries ({feature_start}-{feature_stop}) "
179+
f"on {chrom}."
180+
)
174181

175182
effect = _get_within_transcript_effect(
176183
ann=self,
@@ -276,7 +283,11 @@ def _get_cds_effect(ann, base_effect, cds, cdss):
276283
cds_stop = cds.end
277284

278285
# reference allele falls within current transcript
279-
assert cds_start <= ref_start <= ref_stop <= cds_stop
286+
if not (cds_start <= ref_start <= ref_stop <= cds_stop):
287+
raise ValueError(
288+
f"Variant coordinates ({ref_start}-{ref_stop}) fall outside "
289+
f"CDS boundaries ({cds_start}-{cds_stop})."
290+
)
280291
return _get_within_cds_effect(ann, base_effect, cds, cdss)
281292

282293

0 commit comments

Comments
 (0)