def _normalize_alleles(self, var, boundary):
        """Normalize the variant until it could not be shuffled
        """

        ref, alt = self._get_ref_alt(var, boundary)
        win_size = hgvs.global_config.normalizer.window_size

        if self.shuffle_direction == 3:
            if var.posedit.edit.type == "ins":
                base = var.posedit.pos.start.base
                start = 1
                stop = 1
            elif var.posedit.edit.type == "dup":
                base = var.posedit.pos.end.base
                start = 1
                stop = 1
            else:
                base = var.posedit.pos.start.base
                start = 0
                stop = var.posedit.pos.end.base - base + 1

            while True:
                ref_seq = self._fetch_bounded_seq(var, base - 1, base + stop - 1 + win_size,
                                                  win_size, boundary)
                if ref_seq == "":
                    break
                orig_start, orig_stop = start, stop
                start, stop, (ref, alt) = normalize_alleles(ref_seq, start, stop, (ref, alt),
                                                            len(ref_seq), win_size, False)
                if stop < len(ref_seq) or start == orig_start:
                    break
                # if stop at the end of the window, try to extend the shuffling to the right
                base += start - orig_start
                stop -= start - orig_start
                start = orig_start

        elif self.shuffle_direction == 5:
            if var.posedit.edit.type == "ins":
                base = max(var.posedit.pos.start.base - win_size, 1)
                start = var.posedit.pos.end.base - base
                stop = var.posedit.pos.end.base - base
            elif var.posedit.edit.type == "dup":
                base = max(var.posedit.pos.start.base - win_size, 1)
                start = var.posedit.pos.end.base - base + 1
                stop = var.posedit.pos.end.base - base + 1
            else:
                base = max(var.posedit.pos.start.base - win_size, 1)
                start = var.posedit.pos.start.base - base
                stop = var.posedit.pos.end.base - base + 1

            while True:
                if base < boundary[0] + 1:
                    start -= boundary[0] + 1 - base
                    stop -= boundary[0] + 1 - base
                    base = boundary[0] + 1
                ref_seq = self._fetch_bounded_seq(var, base - 1, base + stop - 1, start, boundary)
                if ref_seq == "":
                    break
                orig_start, orig_stop = start, stop
                start, stop, (ref, alt) = normalize_alleles(ref_seq, start, stop, (ref, alt), 0,
                                                            win_size, True)
                if start > 0 or stop == orig_stop:
                    break
                # if stop at the end of the window, try to extend the shuffling to the left
                base -= orig_stop - stop
                start += orig_stop - stop
                stop = orig_stop

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