Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixes #260, #322: added tests to verify that exceptions are raised wh…
…en mapping invalid variants
  • Loading branch information
reece committed Sep 15, 2016
1 parent cbda326 commit ac37ae0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hgvs/validator.py
Expand Up @@ -15,7 +15,7 @@
BASE_RANGE_ERROR_MSG = "base start position must be <= end position"
OFFSET_RANGE_ERROR_MSG = "offset start must be <= end position"
INS_ERROR_MSG = "insertion length must be 1"
DEL_ERROR_MSG = "Length implied by coordinates ({span_len}) must equal sequence deletion length ({del_len})"
DEL_ERROR_MSG = "Length implied by coordinates ({span_len}) must equal sequence deletion length ({del_len})"
AC_ERROR_MSG = "Accession is not present in BDI database"
SEQ_ERROR_MSG = "Variant reference ({var_ref_seq}) does not agree with reference sequence ({ref_seq})"

Expand Down
17 changes: 10 additions & 7 deletions tests/test_bugs.py
Expand Up @@ -9,7 +9,7 @@

from nose.plugins.attrib import attr

from hgvs.exceptions import HGVSError, HGVSDataNotAvailableError, HGVSParseError
from hgvs.exceptions import HGVSError, HGVSDataNotAvailableError, HGVSParseError, HGVSInvalidVariantError, HGVSValidationError
import hgvs.dataproviders.uta
import hgvs.normalizer
import hgvs.parser
Expand All @@ -31,14 +31,18 @@ def setUp(self):
self.vn = hgvs.normalizer.Normalizer(self.hdp, shuffle_direction=3, cross_boundaries=True)


def test_260_raise_exception_when_mapping_bogus_variant(self):
v = self.hp.parse_hgvs_variant("NM_000059.3:c.7790delAAG")
with self.assertRaises(HGVSValidationError):
self.evm.c_to_p(v)

def test_285_partial_palindrome_inversion(self):
# https://bitbucket.org/biocommons/hgvs/issues/285/
# Inversion mapping is not palindrome aware
v = self.hp.parse_hgvs_variant("NM_000088.3:c.589_600inv")
vn = self.vn.normalize(v)
self.assertEqual(str(vn), "NM_000088.3:c.590_599inv")


def test_293_parser_attribute_assignment_error(self):
# https://bitbucket.org/biocommons/hgvs/issues/293/
var = self.hp.parse_hgvs_variant('NG_029146.1:g.6494delG')
Expand All @@ -51,6 +55,10 @@ def test_314_parsing_identity_variant(self):
v = self.hp.parse_hgvs_variant("NM_206933.2:c.6317C=")
self.assertEqual(str(v), "NM_206933.2:c.6317C=")

def test_322_raise_exception_when_mapping_bogus_variant(self):
v = self.hp.parse_hgvs_variant("chrX:g.71684476delTGGAGinsAC")
with self.assertRaises(HGVSValidationError):
self.evm.g_to_c(v, "NM_018486.2")

def test_324_error_normalizing_simple_inversion(self):
v = self.hp.parse_hgvs_variant("NM_000535.5:c.1673_1674inv")
Expand All @@ -61,7 +69,6 @@ def test_324_error_normalizing_simple_inversion(self):
v2 = self.evm.g_to_c(vg, tx_ac = v.ac)
self.assertEqual(str(v), str(v2)) # no change after roundtrip


def test_330_incorrect_end_datum_post_ter(self):
# https://bitbucket.org/biocommons/hgvs/issues/330/
# In a variant like NM_004006.2:c.*87_91del, the interval
Expand All @@ -71,7 +78,6 @@ def test_330_incorrect_end_datum_post_ter(self):
self.assertEqual(v.posedit.pos.start.datum, hgvs.location.CDS_END)
self.assertEqual(v.posedit.pos.end.datum, hgvs.location.CDS_END)


def test_334_delins_normalization(self):
# also tests 335 re: inv including sequence (e.g., NC_000009.11:g.36233991_36233992invCA)
v = self.hp.parse_hgvs_variant("NC_000009.11:g.36233991_36233992delCAinsAC")
Expand All @@ -86,14 +92,11 @@ def test_334_delins_normalization(self):
vn = self.vn.normalize(v)
self.assertEqual(str(vn), "NM_000535.5:c.1_3inv")


def test_340_inv_without_sequence(self):
# inversions should not accept sequence
with self.assertRaises(HGVSParseError):
self.hp.parse_hgvs_variant("NM_000535.5:c.1673_1674invCC")



def test_346_reject_partial_alignments(self):
# hgvs-346: verify that alignment data covers full-length transcript
with self.assertRaises(HGVSDataNotAvailableError):
Expand Down

0 comments on commit ac37ae0

Please sign in to comment.