How to do it...

Take a look at the following steps:

  1. Let's start by defining a function that will cull individuals according to their age and policy:
def kill(pop):    kills = []    for i in pop.individuals():        if i.sex() == 1:            cut = pop.dvars().survival_male[int(i.age)]        else:            cut = pop.dvars().survival_female[int(i.age)]            if pop.dvars().gen > pop.dvars().cut_gen and i.age == 2:                cut = 0        if random.random() > cut:            kills.append(i.ind_id)    pop.removeIndividuals(IDs=kills)    return True

This function assumes that there are a couple of population variables (that we will create later) with the survival rate per sex. Also, there is a provision to kill all females of age 2 after a certain generation.

  1. We need to have a function to choose the parents, since ...

Get Bioinformatics with Python Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.