Hitchhiking in space: Ancestry in adapting, spatially extended populations *

Selective sweeps reduce neutral genetic diversity. In sexual populations, this “hitchhiking” effect is thought to be limited to the local genomic region of the sweeping allele. While this is true in panmictic populations, we find that in spatially extended populations the combined effects of many unlinked sweeps can affect patterns of ancestry (and therefore neutral genetic diversity) across the whole genome. Even low rates of sweeps can be enough to skew the spatial locations of ancestors such that neutral mutations that occur in an individual living outside a small region in the center of the range have virtually no chance of fixing in the population. The fact that nearly all ancestry rapidly traces back to a small spatial region also means that relatedness between individuals falls off very slowly as a function of the spatial distance between them.

In large populations even a fairly low rate of selective sweeps is sufficient to reduce diversity across most of the genome via hitchhiking (Gillespie 2000;Weissman and Barton 2012). Most modeling of the effects of hitchhiking on diversity has considered well-mixed populations. However, the effects are potentially quite different in spatially extended populations with only shortrange dispersal, because instead of quickly fixing through logistic growth, sweeps must spread out in a spatial wave of advance over the whole range (Fisher 1937). Barton et al. (2013) recently showed that this increase in the time to sweep tends to reduce the size of the genomic region over which diversity is depressed by a sweep. While the effect of sweeps on genetic diversity at linked loci is therefore reduced by spatial structure, we show here that collective effect of sweeps on the diversity at unlinked loci can be much stronger than in panmictic populations. Surprisingly, this effect is dependent on the geometry of the range-it only appears for realistic range shapes with relatively well-defined central regions, not for the perfectly symmetric idealizations of ring-shaped and toroidal ranges often used in theoretical models. In particular, we find that probability of fixation of an allele can * This article corresponds to Hartfield, M. 2018. Digest: Effects of spatially-spreading adaptive mutations on genome-wide diversity. Evolution. https://doi.org/10.1111/evo.13462. be strongly position-dependent, with alleles near the center of the range orders of magnitude more likely to fix than those at typical locations. This is because all individuals trace most of their ancestry, even in the not-too-distant past, to individuals living in the center, which also causes far-away individuals to be much more closely related to each other than they would be in the absence of the unlinked sweeps, with relatedness falling off only as a power law of distance rather than exponentially.

Model
We wish to find the expected number of copies that an allele found in an individual at spatial position x will leave far in the future, that is its reproductive value (Barton and Etheridge 2011), which we denote φ(x). Equivalently, φ(x)ρ(x), where ρ is the population density, is the probability density of a present-day individual's ancestor being at location x at some time in the distant past. Maruyama (1970) showed that in the absence of selection, φ(x) ≡ 1 regardless of the details of the population structure, as long as dispersal does not change expected allele frequencies.
Here, we show that this result does not extend to populations undergoing selection. Populations living in perfectly symmetric ranges (circles in one dimension, tori in two) necessarily have φ(x) ≡ 1, but when this symmetry is broken, recurrent sweeps can make reproductive value strongly dependent on spatial position, Reproductive value of individuals at location x ψ(x) Identity-by-descent between individuals separated by x * In continuous space. In the corresponding model of discrete demes on a square lattice, ρ is the deme size, L is the radius in demes, and D is the rate of migration between each pair of neighboring demes.
with high φ in a small region in the center of the range and very small φ everywhere else.
We consider a population with uniform, constant density ρ distributed over a d-dimensional range with radius L, with uniform local dispersal with diffusion constant D, that is 2D is the mean squared displacement after unit time. We assume that selective sweeps with advantage s occur in the population at a rate per generation, originating at points uniformly distributed over time and space, and at loci uniformly distributed over the genome. As long as the density is sufficiently high (ρ (s/D) d/2 /s, Nagylaki (1978); Barton et al. (2013)), they will spread roughly deterministically in waves with speed c ≈ 2 √ Ds with characteristic wavefront width l ≈ √ D/s (Fisher 1937), which we take to be much smaller than the range size, l L. (However, even for fairly large densities, the stochastic corrections to c can be substantial; see eq. 18 in the Methods.) We assume that is low enough compared to the frequency of outcrossing, f , and the average number of crossovers per outcrossing, K , that the waves do not interfere with each other. For well-mixed populations, this means that f K and s f 2 /4 (Weissman and Barton 2012); we are currently preparing a manuscript in which we show that spatially extended populations have similar limits on , up to logarithmic factors. The definitions of symbols are collected in Table 1.

