Example #1
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
Example #2
0
def checkAlleles(file):
    df = FileParser.read(file)
    countAlleles = []
    for locus in df.loci_list:
        countAlleles.append(set())
    indiv = df.get_individual()
    while indiv:
        if type(indiv) == tuple:
            name, loci = indiv
            for l in range(len(loci)):
                for a in loci[l]:
                    if a:
                        countAlleles[l].add(a)
        indiv = df.get_individual()
    probLoci = []
    for l in range(len(countAlleles)):
        if len(countAlleles[l]) > 2:
            probLoci.append(df.loci_list[l])
    if probLoci != []:
        if len(probLoci) > 5:
            error(frame,
                  "Many (%d) loci have more than 2 alleles" % (len(probLoci)))
        else:
            error(frame,
                  "Some loci have more than 2 alleles: %s" % (str(probLoci)))
Example #3
0
 def propertyChange(self, evt):
     if self.ignoreChanges: return
     change = False
     if not self.isTemporal:
         if evt.getSource() == self.fst and evt.getPropertyName() == 'value':
             new = float(evt.getNewValue())
             old = float(evt.getOldValue())
             if new > 0.99:
                 evt.getSource().setValue(old)
             if new < -0.2:
                 evt.getSource().setValue(old)
             elif new< 0.0:
                 self.systemPanel.force.setSelected(False)
                 self.systemPanel.force.setEnabled(False)
             else:
                 self.systemPanel.force.setEnabled(True)
     else:
         if evt.getSource() == self.ne and evt.getPropertyName() == 'value':
             new = int(evt.getNewValue())
             old = int(evt.getOldValue())
             if new < 0:
                 evt.getSource().setValue(old)
     if self.isDominant and evt.getSource() in [self.theta, self.beta1,
         self.beta2, self.crit] and evt.getPropertyName() == 'value':
         new = float(evt.getNewValue())
         old = float(evt.getOldValue())
         if new > 0.99 or new < -0.2:
             evt.getSource().setValue(old)
     if evt.getSource() == self.sampleSize and evt.getPropertyName() == 'value':
         change = True
         new = int(evt.getNewValue())
         old = int(evt.getOldValue())
         if new > 50 and old > 4:
             warn(self, 'A sample size bigger than 50 is not expected to produce better results, while it slows the computation')
         if new < 5 and (new!=0 and not self.isDominant):
             evt.getSource().setValue(old)
     if evt.getSource() == self.pops and evt.getPropertyName() == 'value':
         change = True
         new = int(evt.getNewValue())
         old = int(evt.getOldValue())
         if new > 100:
             error(self, 'Maximum value for total populations is 100')
             evt.getSource().setValue(100)
         if new < self.knownPops:
             error(self,
             'Expected total populations has to be at least the same as the number of populations under study.'
             )
             evt.getSource().setValue(self.knownPops)
     if not self.isTemporal:
         if evt.getSource() == self.mut:
             change = True
     if not change: return
     if self.menuHandles['item5000'].isEnabled():
         self.menuHandles['item5000'].setEnabled(False)
         warn(self, "Changed parameter will require restarting simulations")
Example #4
0
def loadGenePop(file):
    global rec2, popNames, remPops, remLoci #,rec
    #rec = GenePop.read(open(str(file)))
    try:
        rec2 = FileParser.read(file)
        if isDominant:
            checkAlleles(file)
        remPops = []
        remLoci = []
        #popNames = ['pop' + str(i+1) for i in range(len(rec.populations))]
        popNames = ['pop' + str(i+1) for i in range(countPops(rec2))]
    except:
        error(frame, "Not a genepop file!")
Example #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))
Example #6
0
def _changeList(dialog, orig_list, orig_model, dest_model, requiresTwo = True):
    #sel = orig_list.getSelectedIndex()
    #if sel == -1:
    #    return
    #value = orig_model.get(sel)
    #orig_model.remove(sel)
    #dest_model.addElement(value)
    sels = orig_list.getSelectedIndices()
    if requiresTwo:
        if len(sels) > orig_model.getSize() - 2:
            error(dialog, 'At least 2 elements have to remain')
            return
    selsA = []
    for sel in sels:
        selsA.append(sel)
    selsA.sort(lambda x, y : cmp(y,x))
    for sel in selsA:
        value = orig_model.get(sel)
        orig_model.remove(sel)
        dest_model.addElement(value)
Example #7
0
def _changeList(dialog, orig_list, orig_model, dest_model, requiresTwo=True):
    #sel = orig_list.getSelectedIndex()
    #if sel == -1:
    #    return
    #value = orig_model.get(sel)
    #orig_model.remove(sel)
    #dest_model.addElement(value)
    sels = orig_list.getSelectedIndices()
    if requiresTwo:
        if len(sels) > orig_model.getSize() - 2:
            error(dialog, 'At least 2 elements have to remain')
            return
    selsA = []
    for sel in sels:
        selsA.append(sel)
    selsA.sort(lambda x, y: cmp(y, x))
    for sel in selsA:
        value = orig_model.get(sel)
        orig_model.remove(sel)
        dest_model.addElement(value)
