Introduction

Active motility is a defining feature of many cell types, governing their ecology and physiological functions. Immune cells such as neutrophils patrol multicellular organisms in their relentless search for invading microbes. Sperm cells actively swim and search ovules to fuse with. Growth cones of neurons seek their synaptic targets. Active motility is also fundamental for many unicellular organisms ranging from bacteria to amoeba and algae. It allows them to find nutrients, light or a host, and avoid toxic compounds, predators or parasites. In particular, bacterial motility has been thoroughly studied once it became understood as key for the reproductive success of bacteria and, more specifically, for their ability to cause disease1,2,3,4,5,6,7. Despite these important realizations, we know little about how cell motility contributes to bacterial adaptation, namely to the evolution of antibiotic resistance, which is a major public health concern8.

Laboratory experiments suggest that bacterial motility is important for bacterial adaptation in antibiotic landscapes where cells can move through different concentrations of antibiotics9,10,11. In particular, it was found that in spatially heterogeneous environments, bacteria evolve antibiotic resistance faster than in homogeneous conditions9. However, cell motility was not controlled in these experiments, and its precise contribution to the evolutionary dynamics found is not known. Notably, other authors did not find an accelerated adaptation in their antibiotic landscapes and argued that the discrepancy likely derived from the ability of bacteria to experience the diverse antibiotic concentrations, which was different in their experiments10.

Arguably, the best understood link between cell motility and the ability of bacteria to cope with antibiotics comes from bacterial swarming, a form of group motility on surfaces where cells are particularly resilient to antibiotic stress12,13. More precisely, in swarming conditions, cell motility is thought to reduce exposure of individual cells to antibiotics, which leads to antibiotic tolerance14. While there are many studies relating bacterial swarming and phenotypic resistance12,14,15,16,17,18,19,20,21, the effect of swarming motility on the evolution of genetic resistance has not been explored. In addition to swarming, other links between bacterial motility and antibiotic landscapes have been reported. In particular, it has been shown that antibiotics trigger motile responses22,23,24. However, the impact of such bacterial behaviour on the evolution of antibiotic resistance was not addressed. In short, one can find works that study bacterial evolution in antibiotic landscapes, but these do not explore the role of cell motility explicitly; and one can find works that study bacterial motility upon antibiotic exposure, but these do not explore evolutionary timescales.

In addition to these experimental works, several mathematical models have been developed to understand how concentration gradients of antibiotics and other drugs affect resistance evolution25,26,27,28,29,30,31, and a key conclusion is that antibiotic gradients accelerate the evolution of antibiotic resistance25,26. These quantitative models consider bacterial movement between environments with different antibiotic concentrations, such as different organs or parts of the human body, but the migration considered is essentially a passive and rare event. This assumption is in sharp contrast with the migration rates of bacteria evolving in natural and experimental settings, where cells can move at speeds up to ~ 50 μm/s, and the fact that in these environments bacteria can experience steep and stable gradients of antibiotics and other drugs9,10,11,22.

In this work, we build upon these quantitative models and study how bacterial motility affects the evolution of antibiotic resistance in spatially heterogeneous environments with different concentrations of antibiotics. We find that bacterial motility can govern the spatiotemporal dynamics of antibiotic resistance evolution.

Results

Model overview and basic dynamics

We are interested to understand how bacterial motility shapes the evolution of resistance in heterogeneous environments where cells experience spatial gradients of antibiotics. We build upon the so-called staircase model25, which was developed to understand bacterial evolution in drug gradients. The staircase model is a lattice model, which considers cells of specified genotype g ϵ {1, …, L} (of increasing resistance) and spatial compartments x {1, …, L} (of increasing antibiotic concentration), Fig. 1a. An initial population of susceptible cells g = 1 at position x = 1 evolves via stochastic processes of death (rate δ), movement to a neighbouring spatial compartment (rate ν), mutation (rates μf/μb for forward/backward), or division (maximal rate r)25. In this model, antibiotics inhibit the growth of susceptible genotypes g < x. Therefore, the diagonal of position-genotype lattice in Fig. 1a defines a staircase which separates areas where cells can divide (above the staircase, white) from areas where they cannot (below the staircase, grey). Moreover, the division rate of the Nx cells at position x is logistic with a carrying capacity K:

$$\left\{\begin{array}{ll}r(1-{N}_{x}/K),\quad &{{{{{{{\rm{if}}}}}}}}\, x\le g \,{{{{{{{\rm{ and }}}}}}}}\, {N}_{x}\le K,\\ 0,\hfill &{{{{{{{\rm{otherwise}}}}}}}}.\hfill\end{array}\right.$$
(1)
Fig. 1: Model overview and basic evolutionary dynamics.
figure 1

a Model description. In the staircase model, bacterial cells (blue and red dots) have a specified position x (of increasing antibiotic concentration) and a genotype g (of increasing resistance). The population adapts to a stable spatial antibiotic gradient as cells migrate, mutate, die and divide at specified stochastic rates. Antibiotics prevent cell division of susceptible genotypes g < x (shaded region under the staircase). b Adaptation process. Bacterial adaptation in the staircase model can be conceptualised as a series of random jumps between locally stable resistance states R that happen at an adaptation rate aR. At a given time, R denotes the genotype of highest resistance in the population, as well as the highest spatial compartment where this genotype can divide. Genotypes g ≤ R are defined as wild-type (blue dots) and genotype g = R + 1 as mutant (red dots). Importantly, in the overlap region x = R + 1, mutant cells can divide but wild-type cells cannot. c Snapshots of the population evolving antibiotic resistance for different motility rates, ν = 0.01/h (low motility) and 1/h (high motility). Shades of grey represent density of cells, where black represents highest density. The adaptive dynamics of bacteria with low (top) and high (bottom) motility is qualitatively different. d Population profiles and fitness along the antibiotic gradient. Different motility regimes affect the distribution of wild-type bacteria along the gradient (blue area), which shapes the fitness of resistant mutants (red bars). Parameters: L = 8, K = 105, r = 1/h, δ = 0.1/h, μb = 10−4/h, μf = 10−7/h.

The processes of birth, death, mutation and migration drive bacterial adaptation up the antibiotic gradient. Assuming low mutation rates (μfδ, ν, r) and a large carrying capacity (K 1)25,26, this adaptation corresponds to random jumps R → R + 1 between relatively stable population states R {1, …, L}, which we define as resistance states (Fig. 1b). We note, however, that R can be understood as both the genotype g of highest resistance in the population and the compartment of highest antibiotic concentration x where this genotype can divide because the genotypic and spatial dimensions are interchangeable in this model. Genotypes g ≤ R are defined as wild-type and genotype g = R + 1 as mutant. Resistance R increases to R + 1 when mutants outcompete the wild-type in the overlap region at a position x = R + 1. The overlap region is the region where the population first adapts because it is the only spatial compartment where the regions where mutant cells can grow and regions where wild-type cells cannot grow overlap (Fig. 1b).

We start by studying how different motility rates ν affect the evolutionary dynamics of bacteria in this model as previous work25,26 only considers situations where bacteria are unlikely to move between different antibiotic concentrations during their lifetime (ν < δ). In particular, we start by describing and comparing bacterial adaptation when cells rarely move during their lifespan (ν < δ) and situations where motility is common (ν > δ). Unexpectedly, our simulations show that bacterial adaptation is qualitatively different for low and high motility (Fig. 1c, Supplementary Movie 1). To understand this difference, we first study the qualitative properties of the stable population at a fixed resistance state R and, in the next section, we focus on the adaptation rate aR at which the jump in resistance R → R + 1 occurs (Fig. 1b).

Notably, we find that the low and high motility regimes differ in the shape of the wild-type population Nx (SI Theorem 1), which impacts the mutant fitness landscape (Fig. 1d) that is defined by the net growth rate of mutant cells:

$$\left\{\begin{array}{ll}r(1-{N}_{x}/K)-\delta,\quad &{{{{{{{\rm{if}}}}}}}}\, x\le R \,+\, 1,\\ -\delta,\hfill &{{{{{{{\rm{otherwise}}}}}}}}.\end{array}\right.$$
(2)

Moreover, we find that at low motility (ν < δ, Supplementary Movie 1), bacterial adaptation is limited by the movement of the first mutant into the overlap region, where mutant cells have low competition from wild-type cells and high fitness to set up a mutant population (Fig. 1d). In this case, bacterial adaptation is located at the population front (SI Theorem 3), while the rest of the population forms a typical inclined comet tail (Fig. 1c) corresponding to a diversity of strains with different antibiotic susceptibility (Fig. 1d). At high motility (ν > δ, Supplementary Movie 1), the wild-type is maintained even in regions where it cannot grow by influx from compartments where it can (SI Theorem 3), and, therefore, competes with mutants by contributing to the carrying capacity. The fitness of mutants is decreased in the overlap region and leveled across the region where mutants can divide (Fig. 1d). Therefore, mutant cells grow slowly and outcompete the wild-type everywhere. In these conditions, the population is made of a single strain that can grow in x ≤ R (Fig. 1d) and the comet tail is now horizontal (Fig. 1c).

Cell motility accelerates and decelerates bacterial adaptive evolution

We have shown that bacterial adaptation in antibiotic gradients is qualitatively different at low and high motility regimes. To gain quantitative understanding about this difference, we now study how motility affects the adaptation rate aR (Figs. 1b, 2a), which is defined by two waiting times:

  1. 1.

    The evolutionary time \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\), defined as the earliest time when the wild-type produces a first mutant in the overlap region (i.e., mutants reach a founder state in Fig. 2a).

    Fig. 2: Motility can accelerate and decelerate the rate of bacterial adaptation to antibiotics.
    figure 2

    a Definitions. The adaptation process in the staircase model corresponds to jumps between resistance states R → R + 1 that happen at rate aR. The resistance states R are characterised by founder states (a first mutant appears in the overlap region) and winner states (mutants outgrow wild-type cells in the overlap region), which are separated by evolutionary \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\) and ecological \({T}_{{{{{{{{\rm{eco}}}}}}}}}^{R}\) waiting times. Following Hermsen et al.26, we define the adaptation rate aR as the rate at which consecutive founder states appear, but we also consider an alternative definition based on the winner states and show it does not affect our conclusions (Supplementary Fig. 1). The evolutionary dynamics depends on the average wild-type fitness that is defined as \(\overline{f}=rR/L-\delta\) with r being the birth rate, δ death rate, and R/L the proportion of space where wild-type cells can divide. b Adaptation rate as a function of motility rate. The lines represent analytical prediction and the symbols represent averages over 50 simulations, with errors smaller than the symbols. The adaptation rate increases with motility in the low motility regime, but decreases in the high motility regime, i.e., motility accelerates adaptation in the low motility regime, but decelerates adaptation in the high motility regime. If the wild-type has a negative average fitness and motility above a critical motility νc, it cannot survive and adapt (deadly motility regime). The current resistance state R does not affect the adaptation rate when motility is low, but decreases the adaptation rate when motility is high. We plot the predicted dynamics from the analytical theory of Hermsen et al.26 (dashed line), which matches our results for lower motility only, but note that this theory was developed under the assumption of low motility rates and the interpolation for higher motility shown for completeness is not valid. c Relative importance of evolutionary and ecological times. At low motility, bacterial adaptation is largely dependent on the evolutionary time \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\). At high motility, however, the ecological time \({T}_{{{{{{{{\rm{eco}}}}}}}}}^{R}\) becomes equally important due to increased competition between strains. Near critical motility νc, bacterial adaptation is again mainly limited by the evolutionary time \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\). At high motility, the number of compartments where the wild-type can divide R increases the ecological time \({T}_{{{{{{{{\rm{eco}}}}}}}}}^{R}\) and decreases the evolutionary time \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\). d The importance of wild-type profiles. At low motility regimes, motility promotes the movement of mutants from the population front into the overlap region (\({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\) reduced), where mutants have larger fitness than the wild-type and grow quickly (\({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\gg {T}_{{{{{{{{\rm{eco}}}}}}}}}^{{R}^{{\prime} }}\)). At high motility regimes, motility promotes the spatial spread of the wild-type population with genotypes g ≤ R, so that the first mutant is produced quickly but mutant fitness is decreased due to higher competition for space with the wild-type (\({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R} < {T}_{{{{{{{{\rm{eco}}}}}}}}}^{{R}^{{\prime} }}\)). Parameters: L = 8, K = 105, r = 1/h, δ = 0.1/h for source-like environment, δ = 0.3/h for sink-like environment, μb = 10−4/h, μf = 10−7/h.

  2. 2.

    The ecological time \({T}_{{{{{{{{\rm{eco}}}}}}}}}^{R}\), defined as the earliest time when the first mutant establishes a mutant population that becomes larger than the wild-type in the overlap region (i.e., mutants reach a winner state in Fig. 2a).

We follow Hermsen et al.26 and define adaptation rate as the rate at which mutants reach consecutive founder states in Fig. 2a:

$${a}_{R}=\frac{1}{{\mathbb{E}}{T}_{{{{{{{{\rm{eco}}}}}}}}}^{R-1}+{\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}},$$
(3)

where \({\mathbb{E}}\) denotes the expected value of the random waiting times. To determine the adaptation rates, we record the times of founder states in computer simulations (Fig. 2b and Methods), and compute the waiting times by a combination of analytical and numerical techniques that confirm and extend our simulations (Fig. 2b, 2c and Methods). Alternatively, one can define adaptation rate considering consecutive winner states instead of founder states (Supplementary Fig. 1a, b). However, as we note below, this alternative definition of adaptation rate does not affect our conclusions.

How does the adaptation rate aR vary in the two motility regimes we identified earlier? Our simulations show that in the low motility regime (ν < δ), increasing motility accelerates the adaptation rate of bacteria (Fig. 2b, Supplementary Fig. 1c), in accordance with previous theory25,26. Our analysis shows that in these conditions, the evolutionary time is much larger than the ecological time (Fig. 2c), because mutants have high fitness in the overlap region and can grow quickly (Fig. 2d). For this reason, Hermsen et al.26 that considered low motility only, neglected the ecological time (\({T}_{{{{{{{{\rm{eco}}}}}}}}}^{R}\approx 0\), Fig. 2a). Moreover, Hermsen et al.26 noticed that the rate at which the population front advances becomes constant (i.e., it is independent of R) and implicitly identified all evolutionary times \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}={T}_{{{{{{{{\rm{evo}}}}}}}}}\). Our work supports this claim: the adaptation rate aR is identical for all R when motility is low (Fig. 2b) and the shape of the population front is independent of R (Fig. 1d, SI Theorem 3). Under these conditions, motility helps the first mutant to move from the population front into the overlap region and decreases the dominant waiting time, the evolutionary time Tevo. Therefore, in the low motility regime, there is a positive relationship between cell motility and bacterial adaptation (i.e., cell motility accelerates bacterial adaptation within this regime).