ONE AND TWO DIMENSIONS
We consider both one-dimensional ranges (lines with length 2L) and two-dimensional ranges. In two dimensions, the shape of the range will have some effect on many of our results; however, as long as the shape is fairly "nice," with a clear center and single characteristic length scale L, this effect will be modest. We will therefore ignore it for simplicity. For our purposes, the main difference between one and two dimensions will be in the density of individuals a distance x from the center, ρ(x). Since we are assuming a uniform spatial density, in one dimension this is just ρ, a constant. In two dimensions, however, we must account for the fact that there is more area at larger x, and thus ρ(x) ≈ 2πxρ. (Necessarily, ρ(x > L) = 0 in both one and two dimensions.)

Results
In spatially extended populations, genetic hitchhiking not only changes the frequency of neutral alleles, but also shifts their distribution in space. To see this, consider the ancestry of a lineage going backward in time, so that sweeps appear as receding waves. When one passes over the focal lineage, it "pulls" it back toward origin of the sweep at the same speed c as the wave. If there is no recombination, the lineage will necessarily be pulled all the way back to the origin (i.e., all present-day individuals necessarily descend from the original mutant at the swept locus), but if recombination is frequent, the lineage will be pulled only a short distance before recombining out of the wave and stopping (Fig. 1). If recombination occurs at rate r , then we expect that the lineage will remain in the wavefront for a time of O(1/r ) before recombining, and therefore be pulled a distance of ∼ c/r toward the origin of the sweep (Barton et al. 2013). We can also understand this forward in time: a sweep will pick up genetic material via recombination as it moves through the population and deposit it further away from the origin of the sweep (Barton 2000). For most positions in most realistic range shapes, sweeps tend to arrive (forward in time) from the direction of the center of the range, and so pull the ancestry back toward the center; the collective effect of many sweeps is then to concentrate the ancestry in the center (Fig. 2).
To make this description more quantitative, it will be convenient to classify sweeps based on their genetic map distance r to the focal locus. We will refer to sweeps at r s as tightly linked and those at r s as loosely linked. Barton et al. (2013) found that a tightly linked sweep pulls a lineage a distance that is approximately exponentially distributed with mean c/r , going backward in time, with an upper cutoff at the distance to the origin of the sweep. In this article, we calculate the effect of a loosely linked sweep and find that the lineage is only pulled an expected distance c/2r (see Methods). To calculate the net effect of hitchhiking on a locus over time, we need to integrate over all sweeps occurring across the genome at different recombination fractions r . The 1/r dependence for the expected pull suggests that this net effect should be dominated by some combination of a  few very tightly linked sweeps and the many very loosely linked sweeps (rather than the moderately linked sweeps with r ∼ s). This actually overstates the importance of tightly linked sweeps, since the 1/r dependence has an upper cutoff for r L/c, and understates the importance of loosely linked sweeps, since even if a sweep occurs very far away on the genome the recombination fraction cannot exceed f /2. Thus we expect that if the genome is sufficiently long (in a sense that will be made more precise below), the total average displacement of a typical locus will be dominated by loosely linked sweeps. We will begin by focusing on this case, making the further approximation that most sweeps are not just loosely linked but unlinked (r = f /2), as will be the case for even moderately long genomes, K 1. This case is also relevant for loci that are far from all loci undergoing selection, that is the ones whose evolution might be expected to depend only on demography. It also describes bacterial populations in which recombination primarily involves relatively short lengths of DNA, so that most pairs of loci in the genome recombine at roughly the same rate, as long as this recombination is still rapid relative to selection (the "quasisexual" case, Rosen et al. 2015).
"Unlinked" versus "in linkage equilibrium" Before describing our results, we will briefly describe how it is even possible for unlinked sweeps to affect a neutral locus. The key point is that even r = 1/2 is a finite rate of recombination that takes multiple generations to abolish linkage disequilibrium; qualitatively, there is nothing special that distinguishes r = 1/2 from lower rates of recombination. To see this, consider an admixed population consisting of equal numbers of individuals of haplotype ab and haplotype AB, with linkage disequilibrium LD = 0.25. If the loci are unlinked and there is obligatory random mating, in the next generation the population will consist of 37.5% each ab and AB and 12.5% each a B and Ab, that is there will still be substantial linkage disequilibrium, LD = 0.125. (Note the contrast here between recombination and segregation: if the population is diploid, while there will be linkage disequilibrium in the haplotypes, at each locus a single generation of random mating suffices to produce Hardy-Weinberg proportions.) Thus, if there is selection on the a locus, it will have some (typically weak) effect on the b locus, and the fact that the recombination rate is not infinite means that the effect is stronger than the same level of nonheritable variation in fitness (Robertson 1961;Santiago and Caballero 1995;Barton 2000;Weissman and Barton 2012).

