Пример #1
0
def createGalaxyGSuiteBySplittingInputFileOnAttribute \
        (galaxyFn, inputGeSource, genome, composerCls, valAttr):
    from quick.application.ExternalTrackManager import ExternalTrackManager
    
    threadInfoDict = OrderedDict()
    baseDir = ExternalTrackManager.getGalaxyFilesDir(galaxyFn)
    finishedCond = Condition()
    threadFactoryFunc = ValSpecificFileComposerThread.\
        getThreadFactoryFunc(composerCls, baseDir, finishedCond)

    geSourceLock = RLock()
    valDepThreadedGeSource = \
        ValueDependentThreadedGESource(inputGeSource, geSourceLock, \
                                       threadInfoDict, valAttr, threadFactoryFunc)
    valDepThreadedGeSource.iter()

    firstThreadCond = Condition(geSourceLock)
    firstThread = threadFactoryFunc(valDepThreadedGeSource)
    firstVal = valDepThreadedGeSource.curVal()
    threadInfoDict[firstVal] = ThreadInfo(firstThread, firstThreadCond)

    with finishedCond:
        firstThread.start()
        finishedCond.wait()

    gsuite = GSuite()

    # At this point one of the threads is finished, but the other threads are still waiting.
    for val, ti in threadInfoDict.iteritems():
        with ti.condition:
            ti.condition.notify()

        ti.thread.join()
        
        uri = GalaxyGSuiteTrack.generateURI(galaxyFn=galaxyFn,
                                            extraFileName=ti.thread.extraFileName)
        track = GalaxyGSuiteTrack(uri, title=val, genome=genome)
        gsuite.addTrack(track)

    return gsuite