Exemple #1
0
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim


def demo(pop):
    return int(pop.popSize() * 1.05)


pop = sim.Population(size=10000, loci=1)
pop.evolve(
    initOps=[sim.InitSex(), sim.InitGenotype(freq=[0.7, 0.3])],
    preOps=[
        sim.Stat(popSize=True),
        sim.PyEval(r'"%d %s --> " % (gen, subPopSize)'),
        sim.ResizeSubPops(0, proportions=[0.5], at=2),
        sim.MaPenetrance(loci=0, penetrance=[0.01, 0.2, 0.6], begin=4),
        sim.DiscardIf('ind.affected()', exposeInd='ind', begin=4),
        sim.Stat(popSize=True),
        sim.PyEval(r'"%s --> " % subPopSize'),
    ],
    matingScheme=sim.RandomMating(subPopSize=demo),
    postOps=[sim.Stat(popSize=True),
             sim.PyEval(r'"%s\n" % subPopSize')],
    gen=6)
Exemple #2
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(size=2000, loci=1, infoFields='fitness')
pop.evolve(initOps=[sim.InitSex(),
                    sim.InitGenotype(freq=[.5, .5])],
           preOps=[
               sim.MaPenetrance(loci=0, penetrance=[0.01, 0.1, 0.2]),
               sim.Stat(numOfAffected=True, step=25, vars='propOfAffected'),
               sim.PyEval(r"'Percent of affected: %.3f\t' % propOfAffected",
                          step=50),
               sim.InfoExec('fitness = not ind.affected()', exposeInd='ind')
           ],
           matingScheme=sim.RandomMating(),
           postOps=[
               sim.Stat(alleleFreq=0),
               sim.PyEval(r"'%.4f\n' % alleleFreq[0][1]", step=50)
           ],
           gen=151)
Exemple #3
0
# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
from simuPOP.sampling import indexToID
pop = sim.Population(size=15,
                     loci=5,
                     infoFields=['father_idx', 'mother_idx'],
                     ancGen=2)
pop.evolve(preOps=[
    sim.InitSex(),
    sim.InitGenotype(freq=[0.7, 0.3]),
],
           matingScheme=sim.RandomMating(
               numOffspring=(sim.UNIFORM_DISTRIBUTION, 2, 4),
               ops=[sim.MendelianGenoTransmitter(),
                    sim.ParentsTagger()]),
           postOps=sim.MaPenetrance(loci=3, penetrance=(0.1, 0.4, 0.7)),
           gen=5)
indexToID(pop, reset=True)
# three information fields were added
print(pop.infoFields())
# save this population for future use
pop.save('log/pedigree.pop')

