Genetic drift simulation

(Population Genetics)

OK, I know I promised an examination of the Neutral Theory next, but on reflection there's something I need to cover first. The Neutral Theory examines the behaviour of a genetic drift model of allele distribution, so it would be helpful to provide a short program to simulate this.

(Note that we've moved from examining genotype frequencies to examining allele frequencies. That's because this requires marginally less thought. Once you've got your allele frequencies, I imagine you could use the Hardy-Weinberg law to determine the corresponding genotype frequencies.

Actually, that's something I'll have to check at some point...)

The following program is written in the free, open-source programming language Python. I love this language. It's like QBasic would be if QBasic was cool, or like Lisp would be if Lisp was useable.

The program is very simple - it just randomly selects a new generation from the old generation, and repeats. This doesn't sound terribly meaningful, but it already raises a few interesting questions. For example, if all the alleles in a generation are the same, that allele type is said to be fixed - within this model it's impossible for the next generation to contain any other allele type. But given a starting population containing a mix of allele types, what's the probability of any one of them becoming fixed?

I'll give the answer to this next time, but in the meantime why not play around with the program and see if you can figure out the answer yourself?

The program:

#!/usr/bin/env python

import random

# Select a starting population. I'm going to go for one that's homozygous except for a single differing allele (a mutation?)

popsize = 100
alleles = ["A" for ii in range(popsize-1)] + ["B"]

generations = 1000 # number of times to iterate

for ii in range(generations):
    newalleles = []
    for jj in range(len(alleles)):

    alleles = newalleles

print alleles

I'll probably do a better version at some point, with decent input and output control. However, that's way too long-winded for a blog. When I've done it I'll stick it on some webspace somewhere and link to it. I also intend to produce some decent graphs of the variation over time of alleles.

Note: if you're on Windows, you'll want to strip out the first line ("#!/usr/bin/env python" etc). That's a Unix-only thing.


Marginally better version available here: http://coalescent.freewebpage.org/popgen/gendrift.py


Post a Comment

Links to this post:

Create a Link

<< Home