THE PULL OF UNLINKED SWEEPS
For a lineage a distance x from the center, there is an excess of approximately ∼ x/L sweeps per generation pulling it back toward the center, each of which pulls it an expected distance c/ f . (Note that the effect of the upper cutoff on the displacement from these sweeps is negligible as long as L c/ f .) The expected distance from the center therefore decays exponentially (backward in time) like This implies that there is a characteristic concentration time t con beyond which ancestry is significantly altered by the collective effect of unlinked sweeps: This deterministic move back to the center is opposed by dispersal, and also by the effect of occasional tightly linked sweeps that pull the lineage a distance ∼ L, effectively randomizing its position. The balances between these forces means that the ancestry of the population is not completely concentrated at the center of the range, but is instead distributed around it in some region of size ∼ x c . Figure 3 shows this rapid concentration followed by a balance with dispersal and tightly linked sweeps.

BALANCE WITH DISPERSAL
If tightly linked sweeps are relatively rare, either because the overall rate of sweeps is low or because the focal locus lies in a region of the genome that is not undergoing much adaptation, the main balance will be between the diffusive effect of dispersal and the pull of unlinked sweeps. In this case, the position of the ancestry is an Ornstein-Uhlenbeck process, that is if we denote the position of the ancestral lineage t generations in the past by X t , it evolves backward in time as: where B t is a Brownian motion. By Fick's first law of diffusion, the diffusive flux of ancestry is −D∇φ(x). In the stationary state this must exactly cancel the deterministic pull of unlinked sweeps, so far in the past the distribution of ancestry is normal and concentrated in the center of the range according to: Equation (3) holds in both one and two spatial dimensions (although recall that in two dimensions we are ignoring corrections that depend on the exact shape of the range) and corresponds to a root mean square distance to the center of √ dx c . If x c L, then the reproductive value of an individual at the center of the range can be orders of magnitude higher than than one at a typical distance ∼ L/2 from the center (Fig. 4).
From equation (3), we see that the ancestral range will be substantially reduced by selection if the rate of sweeps per sexual generation is greater than the ratio of the cline width to the range size: / f > l/L. It is unclear what ranges these ratios take in natural populations. /( f K ) is unlikely to be much more than O(1) (Weissman and Barton 2012), but in organisms with many chromosomes (large K ), / f may be substantial. Looking at the right-hand side of the inequality, modeling sweeping alleles by waves spreading across the range necessarily requires l/L 1, so even small values of / f may be enough to distort the distribution of ancestry. Surprisingly little is known about typical values of l for the waves of advance of sweeping alleles in nature, but it seems plausible that for many species it should be much smaller than the total species range (Fisher 1937). For the spread of insecticide resistance in Culex pipiens in southern France, the width of the wave of advance was ∼ 20 km (Lenormand et al. 1999), much smaller than the global scale of the species range, but the dynamics were more complex than a simple selective sweep (Labbé et al. 2007). Much more is known about the width of stable clines and hybrid zones, which are frequently much smaller than species ranges (Barton and Hewitt, 1985). To the extent that the selection maintaining them is comparable in strength to the selection driving sweeps, these should have roughly the same width as the wavefronts.

BALANCE WITH TIGHTLY LINKED SWEEPS
Finding the balance between concentrating effect of unlinked sweeps and the randomizing effect of tightly linked sweeps is slightly trickier, and we do not know of an exact expression for φ(x). However, we can find an approximate expression by using the fact that the mean squared displacement of the ancestral lineage due to linked sweeps is dominated by rare very tightly linked sweeps rather than the many loosely linked ones (Barton et al. 2013). This suggests that for large x, the probability that an individual's ancestor was farther than x from the center at time t 0 in the distant past is roughly just the probability that a single very tightly linked sweep pulled it there at some time within ∼ t con generations of t 0 . Since the distance that a sweep at recombination fraction r pulls the lineage goes like 1/r , the rate of sweeps close enough on the genome to pull the ancestry a distance of at least x falls off like 1/x. Therefore, the probability of finding the ancestry at a distance of at least x should also fall off like 1/x; the probability density of being exactly at x, φ(x)ρ(x), should then fall off like 1/x 2 .
In the Methods, we calculate this more formally, and find: The factor 1 − (x/L) d (where d = 1 or 2 is the dimension of the habitat) reflects the fact that for very large x, x ∼ L, most sweeps start at distances less than x and cannot pull the lineage that far from the center. The cutoff x c = 2L/K is the typical distance that the lineage will have been pulled by the most tightly linked sweep in the past t con generations. For x x c , lineages will tend to experience many sweeps pulling them distances greater than x in time ∼ t con , so the approximation used to derive equation (4) breaks down; for these small values of x, multiple moderately linked sweeps pulling in different directions make contributions, smearing out the divergence in equation (4). Barton et al. (2013) describe the randomizing effect of tightly linked sweeps by "D eff ," an effective dispersal rate, with D eff ≈ 16L 3l K f D (their eq. 9). Comparing equations (3) and (4), however, we see that their effect cannot simply be described as an increase in the dispersal rate, since they create a much longer tail in the spatial distribution of ancestry. Because of this, it is possible that while the bulk of the distribution of ancestry is determined by a balance between unlinked sweeps and dispersal, with linked sweeps too rare to make a difference, linked sweeps make the dominant contribution to the tails of the ancestry distribution (Fig. 4, bottom). (3) and (4), we see that unlinked sweeps reduce the effective size of the ancestral range by a factor x c /L:

