Home / Science / Ecology and organisms / Population genetics / Coalescent simulatorTool #314

Coalescent simulator: draw gene genealogies, mutations, TMRCA and Watterson's theta (Kingman coalescent)

Simulate the family tree of a sample of gene copies back to their most recent common ancestor under the Kingman coalescent. See the tree with its mutations, then compare thousands of genealogies with the expected time to the common ancestor, total branch length, number of segregating sites and Watterson's estimate of θ. Seeded random numbers, so every tree can be repeated.

Keep it one tap away for everyday use.

Bookmark Coalescent simulator?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. n and θ
  2. Genealogy
  3. Mutations
  4. Vs theory
Nothing is uploadedWorks offline once open

Sample and mutation rate

Trace n gene copies back in time until they all meet in one common ancestor (the MRCA). With k lineages, any two merge after a random wait averaging 2/(k(k − 1)) units of 2N generations, so mergers come fast at first and slowly at the end. Mutations fall on the branches at random, θ/2 per unit of branch length. θ = 0 draws trees without mutations. The tree shown is the first of the genealogies averaged; "Next tree" moves to the next seed. Up to n 200 and 5 million tips in all.

One genealogy

Tips are the sampled copies at the bottom (time 0); the root at the top is their most recent common ancestor. Each dot is a mutation; every mutation is one segregating site.

Over many genealogies

Download

What it does

Take a sample of n copies of a gene from a population and follow them back in time. Every so often two copies turn out to come from the same parent copy: their lines coalesce. Eventually all of them meet in a single most recent common ancestor (MRCA). The Kingman coalescent describes this random family tree for a neutral gene in a population of constant effective size N.

This simulator draws such a genealogy, scatters neutral mutations on its branches, and then repeats the process thousands of times to compare the averages with the textbook formulas.

How to use it

  1. Sample size n: how many gene copies you sampled (2 to 200).
  2. θ = 4Nμ: the population mutation rate for the whole locus, with μ the mutation rate per copy per generation. It sets how many mutations fall on the tree: θ/2 per unit of branch length. Use 0 for trees without mutations.
  3. Genealogies to average: how many independent trees to simulate for the comparison table and histogram.
  4. Seed: the same seed always gives the same trees. Next tree steps to the next seed.
  5. Show times in: coalescent units (one unit is 2N generations for a diploid population) or generations, after you give N.

What you get

  • The tree: tips at the bottom, the MRCA at the top, mutations as dots, with its TMRCA, total branch length, number of segregating sites S, Watterson’s θ = S/a (a = 1 + 1/2 + … + 1/(n − 1)) and the share of the TMRCA spent with only two lineages left.
  • A table of expected and simulated means and standard deviations, and a histogram of the TMRCA.
  • Downloads: the tree in Newick (open it in the phylogenetic tree viewer), every genealogy’s values (CSV), and a report as image, PDF or Word.

Worked example

The page opens with n = 10, θ = 5 and seed 1. That first tree has a TMRCA of 2.18 units (expected 2(1 − 1/10) = 1.8), a total branch length of 5.343 (expected 5.658) and 16 segregating sites (expected θa = 14.14), so Watterson’s θ = 16 / 2.829 = 5.656. In this tree the last two lineages took 82 % of the whole time to merge.

Averaged over 10,000 genealogies, the TMRCA is 1.812 (standard deviation 1.095, expected 1.076), S averages 14.19 and Watterson’s θ averages 5.014, close to the true 5. The histogram shows how widely single genes vary.

Tips

  • Add samples and watch the TMRCA barely move: going from 10 to 100 copies raises the expected TMRCA only from 1.8 to 1.98, because the extra lineages merge very quickly near the tips.
  • The final merger of two lineages takes on average 1 unit, more than half of the total: deep history depends on very few lineages.
  • Watterson’s θ is unbiased but noisy: one locus gives a rough estimate. Real studies average many loci.

FAQ

What does a coalescent unit mean in years? One unit is 2N generations. For N = 10,000 and a generation time of 25 years, that is 500,000 years.

Does this include recombination, selection or population growth? No. It is the standard neutral coalescent with constant size, for learning the basics.

Is anything sent anywhere? No. Everything runs in your browser.

Where the numbers come from

  • Theory: J. F. C. Kingman (1982), Stoch. Proc. Appl. 13: 235-248 (the coalescent); G. A. Watterson (1975), Theor. Pop. Biol. 7: 256-276 (θ from segregating sites, E[S] = θ Σ 1/i); F. Tajima (1983), Genetics 105: 437-460 (Var[S] = θa + θ²b). Formulas only; no tables are copied.
  • Checked in the tests: the expectations against exact values for n = 10, and 20,000 simulated genealogies against them. Cross-checked once against msprime 1.4.5 (20,000 genealogies of n = 10, ploidy 1, binary infinite-sites mutations, θ = 5): two-sample Kolmogorov-Smirnov p-values 0.20 for the TMRCA, 0.31 for the total branch length and 0.99 for the number of segregating sites.
  • All settings and trees are simulated; no real data are used.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

Phylogenetic tree viewer #177 Open a Newick or NEXUS tree file and draw it as a rectangular or circular tree, with branch lengths and support values. Reroot it at the midpoint or on any branch, ladderize, swap branches and colour groups. Download SVG, Newick, tip distances (CSV) or a report. Nothing is uploaded. Pairwise sequence alignment #172 Align two DNA or protein sequences end to end (global), with free end gaps (semi-global) or by their best-matching stretch (local), with affine gap scores you can set. See the score, identity, similarity and gaps, the alignment in blocks, and a dot plot. Runs in your browser. VCF viewer and filter #173 Open a VCF or .vcf.gz file of any size and see variant types, Ti/Tv ratio, multi-allelic sites, FILTER and QUAL, allele frequencies, genotypes per sample and counts by chromosome. Filter by chromosome, region, QUAL, depth, PASS and type, then download the filtered VCF. Nothing is uploaded. Allele frequency calculator #312 Type or paste genotype counts (AA, AB, BB) for one or more populations. Get allele and genotype frequencies, expected Hardy-Weinberg counts, the chi-square test and the exact test, observed and expected heterozygosity, and F-statistics (FIS, FST, FIT) by Weir and Cockerham or Nei. Effective population size calculator #313 Estimate the effective population size Ne four ways: from the numbers of breeding males and females, from a population whose size changes over generations (harmonic mean), from the variance in family size, or from how much allele frequencies changed between two samples (Nei and Tajima's Fc with Waples's correction and confidence interval). 1D Schrödinger solver #923 Choose a textbook potential, type a formula or draw your own, and get the lowest energy levels and wavefunctions of the one-dimensional Schrödinger equation by the matrix (finite-difference) method, with the exact levels alongside for the box, harmonic oscillator, finite well, Morse, linear and Pöschl–Teller potentials.