Example #1
0
def endRunDatacal(after):
    global fdc, selRec2, sampSize, locusFst, lpath
    global empiricalPanel, isDominant, systemPanel
    global tempSamples, isTemporal
    #createInfile(convert_genepop_to_fdist(selRec2))
    createInfile(convert_genepop_to_fdist(selRec2, update_load_status))

    if isDominant:
        crit = empiricalPanel.getCrit()
        beta = empiricalPanel.getBeta()
        fst, sampSize, loci, pops, F, obs = fdc.run_datacal(
            data_dir = lpath, version = 2,
            crit_freq=crit, p=0.5, beta=beta)
    elif isTemporal:
        dc = Datacal()
        dc.compute(lpath + os.sep + "infile", lpath + os.sep + "data_fst_outfile")
        sampSize = dc.getSampleSize()
        dc.computeNe(tempSamples[-1] - tempSamples[0])
        ne = dc.getNe()
    else:
        fst, sampSize = fdc.run_datacal(data_dir = lpath)
        print(fst, sampSize)
    if not isTemporal:
        if fst < 0.0:
            systemPanel.force.setEnabled(False)
            systemPanel.force.setSelected(False)
        else:
            systemPanel.force.setEnabled(True)
    f = open(lpath + os.sep + 'data_fst_outfile')
    locusFst = []
    l = f.readline()
    myPos = 0
    while l != '':
        if isDominant:
            lhe, lfst, lheold, llocus = l.rstrip().split(' ')
            while int(llocus)>myPos:
                locusFst.append(None)
                myPos += 1
            myPos += 1
        else:
            lhe, lfst = l.rstrip().split(' ')
            if lhe == "-nan":
                lhe = "nan"
            if lhe == "-nan":
                lhe = "nan"
            if lfst == "-nan":
                lfst = "nan"
            try:
                if float(lfst) < -10.0:
                    lfst = "nan"
            except ValueError:
                lfst = 'nan'
            try:
                if float(lhe) < -10.0:
                    lhe = "nan"
            except ValueError:
                lhe = 'nan'
        locusFst.append((float(lhe), float(lfst)))
        l = f.readline()
    while len(locusFst) < len(selRec2.loci_list):
        locusFst.append(None)
    f.close()
    if sampSize > 50:
        sampSize = 50
    if isTemporal:
        empiricalPanel.setNe(ne)
    else:
        empiricalPanel.setFst(fst)
    empiricalPanel.setSampleSize(sampSize)
    if isTemporal:
       info (frame, "Dataset Ne: %d" % int(ne))
    else:
       info (frame, "Dataset Fst: %f" % fst)
    after()
    loadPanel.dispose()