Combining equations
For typical numbers of chromosomes K , it would seem that ancestry could be concentrated by about an order of magnitude. However, the result 2/K was derived under the assumption that sweeps are distributed uniformly across the genome. If, on the other hand, adaptation is mostly occurring in just a few genes, the rest of the genome will not experience any tightly linked sweeps, and ordinary dispersal will be the only force counteracting the concentration, meaning that the effect could potentially be much stronger. This has the surprising implication that selection can have a stronger effect on some features of the spatial distribution of ancestry at far-away loci than at those nearby.

EFFECT ON DIVERSITY
While the effect of recurrent sweeps on neutral diversity can be quite large, detecting the effect in data from real populations may be tricky. It might seem to be indistinguishable from a range expansion in the absence of time-series data, but there is a simple way to tell them apart: under recurrent sweeps, there is no serial founder effect reducing diversity away from the center. One way to see this is by looking at isolation by distance. The probability ψ(x) that two individuals separated by a distance x are genetically identical can be written in terms of the neutral mutation rate μ and their coalescence time T as For x large compared to the size of a single deme (i.e., the spatial scale over which individuals interact within a generation) and loci far on the genome from any recent sweeps, there are two simple regimes for equation (6). If individuals are close together and μT 1, then we expect that the pull due to sweeps is too slow to cause lineages to coalescence before they mutate, and ψ(x) is just given by the neutral value, ψ(x) ∝ x (1−d)/2 e − √ μ/Dx (Barton et al. 2002), which says that the probability of identity falls off rapidly with distance. On the other hand, larger values of x are quickly collapsed by the pull of sweeps in time ∼ t con log(x/x c ), so we expect that ψ should be of the form ψ(x) ∝ x −2μtcon . A detailed calculation (see Methods) confirms that this is true for x x c √ 2 + 4μt con ; the results are also confirmed by simulations, as shown in Figure 5. The probability of identity thus has a long tail in distance -if μt con is small, individuals at opposite sides of the range (separated by ≈ 2L) are nearly as related as individuals separated by, say, L/2. Notice that ψ does not depend on from where in the range we sampled the pair of individuals. This implies that, while reproductive value is concentrated in the center of the range, genetic diversity is more evenly spread, distinguishing this scenario from a range expansion.
When x x c , we can approximately invert equation (6) to find the distribution of the coalescence time T for onedimensional ranges. In the Methods, we find that the lineages deterministically approach to within ∼ x c of each other in time ∼ t con log(x/x c ), after which they coalesce at roughly the same rate as they would in a neutral, well-mixed population of size ≈ 2 √ πρx c ≡ 1/λ. For comparison, in a purely neutral one-dimensional population with strong spatial structure (L Dρ), the long-term rate of coalescence is λ neut = π 2 D/(8L 2 ) (Maruyama 1971), so hitchhiking greatly increases the rate of coalescence: λ/λ neut ∼ (L/Dρ)(L/x c ) 1. We can also compare the rate of coalescence to that in a well-mixed population with the same pattern of adaptive substitutions. While Barton et al. (2013) showed that spatial structure reduces the coalescence caused by tightly linked sweeps, for loosely linked sweeps it can have the opposite effect. In well-mixed populations, unlinked sweeps only substantially increase the rate of coalescence when they become so frequent that they begin to interfere with each other ( ≈ f 2 /(4s), Weissman and Barton (2012)); for large ranges, coalescence will be increased (i.e., x c L) at much lower values of than this.
So far in our discussion of diversity, we have ignored loci that are close to recent sweeps. If we are considering large enough loci so that μt con 1, then usually only these recently swept regions will be identical between individuals from different parts of the range. In this case, because each sweep causes coalescence between individuals separated by a large distance x over a region of genome with length r ∝ 1/x (Barton et al. 2013), ψ should still have a long tail, but with an exponent that is independent of the population parameters, ψ ∝ 1/x (see Methods). This character-istic exponent is another effect of rare, tightly linked sweeps that cannot be accounted for by any effective dispersal rate D eff .

