← 🧬 Genetics
🧬 Genetics • Difficulty ★★☆

Population Genetics — Hardy-Weinberg & Selection

Model allele frequency changes under natural selection, genetic drift, and mutation. Watch Hardy-Weinberg equilibrium break when selection pressure or small population size is applied.

🧬 Population Genetics Controls

Presets:
p (A allele): 0.50
q (a allele): 0.50
Generation: 0
HWE expected (AA):

Hardy-Weinberg Equilibrium

Under idealised conditions (infinite population, no selection, mutation, drift, or migration), allele frequencies remain constant: p² + 2pq + q² = 1, where p = freq(A) and q = freq(a). This HWE is disrupted by any evolutionary force. The simulation shows how these forces change p over generations.

Natural Selection

Mean fitness w̄ = p²w_AA + 2pq·w_Aa + q²w_aa. Change in p: Δp = pq·[p(w_AA−w_Aa)+q(w_Aa−w_aa)]/w̄. Dominant advantage drives A to fixation. Heterozygote advantage (overdominance) maintains a stable equilibrium — this is why sickle cell trait persists in malaria regions: Aa carriers have enhanced malaria resistance.

Genetic Drift

In finite populations, allele frequencies change randomly due to sampling: each generation, 2N alleles are drawn from the gene pool. Smaller N means larger random fluctuations. Eventually, one allele fixes (p=1 or p=0). Fixation probability for a neutral allele = 1/(2N). This explains why small populations lose genetic diversity faster.

About this simulation

This simulation runs a discrete-generation Wright-Fisher model of a single gene with two alleles, A and a. Each generation it applies natural selection using genotype fitness values w_AA, w_Aa and w_aa, then optional mutation at rate μ, then optional genetic drift by resampling 2N alleles binomially from the new allele frequency — so you can watch Hardy-Weinberg equilibrium hold or break down as you change population size and selection pressure.

🔬 What it shows

The allele frequency p (for A) and q = 1−p (for a) plotted over generations, alongside live genotype frequency bars for AA, Aa and aa. Selection moves p each generation via Δp determined by the fitness differences between genotypes weighted by mean fitness w̄; drift adds random sampling noise from a finite population of size N; mutation nudges p toward q at rate μ.

🎮 How to use

Set Population Size N (10–1000), the three genotype fitness sliders w_AA/w_Aa/w_aa (0–2), and Mutation Rate μ, then press Run. Toggle Genetic Drift on or off to compare a noisy finite population against a smooth deterministic selection curve. Try the four presets — Neutral Drift, Dominant Advantage, Heterozygote Advantage (Sickle Cell), and Lethal Recessive — or click Add Mutation to perturb p by hand.

💡 Did you know?

The Heterozygote Advantage preset models real biology: in malaria-endemic regions the sickle-cell allele persists at surprisingly high frequency because Aa carriers resist malaria better than either AA or aa homozygotes, an equilibrium called overdominance or balancing selection. Meanwhile, the probability that any single neutral allele eventually fixes by drift alone is exactly 1/(2N) — smaller populations lose diversity far faster than large ones.

Frequently asked questions

What model does this simulation use to change allele frequencies?

It uses a Wright-Fisher-style discrete-generation model. Each generation, the current allele frequency p is updated by natural selection based on the fitness weights w_AA, w_Aa and w_aa, then mutation shifts p toward q at rate μ, and finally — if Genetic Drift is enabled — 2N new alleles are drawn binomially from that updated frequency to simulate finite-population sampling noise.

How does the simulation calculate the effect of natural selection?

Mean population fitness is w̄ = p²·w_AA + 2pq·w_Aa + q²·w_aa. The new frequency of A is pNew = (p²·w_AA + pq·w_Aa) / w̄, which is the classic one-locus selection equation for a randomly mating diploid population. If w_AA is largest, A rises toward fixation; if w_Aa is largest (heterozygote advantage), p settles at a stable interior equilibrium instead of fixing.

What is genetic drift and how is it modelled here?

Genetic drift is random change in allele frequency caused by chance sampling of a finite number of parents each generation. The simulation models it by drawing 2N alleles (one binomial trial per allele, each with probability pNew of being A) and using the resulting fraction as the next generation's frequency. Smaller N produces visibly noisier, more erratic p trajectories, and can carry an allele all the way to fixation (p=1) or loss (p=0) even without any selective advantage.

Why does the Heterozygote Advantage (Sickle Cell) preset not go to fixation?

That preset sets w_Aa above both w_AA and w_aa (0.8, 1.3 and 0.4 in the simulation), which is overdominance or heterozygote advantage. Because carriers of one copy of each allele are the fittest genotype, selection cannot fix either allele — pushing p toward 1 lowers the frequency of the fittest Aa genotype, and the same happens pushing p toward 0. The population instead settles at a stable interior equilibrium, mirroring how the sickle-cell allele persists in human populations exposed to malaria.

What does the Hardy-Weinberg equilibrium reference line represent?

Hardy-Weinberg equilibrium describes the genotype frequencies p², 2pq and q² that a population would maintain forever if there were no selection, mutation, drift, or migration — an idealised baseline, not a prediction of what should happen here. The dashed line at p=0.5 and the readout labelled "HWE expected (AA)" let you compare the population's actual trajectory against that null expectation, making it visually obvious when and how strongly selection or drift pulls the population away from equilibrium.