In contrast, at high motility (ν > δ), there is a negative correlation between cell motility and bacterial adaptation (i.e., cell motility decelerates bacterial adaptation within this regime), see Fig. 2b, Supplementary Fig. 1c. In this regime, the ecological time becomes larger than the evolutionary time (Fig. 2c) because mutant fitness is significantly decreased, which results from the increased competition for space with a large wild-type population in the overlap region. This competition is amplified with increasing motility ν and resistance state R, which promote the spread and size of the population (Fig. 2c).

The reduction in adaptation rate with higher motility becomes even more important if the wild-type has negative spatially-averaged fitness, which is defined as \(\overline{f}=rR/L-\delta\) with r being the birth rate, δ death rate, and R/L the proportion of space where wild-type cells can divide. By definition, environments with this property, \(\overline{f} < \, 0\), cannot sustain the wild-type if the system is spatially homogeneous, and we call them sink-like (as opposed to source-like with \(\overline{f} > \, 0\)). This terminology is inspired by the source-sink theory, which defines a source (resp. sink) as an environment with positive (resp. negative) local fitness32, as opposed to the average fitness in our model that considers fitness across all compartments. Notably, we find that cell motility creates sufficient mixing in sink-like environments above a critical motility threshold (ν > νc), and that in these conditions the wild-type cannot survive and adapt (Fig. 2b, SI Theorem 1, SI Theorem 4, SI Corollary 1). Therefore, we call it a deadly motility regime. We note that the deadly motility regime would not occur if resistant cells were present in the population from the beginning, which would increase the average wild-type fitness from \(\overline{f} < \, 0\) to \(\overline{f} > \, 0\) due to higher R. In the latter case, the same environment would become source-like, with survival and adaptation possible for any motility (dashed lines in Fig. 2b). We further note that the existence of the deadly motility regime requires the system to be closed, with no external import of wild-type cells.

In summary, our analysis identifies three distinct regimes of bacterial adaptation in antibiotic gradients that depend on the motility rate of cells, which we call low motility, high motility and deadly motility regimes (Fig. 2b). Notably, we find the same regimes when an alternative definition of adaptation rate is considered (Supplementary Fig. 1c), when antibiotic resistance carries fitness costs (Supplementary Fig. 2, Supplementary Note 4), when mutation rates are high (Supplementary Fig. 3, Supplementary Note 4), when non-growing cells compete with growing cells at a reduced rate (Supplementary Fig. 4, Supplementary Note 4), and when instead of bacteriostatic antibiotics we consider bactericidal antibiotics (Supplementary Fig. 5, Supplementary Note 4). Unexpectedly, we find the same regimes even when cell motility is biased (Supplementary Fig. 6, Supplementary Note 4, Supplementary Movie 2). It has recently been shown that antibiotics can trigger both positive22 and negative24 chemotaxis in bacterial cells, but our results show that such biased motility does affect our key findings (Supplementary Fig. 6). Overall, these different scenarios highlight the robustness of our conclusions.

Evolutionary dynamics of phenotypically heterogeneous populations

So far, we have considered evolving populations that are phenotypically homogenous and bacterial cells that always move at the same rate. The same simplifying assumption has been made in previous models of bacterial evolution in antibiotic gradients25,26,27,28,29,30,31. However, in reality, bacteria can change their motility rate, and their communities are phenotypically heterogeneous in terms of cell motility. For example, one of the most important transitions in a bacterial life-cycle, from free-living (plankton) to surface-attached communities (biofilms), is associated with major changes in cell motility. Planktonic bacteria can move at 45 μm/s2, while biofilm bacteria can move at 1 μm/min or less33. The plankton-biofilm switch can occur both stochastically34 or as a response to multiple factors, such as cell density35 or the presence of other strains36. Another well-known transition in bacterial populations that is associated with changes in cell movement is the swarming phenotype, where bacteria move collectively on semi-solid surfaces when a threshold of cell density is reached37. We found it important to understand if this phenotypic heterogeneity could affect the evolutionary dynamics we presented earlier.

To address this issue, we now consider populations harbouring two motility phenotypes where cells can switch between phenotypes either stochastically (Fig. 3) or as a response to local cell density (Fig. 4). In practice, for stochastic switching, we add a new dimension of motility phenotypes to our position-genotype lattice and allow cells to switch between phenotypes at a stochastic rate s, where each phenotype is characterized by different motility rates, ν1 and ν2 (Fig. 3a). Density-dependent motility ν(Nx) is modelled differently, and the switch between motility phenotypes is modelled by a step-function that is controlled by the local number of cells Nx and a switching density threshold S (Fig. 4a). If cell density Nx at position x is below (resp. above) the switching threshold S, all cells at position x move at low-density (resp. high-density) motility νL (resp. νH). Density-dependent motility can also be modelled explicitly (Supplementary Note 6), and we note below that it does not affect our conclusions.

Fig. 3: Effect of switching between motility phenotypes stochastically.
figure 3