COMPARING ANALYSIS AND SIMULATIONS
The results shown in Figures 3 and 5 indicate that our analytical predictions are roughly right, but not completely -both figures show that we overestimate the total pull in simulations. We also directly tested our basic prediction for the average pull of sweeps, equation (1), and found similar results (Fig. 6, left panel; see eq. (23) in the Methods for why eq. (1) applies to the separation between pairs of lineages, as well as the position of a single lineage). A value of t con approximately 40% higher than predicted by equation (2) appears to give the best fit to the simulations. Plugging this value into equation (27) also gives a slightly better fit to the relatedness as a function of distance ψ(x) than the predicted t con does, but not by much, and the simulations lie between the two predictions ( Fig. 6, right panel). This difference between the simulation results for the short-term pull and the longterm relatedness may be because edge effects (visible for large separations in the left panel of Fig. 6) propagate into the bulk on longer time scales and slightly increase long-range homozygosity.
There are two likely sources for the discrepancy between the the analytical predictions and the simulations. First, our prediction that each sweep pulls ancestral lineages by a distance ≈ c/(2r ) assumes that the sweep itself is deterministic, and it is not clear how to accurately incorporate stochasticity; see Methods below. Second, while sweeps are rare enough in the simulations that interference among them is weak, it is not tiny. The rate of sweeps is reduced by approximately 15% from what it would be in the absence of interference, 0 = 4LρU b s, where U b is the beneficial mutation rate. (This correction is already incorporated into Figs. 3 and 5, which use the observed for the  predicted curves.) Conversely, the sweeps that do succeed tend to be slightly helped by the other sweeps and move faster than predicted. For the simulated parameters, the infinite-density limiting speed is c ∞ = 2 √ Ds ≈ 0.22 (measured in demes per generation), while incorporating finite-density effects in equation (18) gives c ≈ 0.13; the observed mean speed of sweeps in the simulations is in between, c obs ≈ 0.18. This change in speed is a sign that the underlying dynamics are somewhat different from the isolated-sweep dynamics we have assumed, and it is unclear what this means for their effect on neutral lineages. The 50% differences in the estimates of t con and c are not so important in and of themselves -just using our simple model to describe any natural population would introduce inaccuracies at least as largebut they are a sign that there is more to understand about hitchhiking in space, and it is possible that the factors that produce moderate errors in our simulations could produce large errors in other interesting regions of parameter space.

Discussion
Because selection and demography are often difficult or impossible to measure directly in natural populations, both are typically inferred from patterns of genetic diversity. This inference can be difficult, because the two processes can produce similar signals. For instance, both purifying selection and population expansion tend to produce site frequency spectra with a relative excess of rare alleles. To tease apart the two factors, demography is often first inferred using data from loci that are thought to be neutral, and then the answer is used to infer the pattern of selection at the remaining loci. However, in order for the demography to be inferred correctly, this method requires that the first set of loci be not just neutral, but also unaffected by selection at linked loci. Typically, this is done by using loci that are far from sites where selection is thought to have been important (e.g., Sattath et al. (2011)). Our results suggest that this may be problematic in spatially structured populations -even diversity at these loci may be strongly affected by unlinked sweeps. Instead, selection and demography should be inferred simultaneously.

GEOMETRY, NOT TOPOLOGY
Our results might seem to show that the genetic diversity in a population depends sensitively on the topology of the range and can therefore change drastically as the result of small perturbations to the environment. For example, a circular range (which by symmetry has no concentration of ancestry) can be transformed into a linear one (with very concentrated ancestry) by removing a single point. However, this is a misleading interpretation. In fact, a "circular" range is an annulus with radius large compared to its thickness (Fig. 7 A). A small perturbation that slightly reduces the population in one part of the range will only have a correspondingly small effect on the distribution of ancestry (Fig. 7 B), and the bias of the ancestry ancestry increases smoothly as the perturbation grows (Fig. 7 C), until the annulus is completely pinched off (Fig. 7 D). More generally, the common-sense intuition that the pattern of diversity should not depend on the details of the shape of the range is correct. All that matters is that, in at least some parts of the range, sweeps are more likely to come from some directions than others. If we consider the vector field defined by the net flow of sweeps, ancestry/reproductive value will tend to concentrate around critical points with positive divergence. (Technically, the distribution of ancestry will evolve according to a convection-diffusion equation.) For the simple range shapes with uniformly distributed sweeps that we have considered in this article, this occurs in the center of the range. If instead sweeps tended to originate from one end of the range (e.g., if they tend to be introgressed alleles from a hybrid zone), ancestry would concentrate there instead.

