BoPeng/simuPOP

Simulate a declining population that has two VSPs

Closed this issue · 4 comments

Bo,

I am simulating a population that is 1) in decline and 2) is made up of two VSPs. I want to continue the population decline throughout the simulation. But at mid-run I want the reproduction of each VSP to differ relative to its proportion of the total population (e.g., VSP 1 is 25% of population but I want it to produce 2/3 of offspring for the next generation).

I am able to simulate this shift in mating scheme but I am having difficulty coding the population to continue declining for the remainder of the run. I have tried a nested conditionalMating design (not shown) and also the simpler model shown below (see attached file
Decline_&_VSPs.py.txt
.

I am not certain what I am coding incorrectly. Do you have any suggestions to point me in the right direction to correct my code to allow for continuous decline along with changes in mating scheme after a given generation?

Thanks,
Evan

import simuPOP as sim
def demo(pop):# Population declineof 5%/generation
    return int(pop.popSize() / 1.05) # Population declineof 5%/generation

pop = sim.Population(size=[500], loci=[1], infoFields=['mark'])
pop.setVirtualSplitter(sim.ProportionSplitter([0.75, 0.25])) # VSP0 = 75% of subPop 0, VSP1 = 25%

pop.evolve(
    initOps=[
        sim.InitSex(), # Equal sex ratio
        sim.InitGenotype(freq=[0.50, 0.50]), # 2 alleles or equal fequency at one locus
        ],
#################################################################################################################################
    matingScheme=sim.ConditionalMating('gen < 10', #random mating until generation 10
        sim.RandomMating(subPops=0, weight=1, subPopSize=(demo), # subPopSize=(demo) codes for popualtion decline as defines in lines 2 & 3
            ops=[sim.InfoExec('mark=0'), sim.MendelianGenoTransmitter()]),
####-------------------------------------------------------------------------------------------------------------------------------------
####-------------------------------------------FOR REMAINING GENERATIONS (>=10)----------------------------------------------------------
####-----------------------I AM UNCERTAIN HOW TO CODE SECTION BELOW TO CONTINUE WITH POPULATION DECLINE STARTED IN SECTION ABOVE---------
####-------------------------------------------------------------------------------------------------------------------------------------
        sim.HeteroMating([ #from generation 10 onwards, VSP 0 contributes 1/2 as many offspring as VSP1, with no overlap into subPop 0 (contributes zero by itself)
        sim.RandomMating(subPops=0, weight=0, # subpop 0 contributes no offspring separate from VSPs 0 & 1
            ops=[sim.InfoExec('mark=0'), sim.MendelianGenoTransmitter()]),
        sim.RandomMating(subPops=[(0, 0)], weight=1, # VSP 0 contributes 1/3 of offspring
            ops=[sim.InfoExec('mark=1'), sim.MendelianGenoTransmitter()]),
        sim.RandomMating(subPops=[(0, 1)], weight=2, # VSP 1 contributes 1/3 of offspring
            ops=[sim.InfoExec('mark=2'), sim.MendelianGenoTransmitter()])
        ])
    ),
#################################################################################################################################
    postOps=[
        sim.Stat(popSize=True), # Keep population size steady each generation
        sim.PyEval(r'"%s\n" % subPopSize'),
		],
    gen=20 # Number of generations for simulation
    )
#################################################################################################################################
marks = list(pop.indInfo('mark'))
marks.count(0.) #counts for subPop 0
marks.count(1.) #counts for VSP 0 (= subPop (0, 0))
marks.count(2.) # counts for VSP 1 (= subPop (0, 1))

Because you forgot to put subPopSize=demo in the HeteroMating scheme.

Thanks. I must be adding subPopSize=demo incorrectly to the HeteroMating scheme because I already tried adding to HeteroMating. That seems like the obvious thing to do. But either way I code it, the population stabilizes rather than declines further at initiation of HeteroMating. I am sorry I need to ask for help on something that seems simple.

Below is an example of where I have added subPopSize=demo to HeteroMating yet still had the population stabilize instead of decline.

Thanks again for your help.
Evan

    sim.HeteroMating([ #from generation 10 onwards, VSP 0 contributes 1/2 as many offspring as VSP1, with no overlap into subPop 0 (contributes zero by itself)
    sim.RandomMating(subPops=0, weight=0, subPopSize=demo, # subpop 0 contributes no offspring separate from VSPs 0 & 1
        ops=[sim.InfoExec('mark=0'), sim.MendelianGenoTransmitter()]),
    sim.RandomMating(subPops=[(0, 0)], weight=1, subPopSize=demo, # VSP 0 contributes 1/3 of offspring
        ops=[sim.InfoExec('mark=1'), sim.MendelianGenoTransmitter()]),
    sim.RandomMating(subPops=[(0, 1)], weight=2, subPopSize=demo, # VSP 1 contributes 1/3 of offspring
        ops=[sim.InfoExec('mark=2'), sim.MendelianGenoTransmitter()])
    ])
),

You need to add subPopSize=demo for HeteroMating outside of the list of homogeneous mating schemes.

Excellent. Thanks for the guidance.

Should other users run into the same problem, here's what worked as a modification to script in my initial query:

matingScheme=sim.ConditionalMating('gen < 10', #random mating until generation 10
    sim.RandomMating(subPops=0, weight=1, subPopSize=(demo), # subPopSize=(demo) codes for popualtion decline as defines in lines 2 & 3
        ops=[sim.InfoExec('mark=0'), sim.MendelianGenoTransmitter()]),
    sim.HeteroMating(subPopSize=demo, matingSchemes=[ #from generation 10 onwards, VSP 0 contributes 1/2 as many offspring as VSP1, with no overlap into subPop 0 (contributes zero by itself)
    sim.RandomMating(subPops=0, weight=0, # subpop 0 contributes no offspring separate from VSPs 0 & 1
        ops=[sim.InfoExec('mark=0'), sim.MendelianGenoTransmitter()]),
    sim.RandomMating(subPops=[(0, 0)], weight=1, # VSP 0 contributes 1/3 of offspring
        ops=[sim.InfoExec('mark=1'), sim.MendelianGenoTransmitter()]),
    sim.RandomMating(subPops=[(0, 1)], weight=2, # VSP 1 contributes 1/3 of offspring
        ops=[sim.InfoExec('mark=2'), sim.MendelianGenoTransmitter()])
    ])
),