Skip to content

Commit

Permalink
fixes #258, #330, #342: ensure that start and end datums are compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
reece committed Sep 15, 2016
1 parent e05674b commit 247d8bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions hgvs/location.py
Expand Up @@ -115,6 +115,11 @@ def is_uncertain(self):
"""return True if the position is marked uncertain or undefined"""
return self.uncertain or self.base is None or self.offset is None

@property
def is_intronic(self):
"""returns True if the variant is intronic (if the offset is None or non-zero)"""
return (self.offset is None or self.offset != 0)

def __sub__(lhs, rhs):
assert type(lhs) == type(rhs), "Cannot substract coordinates of different representations"
if lhs.datum != rhs.datum:
Expand Down
20 changes: 13 additions & 7 deletions tests/test_bugs.py
Expand Up @@ -39,6 +39,19 @@ def test_285_partial_palindrome_inversion(self):
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')
self.vn.normalize(var) # per issue, should raise error

def test_314_parsing_identity_variant(self):
v = self.hp.parse_hgvs_variant("NM_206933.2:c.6317=")
self.assertEqual(str(v), "NM_206933.2:c.6317=")

v = self.hp.parse_hgvs_variant("NM_206933.2:c.6317C=")
self.assertEqual(str(v), "NM_206933.2:c.6317C=")


def test_324_error_normalizing_simple_inversion(self):
v = self.hp.parse_hgvs_variant("NM_000535.5:c.1673_1674inv")
vn = self.vn.normalize(v)
Expand Down Expand Up @@ -89,10 +102,3 @@ def test_346_reject_partial_alignments(self):
alt_ac="NC_000010.10",
alt_aln_method="splign")

def test_314_parsing_identity_variant(self):
v = self.hp.parse_hgvs_variant("NM_206933.2:c.6317=")
self.assertEqual(str(v), "NM_206933.2:c.6317=")

v = self.hp.parse_hgvs_variant("NM_206933.2:c.6317C=")
self.assertEqual(str(v), "NM_206933.2:c.6317C=")

3 changes: 3 additions & 0 deletions tests/test_hgvs_location.py
Expand Up @@ -35,14 +35,17 @@ def test_success(self):
self.assertEqual(cdsp.base, 5)
self.assertEqual(cdsp.offset, 0)
self.assertEqual(str(cdsp), "5")
self.assertFalse(cdsp.is_intronic)

#r.5+6
cdsp.offset = 6
self.assertEqual(str(cdsp), "5+6")
self.assertTrue(cdsp.is_intronic)

#r.5+?
cdsp.offset = None
self.assertEqual(str(cdsp), "5+?")
self.assertTrue(cdsp.is_intronic)

#r.(5+?)
cdsp.uncertain = True
Expand Down

0 comments on commit 247d8bf

Please sign in to comment.