Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Simulate and Date Local Genealogies

Use the forward population from the first notebook. Fit a local tree and its node ages from a short window, then allow the tree to change along a chromosome. The simulation’s recorded ancestry supplies the reference for each check.

Source

Observe the final DNA

The simulation starts at size 100. It goes through 20 generations at size 20 and expands to 1,000 over the next 40 generations. The full sample contains 64 diploid people and eight 10,000-base chromosomes. Each chromosome has a 0.2-Morgan map and the mutation rate is 2.5 × 10⁻⁵ per base per generation.

Use the first six people on chromosome 1. H1–H12 identify their paired haplotypes. The copying model uses sites that vary among the twelve copies. The mutation clock uses the full sequence span, including invariant sites.

sampled_haplotypes     variable_sites     analyzed_bases 
                12                276              10000 

Why polymorphic sites favor older genealogies

For a fixed rate, longer branches have a higher probability of carrying a mutation. That is why conditioning on variable sites favors older genealogies. For two copies with a shared ancestor tt generations ago, the probability of at least one mutation at one base is 1−exp⁡(−2μt)≈2μt1-\exp(-2\mu t)\approx 2\mu t when 2μt2\mu t is small. Under a neutral model, mutations shared by many copies tend to lie on deeper branches. Different trees can yield the same carrier count at different mutation ages. In humans, heterozygous sites can reflect mutations hundreds of thousands of years old (Pritchard, Sec. 2.2, note 164).

Start with four copies

Use H1–H4 from the same chromosome. Shared derived alleles constrain which copies descend from the same branch. Mutation counts also give information about how far back the branches meet.

Infer topology from shared alleles

Study chromosome 1, bases 1–250. This window has five variable sites. The data support the clade containing H1 and H3 and leave three compatible binary trees under a single-tree infinite-sites model.

$variable_sites
[1] 5

$supported_clades
$supported_clades[[1]]
[1] 1 3


$compatible_binary_trees
[1] 3

Plot with title “Supported branches”

Date ancestors with the mutation clock

Under a one-tree infinite-sites model, assign each derived pattern to its branch. Let MbM_b count mutations on branch bb over all L=250L=250 bases, including invariant sites. With the supplied mutation rate μ\mu,

Mb∣tb,μ,L∼Poisson⁡(μLtb),tb=parent age−child age.M_b\mid t_b,\mu,L\sim\operatorname{Poisson}(\mu L t_b), \qquad t_b=\text{parent age}-\text{child age}.

Sample ages are zero. On the supported tree, let aa be the age of the H1–H3 ancestor and ww the additional time to the root. Three mutations lie on the branch above the H1–H3 ancestor, and two lie on the H4 branch. The tree has total branch length 4a+3w4a+3w. Multiplying the five branch likelihoods gives

L(a,w)∝w3(a+w)2exp⁡{−μL(4a+3w)},a^=0,w^=53μL≈267.\mathcal L(a,w)\propto w^3(a+w)^2 \exp\{-\mu L(4a+3w)\}, \qquad \hat a=0,\quad \hat w=\frac{5}{3\mu L}\approx 267.

H1 and H3 have zero observed differences in this window. Their fitted ancestor age is on the boundary. Unsupported internal edges can have zero length in compatible binary refinements. The interval shows how much time can pass while still producing zero differences.

For any pair i,ji,j, Dij∣Tij∼Poisson⁡(2μLTij)D_{ij}\mid T_{ij}\sim\operatorname{Poisson}(2\mu L T_{ij}). The root age is max⁡i<jTij\max_{i<j}T_{ij}. Form six exact Poisson intervals, each at level 1−0.05/61-0.05/6. By the union bound, all six cover jointly with probability at least 0.95 under this model. Taking the maxima of the six lower endpoints and the six upper endpoints gives the root-age interval. Use the same rule for pairs within a smaller clade. Shared branches make pairwise counts dependent. The union bound still applies.

These are conditional intervals under the supplied mutation rate and one error-free infinite-sites tree across the window. Recombination or recurrent mutation in the forward DNA changes that model.

   clade estimate_min estimate_max same_height_across_best_fits    lower     upper recorded_age
     1,3       0.0000       0.0000                         TRUE  0.00000  438.4511           44
 1,2,3,4     266.6667     266.6667                         TRUE 82.52364 1153.4474          301
plot without title
Plot with title “Recorded ancestors, revealed”

Check the mutation likelihood conditionally

Hold the recorded midpoint tree fixed and simulate 200 independent infinite-sites mutation overlays with the same rate and 250-base length. This isolates the clock model from recombination and recurrent mutation; it is a conditional check, using ancestry already generated by the main population. Include uninformative and unresolved draws.

                replicates simultaneous_root_coverage 
                       200                          1 
Plot with title “Conditional mutation draws”

Simulate linked ancestry under the same size history

Use the same twelve-copy sample size, 10,000-base chromosome, 0.2-Morgan map and symmetric binary mutation rate. The Hudson simulation follows sampled ancestors backward under the same 60 recent generations of size history. It uses an ancestral size of 100 beyond them. The continuous clock and ancestral-equilibrium tail approximate the discrete forward simulation, which used 1,000 generations of burn-in at size 100.