from simuPOP.sampling import drawAffectedSibpairSample
pop = sim.loadPopulation('log/pedigree.pop')
sample = drawAffectedSibpairSample(pop, families=2)
    collected. A penetrance operator is needed to assign affection status
    to each offspring.
    '''
    pop1 = pop.clone()
    pop1.setAncestralDepth(1)
    pop1.addInfoFields(['ind_id', 'father_id', 'mother_id'])
    pop1.evolve(initOps=sim.IdTagger(),
                matingScheme=sim.RandomMating(ops=[
                    sim.MendelianGenoTransmitter(),
                    penetrance,
                    sim.IdTagger(),
                    sim.PedigreeTagger(),
                ],
                                              numOffspring=2,
                                              subPopSize=pop.popSize() * 2),
                gen=1)
    sim.stat(pop1, numOfAffected=True)
    return drawAffectedSibpairSample(pop1, nFamilies)


if __name__ == '__main__':
    pop = sim.Population(size=10000, loci=1)
    sim.initGenotype(pop, freq=[0.5, 0.5])
    sim.initSex(pop)
    sim.maPenetrance(pop, loci=0, penetrance=[0.05, 0.15, 0.30])
    sample = genAffectedSibpairSample(
        pop, 100, sim.MaPenetrance(loci=0, penetrance=[0.05, 0.15, 0.30]))
    #
    sim.stat(sample, numOfAffected=True)
    print(sample.dvars().numOfAffected, sample.dvars().numOfUnaffected)
Exemple #5
0
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(1000, loci=[1], infoFields=['aff', 'numOfAff'])
# define virtual subpopulations by affection sim.status
pop.setVirtualSplitter(sim.AffectionSplitter())
pop.evolve(
    initOps=[
        sim.InitSex(),
        sim.InitGenotype(freq=[0.5, 0.5]),
    ],
    preOps=[
        # get affection sim.status for parents
        sim.MaPenetrance(loci=0, wildtype=0, penetrance=[0.1, 0.2, 0.4]),
        # set 'aff' of parents
        sim.InfoExec('aff = ind.affected()', exposeInd='ind'),
    ],
    # get number of affected parents for each offspring and store in numOfAff
    matingScheme=sim.RandomMating(ops=[
        sim.MendelianGenoTransmitter(),
        sim.SummaryTagger(mode=sim.SUMMATION, infoFields=['aff', 'numOfAff'])
    ]),
    postOps=[
        # get affection sim.status for offspring
        sim.MaPenetrance(loci=0, wildtype=0, penetrance=[0.1, 0.2, 0.4]),
        # calculate mean 'numOfAff' of offspring, for unaffected and affected subpopulations.
        sim.Stat(meanOfInfo='numOfAff',
                 subPops=[(0, 0), (0, 1)],
                 vars=['meanOfInfo_sp']),
Exemple #6
0
def genCaseControlSample(pop, nCase, nControl, penetrance):
    '''Draw nCase affected and nControl unaffected individuals by producing
    offspring from pop repeatedly until enough cases and controls are
    collected. A penetrance operator is needed to assign affection status
    to each offspring.
    '''
    sample = pop.clone()
    sample.setVirtualSplitter(
        sim.ProductSplitter([
            sim.AffectionSplitter(),
            sim.RangeSplitter([[0, nCase], [nCase, nCase + nControl]])
        ]))
    sample.evolve(matingScheme=sim.RandomMating(ops=[
        sim.MendelianGenoTransmitter(), penetrance,
        sim.DiscardIf(True, subPops=[(0, 0), (0, 3)])
    ],
                                                subPopSize=nCase + nControl),
                  gen=1)
    return sample


if __name__ == '__main__':
    pop = sim.Population(size=10000, loci=1)
    sim.initGenotype(pop, freq=[0.8, 0.2])
    sim.initSex(pop)
    sample = genCaseControlSample(
        pop, 500, 500, sim.MaPenetrance(loci=0, penetrance=[0.01, 0.02, 0.10]))
    #
    sim.stat(sample, numOfAffected=True)
    print(sample.dvars().numOfAffected, sample.dvars().numOfUnaffected)
Exemple #7
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(5000, loci=3)
sim.initGenotype(pop, freq=[0.2] * 5)
# the multi-loci penetrance
sim.mlPenetrance(pop,
                 mode=sim.MULTIPLICATIVE,
                 ops=[
                     sim.MaPenetrance(loci=loc, penetrance=[0, 0.3, 0.6])
                     for loc in range(3)
                 ])
# count the number of affected individuals.
sim.stat(pop, numOfAffected=True)
pop.dvars().numOfAffected
Exemple #8
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)
Exemple #9
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(5000, loci=3)
pop.evolve(
    initOps=[
        sim.InitSex(),
        sim.InitGenotype(freq=[0.9] + [0.02]*5)
    ],
    matingScheme=sim.RandomMating(),
    postOps=[
        sim.MaPenetrance(loci=0, penetrance=(0.01, 0.2, 0.3)),
        sim.Stat(numOfAffected=True, vars='propOfAffected'),
        sim.PyEval(r"'Gen: %d Prevalence: %.1f%%\n' % (gen, propOfAffected*100)"),
    ],
    gen = 5
)

Exemple #10
0
# description of this example.
#

import simuPOP as sim
pop = sim.Population(size=500, loci=1)
pop.setVirtualSplitter(sim.ProductSplitter([
    sim.AffectionSplitter(),
    sim.RangeSplitter([[0,500], [500, 1000]]),
    ])
)
pop.evolve(
    initOps=[
        sim.InitSex(),
        sim.InitGenotype(freq=[0.5, 0.5]),
    ],
    matingScheme=sim.RandomMating(
        ops=[
            sim.MendelianGenoTransmitter(),
            sim.MaPenetrance(loci=0, penetrance=[0, 0.01, 0.1]),
            sim.DiscardIf(True, subPops=[
                (0, 'Unaffected, Range [0, 500)'),
                (0, 'Affected, Range [500, 1000)')])
        ],
        subPopSize=1000,
    ),
    gen = 1
)
sim.stat(pop, numOfAffected=True)
print(pop.dvars().numOfAffected, pop.dvars().numOfUnaffected)

Exemple #11
0
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(10000, loci=1)
pop.setVirtualSplitter(sim.AffectionSplitter())
pop.evolve(
    initOps=[
        sim.InitSex(),
        sim.InitGenotype(loci=0, freq=[0.8, 0.2])
    ],
    matingScheme=sim.RandomMating(),
    postOps=[
        sim.MaPenetrance(penetrance=[0.1, 0.4, 0.6], loci=0),
        sim.Stat(alleleFreq=0, subPops=[(0, 0), (0, 1)],
            vars=['alleleFreq', 'alleleFreq_sp']),
        sim.PyEval(r"'Gen: %d, freq: %.2f, freq (aff): %.2f, freq (unaff): %.2f\n' % " + \
            "(gen, alleleFreq[0][1], subPop[(0,1)]['alleleFreq'][0][1]," + \
            "subPop[(0,0)]['alleleFreq'][0][1])"),
    ],
    gen = 5
)