Skip to content

Commit

Permalink
Remove new getattr references
Browse files Browse the repository at this point in the history
  • Loading branch information
b0d0nne11 committed Jan 23, 2024
1 parent 8c9faf2 commit 22705e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
33 changes: 17 additions & 16 deletions src/hgvs/assemblymapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,22 +244,23 @@ def _alt_ac_for_tx_ac(self, tx_ac):
return alt_acs[0]

def _replace_reference(self, var):
if (getattr(var.posedit.pos.start, 'offset', 0) != 0 or getattr(var.posedit.pos.end, 'offset', 0) != 0):
if var.type != 'g':
alt_ac = self._alt_ac_for_tx_ac(var.ac)
if var.type == 'c':
var_g = super(AssemblyMapper, self).c_to_g(var, alt_ac, alt_aln_method=self.alt_aln_method)
if var.type == 'n':
var_g = super(AssemblyMapper, self).n_to_g(var, alt_ac, alt_aln_method=self.alt_aln_method)
if var.type == 't':
var_g = super(AssemblyMapper, self).t_to_g(var, alt_ac, alt_aln_method=self.alt_aln_method)
super(AssemblyMapper, self)._replace_reference(var_g)
ref = var_g.posedit.edit.ref
if self._fetch_AlignmentMapper(tx_ac=var.ac).strand == -1:
ref = reverse_complement(ref)
var.posedit.edit.ref = ref
_logger.debug("Replaced reference sequence in {var} with {ref}".format(var=var, ref=var_g.posedit.edit.ref))
return var
if (
var.type in "cn"
and var.posedit.pos is not None
and (var.posedit.pos.start.offset != 0 or var.posedit.pos.end.offset != 0)
):
alt_ac = self._alt_ac_for_tx_ac(var.ac)
if var.type == 'c':
var_g = super(AssemblyMapper, self).c_to_g(var, alt_ac, alt_aln_method=self.alt_aln_method)
if var.type == 'n':
var_g = super(AssemblyMapper, self).n_to_g(var, alt_ac, alt_aln_method=self.alt_aln_method)
super(AssemblyMapper, self)._replace_reference(var_g)
ref = var_g.posedit.edit.ref
if self._fetch_AlignmentMapper(tx_ac=var.ac).strand == -1:
ref = reverse_complement(ref)
var.posedit.edit.ref = ref
_logger.debug("Replaced reference sequence in {var} with {ref}".format(var=var, ref=var_g.posedit.edit.ref))
return var

return super(AssemblyMapper, self)._replace_reference(var)

Expand Down
19 changes: 12 additions & 7 deletions src/hgvs/variantmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,13 @@ def _replace_reference(self, var):
# these types have no reference sequence (zero-width), so return as-is
return var

pos = var.posedit.pos
if (getattr(pos.start, 'offset', 0) != 0 or getattr(pos.end, 'offset', 0) != 0):
if var.type != "g":
_logger.info("Can't update reference sequence for intronic variant {}".format(var))
return var
if (
var.type in "cnr"
and var.posedit.pos is not None
and (var.posedit.pos.start.offset != 0 or var.posedit.pos.end.offset != 0)
):
_logger.info("Can't update reference sequence for intronic variant {}".format(var))
return var

# For c. variants, we need coords on underlying sequences
if var.type == "c":
Expand All @@ -483,8 +485,11 @@ def _replace_reference(self, var):
else:
pos = var.posedit.pos

seq_start = pos.start.base + getattr(pos.start, 'offset', 0) - 1
seq_end = pos.end.base + getattr(pos.end, 'offset', 0)
seq_start = pos.start.base - 1
seq_end = pos.end.base
if var.type in "cnr":
seq_start += pos.start.offset
seq_end += pos.end.offset

# When strict_bounds is False and an error occurs, return
# variant as-is
Expand Down

0 comments on commit 22705e2

Please sign in to comment.