Skip to content

Commit

Permalink
fix bug in is_valid_seq when using NCBI for sequence backend
Browse files Browse the repository at this point in the history
  • Loading branch information
reece committed Jun 24, 2020
1 parent d880c8e commit fceff98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hgvs/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,16 @@ def normalize(self, var):

def is_valid_pos(ac, pos):
# tests whether the sequence position actually exists
return self.hdp.get_seq(ac, pos-1, pos) # 0-based!
# This is *way* janky.
# TODO: push functionality to hdp which can implement differently
# based on capabilities of sequence backend
try:
s = self.hdp.get_seq(ac, pos-1, pos) # 0-based!
return s != ""
except HGVSDataNotAvailableError as e:
# Bad Request indicates that we got to NCBI, but the request
# was invalid.
return "Bad Request" not in str(e)
if var.posedit.pos.start.base < 0 or not is_valid_pos(var.ac, var.posedit.pos.end.base):
if hgvs.global_config.mapping.strict_bounds:
raise HGVSInvalidVariantError(f"{var}: coordinates are out-of-bounds")
Expand Down
6 changes: 6 additions & 0 deletions tests/issues/test_602.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ def test_602(parser, am37):

hgvs.global_config.mapping.strict_bounds = False
var_c = am37.g_to_c(var_g, "NM_006772.2") # No error


if __name__ == "__main__":
from hgvs.easy import parser, am37
test_602(parser, am37)

0 comments on commit fceff98

Please sign in to comment.