Lets start playing with randomness
Genetic Drift is a name for the effects of random sampling on the frequency of alleles in replicating organisms.
Because populations are finite, sampling effects occur from generation to generation even in the absence of selection, and will cause mutations to sweep through a population over time.
We'll use the random library to generate random numbers and sample from a list.
You can view the random library reference here: https://docs.python.org/3/library/random.html
My general philosophy on coding is that it is never a bad idea to google something!
We'll use the choices function from the random library to sample (with replacement) from a collection. In this case, we're sampling from the possible genotypes to fill up a population of pop_size individuals.
Important! This is a feature of the python3 random library. If you're using python2 we'll have to get a python3 instance running now.
Now that we have a population, and know how to sample from a collection, we can simulate a generation by filling up the next generation with a random sampling of the original population.
Let's do that one more time...
Let's write a little function that returns the frequency of 1s in a population
Now let's plot a simple figure showing the frequency of 1s over these couple of generations
We'll use the matplotlib library, which mimics the way Matlab (hence the name) plots figures.
For a brief tutorial on plotting with matplotlib see this link: https://matplotlib.org/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py
We can start with a perfect 50/50 mix of genotypes by being explicit about the initial population.
We can also plot multiple lines in the same figure by calling plot() multiple times before calling show()!
1. Now in your groups, simulate many (100) generations, and many replicates and plot the dynamics like we did above
Obviously you're not going to want to keep creating variables for each new population... So, you'll want to loop through generations, keeping track of the frequency of ones over time.
2. Now plot many replicates on the same plot!
Insert a Markdown cell and describe what you notice about the populations.
3. If you're breezing through these questions, try visualizing the distribution of generation time until populations fix a genotype (when the population is all 0s or all 1s).
Then, play with the population size to see how the distribution changes!
Insert a Markdown cell and describe what you notice about how the distribution changes.
4. WHOA! You're really flying through this...
If you're here, try figuring out a way to add a fitness value to the "1" genotype that increases their likelihood of being sampled into the next generation (hint: look at the documentation for random.choices).
See how starting with just one or a few of "1" genotypes affects their chances at fixing in the population. How does the value for fitness change the probability of fixation?
5. Now you're just showing off. If you got all that done, see if you can add mutations between genotypes
( and ) With some small probability, for example.
How does mutation change the dynamics of fixation?