EXTENSIONS
We have focused on a very simple population model. Here, we consider several possible modifications. First, we have assumed that the density ρ is constant in time. If density fluctuations typically occur on timescales longer than t con , this approximation should be accurate, and if they are rapid compared to the sweep time L/c they should average out, but it is unclear how fluctuations on moderate timescales should interact with dynamics discussed here.
We have also neglected the possibility of rare long-range dispersal. Tightly linked sweeps already effectively produce occasional long-range jumps in the ancestry of neutral sites, so adding long-range dispersal might not have a large direct effect, but it can have dramatic effects on how sweeps spread (Hallatschek and Fisher 2014), and therefore a large indirect effect on the hitchhiking dynamics. It is not clear what this effect should be -on the one hand, the sweeps will spread faster, increasing their pull, but on the other hand, the direction of that pull may be less reliably toward the center.
We have also neglected the possibility that many sweeps may be "soft," starting from multiple alleles (Hermisson and Pennings 2005), which are likely to be particularly common in spatially extended populations (Ralph and Coop 2010). If these alleles typically descend from a recent single ancestor, that is are concentrated in a small region at the time when they begin to sweep, then the results should be essentially unchanged, with the possible exception of the coalescent effects of tightly linked sweeps. The same should be true if sweeps are "firm," that is multiple mutant lineages contribute to each sweep, but the most successful one typically colonizes most of the population. But sweeps in which many widely spread mutations contribute equally would likely not consistently concentrate ancestry in space.
We have focused on the effect of sweeps on neutral variation, but they will of course also affect selected alleles. Most obviously, if recombination is limited they will interfere with each other (Martens and Hallatschek 2011). They will interfere even more strongly with weakly selected variants. We will address these issues in a subsequent manuscript. Fig. 4, left panel in Fig. 3, and Fig. 5) were conducted using an individual-based Wright-Fisher model, so that every individual was replaced each generation. The population was subdivided into a line of 2L demes of ρ individuals each, with random dispersal between adjacent demes. Each new individual had two parents with probability f , and otherwise had just one parent. Each parent came from the new individual's deme with probability 1 − 2D and from a neighboring deme with probability D each. (For new individuals in the demes at the boundaries of the range, each parent came from the boundary deme with probability 1 − D, and from the neighboring deme with probability D.) Given the deme of origin, parents were drawn from the previous generation in that deme with probability proportional to their fitness (so selection was soft, occurring only within demes). Beneficial mutations were distributed as a Poisson process on the genome with rate U b , so that sweeps occurred at rate ≈ (2L)ρU b (2s). For the simulations shown in the blue histogram in Figure 4, in biparental reproduction crossovers were also a Poisson process, with rate K . For Figures 3 and 5, loci were taken to be unlinked, that is in biparental reproduction each locus was inherited independently.

