예제 #1
0
def meta_generate(n_tracks, fn, win_size):
    from gMiner.manipulate import fusion
    tracks = n_tracks
    sentinel = (sys.maxint, sys.maxint, 0.0)
    tracks = [fusion(t) for t in tracks]
    tracks = [common.sentinelize(t, sentinel) for t in tracks]

    N = len(tracks)
    init = [tracks[i].next() for i in range(N)]
    for i in xrange(N-1,-1,-1):
        if init[i] == sentinel: # empty track
            N-=1
            tracks.pop(i)
            init.pop(i)
    available_tracks = range(N-1,-1,-1)
    activity = [False]*N
    current = []
    current.extend([(init[i][0],i) for i in range(N)])
    current.extend([(init[i][1],i) for i in range(N)])
    current.sort()

    start = current[0][0]
    while current[0][0] == start:
        activity[current[0][1]] = True
        z = current.pop(0)

    k=1
    while available_tracks:
        # load *win_size* bp in memory
        to_remove = []
        for i in available_tracks:
            a = [0,0]
            limit = k*win_size
            while a[1] < limit:
                a = tracks[i].next()
                if a == sentinel:
                    to_remove.append(i)
                    break
                current.append((a[0],i))
                current.append((a[1],i))
        for i in to_remove:
            available_tracks.remove(i)
        current.sort()

        # calculate boolean values for start-next interval
        while current and current[0][0] < limit:
            next = current[0][0]
            res = fn(activity)
            if res:
                yield (start,next,'',0.0,0)
            while current and current[0][0] == next:
                i = current[0][1]
                activity[i] = not(activity[i])
                z = current.pop(0)
            start = next
        k+=1
예제 #2
0
def generate(**kwargs):
    from gMiner.manipulate import fusion
    for f in fusion(meta_generate(**kwargs)): yield f