Skip to content

Commit

Permalink
issue biocommons#606 - catch index error for variants at alignment gap
Browse files Browse the repository at this point in the history
  • Loading branch information
kayleeyuhas committed Dec 17, 2020
1 parent 15c3937 commit 9f109ab
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions hgvs/variantmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import hgvs.sequencevariant
import hgvs.validator

from hgvs.exceptions import HGVSDataNotAvailableError, HGVSUnsupportedOperationError, HGVSInvalidVariantError
from hgvs.exceptions import HGVSDataNotAvailableError, HGVSUnsupportedOperationError, HGVSInvalidVariantError, \
HGVSInvalidIntervalError
from hgvs.decorators.lru_cache import lru_cache
from hgvs.enums import PrevalidationLevel
from hgvs.utils.reftranscriptdata import RefTranscriptData
Expand Down Expand Up @@ -166,10 +167,13 @@ def g_to_n(self, var_g, tx_ac, alt_aln_method=hgvs.global_config.mapping.alt_aln
pos_n.end.base -= 1
edit_n.ref = ''
else:
# variant at alignment gap
pos_g = mapper.n_to_g(pos_n)
edit_n = hgvs.edit.NARefAlt(
ref='', alt=self._get_altered_sequence(mapper.strand, pos_g, var_g))
try:
# variant at alignment gap
pos_g = mapper.n_to_g(pos_n)
edit_n = hgvs.edit.NARefAlt(
ref='', alt=self._get_altered_sequence(mapper.strand, pos_g, var_g))
except IndexError:
raise HGVSInvalidIntervalError("Variant is at alignment gap.")
pos_n.uncertain = var_g.posedit.pos.uncertain
var_n = hgvs.sequencevariant.SequenceVariant(
ac=tx_ac, type="n", posedit=hgvs.posedit.PosEdit(pos_n, edit_n))
Expand Down Expand Up @@ -209,10 +213,13 @@ def n_to_g(self, var_n, alt_ac, alt_aln_method=hgvs.global_config.mapping.alt_al
pos_g.end.base -= 1
edit_g.ref = ''
else:
# variant at alignment gap
pos_n = mapper.g_to_n(pos_g)
edit_g = hgvs.edit.NARefAlt(
ref='', alt=self._get_altered_sequence(mapper.strand, pos_n, var_n))
try:
# variant at alignment gap
pos_n = mapper.g_to_n(pos_g)
edit_g = hgvs.edit.NARefAlt(
ref='', alt=self._get_altered_sequence(mapper.strand, pos_n, var_n))
except IndexError:
raise HGVSInvalidIntervalError("Variant is at alignment gap.")
pos_g.uncertain = var_n.posedit.pos.uncertain
var_g = hgvs.sequencevariant.SequenceVariant(
ac=alt_ac, type="g", posedit=hgvs.posedit.PosEdit(pos_g, edit_g))
Expand Down Expand Up @@ -251,10 +258,13 @@ def g_to_c(self, var_g, tx_ac, alt_aln_method=hgvs.global_config.mapping.alt_aln
pos_c.end.base -= 1
edit_c.ref = ''
else:
# variant at alignment gap
pos_g = mapper.c_to_g(pos_c)
edit_c = hgvs.edit.NARefAlt(
ref='', alt=self._get_altered_sequence(mapper.strand, pos_g, var_g))
try:
# variant at alignment gap
pos_g = mapper.c_to_g(pos_c)
edit_c = hgvs.edit.NARefAlt(
ref='', alt=self._get_altered_sequence(mapper.strand, pos_g, var_g))
except IndexError:
raise HGVSInvalidIntervalError("Variant is at alignment gap.")
pos_c.uncertain = var_g.posedit.pos.uncertain
var_c = hgvs.sequencevariant.SequenceVariant(
ac=tx_ac, type="c", posedit=hgvs.posedit.PosEdit(pos_c, edit_c))
Expand Down Expand Up @@ -292,13 +302,16 @@ def c_to_g(self, var_c, alt_ac, alt_aln_method=hgvs.global_config.mapping.alt_al
pos_g.end.base -= 1
edit_g.ref = ''
else:
# variant at alignment gap
var_n = copy.deepcopy(var_c)
var_n.posedit.pos = mapper.c_to_n(var_c.posedit.pos)
var_n.type = 'n'
pos_n = mapper.g_to_n(pos_g)
edit_g = hgvs.edit.NARefAlt(
ref='', alt=self._get_altered_sequence(mapper.strand, pos_n, var_n))
try:
# variant at alignment gap
var_n = copy.deepcopy(var_c)
var_n.posedit.pos = mapper.c_to_n(var_c.posedit.pos)
var_n.type = 'n'
pos_n = mapper.g_to_n(pos_g)
edit_g = hgvs.edit.NARefAlt(
ref='', alt=self._get_altered_sequence(mapper.strand, pos_n, var_n))
except IndexError:
raise HGVSInvalidIntervalError("Variant is at alignment gap.")
pos_g.uncertain = var_c.posedit.pos.uncertain
var_g = hgvs.sequencevariant.SequenceVariant(
ac=alt_ac, type="g", posedit=hgvs.posedit.PosEdit(pos_g, edit_g))
Expand Down

0 comments on commit 9f109ab

Please sign in to comment.