Beispiel #1
0
def chooseFile():
    global frame, dataPath
    global systemPanel, chartPanel
    global isTemporal
    fc = JFileChooser(dataPath)
    retVal = fc.showOpenDialog(frame)
    if retVal != JFileChooser.APPROVE_OPTION:
        return
    fname = fc.getSelectedFile().getAbsolutePath()
    dataPath = os.sep.join(fname.split(os.sep)[:-1])
    if isTemporal:
        info(frame, "We need a file with information about the temporal point of each sample")
        tfc = JFileChooser(dataPath)
        tRetVal = tfc.showOpenDialog(frame)
        if retVal != JFileChooser.APPROVE_OPTION:
            return
        tname = tfc.getSelectedFile().getAbsolutePath()
    systemPanel.enableChartFun = False
    chartPanel.resetData()
    loadGenePop(fname)
    if isTemporal:
        if not loadTemporal(tname):
            return
    updateAll()
    enablePanel(empiricalPanel)
Beispiel #2
0
def loadTemporal(fname):
    global tempSamples, popNames
    f = open(fname)
    l = f.readline()
    i = 0
    tempSamples = []
    while l != '':
        if i > len(popNames):
            break
        try:
            tempSamples.append(int(l.rstrip()))
        except:
            error(frame, "Temporal file syntax error, please check")
            return False

        i += 1
        l = f.readline()
    f.close()
    if i != len(popNames):
        error(
            frame,
            "Number of temporal samples (%d) is less than the number of time points specified (%d)"
            % (i, len(popNames)))
        return False
    else:
        info(frame, "Temporal points set at: %s" % str(tempSamples))
        return True
Beispiel #3
0
 def actionPerformed(self, event):
     global frame, chartPanel
     global popNames, rec2, remLoci, remPops  # , rec
     global isDominant
     option = event.getActionCommand()
     # print option
     if option == 'Open':
         chooseFile()
     elif option == 'LoadPop':
         loadPopNames()
     elif option == 'EditPop':
         editPopNames()
     elif option == 'SavePop':
         savePopNames()
     elif option == 'Example':
         useExampleData()
     elif option == 'Citation':
         displayCitation()
     elif option == 'ChooseLoci':
         selLoci = rec2.loci_list[:]
         for locus in remLoci:
             selLoci.remove(locus)
         rd = RestrictionDialog(frame, 'Choose loci', selLoci, remLoci,
                                updateLoci)
         rd.show()
     elif option == 'ChoosePops':
         selPops = popNames[:]
         for pop in remPops:
             selPops.remove(pop)
         rd = RestrictionDialog(frame, 'Choose Populations', selPops,
                                remPops, updatePops)
         rd.show()
     elif option == 'RunFDist':
         runFDist()
     elif option == 'CancelFDist':
         cancelFDist()
     elif option == 'Run5000':
         runFDist(True)
     elif option == 'CheckLoci':
         checkLoci()
     elif option == 'ConfGrp':
         configChart()
     elif option == 'Help':
         if isDominant:
             info(frame,
                  'For help please visit http://popgen.eu/soft/mcheza')
         else:
             info(frame,
                  'For help please visit http://popgen.eu/soft/lositan')
     elif option == 'SavePNG':
         chartPanel.save(frame, 'PNG')
     elif option == 'SaveSVG':
         chartPanel.save(frame, 'SVG')
     elif option == 'SavePDF':
         chartPanel.save(frame, 'PDF')
     elif option == 'Exit':
         sys.exit(-1)
