def splitLPOintervals(lpoList, ival, targetIval=None):
    'return list of intervals split to different LPOs'
    if ival.start < 0: # reverse orientation: force into forward ori
        start= -(ival.stop)
        stop= -(ival.start)
    else: # forward orientation
        start=ival.start
        stop=ival.stop
    l = []
    i = len(lpoList) - 1
    while i >= 0:
        offset = lpoList[i].offset
        if offset < stop: # appears to be in this
            if offset <= start: # fits completely in this LPO
                if ival.start < 0: # reverse ori
                    myslice = slice(offset - stop, offset - start)
                else: # forward ori
                    myslice = slice(start - offset, stop - offset)
                if targetIval is not None:
                    l.append((lpoList[i], myslice, targetIval))
                else:
                    l.append((lpoList[i], myslice))
                return l # done
            else: # continues past start of this LPO
                if ival.start < 0: # reverse ori
                    myslice = slice(offset - stop, 0)
                else: # forward ori
                    myslice = slice(0, stop - offset)
                if targetIval is not None:
                    l.append((lpoList[i], myslice, targetIval[offset
                                                              - start:]))
                    # Remove the already-appended part
                    targetIval = targetIval[:offset - start]
                else:
                    l.append((lpoList[i], myslice))
                stop = offset
        i -= 1 # continue to previous LPO
    raise ValueError('empty lpoList or offset not starting at 0?  Debug!')
dataset/ETHPy150Open cjlee112/pygr/pygr/nlmsa_utils.py/splitLPOintervals/original