a Model description. Phenotypes of motility ν1,2 are added as an extra dimension to the staircase model, with individual cells allowed to switch between these phenotypes at rate s. b Adaptation rate heatmap on the (ν1, ν2) plane for different switching rates s. The (ν1, ν2) plane can be partitioned into different combinations of adaptation regimes and its diagonal corresponds to a population of a single motility. In this model, bacteria adapt as if all cells had the same effective motility, which corresponds to the intersection of the level sets (white dashed lines) with the diagonal. At low switching rate (s = 0/h), the effective motility matches the slower motility present in the population \(\min ({\nu }_{1},{\nu }_{2})\). At high switching rate (s = 5/h), the effective motility matches the average motility (ν1 + ν2)/2. When the environment is sink-like, a deadly motility regime (grey) exists in the high motility combination, and also appears in the mixed motility combination when the switching rate is high. c Wild-type profiles for different switching rates s. At low switching rate (s = 10−3/h), the wild-type profile is dominated by the slower phenotype. At high switching rate (s = 5/h), the wild-type profile coincides with the profile of a single average-motility phenotype. Therefore, the adaptation in low (resp. high) motility combinations follows the low (resp. high) motility regime irrespective of switching rate s, but a change of s in the mixed motility combination can change the adaptation regime. In short, stochastic motility switching shapes the evolution of antibiotic resistance by determining the effective motility of bacterial populations. Parameters: L = 8, K = 105, r = 1/h, δ = 0.3/h, μb = 10−4/h, μf = 10−7/h.

Fig. 4: Effect of density-dependent motility.
figure 4

a Model description. In this model, bacterial motility ν(Nx) depends on the local number of cells Nx. If the cell density Nx at position x is below (resp. above) the switching threshold S, all cells at position x move at low-density (resp. high-density) motility νL (νH). b Adaptation rate heatmap on the (νL, νH) plane for different switching thresholds S. The (νL, νH) plane can be partitioned into different combinations of adaptation regimes and its diagonal corresponds to a population of a single motility. The diagonal separates slow-to-fast and fast-to-slow switching combinations. Bacteria generically adapt as if all cells had the same effective motility, which corresponds to the intersection of the level sets (white dashed lines) with the diagonal. This effective motility generically matches the low-density (resp. high-density) motility at high (resp. low) threshold S = 9.5 × 104 (resp. S = 100). At low threshold S, this generic rule has three exceptions. First, the adaptation rate is reduced in the mixed motility combination of fast-to-slow switching. Second, the adaptation rate is reduced for slow-to-fast switching when the environment is sink-like and the high-density motility phenotype moves above the critical motility. Third, a deadly motility regime (grey) can only occur if the initial population is of low density and the low-density motility phenotype moves above the critical motility. c Wild-type profiles in the mixed motility combination. Wild-type profiles match the low-density motility phenotype at high threshold S = 9.5 × 104. At low threshold S = 104.5, the low-density motility phenotype appears only at the front while the bulk of the population is in the high-density motility phenotype. This composition of phenotypes can reduce the antibiotic exposure of the bacterial population: in slow-to-fast switching, the spatial expansion of the fast (yellow) high-density motility phenotype is reduced in sink-like environments, and in fast-to-slow switching, a very slow (blue) and stable population occupies low antibiotic concentrations. In short, density-dependent motility shapes bacterial adaptation by determining the effective motility of bacterial populations and affecting their antibiotic exposure. Parameters: L = 8, K = 105, r = 1/h, δ = 0.3/h, μb = 10−4/h, μf = 10−7/h.

Interestingly, we find that in both models, phenotypically heterogeneous populations of bacteria generically behave as if all cells had a single effective motility phenotype whose motility is controlled by the switching rate s in stochastic switching, or the switching threshold S if switching is density-dependent. Therefore, the previously described adaptation regimes exist in these models and are governed by an effective motility that we characterize next. For stochastic switching, the effective motility matches the motility of the slower phenotype \({\nu }_{-}=\min ({\nu }_{1},{\nu }_{2})\) when the switching rate is low (sδ, Supplementary Movie 3) and it matches the average motility ν+ = (ν1 + ν2)/2 when the switching rate is high (sδ, Supplementary Movie 3), see Fig. 3b and SI Theorems 6, 7, 8 and SI Corollary 2, 3. This result stems from the fact that the slower phenotype is naturally selected for in the absence of phenotypic switching, given that the slower phenotype spends more time in regions of low antibiotic concentration where it can proliferate, and from the fact that large stochastic switching quickly equilibrates the abundance of both phenotypes (Fig. 3c). For density-dependent motility, the effective motility matches the low-density motility phenotype ν = νL at high switching threshold (S > K(1 − δ/r)) and the high-density motility phenotype ν+ = νH at low switching thresholds (S < K(1 − δ/r)), Fig. 4b. This result stems from the fact that the population cannot reach sufficient density for the high-density motility phenotype when the threshold is high, while a lower threshold switches the population bulk into the high-density motility phenotype.

Accordingly, if the population harbours phenotypic heterogeneity of the same motility regime, the adaptation regime corresponding to the effective motility is not changed by the stochastic rate s and the density threshold S. However, for populations that harbour motility phenotypes from different motility regimes (mixed motility in Figs. 3b and 4b), the level of switching shapes the adaptation regime of bacteria (Figs. 3 and 4c). For stochastic switching, such heterogeneous populations have an effective motility in the low motility regime at low switching (ν < δ) and in the high (resp. deadly) motility regime at high switching (ν+ > δ, resp. ν+ > νc). Put differently, a gradual increase in switching rate changes the adaptation regime between the low, high and deadly motility regimes (Fig. 3c, Supplementary Fig. 7a, SI Theorems 6, 8). Similarly to phenotypically homogeneous populations, the deadly motility regime can only occur if the average wild-type fitness is negative (sink-like environment, Fig. 3b, Supplementary Fig. 7c, SI Theorem 8, SI Corollary 3).

For highly heterogenous populations with density-dependent motility, the gradual change in switching threshold S also dictates the effective motility and the corresponding adaptation regime, but there are three exceptions when the density threshold S is low (Fig. 4b). First, when cells switch from fast to slow above the threshold S, the population becomes very stable as the fast cells at the front quickly return to the slow population bulk (Fig. 4c). As a result, the population has decreased antibiotic exposure and adaptation rate (Fig. 4b). Second, a deadly motility regime occurs if the low-density motility (not the effective motility) is above the critical motility (Fig. 4b). Third, if the high-density motility is above the critical motility, the population does not go extinct but instead decreases its range and antibiotic exposure (Fig. 4c, Supplementary Movie 4), leading to a decreased adaptation rate (Fig. 4b). As the last two exceptions are related to critical motility, they are only important in sink-like environments where the wild-type has negative average fitness (Supplementary Fig. 8b, c). Similar conclusions are found when density-dependent motility is modelled explicitly (Supplementary Fig. 8).

