def gnuc_roll_left_del(chrm, beg, end): """ beg and end are 1st and last base in the deleted sequence """ sb = faidx.SeqBuf(chrm, beg) while True: if beg <= 1: break left_base = sb.get_base(chrm, beg - 1) rightmost = sb.get_base(chrm, end) if left_base == 'N' or rightmost == 'N': break if left_base != rightmost: break beg -= 1 end -= 1 return beg, end
def gnuc_roll_left_ins(chrm, pos, gnuc_insseq): """ pos is where insertion occur after """ sb = faidx.SeqBuf(chrm, pos) _gnuc_insseq_ = deque(gnuc_insseq) while True: if pos <= 1: break left_base = sb.get_base(chrm, pos) rightmost = _gnuc_insseq_[-1] if left_base == 'N' or rightmost == 'N': break if left_base != rightmost: break _gnuc_insseq_.pop() _gnuc_insseq_.appendleft(left_base) pos -= 1 return pos, ''.join(_gnuc_insseq_)
def gnuc_roll_right_ins(chrm, pos, gnuc_insseq): """ pos is where insertion occur after """ sb = faidx.SeqBuf(chrm, pos) chrmlen = faidx.refgenome.chrm2len(chrm) _gnuc_insseq_ = deque(gnuc_insseq) while True: if pos + 1 >= chrmlen: break right_base = sb.get_base(chrm, pos + 1) leftmost = _gnuc_insseq_[0] if right_base == 'N' or leftmost == 'N': break if right_base != leftmost: break _gnuc_insseq_.popleft() _gnuc_insseq_.append(right_base) pos += 1 return pos, ''.join(_gnuc_insseq_)
def gnuc_roll_right_del(chrm, beg, end): """ beg and end are 1st and last base in the deleted sequence """ sb = faidx.SeqBuf(chrm, end) chrmlen = faidx.refgenome.chrm2len(chrm) while True: # check end of chromosome if end + 1 >= chrmlen: break right_base = sb.get_base(chrm, end + 1) leftmost = sb.get_base(chrm, beg) if right_base == 'N' or leftmost == 'N': break if right_base != leftmost: break beg += 1 end += 1 return beg, end