For the coalescent run, draw the graph G\mathcal G under the specified size history Ne(t)N_e(t) and recombination rate rr. Then draw the sequences DD by putting mutations on the graph at rate μ\mu:

Pr⁡(G,D∣Ne(t),r,μ)=Pr⁡(G∣Ne(t),r)Pr⁡(D∣G,μ).\Pr(\mathcal G,D\mid N_e(t),r,\mu) =\Pr(\mathcal G\mid N_e(t),r)\Pr(D\mid\mathcal G,\mu).

With r=0r=0 the whole chromosome shares one tree. This run is a fresh coalescent draw. The earlier fits use the original forward DNA.

    sampled_copies     mutation_sites        local_trees recorded_intervals 
                12                252                149                193 

Optional: compare short windows

Keep the same four haplotypes and inspect chromosome 1 bases 1–1,000. Overlapping nonnested carrier groups cannot be clades of one tree under infinite sites. Find the fewest compatible blocks, keeping all equally minimal partitions. These are data constraints under that model; recurrent mutations can also create conflicts.

  quarter compatible_trees
1       1                3
2       2                3
3       3                1
4       4                1
$minimum_blocks
[1] 3

$minimal_partitions
[1] 22

plot without title
Plot with title “Quarter 4: 1 tree”

Compare fixed windows of the same chromosome

Fit bases 1–250 and 9,751–10,000 without consulting the ancestry. The red marks identify the recorded tree at each window midpoint. They do not imply that its genealogy is constant across all 250 bases. No breakpoint or root age was prescribed to generate this example.

plot without title
Plot with title “Bases 9751-10000”

Fit the whole chromosome

Return to H1–H12. Fit relationships first, then date the inferred nodes. A tree sequence stores each node once. Each edge identifies a parent, a child, and the interval over which they are connected. At one position, read the local tree from the edges whose intervals contain that position. If copy cc inherits [a,b)[a,b) from uu and [b,d)[b,d) from vv, one edge stores each interval. Read cc’s parent at bb from the second edge. This representation shares edges across adjacent trees (Kelleher et al., 2016).

Infer the local genealogies

Shared derived variants identify candidate ancestors. The source ancestor builder groups focal sites by their carrier patterns and derived frequencies, then extends each ancestor using consensus among those carriers.

Match older ancestors first with the Li–Stephens copying HMM. Then match the observed copies against the ancestral sequences. The hidden state is the copied ancestor. The fitted copying paths give parent–child edges over genomic intervals. Initial node times give an ordering of ancestors. The matcher probabilities control copying and mismatch.

          inferred_local_trees observed_alleles_reconstructed 
                            62                           3312 

Estimate ages from mutations

For an edge spanning ℓe\ell_e bases with child age tct_c and parent age tpt_p,

Me∣G,μ∼Poisson⁡{μℓe(tp−tc)}.M_e\mid\mathcal G,\mu\sim\operatorname{Poisson}\{\mu\ell_e(t_p-t_c)\}.

The inside–outside method combines edge likelihoods with conditional coalescent priors. A rootward pass uses descendant evidence; a leafward pass uses the rest of the inferred graph. The resulting grid gives each node’s age probabilities. Parent–child constraints give positive branch lengths.

Use the supplied mutation rate and the full panel’s diversity-based size summary, N^e=H^/(4μ)\widehat N_e=\widehat H/(4\mu). The full panel gives N^e≈73.2\widehat N_e\approx73.2, the same diversity estimate used in the Lecture 9 population-size notebook. The node-age probabilities condition on this value and the fitted topology.

The constant-size prior is a fitted approximation to this changing population. The main forward model allows recurrent mutations; the copying mismatch probability is an inference setting, distinct from the biological recombination rate.

prior_Ne_from_observed_diversity            dated_ancestral_nodes 
                        73.22944                         52.00000 
Plot with title “Ancestor of all sampled copies”
mean_age_change_with_finer_grid 
                      0.5939651 

The curves date the ancestor of H1 and H2 and the root of the twelve-copy tree along the chromosome. Red points show recorded ages at five fixed positions. The intervals condition on the fitted topology and on the mutation rate and constant-size prior used to date it.

Methods for local genealogies

  • ARGweaver samples graphs under a coalescent and mutation model. Its Markov chain Monte Carlo (MCMC) draws represent uncertainty in relationships and branch times. ARGweaver-D adds population splits and migrant paths.

  • tsinfer uses haplotype matching for topology. tsdate uses the mutation clock and a coalescent prior to date the inferred nodes.

  • Relate estimates local topologies and times at large sample sizes. SINGER samples approximate posterior genealogies to represent uncertainty in relationships and times.

Coalescence times carry information about past population sizes. A region with unusual branching times can motivate a test for selection. Both analyses inherit uncertainty in the local trees.

Compare model predictions for allele frequencies, LD, and sharing with observed summaries. Check sensitivity to phasing, the recombination map, genotype errors, and sample composition.

Sources: Rasmussen et al. (2014), Kelleher et al. (2019), Speidel et al. (2019), Hubisz et al. (2020), Wohns et al. (2022), and Deng et al. (2025).