Forward-time simulations (blue histogram in
To find the effects of sweeps on neutral ancestry and diversity, we used the approach of Weissman and Barton (2012), which draws on that of Kim and Stephan (2003). After allowing the simulated populations to reach a steady-state rate of adaptation, every individual in one generation was "painted" with a unique neutral marker allele at a locus in the middle of the genome, and then the simulation was continued until one allele fixed. The blue histogram in Figure 4 shows the deme of origin of these fixed alleles. The left panel of Figure 3 is based on the dynamics of the neutral alleles in the generations immediately following their introduction; as time goes on and diversity is lost, detailed dynamics can no longer be resolved. To calculate the homozygosity ψ(x) , we used integration by parts to rewrite equation (6) as P[T < t | x] is straightforward to evaluate in the simulations, since each allele marks a unique ancestor. Let f i y (t) be the frequency of the i th neutral allele in deme y t generations after the marking generation. Then averaging over all pairs of demes separated by x, we have: Plugging equation (8) into equation (7) and evaluating the integral (which becomes a sum, since the simulations used discrete generations) gives the curves plotted in Figure 5. Because these forward-time simulations were extremely computationally demanding, we also conducted approximate backward-time simulations to get better statistics and investigate rare events (right panel of Fig. 3 and gold histograms in Fig. 4). These simulations followed a lineage back in time at one neutral locus as it diffused through a continuous one-dimensional space. Sweeps were treated as instantaneous events arising uniformly at random in space and time, with no interference among them. Sweeps occurring at a recombination fraction r from the focal locus pulled each lineage an exponentially distributed distance with mean c/r or c/(2r ) (for r < s and r > s, respectively), truncated at the origin of the sweep. For the backward-time simulations in Figure 3 and all simulations in Figure 4, the focal locus was at the center of a linear genome with map length K Morgans with sweeps arising uniformly at random across the genome.

SWEEP
We would like to find the expected spatial displacement of a lineage caused by an loosely linked sweep, tracing backward in time. To do so, suppose that we sample an allele in a present-day individual in the middle of a very large one-dimensional range, and that a long time ago a selective sweep occurred at a locus a recombination fraction r away from the focal allele, starting a very long distance away from our sample. We wish to find the expected location of the ancestor of the sampled allele before the sweep began. Let p(x, τ) be the probability density for finding the ancestor at location x τ generations in the past, with x = 0 corresponding to the present location. We want to find: To find ∂ τ p, first define p i (x, τ) as the probability density that the ancestor was at location x and in genetic background i, where i = 0 is the ancestral genetic background, and i = 1 is the background with the allele that swept. (Note p = p 0 + p 1 .) If we define u(x, τ) ≡ u 1 (x, τ) and u 0 (x, τ) to be the frequencies of the sweeping allele and the background allele, respectively, with u 1 + u 0 = 1, p i satisfies the partial differential equation The first term on the right-hand side is the backward-time version of the decay in linkage disequilibrium due to recombination. The second term is backward diffusion; see Appendix A of Hallatschek and Nelson (2008). (Note that their equation (3) differs from our equation (10) because it includes an additional deterministic drift term due to their use of the co-moving frame of the sweep.) The piece containing ∂ x log u i accounts for the fact that the diffusion is biased toward the direction of increasing frequency of the focal genotype, because migrants of a given genotype are more likely to come from a location where that genotype is frequent than one where it is rare. Technically, in models with discrete generations, equation (10) only applies when the recombination rate per generation is small, but we will use it for unlinked loci anyway.
The equivalent of linkage disequilibrium in this system is ≡ u 0 p 1 − u 1 p 0 ; we expect it to be small for large r . Using to change variables back to p, equation (10) becomes Plugging equation (11) into equation (9), we have where we have used integration by parts and the fact that p(±∞, τ) = 0. It now remains to find an expression for . Equation (12) is quite complicated, but for large r we will have p and the dominant balance will be between the first and third terms on the right-hand side, giving where p neut is the value of p ignoring the perturbation caused by the sweep, that is p neut = 1 √ 4πDτ exp(− x 2 4Dτ ). (eq. 14 is the equivalent of quasi-linkage equilibrium in this system.) We can simplify this further by noting that u solves Fisher's equation: (Recall that τ is backward time.) Using this relation and substituting equation (14) into equation (13), we have We are interested in the effect of a long-past sweep. Let τ 0 be the time at which the wave of advance passed the point where we sampled the allele; we will take τ 0 to be extremely large. At time τ 0 , p neut has width ∼ √ Dτ 0 , so the wave crosses the region where the ancestor might have lived in a time ∼ √ Dτ 0 /c τ 0 , and the integral in equation (16) is dominated by times τ in the approximate range |τ − τ 0 | √ Dτ 0 /c. Since τ does not vary by much (proportionately) in this interval, p neut (x, τ) ≈ p neut (x, τ 0 ) is approximately constant in τ. Using this approximation in equation (16) yields Note that this result did not depend on the form of p neut , only that it was approximately constant in time; in particular, it also holds if the ancestry settles down to a stationary distribution, as in equation (3).

Effects of finite density on sweeps
In equation (15) above, we have assumed that sweeps spread as smooth, deterministic waves. In fact, for finite ρ, they will be stochastic, and this will tend to reduce their speed c (see, e.g., Brunet et al. (2006); Hallatschek and Korolev (2009); and the references in Barton et al. (2013)). We have not attempted a full stochastic derivation of equation (17); instead, we simply use the noise-adjusted speed for c. In one dimension, this is ( Barton et al. (2013), eq. 5): The speed c approaches 2 √ Ds as ρ √ Ds → ∞, but only very slowly, so the finite-density correction usually cannot be neglected. It is not obvious that substituting equation (18) into the final expression equation (17) gives the correct answer. For instance, we could alternatively substitute into the previous line where c first explicitly appears, but this would give the implausible result that the reduction in c causes an increase in the pull of sweeps. More simulations, or perhaps numerical solutions to equations (9) and (10) for given simulated sweep trajectories u(x, t), would help resolve the question. Direct simulations are somewhat challenging, because the predicted pull is typically small compared to the standard deviation in the lineage's position over the course of the sweep, so many iterations are needed for accurate estimates.
Other kinds of loosely linked sweep Above, we have assumed that the sweeping allele spread according to Fisher's equation, equation (15), which describes an allele with a constant selective advantage s. However, the allele may have a varying selective advantage if, for instance, dominance or frequency-dependent effects are important, or if there is environmental variation. More generally, the changing allele frequency is described by for some function f . Otherwise, the derivation of the expected displacement is the same as above, and we have Assuming that f is such that u(x, τ) is still a traveling wave moving at some speed c, we can change variables in the second integral to obtain: u, x, τ(x, u)). (21)

EFFECT OF TIGHTLY LINKED SWEEPS
We wish to calculate φ(x) for large x, including the effect of occasional tightly linked sweeps. It is easiest to consider L x dy ρ(y)φ(y), which we can think of as the probability that at some time t 0 in the distant past, the ancestor of a present-day individual was at a distance greater than x from the center. For large x, we expect that this is dominated by the probability that it was pulled there by a "recent" tightly linked sweep t generations "before" t 0 (i.e., t generations closer to the present), with t not too large. This sweep must have pulled the lineage out to a distance of at least xe t/tcon for it still to be at a distance of at least x t generations "later," and therefore the sweep must have originated a distance z > xe t/tcon from the center. Given that it did, the probability that it pulled the lineage out far enough is exp[− r c xe t/tcon ]. Putting this all together, and using that the density of sweeps per generation per unit map length per distance (or area in two dimensions) at distance z from the center and genetic map distance r from the focal locus is 2 /( f K L) (or 4 z/( f K L 2 ) in two dimensions), the expected number of sweeps that would have left the lineage more than x from the center at time t 0 is: Taking the derivative of both sides of equation (22) with respect to x gives the probability density, equation (4). Note that equation (22) approximates the probability that there is at least one tightly linked sweep by the expected number of such sweeps, so it is only valid when the right-hand side is small, x 2L/K . It also obviously typically breaks down as x approaches L and the particular geometry of the habitat begins to matter.

ISOLATION BY DISTANCE
We wish to find the probability ψ(x) that a pair of lineages a distance x apart will be identical at a neutral locus. Let us assume that the locus is far from any recent sweeps. (We relax this assumption below.) Then tracing the ancestry back in time, the separation X τ between them can be approximated by a Brownian motion, with diffusion constant 2D (since it combines the motion of both lineages), and with the lineages moving together at a mean velocity of ≈ − cX/ f L = −X/t con from (unlinked) sweeps that start in between them. In other words, we can approximate the motion by where B is a Brownian motion. We write Y to emphasize that this is not quite the same as the real path of the lineages X . In particular, unlike X , Y does not include coalescence. (In two dimensions, Y fails to approximate X even when the lineages are just very close together, but since most of the coalescence time will be spent at some distance away, it is still a useful approximation.) In addition, equation (23) ignores the fact that X cannot exceed the diameter of the range 2L, and so will only be valid for ranges sufficiently large that lineages are unlikely to bump into the boundaries. We would like to find an explicit form for equation (6). To do this, we can rewrite in terms of the behavior of Y . First, note that the rate of coalescence for the two lineages when they are in the same place is 1/ρ, and therefore the probability density of coalescence at time τ is ≈ δ(Yτ) ρ exp(− τ 0 dτ δ(Y τ ) ρ ), where δ is the Dirac delta. (The exponential factor accounts for the possibility that the two lineages have already coalesced.) Plugging this into equation (6) gives: We can use the Feynman-Kac formula (Pham 2009, p25) to rewrite equation (24) as an ordinary differential equation: where δ is the Dirac delta. Equation (25) breaks down for x → 0 in d = 2 dimensions; in this case, some kind of small-scale cutoff is needed, but this does not change the shape of ψ(x) at larger scales. In one dimension, to handle the x = 0 boundary, we need to understand what we mean by ψ and ψ at x = 0. The correct interpretation is that x is actually the signed distance between the lineages, that is we should remove the absolute value signs around X 0 and Y 0 in equation (24) (Barton et al. 2002). Thus ψ(x) = ψ(−x), lim x→0 − ψ (x) = − lim x→0 + ψ (x), and ψ has a discontinuity at x = 0, that is ψ has a singularity that must cancel with the last term in equation (25). This coalescent term can therefore be seen as just a boundary condition that sets the overall normalization of ψ. Explicitly, we have: The solution to equation (25) can be written exactly in terms of special functions. For d = 1 and x > 0, equation (25) is the Hermite equation, with solution: where H ν (z) is a Hermite function and D ν (z) is a parabolic cylinder function (Wolfram Research (2017) functions HermiteH and ParabolicCylinderD, respectively), and x c = √ Dt con . A is a normalization constant, fixed by equation (26) to be: A = 2 (2μt con ) (μt con ) + 4ρ √ D/t con (μt con + 1/2) , where is the gamma function.
We have not been able to find an exact closed-form expression for the inverse Laplace transform of equation (27) (i.e., the distribution of coalescence times) but the mean pairwise coalescent time τ 2 is: where γ ≈ 0.577 is the Euler-Mascheroni constant. Note that two randomly sampled individuals will typically be a distance ∼ L apart, so the mean pairwise coalescence time over the whole population can be roughly approximated by τ 2 (L). For large separations x x c √ 2 + 4μt con , equation (27) is approximately: Notice that ψ decays only as a power of distance. Up to the normalization constant, equation (30) is also valid in two dimensions. For μt con 1, equation (28) approaches A ≈ 1/(1 + 4 √ πμρx c ), and equation (30) approaches the Laplace transform of a simple convolution: first, a nearly deterministic concentration phase lasting t con log(x/x c ) generations, followed by an exponentially distributed phase with mean 2 √ πρx c , consistent with equation (29).
In other words, first the lineages are pulled to within ∼ x c of each other, and then undergo neutral coalescence within an effective range of radius ∼ x c .