Beispiel #4
0
 def actionPerformed(self, event):
     global frame, chartPanel
     global popNames, rec2, remLoci, remPops #, rec
     global isDominant
     option = event.getActionCommand()
     #print option
     if option == 'Open':
         chooseFile()
     elif option == 'LoadPop':
         loadPopNames()
     elif option == 'EditPop':
         editPopNames()
     elif option == 'SavePop':
         savePopNames()
     elif option == 'Example':
         useExampleData()
     elif option == 'Citation':
         displayCitation()
     elif option == 'ChooseLoci':
         selLoci = rec2.loci_list[:]
         for locus in remLoci:
             selLoci.remove(locus)
         rd = RestrictionDialog(frame, 'Choose loci',
             selLoci, remLoci, updateLoci)
         rd.show()
     elif option == 'ChoosePops':
         selPops = popNames[:]
         for pop in remPops:
             selPops.remove(pop)
         rd = RestrictionDialog(frame, 'Choose Populations',
             selPops, remPops, updatePops)
         rd.show()
     elif option == 'RunFDist':
         runFDist()
     elif option == 'CancelFDist':
         cancelFDist()
     elif option == 'Run5000':
         runFDist(True)
     elif option == 'CheckLoci':
         checkLoci()
     elif option == 'ConfGrp':
         configChart()
     elif option == 'Help':
         if isDominant:
             info(frame, 'For help please visit http://popgen.eu/soft/mcheza')
         else:
             info(frame, 'For help please visit http://popgen.eu/soft/lositan')
     elif option == 'SavePNG':
         chartPanel.save(frame, 'PNG')
     elif option == 'SaveSVG':
         chartPanel.save(frame, 'SVG')
     elif option == 'SavePDF':
         chartPanel.save(frame, 'PDF')
     elif option == 'Exit':
         sys.exit(-1)
Beispiel #5
0
def loadTemporal(fname):
    global tempSamples, popNames
    f = open(fname)
    l = f.readline()
    i = 0
    tempSamples = []
    while l<>'':
        if i>len(popNames):
            break
        tempSamples.append(int(l.rstrip()))
        i += 1
        l = f.readline()
    f.close()
    if i!=len(popNames):
        error(frame, "Number of temporal samples is less than the number of time points specified")
    else:
        info(frame, "Temporal points set at: %s" % str(tempSamples))
Beispiel #6
0
def displayCitation():
    if isTemporal:
        info(frame, """If you use LosiTemp please cite:
        ...
        """)
    elif isDominant:
        info(
            frame, """If you use Mcheza please cite:
Antao T, Beaumont MA (2011)
Mcheza: A workbench to detect selection using dominant markers
Bioinformatics doi: 10.1093/bioinformatics/btr253
    """)
    else:
        info(
            frame, """If you use LOSITAN please cite both:

Beaumont MA, Nichols RA (1996)
Evaluating loci for use in the genetic analysis of population structure
Proceedings of the Royal Society of London B 263: 1619-1626

AND

LOSITAN: A workbench to detect molecular adaptation based on a Fst-outlier method
Tiago Antao, Ana Lopes, Ricardo J Lopes, Albano Beja-Pereira, Gordon Luikart
BMC Bioinformatics 2008, 9:323
    """)
Beispiel #7
0
def loadTemporal(fname):
    global tempSamples, popNames
    f = open(fname)
    l = f.readline()
    i = 0
    tempSamples = []
    while l != '':
        if i > len(popNames):
            break
        try:
            tempSamples.append(int(l.rstrip()))
        except:
            error(frame, "Temporal file syntax error, please check")
            return False

        i += 1
        l = f.readline()
    f.close()
    if i != len(popNames):
        error(frame, "Number of temporal samples (%d) is less than the number of time points specified (%d)" % (i, len(popNames)))
        return False
    else:
        info(frame, "Temporal points set at: %s" % str(tempSamples))
        return True
Beispiel #8
0
def displayCitation():
    if isTemporal:
        info(frame, """If you use LosiTemp please cite:
        ...
        """)
    elif isDominant:
        info(frame, """If you use Mcheza please cite:
Antao T, Beaumont MA (2011)
Mcheza: A workbench to detect selection using dominant markers
Bioinformatics doi: 10.1093/bioinformatics/btr253
    """)
    else:
        info(frame, """If you use LOSITAN please cite both:

Beaumont MA, Nichols RA (1996)
Evaluating loci for use in the genetic analysis of population structure
Proceedings of the Royal Society of London B 263: 1619-1626

AND

LOSITAN: A workbench to detect molecular adaptation based on a Fst-outlier method
Tiago Antao, Ana Lopes, Ricardo J Lopes, Albano Beja-Pereira, Gordon Luikart
BMC Bioinformatics 2008, 9:323
    """)
Beispiel #9
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()
Beispiel #10
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()