コード例 #1
0
    def pre_sel_sort(self, pop):
        """
        Meant to set up the population for truncation selection.
        Can be used in an evolutionary process to provide easy
        way to implement non-random mating schemes.

        :warning: Replaces current virtual sub-population split

        :param pop:
        :return:
        """

        pop.sortIndividuals('p')
        pop.setVirtualSplitter(sim.ProportionSplitter(self.proportions,
                                      names=['not_selected','selected']))
        return True
コード例 #2
0
import simuPOP as sim
pop = sim.Population(size=[10000, 10000], loci=1)
pop.setVirtualSplitter(sim.ProportionSplitter([0.8, 0.2]))
pop.evolve(initOps=[sim.InitSex(),
                    sim.InitGenotype(freq=[0.5, 0.5])],
           preOps=[
               sim.Stat(homoFreq=0, subPops=[0, 1], vars='homoFreq_sp'),
               sim.PyEval(r"'(%.2f, %.2f)\n' % (subPop[0]['homoFreq'][0], "
                          "subPop[1]['homoFreq'][0])"),
           ],
           matingScheme=sim.HeteroMating(matingSchemes=[
               sim.RandomMating(subPops=[(0, 0), 1]),
               sim.SelfMating(subPops=[(0, 1)]),
           ]),
           gen=3)
コード例 #3
0
pop = sim.Population(size=[2, 3], loci=[5, 7])
sim.initGenotype(pop, genotype=[1] * 5 + [2] * 7 + [3] * 5 + [4] * 7)
sim.dump(pop, structure=False)
#
# use virtual subpopulation
pop = sim.Population(size=[2000, 3000], loci=[5, 7])
pop.setVirtualSplitter(sim.SexSplitter())
sim.initSex(pop)
sim.initGenotype(pop, genotype=range(10), loci=range(5))
# initialize all males
sim.initGenotype(pop,
                 genotype=[2] * 7,
                 loci=range(5, 12),
                 subPops=[(0, 0), (1, 0)])
# assign genotype by proportions
pop.setVirtualSplitter(sim.ProportionSplitter([0.4, 0.6]))
sim.initGenotype(pop, freq=[0.2, 0.8], subPops=[(0, 0)])
sim.initGenotype(pop, freq=[0.5, 0.5], subPops=[(0, 1)])
#
# initialize by random allele frequency
import random
sim.initGenotype(pop, freq=lambda: random.random())
printFreq(pop, range(5))
# initialize with loci specific frequency. here
# lambda loc: 0.01*loc is equivalent to
# lambda loc: [0.01*loc, 1-0.01*loc]
sim.initGenotype(pop, freq=lambda loc: 0.01 * loc)
printFreq(pop, range(5))
# initialize with VSP-specific frequency
sim.initGenotype(pop,
                 freq=lambda vsp: [[0.2, 0.8], [0.5, 0.5]][vsp[1]],
コード例 #4
0
from simuPOP.sampling import drawCaseControlSample


def assoTest(pop):
    'Draw case-control sample and apply association tests'
    sample = drawCaseControlSample(pop, cases=500, controls=500)
    sim.stat(sample,
             association=(0, 2),
             vars=['Allele_ChiSq_p', 'Geno_ChiSq_p', 'Armitage_p'])
    print('Allele test: %.2e, %.2e, Geno test: %.2e, %.2e, Trend test: %.2e, %.2e' \
        % (sample.dvars().Allele_ChiSq_p[0], sample.dvars().Allele_ChiSq_p[2],
        sample.dvars().Geno_ChiSq_p[0], sample.dvars().Geno_ChiSq_p[2],
        sample.dvars().Armitage_p[0], sample.dvars().Armitage_p[2]))
    return True


pop = sim.Population(size=100000, loci=3)
pop.setVirtualSplitter(sim.ProportionSplitter([0.5, 0.5]))
pop.evolve(initOps=[
    sim.InitSex(),
    sim.InitGenotype(genotype=[0] * 3, subPops=[(0, 0)]),
    sim.InitGenotype(genotype=[1] * 3, subPops=[(0, 1)]),
],
           matingScheme=sim.RandomMating(
               ops=sim.Recombinator(loci=[0, 1], rates=[0.01, 0.005])),
           postOps=[
               sim.MaPenetrance(loci=1, penetrance=[0.1, 0.2, 0.4]),
               sim.PyOperator(func=assoTest, step=20),
           ],
           gen=100)