BoPeng / simuPOP

A general-purpose forward-time population genetics simulation environment.
http://bopeng.github.io/simuPOP/
GNU General Public License v2.0
31 stars 12 forks source link

vary fecundity by age #68

Closed khornick1 closed 5 years ago

khornick1 commented 5 years ago

Hi,

I am new to simuPOP and Python. I want to simulate a population with high variance in reproductive success and age structure- overlapping generations, and age-specific fecundity and mortality rates. I have had success with simulating high variance in reproductive success, overlapping generations, and age-specific mortality rates using a heterogeneous mating scheme w/ clone mating and random mating. After looking over examples that incorporate age-specific fecundity rates, I guess I will have to use a homomating scheme with a parentchooser (e.g. sim.PyParentsChoose(choose_parents) from complex demography simulation #8). Is this the only way to model this type of scenario?

BoPeng commented 5 years ago

Can you simulate age-specific fecunidity rates with age-specific fitness (less chance to mate or probability of survival of offspring)? Basically you can add a fitness model before mating, or DiscardIf during mating.

khornick1 commented 5 years ago

Thank you for the prompt response. That could work; however, I do not want that trait to "evolve," it needs to be fixed within age classes. Can fecundity be "set" sort of like a trait via a vector across ages? Currently the number of offspring follow the geometric distribution to reflect high variance in reproductive success, but could the mean (1/p) be vectorized or the offspring distribution function re-written to take input from a vector of age-specific fecundities? Thank you in advance for your help.

On Thu, Jan 24, 2019 at 5:40 PM Bo notifications@github.com wrote:

Can you simulate age-specific fecunidity rates with age-specific fitness (less chance to mate or probability of survival of offspring)? Basically you can add a fitness model before mating, or DiscardIf during mating.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BoPeng/simuPOP/issues/68#issuecomment-457385865, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ8WHOZ0GG7EDcLARh3LXPC4Woi-aLnKks5vGjZagaJpZM4aRy6d .

-- Katherine Hornick PhD Candidate University of Maryland Center for Environmental Science Horn Point Laboratory PO BOX 775, Cambridge, MD 21613 Office: (410) 221-8259

BoPeng commented 5 years ago

Did you check the last example of http://simupop.sourceforge.net/manual_svn/build/userGuide_ch6_sec1.html#numoff ? Basically you can set a maximum number of numOffspring and use a DiscardIf during mating operator to remove offspring by age.

khornick1 commented 5 years ago

Ahhh I see. That makes sense and I think that will work. Thank you so much for your help and prompt responses.

khornick1 commented 5 years ago

Finally getting back to this after working on other parts of my simulations. When I add the DiscardIf during mating operator to remove a proportion of offspring from parents with younger ages to reflect their lower fecundity, my simulations slow down significantly (they normally take an hour or so, now with the DiscardIf function they have been running for a day with no output).

  1. Is this normal? Or have I coded this incorrectly?
  2. If this is normal, I suppose I would have to code it a different way....

Thanks in advance for your help. Katie

Here is my code:

matingScheme=sim.HeteroMating([
        sim.CloneMating(subPops=[(0,sim.ALL_AVAIL), (1,sim.ALL_AVAIL)], weight=-1),
        sim.RandomMating(ops=[
            sim.DiscardIf(0.5, 'age<=5', begin=3),
            sim.IdTagger(),  # give new born an ID
            sim.PedigreeTagger(),
            sim.ParentsTagger(),# track parents of each individual
            sim.MendelianGenoTransmitter(),  # transmit genotype
        ],
            numOffspring=(sim.GEOMETRIC_DISTRIBUTION, 0.01),
            subPops=[(0,2),(0,3),(0,4),(0,5),(0,6),(0,7),(0,8),(0,9),(0,10),(0,11),
                     (1,2), (1,3), (1,4), (1,5), (1,6), (1,7), (1,8), (1,9), (1,10), (1,11)]),],
        subPopSize=demo),
BoPeng commented 5 years ago
            sim.DiscardIf(0.5, 'age<=5', begin=3),

You are discarding offspring based on their age, which should be the age of parent, right? How do you assign age of offspring? I do not see anything like InheritTagger to pass age of parents to offspring (whether or not this should be done is another question) so the age of offspring should be zero or some random value. If you assign age to zero, then all offspring would be discarded.

khornick1 commented 5 years ago

I want to discard a proportion of offspring from parents of younger ages. My offspring are age 0 (unless I'm coding it incorrectly, see below), so the idea is to remove some of the age-0 offspring from parents of younger ages (in this case, parents with ages<5 produce half the amt of offspring as older individuals). I assign age early in simulations as an infofield and then use a virtual splitter and initiate ages as such:

pop = sim.Population(size=[5000,5000], loci= [1]*250,
                     subPopNames = ['wild', 'broodstock', 'hatchery'],
                     infoFields=[ 'age', 'ind_id','father_id', 'mother_id', 'migrate_to', 'migrate_from'])
pop.setVirtualSplitter(sim.InfoSplitter(field='age', cutoff=[1,2,3,4,5,6,7,8,9,10,11]))
sim.InitInfo(lambda: random.randint(0, 11), infoFields='age'),

I don't think I would need an InheritTagger for this since the offspring have a different age than their parents?

BoPeng commented 5 years ago

My point was that

            sim.DiscardIf(0.5, 'age<=5', begin=3),

is applied as a during mating operator to offsprings (not their parents), but age for offspring is not defined.

khornick1 commented 5 years ago

Ahhh I see. That makes sense.

So, if I want to discard a proportion of offspring with parents <=age5, I would have to use an InheritTagger so that the offspring inherit parent age infofields and then I would be able discard offspring with parents of a certain age?

BoPeng commented 5 years ago

Yes, but then you would need to reset age to zero for surviving offspring.

khornick1 commented 5 years ago

Got it. Thank you!