With the exception of the highly heterogeneous populations with density-dependent motility, we showed that bacterial populations with different motility phenotypes evolve antibiotic resistance as if all cells had the same effective motility. Therefore, in these conditions, bacterial adaptation is characterised by the same adaptation regimes of phenotypically homogeneous populations. Switching between motility phenotypes can shape the adaptation regime under which bacteria evolve only if the motility of the different phenotypes is very different. But even in these cases, we find that our general conclusions hold, low effective motility accelerates bacterial adaptation while high effective motility decelerates bacterial adaptation. For very high effective motility, bacterial populations can perish.

Cell motility as a factor that limits bacterial survival in sink-like environments

We have seen how bacterial motility shapes the evolution of antibiotic resistance in a variety of models. We have shown that wild-type profiles form the basis of bacterial adaptation by creating mutants and dictating their fitness in antibiotic landscapes (Fig. 1d). Moreover, all our models admit a deadly motility regime, defined by a critical motility (Fig. 2b, Fig. 3b, Fig. 4b). Above the critical motility, the wild-type goes extinct and adaptation is not possible (Supplementary Movie 5). The goal of this last section is to explain the emergence of such critical motility regime, and to bring together the previous sections.

We start by studying analytically how the wild-type profile forms at a fixed resistance state R (Fig. 1b, d). A wild-type profile (N1, …, NL) can be conceptualised as a point in the profile space of cell numbers (Fig. 5a) and its time-evolution can be described by the mean-field equations that are derived from the stochastic dynamics. We illustrate the general approach (SI Theorems 2, 3) using the staircase model with only two compartments (L = 2, R = 1), which is known as the source-sink model25. In this model, the mean-field equations for the wild-type profile formation are the following,

$$\dot{{N}_{1}}= r(1-{N}_{1}/K){N}_{1}-(\delta+\nu ){N}_{1}+\nu {N}_{2},\\ \dot{{N}_{2}}= -(\delta+\nu ){N}_{2}+\nu {N}_{1}.$$
(4)

This system can be analysed with dynamical systems theory, which studies qualitative features of systems of ordinary differential equations (ODE). More precisely, the time-evolution of this system on \({{\mathbb{R}}}^{2}\) can be characterised by phase portraits (Fig. 5b), which in this case have two fixed-points: a trivial fixed point N1 = N2 = 0 where the population goes extinct, and a non-trivial fixed point where the population survives, which is defined as

$${N}_{1} =K\left(1-\frac{\delta (\delta+2\nu )}{r(\delta+\nu )}\right),\\ {N}_{2} =\frac{\nu }{\nu+\delta }{N}_{1}.$$
(5)

These phase portraits admit only two distinct types of trajectory flows (Fig. 5b). Either the non-trivial fixed point has positive physical densities Nx > 0 and globally attracts all possible wild-type profiles with Nx > 0 (i.e., the bacterial population survives); or the non-trivial fixed point is non-physical Nx < 0 and the trivial fixed point attracts all possible wild-type profiles with Nx > 0 (i.e., the bacterial population does not survive). These two types of phase portraits appear at different motility rates ν. Furthermore, we can understand this dynamics with bifurcation theory, and study how the non-trivial fixed point moves through the profile space as motility ν increases from zero (Fig. 5c). At low motility, the non-trivial fixed point is stable and located in the non-negative quadrant N1,2 ≥ 0. As motility increases, the dynamics is different in source-like (\(\overline{f} > \, 0\)) and sink-like (\(\overline{f} < \, 0\)) environments, where the average wild-type fitness of the source-sink model is \(\overline{f}=r/2-\delta\). If the environment is source-like, the non-trivial fixed point never leaves the quadrant N1,2 > 0 and remains stable. However, in sink-like environment, the non-trivial fixed point collides with the trivial fixed point through a transcritical bifurcation, which exchanges their stability. In these cases, there is a critical motility,

$${\nu }_{c}=\frac{\delta (r-\delta )}{2\delta -r} \, > \, 0$$
(6)

which corresponds to this bifurcation. The emergence of a bifurcation is necessary, since (a) the trivial fixed point must be stable as ν →  when cells experience an average sink-like environment, and (b) the non-trivial fixed point must be stable as ν → 0 when cells grow locally in the source at x = 1 (SI Theorem 3). Therefore, these fixed points must collide and exchange their stability through a transcritical bifurcation. This bifurcation theory argument is general and provides a robust mechanism for the emergence of the critical motility regime in all our models (Supplementary Note 2).

Fig. 5: Cell motility as a factor that limits bacterial survival in sink-like environments.
figure 5

a Formation of the wild-type profile. The formation of a wild-type profile corresponding to a fixed resistance state R is described by mean-field equations, which explain the flow of the initial profile in the profile space of cell numbers (N1, …, NL). This flow admits two fixed points: a trivial fixed point Nx = 0 (red, population extinction if stable) and a non-trivial fixed-point (yellow, population survival if stable). b Phase portraits of the wild-type profile formation in the staircase model with L = 2, R = 1 (the so-called source-sink model25). Phase portraits are shown for different motility rates ν and different environment types (source-like/sink-like), depending on the average wild-type fitness \(\overline{f}=r/2-\delta\). Only two topologically distinct types of flow are possible: the non-trivial fixed point globally attracts all possible wild-type profiles with Nx > 0 (population survival), or the trivial fixed point globally attracts all possible wild-type profiles with Nx > 0 (population extinction). Extinction occurs in sink-like environments (\(\overline{f} < \, 0\)) with motility above the critical motility ν > νc. c Critical motility νc corresponds to a bifurcation of this dynamical system. When motility ν is varied, the non-trivial fixed point moves through the space of possible profiles. At low motility, the non-trivial fixed point is stable and corresponds to a wild-type profile that predominantly occupies spatial positions x ≤ R where it can divide. As motility increases, the wild-type profile gets increasingly levelled across all spatial compartments, and its dynamics becomes governed by the average fitness \(\overline{f}\). Precisely when the environment is sink-like \(\overline{f} < \, 0\), the stable non-trivial fixed point (surviving wild-type) collides with the unstable trivial fixed point (extinct wild-type), and they exchange their stability at the critical motility νc. In short, highly motile populations experience an average environment, which can drive their extinction if the environment is sink-like. Parameters: L = 8, K = 105, r = 1/h, δ = 0.75/h for source-like environment, δ = 0.25/h for sink-like environment.

In short, and put differently in a more biological realm, a bacterial population can be driven to extinction by increasing the rate at which cells move in sink-like environments (i.e., in spatially heterogeneous environments where the average wild-type fitness is negative) because highly motile cells experience an average environment. This idea suggests that one can limit bacterial adaptation in heterogeneous landscapes by targeting cell motility.

Discussion

