def normalize(self, var):
assert isinstance(var, hgvs.sequencevariant.SequenceVariant<EOL>), "<STR_LIT>"<EOL>if self.validator:<EOL><INDENT>self.validator.validate(var)<EOL><DEDENT>init_met = False<EOL>if var.posedit is not None and isinstance(var.posedit, hgvs.edit.AARefAlt):<EOL><INDENT>init_met = var.posedit.init_met<EOL><DEDENT>if var.posedit is None or var.posedit.uncertain or init_met or var.posedit.pos is None:<EOL><INDENT>return var<EOL><DEDENT>type = var.type<EOL>if type == "<STR_LIT:p>":<EOL><INDENT>raise HGVSUnsupportedOperationError(<EOL>"<STR_LIT>".format(var))<EOL><DEDENT>if var.posedit.edit.type == "<STR_LIT>":<EOL><INDENT>raise HGVSUnsupportedOperationError(<EOL>"<STR_LIT>", format(var))<EOL><DEDENT>var.fill_ref(self.hdp)<EOL>if var.posedit.edit.type == "<STR_LIT>":<EOL><INDENT>var_norm = copy.deepcopy(var)<EOL>return var_norm<EOL><DEDENT>if type == "<STR_LIT:c>":<EOL><INDENT>var = self.hm.c_to_n(var)<EOL><DEDENT>if var.type in "<STR_LIT>":<EOL><INDENT>if var.posedit.pos.start.offset != <NUM_LIT:0> or var.posedit.pos.end.offset != <NUM_LIT:0>:<EOL><INDENT>raise HGVSUnsupportedOperationError(<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>assert var.type in "<STR_LIT>", "<STR_LIT>"<EOL>bound_s, bound_e = self._get_boundary(var)<EOL>boundary = (bound_s, bound_e)<EOL>start, end, (ref, alt) = self._normalize_alleles(var, boundary)<EOL>ref_len = len(ref)<EOL>alt_len = len(alt)<EOL>if alt_len == ref_len:<EOL><INDENT>ref_start = start<EOL>ref_end = end - <NUM_LIT:1><EOL>if ref_len > <NUM_LIT:1> and ref == reverse_complement(alt):<EOL><INDENT>edit = hgvs.edit.Inv(ref=ref)<EOL><DEDENT>elif ref_len == <NUM_LIT:0> and alt_len == <NUM_LIT:0>:<EOL><INDENT>ref_start = ref_end<EOL>edit = hgvs.edit.NARefAlt(ref=ref, alt=alt)<EOL><DEDENT>else:<EOL><INDENT>edit = hgvs.edit.NARefAlt(ref=ref, alt=alt)<EOL><DEDENT><DEDENT>if alt_len < ref_len:<EOL><INDENT>ref_start = start<EOL>ref_end = end - <NUM_LIT:1><EOL>edit = hgvs.edit.NARefAlt(ref=ref, alt=None if alt_len == <NUM_LIT:0> else alt)<EOL><DEDENT>elif alt_len > ref_len:<EOL><INDENT>if ref_len == <NUM_LIT:0>:<EOL><INDENT>if self.shuffle_direction == <NUM_LIT:3>:<EOL><INDENT>adj_seq = self._fetch_bounded_seq(var, start - alt_len - <NUM_LIT:1>, end - <NUM_LIT:1>, <NUM_LIT:0>,<EOL>boundary)<EOL><DEDENT>else:<EOL><INDENT>adj_seq = self._fetch_bounded_seq(var, start - <NUM_LIT:1>, start + alt_len - <NUM_LIT:1>, <NUM_LIT:0>,<EOL>boundary)<EOL><DEDENT>if alt != adj_seq:<EOL><INDENT>ref_start = start - <NUM_LIT:1><EOL>ref_end = end<EOL>edit = hgvs.edit.NARefAlt(ref=None, alt=alt)<EOL><DEDENT>else:<EOL><INDENT>if self.shuffle_direction == <NUM_LIT:3>:<EOL><INDENT>ref_start = start - alt_len<EOL>ref_end = end - <NUM_LIT:1><EOL>edit = hgvs.edit.Dup(ref=alt)<EOL><DEDENT>else:<EOL><INDENT>ref_start = start<EOL>ref_end = start + alt_len - <NUM_LIT:1><EOL>edit = hgvs.edit.Dup(ref=alt)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>ref_start = start<EOL>ref_end = end - <NUM_LIT:1><EOL>edit = hgvs.edit.NARefAlt(ref=ref, alt=alt)<EOL><DEDENT><DEDENT>if ref_start == <NUM_LIT:0>:<EOL><INDENT>ref = self._fetch_bounded_seq(var, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>, boundary)<EOL>alt = alt + ref<EOL>edit = hgvs.edit.NARefAlt(ref=ref, alt=alt)<EOL>ref_start = <NUM_LIT:1><EOL>ref_end = <NUM_LIT:1><EOL><DEDENT>tgt_len = self._get_tgt_length(var)<EOL>if ref_end == tgt_len + <NUM_LIT:1>:<EOL><INDENT>ref = self._fetch_bounded_seq(var, tgt_len - <NUM_LIT:1>, tgt_len, <NUM_LIT:0>, boundary)<EOL>alt = ref + alt<EOL>edit = hgvs.edit.NARefAlt(ref=ref, alt=alt)<EOL>ref_start = tgt_len<EOL>ref_end = tgt_len<EOL><DEDENT>var_norm = copy.deepcopy(var)<EOL>var_norm.posedit.edit = edit<EOL>var_norm.posedit.pos.start.base = ref_start<EOL>var_norm.posedit.pos.end.base = ref_end<EOL>if type == "<STR_LIT:c>":<EOL><INDENT>var_norm = self.hm.n_to_c(var_norm)<EOL><DEDENT>return var_norm<EOL>
Perform sequence variants normalization for single variant