

def splitLPOintervals(lpoList, ival, targetIval=None):
    'return list of intervals split to different LPOs'
    if (ival.start < 0):
        start = (- ival.stop)
        stop = (- ival.start)
    else:
        start = ival.start
        stop = ival.stop
    l = []
    i = (len(lpoList) - 1)
    while (i >= 0):
        offset = lpoList[i].offset
        if (offset < stop):
            if (offset <= start):
                if (ival.start < 0):
                    myslice = slice((offset - stop), (offset - start))
                else:
                    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
            else:
                if (ival.start < 0):
                    myslice = slice((offset - stop), 0)
                else:
                    myslice = slice(0, (stop - offset))
                if (targetIval is not None):
                    l.append((lpoList[i], myslice, targetIval[(offset - start):]))
                    targetIval = targetIval[:(offset - start)]
                else:
                    l.append((lpoList[i], myslice))
                stop = offset
        i -= 1
    raise ValueError('empty lpoList or offset not starting at 0?  Debug!')

dataset/ETHPy150Open cjlee112/pygr/pygr/nlmsa_utils.py splitLPOintervals/original