In this work, we have used mathematical analysis to study how bacterial motility affects the evolution of antibiotic resistance in spatially heterogeneous environments that have different antibiotic concentrations. By doing so, our study contributes to the large body of literature that has recognized spatial heterogeneity as an important factor for bacterial adaptive evolution but where active motility of bacteria remains poorly explored9,10,11,25,26,27,28,29,30,31.

We have identified three regimes of bacterial adaptation, which are defined by the degree of cell motility in evolving populations. Accordingly, we called them low motility, high motility and deadly motility regimes (Fig. 2b). The theory of the low motility regime has already been discussed25,26, and has been compared with experimental works that studied how antibiotic gradients affect bacterial adaptation rate9,10. Interestingly, while Zhang et al.9 reported an increased adaptation rate in their antibiotic gradients compared to well-mixed conditions, Baym et al.10 did not find such an acceleration in theirs. We note that while the same bacterial species were used, the antibiotic landscape that cells experienced was very different in these two experimental systems, which would be sufficient to affect the adaptation rates according to our work (Fig. 2b). Such difference can emerge when cells move at different rates (Fig. 2b), or for different gradient steepness27,28,31. Indeed, these effects are interchangeable because increasing gradient steepness brings spatial points of fixed antibiotic concentrations closer, which resembles the effect of increasing effective motility.

This effect then suggests that the adaptation regime of an evolving population is governed by the antibiotic variability explored by bacteria during their lifetime. The adaptation rate can therefore be quantified by a dimensionless visiting number V, defined as the number of regions that differ in antibiotic concentrations and that are visited by an average cell during its life-time (Supplementary Note 7). In our model, V = ν/δ as cells change antibiotic regions at a rate ν and live for time 1/δ. Therefore, V < 1 (resp. V > 1) corresponds to the low (resp. high) motility regime (Fig. 2). In experiments, the visiting number can be calculated from the characteristic cell speed v, doubling time in the absence of antibiotics t and length-scale over which the drug concentrations vary on MIC scales l. The visiting number is V = vt/l as cells explore length-scale of vt during their lifespan, while antibiotics differ at length-scale l. We estimated the visiting numbers in Zhang et al.9 and Baym et al.10 and predict that cells in Baym et al.10 were evolving in a low motility regime (V ≈ 0.1846 < 1) and cells in Zhang et al.9 in the high motility regime (V ≈ 120 > 1). Notably, Baym et al.10 observed adaptation at the population front and coexistence of resistance strains, which is consistent with a low motility regime (Fig. 1d), while Zhang et al.9 observed that resistant mutants quickly invade the entire environment, consistent with high motility regime (Fig. 1d). If bacteria were evolving in different motility regimes as predicted by our visiting number, it may help to explain why the authors observed different rates of bacterial adaptation in their studies (Supplementary Table 1).

As a corollary of our analysis, we find that there is an optimal level of cell motility for bacterial adaptation in spatially heterogeneous environments (Fig. 2b). A similar optimum has been identified in models of HIV38 and cancer39 drug resistance evolution. These models are analogous to our setting in that they consider the movement of viruses or cancer cells between compartments of different drug concentrations. However, the deadly motility regime was not identified in these works. It is not clear if these models do not allow for a deadly motility regime or if instead the authors simply did not explore their model fully. Since our models rest on general features of living cells, they may be useful to understand the evolutionary dynamics of cell types other than bacteria, namely cancer cells during chemotherapy, where the role of cell motility and drug gradients remains poorly explored40,41.

Some of our findings are closely related to those from ecology works that study biological adaptation at range edges where species expand their range in an environmental gradient by dispersal and mutation42,43,44,45. In this literature, local adaptation is known to be prevented by high motility, the so-called motility load43, where less fit wild-type genotypes migrate enough to increase competition with mutant genotypes, which decreases selection for the latter. As a result, genetic diversity is lower in their high motility regime when compared to the low motility regime, as we find in our work (Fig. 1d). This loss of genetic diversity in the ecological models is often associated with critical motility43,46,47, which can be compared with our critical motility. Notably, the emergence of a critical motility in these works can be explained by the same bifurcation mechanism that we identified (Supplementary Note 2), which highlights the robustness of our mechanism across modelling frameworks. Moreover, due to its simplicity, the staircase model can be used to provide analytical insights into biological adaptation at range edges as in Lenormand43, Nagylaki48 and Kirkpatrick & Barton42, while considering the important stochasticity of natural processes as in Polechova & Barton45.

Our models make multiple simplifying assumptions regarding the biology of bacteria. While we extended our initial staircase model to account for some of this biology, such as the effect of resistance costs (Supplementary Fig. 2), level of mutation rates (Supplementary Fig. 3), differential competition between growing and non-growing cells (Supplementary Fig. 4), bactericidal antibiotics (Supplementary Fig. 5) and biased motility (Supplementary Fig. 6), these processes could be modelled differently. For example, we modelled resistance costs as a reduction in division rate (Supplementary Fig. 2), while one could study resistance costs that decrease motility rate. Moreover, we assumed implicitly that bacterial adaptation results from the vertical transmission of resistance genes only, and horizontal gene transfer (HGT) is known to affect the evolution of antibiotic resistance49. However, the staircase model is a closed system and it is known that for these systems, HGT does not have an important impact50,51,52,53,54. While considering the effect of immigration of cells was beyond the scope of this work, we tested the predictions for closed systems by implementing HGT in the staircase model and found that HGT does not affect our conclusions (Supplementary Fig. 9, Supplementary Note 4).

In addition to considering the effect of HGT more thoroughly, one may extend our models to account for other relevant biology of bacteria such as the existence of persister phenotypes, which can affect the stability of microbial communities55, or the effect of phage infection, which can affect bacterial motility24. Regardless, our current results lead us to conclude that cell motility limits bacterial adaptive evolution in spatially heterogeneous environments. This realization then suggests that manipulating motility may prove to be a useful approach for controlling bacterial systems and their impacts on us.

Methods

Simulations

A major component of our methods is computer simulations of the staircase model and its extensions. Hereby, we describe how to simulate the basic staircase model. The staircase model treats bacterial evolution in drug gradients as a continuous-time Markov process, which is a stochastic process whose future state depends only on the present state and not on the past states. A state of the staircase model is specified by the number of bacterial cells Nx,g at each lattice point (x, g)  {1, …, L}2 of the position-genotype lattice. The initial state of the staircase model at time t = 0 is chosen as N1,1 = 10−3K and Nx,g = 0 for other lattice points (x, g) ≠ (1, 1). The time-evolution of the initial state of the staircase model Nx,g is determined by the following processes iI:

  • death of a cell of genotype g at position x (Nx,g → Nx,g − 1): rate bi = δNx,g,

  • division of a cell of genotype g at position x ≤ g when ∑gNx,g≤  K (Nx,g → Nx,g + 1): rate bi = r(1 − ∑gNx,g),

  • movement of a cell of genotype g from position x to position x + 1 (Nx,g → Nx,g − 1, Nx+1,g → Nx+1,g + 1): rate bi = νNx,g,

  • movement of a cell of genotype g from position x to position x − 1 (Nx,g → Nx,g − 1, Nx−1,g → Nx−1,g + 1): rate bi = νNx,g,

  • mutation of a cell at position x from genotype g to genotype g + 1 (Nx,g → Nx,g − 1, Nx,g+1 → Nx,g+1 + 1): rate bi = μfNx,g,

  • mutation of a cell at position x from genotype g to genotype g − 1 (Nx,g → Nx,g − 1, Nx,g−1 → Nx,g−1 + 1): rate bi = μgNx,g.