Example #8
0
def checkAlleles(file):
    df = FileParser.read(file)
    countAlleles = []
    for locus in df.loci_list:
        countAlleles.append(set())
    indiv = df.get_individual()
    while indiv:
        if type(indiv) == tuple:
            name, loci = indiv
            for l in range(len(loci)):
                for a in loci[l]:
                    if a: countAlleles[l].add(a)
        indiv = df.get_individual()
    probLoci = []
    for l in range(len(countAlleles)):
        if len(countAlleles[l])>2:
            probLoci.append(df.loci_list[l])
    if probLoci != []:
        if len(probLoci)>5:
            error(frame, "Many (%d) loci have more than 2 alleles" % (len(probLoci)))
        else:
            error(frame, "Some loci have more than 2 alleles: %s" % (str(probLoci)))
Example #9
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
Example #10
0
def runFDist(more=False):
    global numAttempts
    global selRec2, frame, fdRequest, runState
    global empiricalPanel, systemPanel, statusPanel, chartPanel
    global isDominant, isTemporal
    chartPanel.resetData(True)
    try:
        if not more:
            os.remove(lpath + os.sep + 'out.dat') # careful, not for 5000 case
    except OSError:
        pass  # Its ok if it doesn't exist
    disableAllMenus()
    disablePanel(empiricalPanel)
    disablePanel(systemPanel)
    npops = empiricalPanel.getTotalPops()
    nsamples = countPops(selRec2)
    if nsamples > npops:
        error(frame, "Expected total populations lower then selected populations")
        return
    if isTemporal:
        ne = empiricalPanel.getNe()
    else:
        fst = empiricalPanel.getFst()
    if not isTemporal and not isDominant:
        mutStr = empiricalPanel.mut.getSelectedItem()
        mut = getMut(mutStr)
    if isDominant:
        theta = empiricalPanel.getTheta()
        beta = empiricalPanel.getBeta()
        crit = empiricalPanel.getCrit()
        mut = None
    else:
        theta = beta = crit = None
    if more:
        statusPanel.setStatus('Running an extra 5000 simulations', Color.YELLOW)
        numSims = 5000
    else:
        numSims = systemPanel.getNumSims()
    numCores = systemPanel.getNumCores()
    sampSize = empiricalPanel.getSampleSize()
    if not more:
        if not isTemporal:
            force = systemPanel.getForce()
        else:
            force = False
        neutral = systemPanel.getNeutral()
        if neutral and force:
            statusPanel.setStatus('Forcing correct mean Fst for first pass', Color.RED)
            fdRequest = 'NeuFor'
            runState  = 'ForceBeforeNeutral'
            numAttempts = 0
            numSims   = 50000
        elif neutral:
            statusPanel.setStatus('First simulation pass to determine initial neutral set', Color.CYAN)
            fdRequest = 'Neutral'
            runState  = 'Neutral'
        elif force:
            statusPanel.setStatus('Forcing correct mean Fst for final simulation', Color.RED)
            fdRequest = 'Force'
            runState  = 'Force'
            numAttempts = 0
            numSims   = 50000
        else:
            statusPanel.setStatus('Running simulation', Color.YELLOW)
            fdRequest = ''
            runState  = 'Final'
    else:
        fdRequest = ''
        runState  = 'Final'
    if isTemporal:
        runFtempPart(more, selRec2, numSims, npops, nsamples, ne,
            sampSize, numCores)
    else:
        runFDistPart(more, selRec2, mut, numSims, npops, nsamples, fst,
            sampSize, theta, beta, crit, numCores)
Example #11
0
    def propertyChange(self, evt):
        if self.ignoreChanges:
            return
        change = False
        if not self.isTemporal:
            if evt.getSource() == self.fst and evt.getPropertyName(
            ) == 'value':
                new = float(evt.getNewValue())
                old = float(evt.getOldValue())
                if new > 0.99:
                    evt.getSource().setValue(old)
                if new < -0.2:
                    evt.getSource().setValue(old)
                elif new < 0.0:
                    self.systemPanel.force.setSelected(False)
                    self.systemPanel.force.setEnabled(False)
                else:
                    self.systemPanel.force.setEnabled(True)
        else:
            if evt.getSource() == self.ne and evt.getPropertyName() == 'value':
                new = int(evt.getNewValue())
                old = int(evt.getOldValue())
                if new < 0:
                    evt.getSource().setValue(old)

        if self.isDominant and \
                evt.getSource() in [self.theta, self.beta1, self.beta2, self.crit] and \
                evt.getPropertyName() == 'value':
            new = float(evt.getNewValue())
            old = float(evt.getOldValue())
            if new > 0.99 or new < -0.2:
                evt.getSource().setValue(old)

        # Subsample size
        if evt.getSource() == self.sampleSize and evt.getPropertyName(
        ) == 'value':
            change = True
            new = int(evt.getNewValue())
            old = int(evt.getOldValue())
            if new > 50 and old > 4:
                warn(
                    self,
                    'A sample size bigger than 50 is not expected to produce better results, '
                    + 'while it slows the computation')
            if new < 5 and (new != 0 and not self.isDominant):
                evt.getSource().setValue(old)

        if evt.getSource() == self.pops and evt.getPropertyName() == 'value':
            change = True
            new = int(evt.getNewValue())
            old = int(evt.getOldValue())
            if new > 100:
                error(self, 'Maximum value for total populations is 100')
                evt.getSource().setValue(100)
            if new < self.knownPops:
                error(
                    self,
                    'Expected total populations has to be at least the same as the number of populations under study.'
                )
                evt.getSource().setValue(self.knownPops)

        if not self.isTemporal:
            if evt.getSource() == self.mut:
                change = True
        if not change:
            return
        if self.menuHandles['item5000'].isEnabled():
            self.menuHandles['item5000'].setEnabled(False)
            warn(self, "Changed parameter will require restarting simulations")