Read Pritchard, Fig. 3.83. Mal’ta lived about 24,000 years ago. Its DNA records the recombination between admixture and sampling. Add the elapsed generations, expressed in years, to the sample’s age to date gene flow.
This notebook follows The Recombination Clock, Calibrating the Clock, and Timing and Duration of Gene Flow. Start from ancestry along one chromosome and then estimate a common date from markers in dated genomes.
library(hpgR)
options(repr.plot.width = 9, repr.plot.height = 3.8)
set.seed(1202)
generationYears <- 28
dateTruth <- 47100
durationTruth <- 6800
ages <- c(0, 24000, 35000, 41000)Cross a chromosome after a pulse¶
At distance Morgans, two positions share the previous ancestry draw with probability in this model. Otherwise the second position draws an ancestry label with the same source probability. Here the observed inputs are phased ancestry calls. One could instead estimate local ancestry using sequence data and reference panels.
coancestryCurves() uses Daniel Nachun’s deterministic all-pairs
coancestry calculation. In a stationary two-source model its expectation
is twice the covariance of one ancestry indicator. Compare the curve of
one chromosome with the mean across 22 independent chromosomes.
positionsCm <- seq(0, by = .02, length.out = 1400L)
sourceFraction <- .03
elapsed <- (dateTruth - ages[2]) / generationYears
ancestries <- lapply(1:22, function(chr) {
t(replicate(2L, sampleMosaic(positionsCm / 100,
c(1 - sourceFraction, sourceFraction), elapsed) - 1L))
})
curves <- lapply(ancestries, function(x) {
probabilities <- array(c(1L - x, x), c(dim(x), 2L))
coancestryCurves(probabilities, positionsCm, maxDistanceCm = .70, bins = 28L)
})
path <- ancestries[[1L]]
coancestry <- curves[[1L]]
pooled <- rowMeans(sapply(curves, "[[", "curve")) / 2oldPar <- par(mfrow = c(1, 2), mar = c(4, 4, 2, 1))
plot(positionsCm, path[1, ], type = "s", col = "#286787",
ylim = c(0, 1.1), yaxt = "n", xlab = "Position (cM)",
ylab = "", main = "One simulated chromosome")
axis(2, at = c(0, 1), labels = c("Other", "Introduced"), las = 1, cex.axis = .72)
generating <- sourceFraction * (1 - sourceFraction) *
ancestryDecay(coancestry$distance / 100, elapsed)
plot(coancestry$distance, coancestry$curve / 2, pch = 16, cex = .54, col = "#929292",
xlab = "Distance (cM)", ylab = "Ancestry covariance", main = "One chromosome and 22",
ylim = range(c(generating, pooled, coancestry$curve / 2)))
points(coancestry$distance, pooled, col = "#285687", pch = 16, cex = .65)
lines(coancestry$distance, generating, col = "#B22732", lwd = 2)
legend("topright", c("One chromosome", "22 chromosomes", "Generating expectation"),
col = c("#929292", "#285687", "#B22732"), pch = c(16, 16, NA),
lty = c(NA, NA, 1), lwd = 2, bty = "n", cex = .78, y.intersp = 2.1)
par(oldPar)
Generate informative markers on dated chromosomes¶
Follow the order of the Iasi study. For each dated panel, generate introduced ancestry tracts along 22 chromosomes and sample alleles at markers that distinguish the two ancestries. The probability of allele 1 is 0.85 in introduced tracts and 0.015 in background tracts. The estimate uses diploid allele fractions at these markers. It has no access to the generating ancestry of a chromosome.
A pulse with age generations gives an exponential tract length with mean Morgans. For extended gene flow, the ages of tracts at random bases follow a Gamma distribution. Older tracts begin more often per Morgan because they are shorter. The duration is four standard deviations of the pulse ages. Here a mean date of 47,100 years and duration of 6,800 years generate four samples per age group, sixteen diploids in all.
ages <- c(24000, 32000, 38000, 40000)
sourceFraction <- .03
chromosomes <- 1:22
step <- .00025
lags <- 1:75
distance <- step * lags
bounds <- c(43100, 52000)
seeds <- 12201:12204
panels <- array(NA_real_, c(length(lags), length(ages), length(chromosomes), length(seeds)))
for (rep in seq_along(seeds)) {
set.seed(seeds[rep])
for (j in seq_along(ages)) {
for (chr in chromosomes) {
position <- seq(0, 1 + chr / 88, by = step)
dna <- simulatePulseMarkers(position, 4L, sourceFraction,
(dateTruth - ages[j]) / generationYears, durationTruth / generationYears)
panels[, j, chr, rep] <- markerAncestryCovariance(dna$marker, lags)
}
}
}Fit the mean date and duration¶
A single pulse predicts decay at distance and elapsed time . The Gamma pulse averages the decay over tract ages. In the fit, each age group has its own amplitude and baseline. The date and duration are shared. The simulated overlap of tracts introduces a small correction to the decay curve at 3% ancestry.
Compare the answer from each independent set of sixteen genomes with the pooled answer from 64. To measure uncertainty for the pooled fit, delete the same chromosome from each sampled genome and refit.
model <- list(distance = distance, ages = ages, yearsPerGeneration = generationYears,
dateLimits = bounds, maximumDuration = 12000, coverageFraction = sourceFraction)
byPanel <- t(apply(panels, 4, function(x) {
fit <- do.call(fitAncestryDecay, c(model, list(covariance = apply(x, 1:2, mean))))
unlist(fit[c("date", "duration")])
}))
meanCovariance <- apply(panels, 1:2, mean)
pulse <- fitAncestryDecay(distance, meanCovariance, ages, generationYears, bounds,
coverageFraction = sourceFraction)
extended <- do.call(fitAncestryDecay, c(model, list(covariance = meanCovariance)))
leaveOut <- vapply(chromosomes, function(chr) {
covariance <- apply(panels[, , -chr, ], 1:2, mean)
fit <- do.call(fitAncestryDecay, c(model, list(covariance = covariance)))
unlist(fit[c("date", "duration")])
}, numeric(2L))
se <- sqrt(21 / 22 * rowSums((leaveOut - rowMeans(leaveOut))^2))
data.frame(sample = c("Generating", paste("16 genomes, panel", 1:4),
"64 genomes, single pulse", "64 genomes, extended"),
years = round(c(dateTruth, byPanel[, 1], pulse$date, extended$date)),
duration = round(c(durationTruth, byPanel[, 2], pulse$duration, extended$duration)))
round(se)oldPar <- par(mfrow = c(1, 2), mar = c(4.3, 4.6, 2.2, .9))
palette <- c("#285687", "#694E83", "#008270", "#AA691D")
matplot(100 * distance, meanCovariance, type = "p", pch = 16, cex = .46, col = palette,
xlab = "Genetic distance (cM)", ylab = "Marker covariance", main = "Dated chromosomes")
matlines(100 * distance, extended$predicted, col = palette, lty = 1, lwd = 1.65)
expected <- vapply(ages, function(age) {
shape <- ancestryDecay(distance, (dateTruth - age) / generationYears,
durationTruth / generationYears)
(.85 - .015)^2 * (1 - sourceFraction)^2 / 2 *
expm1(-log1p(-sourceFraction) * shape)
}, numeric(length(distance)))
matlines(100 * distance, expected, col = palette, lty = 3, lwd = 1.2)
legend("topright", legend = paste(ages / 1000, "kya"), col = palette, pch = 16, bty = "n",
y.intersp = 2.0, ncol = 2, cex = .83)
duration <- c(byPanel[, 2], extended$duration)
plot(1:5, duration / 1000, xlim = c(.75, 5.25), ylim = c(0, 12.5),
pch = c(rep(16, 4), 18), col = c(rep("#285687", 4), "#008270"),
xaxt = "n", xlab = "Independent panels and pooled analysis", ylab = "Duration (kyr)",
main = "Precision of pulse duration")
axis(1, 1:5, c(1:4, "Pooled"))
abline(h = durationTruth / 1000, col = "#B22732", lwd = 2)
arrows(5, max(0, extended$duration - 2 * se["duration"]) / 1000,
5, min(12000, extended$duration + 2 * se["duration"]) / 1000,
length = .055, code = 3, angle = 90, col = "#008270")
legend("bottomleft", "Generating duration", lty = 1, col = "#B22732", lwd = 2, bty = "n")
par(oldPar)
Exercise 1: What Do the Oldest Genomes Add?¶
The oldest group lived closest to the gene-flow event. Its ancestry tracts had fewer generations to break up. Predict whether removing that group will affect the precision of the mean date or of the duration more. Recompute the chromosome jackknife after dropping the 40,000-year cohort.
younger <- ages < max(ages)
reduced <- fitAncestryDecay(distance, meanCovariance[, younger], ages[younger],
generationYears, bounds, maximumDuration = 12000, coverageFraction = sourceFraction)
reducedLeaveOut <- vapply(chromosomes, function(chr) {
covariance <- apply(panels[, younger, -chr, ], 1:2, mean)
fit <- fitAncestryDecay(distance, covariance, ages[younger], generationYears, bounds,
maximumDuration = 12000, coverageFraction = sourceFraction)
unlist(fit[c("date", "duration")])
}, numeric(2L))
reducedSE <- sqrt(21 / 22 * rowSums((reducedLeaveOut - rowMeans(reducedLeaveOut))^2))
round(rbind(truth = c(dateTruth, durationTruth),
allAges = unlist(extended[c("date", "duration")]), allAgesSE = se,
youngerOnly = unlist(reduced[c("date", "duration")]), youngerOnlySE = reducedSE))The date largely follows the slope of the covariance decay. Duration follows its curvature, which can be weak over the observed distances. The dashed lines are the generating covariances before centering each chromosome. An estimate at the top of the plotted range has hit the 12,000 year search bound. Interpret the error bar as a chromosome jackknife summary.
The paper estimated ancestry from reads with admixfrog and accounted for uncertainty in ancient sample ages. Here the age groups and sample ages are given, and all sampled chromosomes have an informative marker grid.
Exercise 2: Date Admixture from Two Genomes¶
One ancient sample dates to 40,000 years before present. Its ancestry covariance gives 200 generations since admixture. A sample from 26,000 years ago gives 700 generations. Assuming one shared admixture date and a constant average generation time, estimate years per generation and years since admixture.
Let be the sample age, the fitted number of generations since admixture, and years per generation. Both samples satisfy , so .
sampleAges <- c(40000, 26000)
elapsedGenerations <- c(200, 700)
yearsPerGeneration <- (sampleAges[1] - sampleAges[2]) /
(elapsedGenerations[2] - elapsedGenerations[1])
admixtureDates <- sampleAges + yearsPerGeneration * elapsedGenerations
data.frame(sampleAgeYearsBP = sampleAges, elapsedGenerations = elapsedGenerations,
yearsPerGeneration = yearsPerGeneration, admixtureYearsBP = admixtureDates)Now consider the older sample. What happens to its covariance curve if some ancestry entered just five generations before the person lived?
The toy curves use in Morgans and the same covariance at distance zero. The recent contribution accounts for 20% of that covariance. It follows and adds a slower decay to the signal from the earlier admixture.
distanceCm <- seq(0, 1, length.out = 201)
distanceMorgan <- distanceCm / 100
earlierCovariance <- exp(-elapsedGenerations[1] * distanceMorgan)
recentWeight <- 0.20
mixedCovariance <- (1 - recentWeight) * earlierCovariance +
recentWeight * exp(-5 * distanceMorgan)
plotColors <- c("#1D4F91", "#B73723")
matplot(distanceCm, cbind(earlierCovariance, mixedCovariance),
type = "l", lty = 1, lwd = 2, col = plotColors,
xlab = "Genetic distance (cM)", ylab = "Normalized ancestry covariance")
legend("topright", c("Earlier admixture", "With recent contribution"),
col = plotColors, lty = 1, lwd = 2, bty = "n",
horiz = TRUE, cex = 0.85, inset = 0.02)
The two dated samples give 28 years per generation and a shared admixture date of 45,600 years ago. A recent contribution raises covariance at larger distances. A single exponential fitted to that curve can suggest a more recent admixture date for this individual.
- Iasi, L. N. M., Chintalapati, M., Skov, L., Mesa, A. B., Hajdinjak, M., Peter, B. M., & Moorjani, P. (2024). Neanderthal ancestry through time: Insights from genomes of ancient and present-day humans. Science, 386(6727). 10.1126/science.adq3010