To simulate this time-evolution, we use the exact sampling of stochastic trajectories of the staircase model via a computationally efficient Next Reaction Method56, which samples the next process that takes place and the time when it happens. Effectively, this method combines computationally efficient data structures and the Gillespie’s algorithm57:

  1. 1.

    sample the next process i, which happens with probability bi/∑jIbj,

  2. 2.

    sample the waiting time Δt, which has distribution \({{{{{{{\rm{Exp}}}}}}}}({\sum }_{i\in I} \, {b}_{i})\),

  3. 3.

    update the time t → t + Δt when the next process i happens and execute the process i.

Using this sampling technique, the times that correspond to the founder and winner states can be measured for all resistance states R (Fig. 2a). Founder states are defined by the first time when a single mutant cell (g = R + 1) appears in the overlap region (x = R + 1), while the winner states are defined by the first time when there is more mutant cells (g = R + 1) than wild-type cells (g ≤ R) in the overlap region (x = R + 1). As in Hermsen et al.26, we record the times that correspond to the founder states \({T}_{i}^{R}\) in n = 50 independent simulations i and set \({T}_{i}^{0}=0\). The adaptation rate is estimated as,

$${a}_{R}=\frac{n}{\mathop{\sum }\nolimits_{i}({T}_{i}^{R}-{T}_{i}^{R-1})}.$$
(7)

This expression matches the definition of the adaptation rate precisely when n → , because \({\sum }_{i}({T}_{i}^{R}-{T}_{i}^{R-1})/n\to {\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}+{\mathbb{E}}{T}_{{{{{{{{\rm{eco}}}}}}}}}^{R-1}\) by the law of large numbers. The standard deviations associated with taking finite n = 50 can be computed using the central limit theorem and we checked that their corresponding error bars are smaller than the symbols in Fig. 2b. As we use n = 50 simulations in all Figures and all Figures include the original staircase model as a special case, errors are expected to be negligible in all other Figures. The standard deviations are provided in the Source Data.

The same algorithm is used to simulate the extensions of the staircase model and the precise parameters used in simulations are detailed in the Supplementary Note 10.

Analytical and numerical techniques

