PatWright / BatSimuPOP

Simulation of population changes over time to assess the use of temporal sampling
0 stars 0 forks source link

Info on age and sex for each individual #4

Open PatWright opened 6 years ago

PatWright commented 6 years ago

I've added my latest script (Bat_3agecat.py). I've added a third age category and added some recombination.

I was wondering if :

Thanks.

BoPeng commented 6 years ago
  1. I think you can adapt the function (copy it to the script) defined here and add the information fields at the end of each line. Something like
def outputPop(pop):
    with open(f'{pop.dvars().gen}.txt', 'w') as output:
        ...

ops = [PyOperator(func=outputPop) ...]

with ind.sex() etc added after this line.

  1. Fertility could be simulated by natural selection or discard. For example, you could apply an selection operator (e.g. http://simupop.sourceforge.net/manual_release/build/userGuide_ch5_sec9.html#a-hybrid-selector-operator-pyselector) and assign fitness depending on age, and older bat would have lower chances to be selected. You can also explicitly discard offspring after they are born following examples at http://simupop.sourceforge.net/manual_release/build/userGuide_ch5_sec12.html#conditional-during-mating-operator-operator-discardif .
PatWright commented 6 years ago
  1. I don't think I got that right. I've added the bit of code below and ind.sex() to utils.py. The model will run but I don't get any info on age or sex.
def outputPop(pop):
    with open(f'{pop.dvars().gen}.txt', 'w') as output:
        'age', 'sex'

ops = [PyOperator(func=outputPop) 'age','sex'] 
  1. Is this the correct approach? I've added the fitness for all three categories but get this error message. SyntaxError: positional argument follows keyword argument
preOps=[
        migr,
        sim.InfoExec('age += 1'),
    ],
    sim.MapSelector(loci='age', fitness={'age < 3':0.3, '3 <= age < 9':0.85, '9<= age < 17':0.6}),
...
...

Thanks!

BoPeng commented 6 years ago
  1. I meant for you to understand the export function, copy the entire function over there and make the change to the line I point out. I will do it in a minutes.

  2. You need to assign fitness to VSPs.

BoPeng commented 6 years ago

I have added a fitness model as

        sim.InfoExec('fitness = (50 - ind.age)/50', exposeInd='ind'),

which basically means fitness ~ 1 for ind.age=2 and ~0.6 for ind.age = 17. You can define your own fitness model in a similar fashion.

PatWright commented 6 years ago

That works perfectly! Thanks.