#note Population Genetics A Concise Guide (11)

Page 24

Problem 2.2 If you know how to program a computer, write a simulation of genetic drift.

Note:

The simulation model:

1. Choose an allele at random from among the 2N (N is the number of the diploid individuals) alleles in the parent generation.

2. Make an exact copy of the allele.

3. Place the copy in the new generation.

For one trial, the algorithm by using Java:

public List<Double> geneDrift(int population, double frequency, int generations){
  List<Double> list = new ArrayList<>();
  list.add(frequency);
  while(generations != 0) {
    double currentFrequency = frequency;
    long count = DoubleStream.generate(Math::random).limit(population).filter(i -> i < currentFrequency).count();
    frequency = (double)count / population;
    list.add(frequency);
    generations--;
  }
  return list;
}

By using Spring boot and Highcharts I did the virtualization:

Figure 1: Genetic drift simulation by using Highcharts. Default parameters: trials=20, population size=40, initial frequency=0.2, generations=100
Figure 2: Genetic drift simulation by using Highcharts. Custom parameters: trials=100, population size=100, initial frequency=0.5, generations=500

Code: https://github.com/xlinxlin/GeneticDriftSimulationVirtualization

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top