In addition to computer simulations, we developed a combination of analytical and numerical techniques, which are used to compute the evolutionary time, ecological time and the adaptation rate. In contrast to simulations, these techniques are based on closed-form solutions of master equations, numerical methods for solving algebraic equations (such as Newton-Raphson method) and solving ODEs (such as Runge-Kutta method). To illustrate these techniques, we show how to compute the expected waiting times at a resistance state R and the adaptation rate aR in the original staircase model.

  1. 1.

    Find the wild-type profile Nx at a resistance state R. Use Newton-Raphson method to solve the algebraic equations for the non-trivial fixed point of the mean-field theory

    $$0= r(1-{N}_{x}/K){N}_{x}{{\mathbb{1}}}_{x\le R}-\delta {N}_{x}\\ +\nu ({N}_{x-1}-{N}_{x}){{\mathbb{1}}}_{1 < x}+\nu ({N}_{x+1}-{N}_{x}){{\mathbb{1}}}_{x < L},$$
    (8)

    where \({\mathbb{1}}\) is the indicator function.

  2. 2.

    Compute the evolutionary time \({\mathbb{E}}{T}_{{{{{{{{\bf{evo}}}}}}}}}^{R}\). A closed-form solution exists and follows from a modification of the theory in Hermsen et al.25,26. We consider three independent adaptation paths along which wild-type can produce a first mutant in the overlap region x = R + 1. On the position-genotype lattice (x, g), they are the division path D: (R, R) → (R, R + 1) → (R + 1, R + 1) (mutation at x = R followed by migration to the right); the overlap path O: (R + 1, R) → (R + 1, R + 1) (mutation at x = R + 1); and the no-division path N: (R + 2, R) → (R + 2, R + 1) → (R + 1, R + 1) (mutation at x = R + 2 followed by migration to the left). As the original theory26 assumes low motility, it neglects the no-division path since there are no wild-type cells to mutate at position x = R + 2 in this regime (SI Theorem 3). Moreover, we assume that the flux of mutants between neighbouring compartments in the division region x ≤ R and the no-divison region x ≥  R + 2 is equilibrated, so that we can ignore the net probability flux of mutants that enter or exit the compartments x = R − 1, R, R + 1 and also ignore longer paths such as (R − 1, R) → (R − 1, R + 1) → (R, R + 1) → (R + 1, R + 1) (mutation at x = R − 1 followed by double migration to the right). This is a reasonable assumption as the flux of mutant-producing wild-type is equilibrated far from the population front. The computation of \({\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\) has the following structure.

    1. (a)

      The waiting times till a mutant is produced in the overlap region along path i {D, O, N} are denoted by Ti (Fig. 2a).

    2. (b)

      The probability that the waiting will be longer than t is \({S}_{i}(t)={\mathbb{P}}({T}_{i} \, > \, t)\) and the probability density function of Ti is given by Fi(t) = −dSi/dt.

    3. (c)

      Notice that \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}=\mathop{\min }\nolimits_{i}{T}_{i}\) and that Ti are independent. Thus, \(S(t)={\mathbb{P}}({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R} > \, t)={S}_{D}(t){S}_{O}(t){S}_{N}(t)\).

    4. (d)

      The probability density function of \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\) is

    $$F(t)= -\frac{{{{{{{{\rm{d}}}}}}}}S}{{{{{{{{\rm{d}}}}}}}}t}={F}_{D}(t){S}_{O}(t){S}_{N}(t)\\ +{S}_{D}(t){F}_{O}(t){S}_{N}(t)\\ +{S}_{D}(t){S}_{O}(t){F}_{N}(t).$$
    (9)
    1. (a)

      The expected time \({\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}=\int\nolimits_{0}^{\infty }tF(t){{{{{{{\rm{d}}}}}}}}t\) is found by numerical integration.

    Therefore, the problem is solved by finding the functions Si(t) and differentiating them to produce Fi(t). According to Hermsen et al.25,26, these functions are:

    1. (a)

      For path D:

      $${S}_{D}(t)={\left(\frac{{c}_{D}{e}^{{b}_{D}t}}{{c}_{D}\cosh ({c}_{D}t)+{b}_{D}\sinh ({c}_{D}t)}\right)}^{{a}_{D}}$$
      (10)

      where

      $${a}_{D} =\frac{{\mu }_{f}{N}_{R}}{{r}^{{\prime} }-{\mu }_{f}},\, {b}_{D}=\frac{1}{2}(\nu+\delta -{r}^{{\prime} }+{\mu }_{f}+{\mu }_{b}),\\ {c}_{D} =\frac{1}{2}\left[{\left(\nu+{r}^{{\prime} }-{\mu }_{f}+\delta+{\mu }_{b}\right)}^{2}\right. -{\left.4({r}^{{\prime} }-{\mu }_{f})(\delta+{\mu }_{b})\right]}^{1/2},$$
      (11)

      and

      $${F}_{D}(t)=\nu {S}_{D}(t){\langle n(t)\rangle }_{D},$$
      (12)

      where 〈n(t)〉D is the average mutant population in compartment x = R at time t

      $${\langle n(t)\rangle }_{D}=\frac{{\mu }_{f}{N}_{R}\tanh ({c}_{D}t)}{{c}_{D}+{b}_{D}\tanh ({c}_{D}t)}.$$
      (13)
    2. (b)

      For path O:

      $${S}_{O}(t)={e}^{-{\mu }_{f}{N}_{R+1}t},$$
      (14)
      $${F}_{O}(t)={\mu }_{f}{N}_{R+1}{e}^{-{\mu }_{f}{N}_{R+1}t}.$$
      (15)
    3. (c)

      For path N:

      $${S}_{N}(t)={\left(\frac{{c}_{N}{e}^{{b}_{N}t}}{{c}_{N}\cosh ({c}_{N}t)+{b}_{N}\sinh ({c}_{N}t)}\right)}^{{a}_{N}}$$
      (16)

      where

      $${a}_{N} =-{N}_{R+2},\, {b}_{N}=\frac{1}{2}(\nu+\delta+{\mu }_{f}+{\mu }_{b}),\\ {c}_{N} =\frac{1}{2}\left[{(\nu -{\mu }_{f}+\delta+{\mu }_{b})}^{2}\right.+{\left.4{\mu }_{f}(\delta+{\mu }_{b})\right]}^{1/2},$$
      (17)

      and

      $${F}_{N}(t)=\nu {S}_{N}(t){\langle n(t)\rangle }_{N},$$
      (18)

      where 〈n(t)〉N is the average mutant population in compartment x = R + 2 at time t

      $${\langle n(t)\rangle }_{N}=\frac{{\mu }_{f}{N}_{R+2}\tanh ({c}_{N}t)}{{c}_{N}+{b}_{N}\tanh ({c}_{N}t)}.$$
      (19)

    Finally, if there is a nonnegligible chance that the first mutant in the overlap region dies before division, the evolutionary time \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}\) must be corrected to \({T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}/q\), where q is the probability that the first mutant in the overlap region divides before its death (Supplementary Note 8).

  3. 3.

    Compute the ecological time \({\mathbb{E}}{T}_{{{{{{{{\bf{eco}}}}}}}}}^{R}\). The competition between wild-type and mutants can be described well by the mean-field equations:

    $$\frac{{{{{{{{\rm{d}}}}}}}}{w}_{x}}{{{{{{{{\rm{d}}}}}}}}t} =-{\mu }_{f}{w}_{x}+{\mu }_{b}{m}_{x}\\ \quad+r\left(1-\frac{{w}_{x}+{m}_{x}}{K}\right){w}_{x}{{\mathbb{1}}}_{x\le R}-\delta {w}_{x}\\ \quad+\nu ({w}_{x-1}-{w}_{x}){{\mathbb{1}}}_{1 < x}+\nu ({w}_{x+1}-{w}_{x}){{\mathbb{1}}}_{x < L}\\ \frac{{{{{{{{\rm{d}}}}}}}}{m}_{x}}{{{{{{{{\rm{d}}}}}}}}t} =+{\mu }_{f}{w}_{x}-{\mu }_{b}{m}_{x}\\ \quad+r\left(1-\frac{{w}_{x}+{m}_{x}}{K}\right){m}_{x}{{\mathbb{1}}}_{x\le R}-\delta {m}_{x}\\ \quad+\nu ({m}_{x-1}-{m}_{x}){{\mathbb{1}}}_{1 < x}+\nu ({m}_{x+1}-{m}_{x}){{\mathbb{1}}}_{x < L}$$
    (20)

    with initial conditions at time t = 0:

    $${w}_{x} ={N}_{x}-{\langle n({\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R})\rangle }_{D}{{{{{{{\rm{,}}}}}}}}\,x=1,\ldots,\, R\\ {w}_{x} ={N}_{R+1}-1{{{{{{{\rm{,}}}}}}}}x=R+1\\ {w}_{x} ={N}_{x}-{\langle n({\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R})\rangle }_{N}{{{{{{{\rm{,}}}}}}}} \,x=R+2,\ldots,\, L\\ {m}_{x} ={\langle n({\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R})\rangle }_{D}{{{{{{{\rm{,}}}}}}}}x=1,\ldots,\, R\\ {m}_{x} =1{{{{{{{\rm{,}}}}}}}} \, x=R+1\\ {m}_{x} ={\langle n({\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R})\rangle }_{N}{{{{{{{\rm{,}}}}}}}} \, x=R+2,\ldots,\, L$$
    (21)

    In these equations wx and mx stand for the number of wild-type and mutant cells in spatial compartment x, respectively. The system is simulated from the end state of the previous stochastic process when a first mutant appears in the overlap region. This system can be simulated efficiently by a Runge-Kutta (RK4) method. The time \(t={\mathbb{E}}{T}_{{{{{{{{\rm{eco}}}}}}}}}^{R}\) is reached when wR+1 < mR+1 for the first time, i.e., the mutants outcompete the wild-type in the overlap region.

  4. 4.

    Find the adaptation rate. The adaptation rate is found from

    $${a}_{R}=\frac{1}{{\mathbb{E}}{T}_{{{{{{{{\rm{evo}}}}}}}}}^{R}+{\mathbb{E}}{T}_{{{{{{{{\rm{eco}}}}}}}}}^{R-1}}.$$
    (22)

For convenience, we refer to this set of techniques as analytical techniques, even though they implement many numerical procedures. The benefit of the analytical techniques, as opposed to simulations, comes from their computational efficacy. In addition to this form of analytical techniques, we developed a purely analytical approach, which describes the formation of the wild-type profile and this approach is detailed in the Supplementary Notes.

Reporting summary

Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.