示例#1
0
    def __init__(self, fdist_dir="", ext=None):
        """Constructor.

        Parameters:
        fdist_dir - Where fdist can be found, if = "", then it
            should be on the path.
        ext - Extension of binary names (e.g. nothing on Unix,
              ".exe" on Windows
        """
        FDistController.__init__(self, fdist_dir, ext)
示例#2
0
    def __init__(self, fdist_dir="", ext=None):
        """Constructor.

        Parameters:
        fdist_dir - Where fdist can be found, if = "", then it
            should be on the path.
        ext - Extension of binary names (e.g. nothing on Unix,
              ".exe" on Windows
        """
        FDistController.__init__(self, fdist_dir, ext)
示例#3
0
def report(fst):
    global numAttempts
    global fda, fdc, fdRequest, runState, selRec2, splitSize
    global chartPanel, simsDonePanel, systemPanel, empiricalPanel
    global empiricalPanel, menuHandles, statusPanel, frame
    global myFst, maxRun, minRun # This is really a private var to be reused
    global isTemporal, tempSamples, fdt
    if isTemporal:
        fdt.acquire()
    else:
        fda.acquire()
        if myFst < 0:
            myFst = empiricalPanel.getFst()
        if maxRun < 0:
            maxRun = 1.0
            minRun = 0.0
    ext = FDistExtra.getExt()
    fdc = FDistController('.', ext)
    ci = systemPanel.getCI()
    chartPanel.drawCI = True
    confLines = changeChartCI(False)
    simsDonePanel.increment(splitSize / 1000.0)
    if isTemporal:
        desiredNe = empiricalPanel.getNe()
    else:
        desiredFst = empiricalPanel.getFst()
    if simsDonePanel.getRange() == simsDonePanel.getValue():
        #print runState
        if isTemporal:
            fdt.release()  # We are the last one, this is safe
        else:
            fda.release()  # We are the last one, this is safe
        if runState == 'ForceBeforeNeutral' or runState == 'Force':
            os.remove(lpath + os.sep + 'out.dat') #careful, not for 5000 case
            #print "max", maxRun, "min", minRun
            nextFst, maxRun, minRun = approximate_fst(desiredFst, fst, myFst,
                maxRun, minRun)
            #print "obtained", fst, "desired", desiredFst, "next", nextFst, "max", maxRun, "min", minRun
            numAttempts += 1
            if nextFst == myFst or numAttempts == 20:
                numSims = systemPanel.getNumSims()
                if runState == 'Force':
                    statusPanel.setStatus('Running final simulation', Color.YELLOW)
                    runState = 'Final'
                else:
                    runState = 'Neutral'
                    statusPanel.setStatus('Simulation pass to determine initial neutral set', Color.CYAN)
            else:
                statusPanel.setStatus('Forcing correct mean Fst, current error is ' +
                                str(round(abs(fst - desiredFst), 3)), Color.RED)
                numSims = 50000
                myFst = nextFst
            npops = empiricalPanel.getTotalPops()
            nsamples = countPops(selRec2)
            numCores = systemPanel.getNumCores()
            sampSize = empiricalPanel.getSampleSize()
            if isDominant:
                theta = empiricalPanel.getTheta()
                beta = empiricalPanel.getBeta()
                crit = empiricalPanel.getCrit()
                mut = None
            else:
                theta = beta = crit = None
                mutStr = empiricalPanel.mut.getSelectedItem()
                mut = getMut(mutStr)
            if isTemporal:
                pass #XXX
            else:
                runFDistPart(False, selRec2, mut, numSims, npops, nsamples,
                    myFst, sampSize, theta, beta, crit, numCores)
        elif runState == 'Neutral':
            maxRun = -1
            minRun = -1
            myFst  = -1
            if isDominant:
                pv = fdc.run_pv(data_dir =  lpath, version=2)
            else:
                pv = fdc.run_pv(data_dir =  lpath, version=1)
            #pv = get_pv(data_dir = lpath)
            selLoci = getSelLoci(pv)
            if fdRequest == 'Neutral':
                runState = 'Final'
                numSims  = systemPanel.getNumSims()
                statusPanel.setStatus('Running final simulation', Color.YELLOW)
            else:
                runState = 'Force'
                numAttempts = 0
                statusPanel.setStatus('Forcing correct mean Fst for final pass', Color.RED)
                numSims  = 50000
            neutralRec = FileParser.read(selRec2.fname)
            #for locus in selLoci:
            neutralRec.remove_loci_by_name(selLoci, lpath+os.sep+"nr.tmp")
            shutil.copyfile(lpath + os.sep + "nr.tmp",
                    lpath + os.sep + "nr")
            neutralRec = FileParser.read(lpath + os.sep + "nr")
            createInfile(convert_genepop_to_fdist(neutralRec))
            if isTemporal:
                dc = Datacal()
                dc.compute(lpath + os.sep + "infile", lpath + os.sep + "data_fst_outfile")
                dc.computeNe(tempSamples[-1] - tempSamples[0])
                myNe = dc.getNe()
            elif isDominant:
                crit = empiricalPanel.getCrit()
                beta = empiricalPanel.getBeta()
                myFst, _sampSize, _loci, _pops, _F, _obs = \
                    fdc.run_datacal(data_dir = lpath,
                    version=2, crit_freq=crit, p=0.5, beta=beta)
            else:
                myFst, _sampSize = fdc.run_datacal(data_dir = lpath)
            #if myFst < 0.005:
            #    myFst = 0.005
            if isTemporal:
                empiricalPanel.setNe(myNe) #actually it is Ne
            else:
                empiricalPanel.setFst(myFst)
                if not isDominant:
                    mutStr = empiricalPanel.mut.getSelectedItem()
                    mut = getMut(mutStr)
                else:
                    mut = None
            npops = empiricalPanel.getTotalPops()
            nsamples = countPops(selRec2)
            numCores = systemPanel.getNumCores()
            sampSize = empiricalPanel.getSampleSize()
            if isDominant:
                theta = empiricalPanel.getTheta()
                beta = empiricalPanel.getBeta()
                crit = empiricalPanel.getCrit()
            else:
                theta = beta = crit = None
            os.remove(lpath + os.sep + 'out.dat') #careful, not for 5000 case
            createInfile(convert_genepop_to_fdist(selRec2))
            if isTemporal:
                dc = Datacal()
                dc.compute(lpath + os.sep + "infile", lpath + os.sep + "data_fst_outfile")
                dc.computeNe(tempSamples[-1] - tempSamples[0])
                ne = dc.getNe()
            elif isDominant:
                _fst, _sampSize, _loci, _pops, _F, _obs = \
                    fdc.run_datacal(data_dir = lpath, version=2,
                        crit_freq = crit, p=0.5, beta=beta)
            else:
                _fst, _sampSize = fdc.run_datacal(data_dir = lpath)
            if isTemporal:
                runFtempPart(False, selRec2, numSims, npops, nsamples, ne,
                    sampSize, numCores)
            else:
                runFDistPart(False, selRec2, mut, numSims, npops, nsamples,
                    myFst, sampSize, theta, beta, crit, numCores)
        elif runState == 'Final':
            maxRun = -1
            minRun = -1
            myFst  = -1
            statusPanel.setStatus('Done (preparing selection table, please wait...)', Color.GRAY)
            if isDominant:
                pv = fdc.run_pv(data_dir =  lpath, version=2)
            else:
                pv = fdc.run_pv(data_dir =  lpath, version=1)
            selLoci = getSelLoci(pv)
            chartPanel.setSelLoci(pv, selRec2.loci_list, selLoci)
            sp = SelPanel(frame, chartPanel, selRec2.loci_list, pv,
                    systemPanel.getCI(), confLines, locusFst, isDominant,
                    systemPanel.getFDR())
            if isTemporal:
                info(frame, "Done")
            else:
                info(frame, "Simulated Fst: %f" % (fst,))
            statusPanel.setStatus('Done')
            sp.show()
            enablePanel(empiricalPanel)
            enablePanel(systemPanel)
            enableAllMenus(True)
            systemPanel.enableChartFun = True
    else:
        if isTemporal:
            fdt.release()
        else:
            fda.release()
示例#4
0
def prepareFDist():
    global fdc
    #print lpath
    FDistExtra.compile(lpath)
    ext = FDistExtra.getExt()
    fdc = FDistController('.', ext)