def _normalize_alleles(self, var, boundary):
ref, alt = self._get_ref_alt(var, boundary)<EOL>win_size = hgvs.global_config.normalizer.window_size<EOL>if self.shuffle_direction == <NUM_LIT:3>:<EOL><INDENT>if var.posedit.edit.type == "<STR_LIT>":<EOL><INDENT>base = var.posedit.pos.start.base<EOL>start = <NUM_LIT:1><EOL>stop = <NUM_LIT:1><EOL><DEDENT>elif var.posedit.edit.type == "<STR_LIT>":<EOL><INDENT>base = var.posedit.pos.end.base<EOL>start = <NUM_LIT:1><EOL>stop = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>base = var.posedit.pos.start.base<EOL>start = <NUM_LIT:0><EOL>stop = var.posedit.pos.end.base - base + <NUM_LIT:1><EOL><DEDENT>while True:<EOL><INDENT>ref_seq = self._fetch_bounded_seq(var, base - <NUM_LIT:1>, base + stop - <NUM_LIT:1> + win_size,<EOL>win_size, boundary)<EOL>if ref_seq == "<STR_LIT>":<EOL><INDENT>break<EOL><DEDENT>orig_start, orig_stop = start, stop<EOL>start, stop, (ref, alt) = normalize_alleles(ref_seq, start, stop, (ref, alt),<EOL>len(ref_seq), win_size, False)<EOL>if stop < len(ref_seq) or start == orig_start:<EOL><INDENT>break<EOL><DEDENT>base += start - orig_start<EOL>stop -= start - orig_start<EOL>start = orig_start<EOL><DEDENT><DEDENT>elif self.shuffle_direction == <NUM_LIT:5>:<EOL><INDENT>if var.posedit.edit.type == "<STR_LIT>":<EOL><INDENT>base = max(var.posedit.pos.start.base - win_size, <NUM_LIT:1>)<EOL>start = var.posedit.pos.end.base - base<EOL>stop = var.posedit.pos.end.base - base<EOL><DEDENT>elif var.posedit.edit.type == "<STR_LIT>":<EOL><INDENT>base = max(var.posedit.pos.start.base - win_size, <NUM_LIT:1>)<EOL>start = var.posedit.pos.end.base - base + <NUM_LIT:1><EOL>stop = var.posedit.pos.end.base - base + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>base = max(var.posedit.pos.start.base - win_size, <NUM_LIT:1>)<EOL>start = var.posedit.pos.start.base - base<EOL>stop = var.posedit.pos.end.base - base + <NUM_LIT:1><EOL><DEDENT>while True:<EOL><INDENT>if base < boundary[<NUM_LIT:0>] + <NUM_LIT:1>:<EOL><INDENT>start -= boundary[<NUM_LIT:0>] + <NUM_LIT:1> - base<EOL>stop -= boundary[<NUM_LIT:0>] + <NUM_LIT:1> - base<EOL>base = boundary[<NUM_LIT:0>] + <NUM_LIT:1><EOL><DEDENT>ref_seq = self._fetch_bounded_seq(var, base - <NUM_LIT:1>, base + stop - <NUM_LIT:1>, start, boundary)<EOL>if ref_seq == "<STR_LIT>":<EOL><INDENT>break<EOL><DEDENT>orig_start, orig_stop = start, stop<EOL>start, stop, (ref, alt) = normalize_alleles(ref_seq, start, stop, (ref, alt), <NUM_LIT:0>,<EOL>win_size, True)<EOL>if start > <NUM_LIT:0> or stop == orig_stop:<EOL><INDENT>break<EOL><DEDENT>base -= orig_stop - stop<EOL>start += orig_stop - stop<EOL>stop = orig_stop<EOL><DEDENT><DEDENT>return base + start, base + stop, (ref, alt)<EOL>
Normalize the variant until it could not be shuffled