Ecology directs host–parasite coevolutionary trajectories across Daphnia–microparasite populations

Host–parasite interactions often fuel coevolutionary change. However, parasitism is one of a myriad of possible ecological interactions in nature. Biotic (for example, predation) and abiotic (for example, temperature) variation can amplify or dilute parasitism as a selective force on hosts and parasites, driving population variation in (co)evolutionary trajectories. We dissected the relationships between wider ecology and coevolutionary trajectory using 16 ecologically complex Daphnia magna–Pasteuria ramosa ponds seeded with an identical starting host (Daphnia) and parasite (Pasteuria) population. We show, using a time-shift experiment and outdoor population data, how multivariate biotic and abiotic ecological differences between ponds caused coevolutionary divergence. Wider ecology drove variation in host evolution of resistance, but not parasite infectivity; parasites subsequently coevolved in response to the changing complement of host genotypes, such that parasites adapted to historically resistant host genotypes. Parasitism was a stronger interaction for the parasite than for its host, probably because the host is the principal environment and selective force, whereas for hosts, parasite-mediated selection is one of many sources of selection. Our findings reveal the mechanisms through which wider ecology creates coevolutionary hotspots and coldspots in biologically realistic arenas of host–parasite interaction, and sheds light on how the ecological theatre can affect the (co)evolutionary play. Ecological factors affect host–parasite coevolution. This study shows how biotic and abiotic forces influence the evolutionary trajectories of Daphnia and its obligate bacterial parasite in 16 replicate ponds.

P arasites are a strong selective force acting on host populations, and vice versa 1,2 , fuelling rapid cycles of adaptation and counter-adaptation in terms of host resistance and parasite capacity to infect [2][3][4][5] . These coevolutionary processes can have profound effects on disease outbreaks. For example, whether the host or the parasite is ahead in the coevolutionary process can, in part, affect whether epidemics are emerging 6 or in decline 7 . A key aim of evolutionary ecologists is to understand the extent to which coevolution is a deterministic process with repeated, predictable outcomes that are either hard-wired or shaped by measurable abiotic and biotic ecological variation; and a stochastic process driven by unpredictable events.
Ecological variation is known to have strong effects on coevolution [8][9][10] . However, dissecting host-parasite coevolution in biologically realistic settings is fraught with difficulty, and much of our understanding of coevolution therefore comes from laboratory experiments that eliminate ecological complexity. This experimental control comes at a cost to biological realism, because parasitism is just one of many ecological interactions that hosts experience in the wild; predation, competition and abiotic variables such as temperature are already known to either amplify or diminish host evolutionary responses to parasite-mediated selection 4,[11][12][13][14][15] . By contrast, we expect parasite evolution, particularly for obligate endoparasites, to be driven primarily by shifts in host-mediated selection caused by changes in host genotype frequencies 16 , because hosts insulate their endoparasites from the wider environment. These asymmetries in host and parasite responses to reciprocal selection could create discrepancies between coevolution observed in the laboratory and in the natural arena.
We quantified how coevolutionary trajectories varied among 16 biologically realistic pond populations of Daphnia magna and its sterilizing bacterial endoparasite, Pasteuria ramosa. Each pond was initiated with an identical suite of Daphnia genotypes and the same starting population and dose of Pasteuria transmission spores. The healthy and parasite-infected densities were then monitored weekly over the course of each pond epidemic. At the end of the epidemic, Daphnia were sampled to determine the change in genotype frequencies and additional infected Daphnia were sampled to obtain parasite isolates from each pond. We subsequently conducted a time-shift experiment, where we exposed replicates of the original 12 Daphnia genotypes to either the ancestral parasite used to initiate the pond populations, or to parasite isolates collected from each pond at the end of the epidemic.
By combining data from the time-shift experiment with changes in relative genotype frequencies, we dissected, for each pond, the effects of the three components of host-parasite coevolution on the change in parasite transmission rate over the course of the season: host evolution of resistance, parasite evolution of infectivity and coevolution (that is, the extent to which the parasite population non-additively evolved in response to a changed complement of host genotypes). When host genotypes that were resistant to the ancestral parasite increased in frequency within a population, that host population evolved host resistance; when a parasite sample collected at the end of the season caused more infections than the ancestral parasite when exposed to the panel of host genotypes, that parasite population evolved increased infectivity; and when a parasite sample collected at the end of the season became proportionately more infectious to host genotypes that were resistant to the ancestral parasite, that parasite population coevolved in response to the changing complement of host genotypes.

Results and discussion
Coevolutionary trajectories varied among ponds. Although the ponds had the same starting populations of hosts and parasites, each Ecology directs host-parasite coevolutionary trajectories across Daphnia-microparasite populations Sam Paplauskas , June Brand and Stuart K. J. R. Auld ✉ Host-parasite interactions often fuel coevolutionary change. However, parasitism is one of a myriad of possible ecological interactions in nature. Biotic (for example, predation) and abiotic (for example, temperature) variation can amplify or dilute parasitism as a selective force on hosts and parasites, driving population variation in (co)evolutionary trajectories. We dissected the relationships between wider ecology and coevolutionary trajectory using 16 ecologically complex Daphnia magna-Pasteuria ramosa ponds seeded with an identical starting host (Daphnia) and parasite (Pasteuria) population. We show, using a time-shift experiment and outdoor population data, how multivariate biotic and abiotic ecological differences between ponds caused coevolutionary divergence. Wider ecology drove variation in host evolution of resistance, but not parasite infectivity; parasites subsequently coevolved in response to the changing complement of host genotypes, such that parasites adapted to historically resistant host genotypes. Parasitism was a stronger interaction for the parasite than for its host, probably because the host is the principal environment and selective force, whereas for hosts, parasite-mediated selection is one of many sources of selection. Our findings reveal the mechanisms through which wider ecology creates coevolutionary hotspots and coldspots in biologically realistic arenas of host-parasite interaction, and sheds light on how the ecological theatre can affect the (co) evolutionary play.
pond experienced its own natural temperature profile (with significant variation across ponds), and half underwent an experimental manipulation of within-population flux (mixing) that simulated extreme precipitation events. We recorded the natural variation in ten biotic and abiotic ecological variables over the season: temperature (mean and variance), pH, dissolved oxygen, chlorophyll, nitrate and total dissolved salt, parasite prevalence, predator density, and adult host density. This allowed us to examine the role of ecological variation early in the season in driving coevolutionary divergence.
We found that each pond population followed its own coevolutionary trajectory (with respect to changes in parasite transmission rate). This was driven by variation in all three coevolutionary axes: host evolution, parasite evolution and coevolution (Fig. 1a-c). We uncovered asymmetry in the magnitude of host and parasite evolution: parasite populations evolved more in their capacity to infect the ancestral host population than their corresponding hosts evolved capacity to resist the ancestral parasite population (paired t = −3.25, P = 0.005; Fig. 1). We also found a strong positive relationship between the change in host resistance and coevolution, that is, a change in transmission rates due to a shifting complement of host genotypes (r s = 0.69, P = 0.004; Fig. 1b): over the course of the season, parasites became disproportionately better at infecting those host genotypes that were previously resistant at the beginning of the season (host genotypes that had become more common), and also disproportionately poorer at infecting host genotypes that were previously susceptible at the beginning of the season (host genotypes that had become rarer). By contrast, there was a lack of relationship between the change in parasite infectivity and coevolution (r s = 0.39, P = 0.135; Fig. 1c). These findings are consistent with the idea that ecological interactions above and beyond parasitism can select on hosts, but do not act on the host-insulated parasites; shifts in host genotype frequencies instead drive parasite genetic change via coevolution. Whereas, for ectoparasites, which live on the host exterior, wider ecological conditions are known to shape the evolution of virulence 17,18 .
Ecology drives variation in coevolution. Initial inspection of the ten ecological variables in isolation revealed that the mixing treatment had no effect on nine of them, but that it was associated with lower total adult host densities (Supplementary Table 1). This supports the idea that the mixing treatment affected the ecology of the system primarily by reducing host densities directly; indeed, it is known that sediment suspension can interfere with Daphnia filter feeding, reducing population growth and the consumption of algae 19 (see later results). Higher temperatures and lower chlorophyll concentration, dissolved oxygen and pH were each associated with the evolution of host resistance, but none of the ecological variables were associated with parasite evolution or coevolution (Supplementary Table 2).
However, a more holistic multivariate analysis uncovered a much more interesting story. A principal component analysis (PCA) of the biotic and abiotic variables (Supplementary Fig. 1) revealed considerable ecological variation among populations, with the first and second principal component axes explaining 36.0% and 21.6% of that variation. The main factors driving variation in unmixed populations were mean temperature and host density, whereas several factors explained variation in mixed populations: chlorophyll, predator density, oxygen, pH and nitrate. There was a strong positive relationship between δ eco , the pairwise Mahalanobian distances between populations in multivariate space for ecological variation, and δ coevo , the pairwise Mahalanobian distances for coevolutionary net change ( Fig. 2: Mantel r = 0.36, P = 0.029). Populations that were more ecologically different from each other had more divergent coevolutionary trajectories. Both theory 20 and empirical data (reviewed in ref. 10 ) have previously shown how host and parasite genotypes can differentially respond to particular environmental variation to create (co)evolutionary hotspots and coldspots 21 ; these results show how such environmental variables can act in concert to mediate coevolution.
Ecology affects host evolution with consequences for coevolution. The next step was to dissect precisely how ecological variation and coevolutionary change were linked. Using structural equation modelling (SEM; Supplementary Fig. 2), we tested which of two credible scenarios better explained the relationship between ecological and coevolutionary variation among populations (Fig. 3). Scenario 1 (SEM1) proposed that mixing affected ecology (measured as the first principal componant, PC1), that ecology directly affected host evolution, parasite evolution and coevolution, and that parasite evolution also separately affected coevolution. Scenario 2 (SEM2) was similar, except it proposed that ecology did not affect coevolution directly; here, ecological effects on coevolution were mediated by both host evolution and parasite evolution (see Methods). While both SEM1 and SEM2 provided adequate fit to the data (SEM1: Fisher's C = 19.80, d.f. = 12, P = 0.071, Bayesian information criterion (BIC) = 64.16; SEM2: Fisher's C = 12.66, d.f. = 12, P = 0.394, BIC = 57.02), SEM2 was the better performing model (ΔBIC = 7.14), demonstrating that there was greater support for the scenario where ecological effects on coevolution were mediated by both host evolution and parasite evolution.
Analysis of SEM2 revealed that ecological conditions, as expressed by PC1, were significantly different between mixed and   Table 3). Ecology was also directly associated with evolution of host resistance (Fig. 4f and Supplementary Table 3), but not parasite infectivity (Fig. 4g and Supplementary Table 3). Finally, the ability to examine partial residuals after controlling for other variables (a major advantage of the SEM approach) allowed us to uncover that coevolution was positively associated with both the evolution of host resistance (Fig. 4h and Supplementary Table 3) and the evolution of parasite infectivity ( Fig. 4i and Supplementary Table 3). These separate effects of epidemic size and wider ecology on host (but not parasite) evolution provide two principal insights. They add support to our assertion that hosts are subject to a wide range of selective pressures owing to both parasite-mediated selection from disease epidemics and from wider ecology, whereas the parasite's insulation within the host environment and the obligate nature of its relationship with the host ensures the host is the principal agent of selection (hence the relationship between host evolution and coevolution). They also raise the intriguing hypothesis that epidemic size and wider ecology (driven in part by the mixing treatment) pull two separate levers to drive host evolution of resistance. First, larger epidemics could have exerted greater parasite-mediated selection for host resistance 13 . Second, populations with greater PC1 values, that is, lower predation and higher temperatures (and thus higher Daphnia reproductive rate), had high population densities 22,23 , and therefore probably had a greater capacity to respond to any parasite-mediated selection. This may have fuelled coevolution, driving the divergence in coevolutionary trajectories that we see in Fig. 1.
The next step is to explain the relationships between host evolution, parasite evolution and coevolution. Previous work demonstrated that the matching-allele model (MAM) best describes the infection genetics of the Daphnia-Pasteuria system 4,24,25 : alleles conferring parasite ability to infect one host genotype often preclude it from infecting other different host genotypes 14 . However, the MAM in its purest sense requires just one susceptible host genotype for every infectious parasite genotype 26 , but in the Daphnia-Pasteuria system parasite genotypes commonly infect >1 host genotype and also vary in the number of host genotypes each parasite can infect 24 . This deviation from the MAM could potentially explain why coevolution was positively associated with the evolution of host resistance and, to a lesser extent, parasite infectivity ( Fig. 4h,i and Supplementary Table 3): parasite populations that were more infectious to the ancestral complement of hosts were also better at infecting the new complement of hosts, and hosts that got better at resisting the ancestral parasite also got better at resisting the evolved parasite. Reciprocal selection could have acted in two ways: first, general selection could have favoured parasite genotypes that infect the broadest range of host genotypes (and vice versa for resistance in host genotypes); second, specific selection could have separately favoured parasite genotypes that could infect host genotypes that had become particularly common (again, vice versa for resistance in host genotypes).

conclusion
These results demonstrate that even in seemingly noisy environments, coevolution was still largely driven by deterministic, ecologically mediated processes. Individual biotic and abiotic variables gave us a small glimpse of how wider ecology shaped coevolution. It was only after viewing multiple ecological variables from a multivariate perspective that we were able to observe that the ecological theatre determined the (co)evolutionary play in a measurable, understandable way (sensu ref. 27 ). Recent work has demonstrated  Epidemic size R 2 = 0.28  Table 3). Note that negative values of Δβ h represent evolution of host resistance. that quantitative differences among qualitatively similar environments can explain evolutionary divergence among stickleback populations 28 ; we show the same is true for more complex host-parasite coevolution, and that knowledge of numerous ecological conditions could help us predict the distribution of coevolutionary hotspots and coldspots 21 .

Methods
Pond experiment. The pond experiment was used to test how epidemic size varied across populations that were initiated with the same suite of hosts and parasites, but experienced biologically realistic variation in biotic and abiotic ecological variables. Additionally, healthy and infected hosts were sampled at the end of the season to quantify the change in relative host genotype frequencies across populations and provide parasite samples for the time-shift experiment.
To start with, replicate lines of the 12 genotypes of D. magna were maintained in the laboratory in a state of clonal reproduction for three generations to reduce variation due to maternal effects. There were five replicates per genotype; each replicate consisted of five Daphnia kept in 200 ml of artificial medium 29 modified using 5% of the recommended SeO 2 concentration 30 . Replicate jars were fed 5.0 ABS of Chlorella vulgaris algal cells per day (where ABS is the optical absorbance of 650 nm white light by the Chlorella culture). Daphnia medium was changed three times per week and three days before the start of the pond experiment. On the day that the pond experiment commenced, offspring of 1-3 days old were pooled according to host genotype. Ten offspring per genotype were randomly allocated to each of the 16 ponds (giving a total of 120 Daphnia per pond). From preliminary work, we knew that the 12 genotypes used in our pond and laboratory experiments were a representative sample of parasite-resistance profiles observed in the source population. The proportion of Daphnia that became infected with the ancestral mastermix Pasteuria after 48 h exposure to 2 × 10 5 spores ranged from 0 to 0.75 depending on genotype, with a mean of 0.27.
Each pond consisted of a 0.65 m tall, 1,000 litre PVC tank filled with rainwater. The ponds were set to different depths into the ground and experienced different temperature profiles 31 . In addition, six of the ponds experienced a weekly mixing treatment where they were stirred once across the middle and once around the circumference with a 0.35 m 2 paddle submerged halfway into the pond (the exception to this was on the first day of the experiment, when all ponds experienced the mixing treatment to ensure hosts and parasites were distributed throughout).
The experimental coevolution began on 2 April 2015 (Julian day 98), when 120 Daphnia (10 Daphnia × 12 genotypes) and 1 × 10 8 Pasteuria spores from the ancestral mastermix were added to each of the 16 ponds. The ancestral mastermix comprised P. ramosa spores propagated using 21 separate Daphnia genotypes exposed to sediment from their original pond (Kaimes, Scottish Borders, United Kingdom 31 ).
Between 2 April and 17 November 2015, we measured key abiotic and biotic ecological variables on a weekly basis. Temperature, pH, dissolved oxygen (%), chlorophyll (µg −1 ), nitrate (mg l −1 ) and total dissolved salt (mg l −1 ) were recorded using an Aquaread AP-5000 probe. Host density (l −1 ), parasite prevalence and predator density (l −1 ) were determined using standard sampling procedures 31 . After peak epidemic (17 November 2015; Julian day 321), 20-30 Daphnia were sampled from each pond for genotyping. The DNA extraction and microsatellite genotyping process is described in full in ref. 14 . Microsatellite genotyping was used to identify the 12 unique multilocus Daphnia, and thus track the change in relative genotype frequencies between the beginning of the experiment (when all genotypes were at equal frequencies) and the end of the experiment. The relative genotype frequencies were used as a measure of relative genotype fitness within each pond. Finally, we sampled 90 infected hosts from each of the 16 ponds, which were homogenized and pooled into three replicate isolates per pond (30 infected Daphnia per isolate).
Time-shift experiment. The time-shift experiment was used to understand host and parasite evolution over the course of the epidemic. Specifically, the same panel of host genotypes used to initiate the pond populations was exposed to either the ancestral parasite, or to parasite samples collected from each population at the end of the epidemic, following a fully factorial design.
We established maternal lines for each of the 12 Daphnia genotypes used in the pond experiment. There were three replicates per genotype; each replicate consisted of eight adult animals in 100 ml of artificial media. The Daphnia were fed 0.5 ABS chemostat-grown C. vulgaris algae per Daphnia per day. Jars were incubated at 20 °C on a 12 h light:12 h dark cycle, and their media was changed three times per week. Offspring from early instars were taken from the second brood for use in the time-shift assay.
The experimental design consisted of a factorial manipulation of the 12 host genotypes and parasite samples collected from each pond (n = 16) plus the original (ancestral) parasite mixed isolate used to seed the populations. There were three independent replicate parasite isolates collected from each pond and a further three replicate isolates of the ancestral parasite (17 parasite treatments; three replicates per treatment). On the day of treatment exposure, neonates from each maternal line were assigned to experimental jars (eight per jar, in 100 ml of artificial media) and allocated to parasite treatments following a split-clutch design. There was a total of 612 experimental jars (4,896 Daphnia). Each jar received a dose of 2 × 10 5 Pasteuria spores and was kept under identical conditions as the maternal lines. After 48 h exposure to the Pasteuria spores, the experimental Daphnia were transferred into fresh media. The infection status of each Daphnia was determined by eye 25 days post exposure.
Using the results of these infection experiments for each host-parasite combination, we calculated transmission rate (β, spores l −1 d −1 ) using the following equation: where Z 0 is the starting density of spores, t is the duration of the trial exposure, S t is the density of uninfected hosts at the end of the exposure and S 0 is the initial density of hosts.
Dissection of host-parasite (co)evolution. By combining transmission rate data from the time-shift experiment with relative genotype frequency data from the pond experiment, we dissected the various host and parasite contributions towards the evolution of transmission rate. To achieve this, we calculated the change in parasite transmission rate over the course of the season and its three contributory components (equation (2)): change in parasite transmission rate due to evolution of host resistance to the ancestral parasite (hereafter, change in host resistance, Δβ h ); change in parasite transmission rate due to evolution of parasite infectivity to a set of reference hosts (hereafter, change in parasite infectivity, Δβ p ); and change in parasite transmission rate due to evolution of parasite infectivity to the evolved host population (non-additive coevolution and hereafter, coevolution, Δβ hp ).
We used two essential pieces of information to determine how host evolution, parasite evolution and coevolution contributed to changes in overall transmission rate for each population: the change in the relative frequency of each host genotype within each population during the course of the pond experiment; and the difference in the susceptibility of these genotypes relative to the ancestral parasite mix used to seed the populations and the parasite samples collected at the end of the epidemic.
First, we calculated the relative frequency of each genotype within each pond, w h;t I , at the end of the epidemic. This was done as follows: where P h,t is the frequency of host genotype h at time t and n h is the total number of host genotypes used to seed the population (in this case, n h = 12). The coevolution experiment started at t = 0, when all hosts had a genotype frequency of 1, and ended at t = 1. Then, for each population, we calculated the overall change in mean transmission rate. This was done by determining the change in parasite transmission rate for each host genotype between the end of epidemic parasite samples and the ancestral parasite sample, and weighting by the change in host genotype frequency to calculate a mean for each population: where β h,t is the transmission rate of each host genotype. Next, we calculated the mean change in transmission rate due to populationlevel evolution of host resistance to the ancestral parasite (Δβ h ) by calculating the mean resistance to the ancestral parasite weighted by the change in host relative genotype frequency for each population (equation (5)) and the mean change in transmission rate due to parasite evolution in the capacity to infect the ancestral host population (Δβ p , equation (6)): Finally, we calculated mean change in transmission rate due to host-parasite coevolution (that is, the non-additive component of disease evolution, Δβ hp ) using equation (2).
To visualize how changes in host resistance, parasite infectivity and coevolution covaried, we made bivariate plots of Δβ h , Δβ p and Δβ hp using vectors.
Quantifying ecological variation among ponds. We calculated mean values (and also variance for temperature) for each of the ten ecological variables over the early half of the epidemic season (over 12 sampling dates; Julian days 106-200). Initially, we tested the effects of the mixing treatment and then fitted separate linear models to examine the relationships between these ten variables and each of Δβ h , Δβ p and Δβ hp ; we evaluated the statistical significance of these relationships after applying a sequential Holm-Bonferroni adjustment for multiple comparisons 32 . Next, we conducted a PCA (using the R function princomp 33 ) on the ten biotic and abiotic environmental variables to generate a multivariate measure of ecological variation across the pond populations ( Supplementary Fig. 1). We identified the first four principal components as the minimum number of principal components necessary for explaining over 80% of the combined variation, following standard practice 34 , and used these in subsequent analyses. For outlier detection, we calculated the squared Mahalanobian distances of each population from the mean and compared these values with the critical threshold for the Mahalanobis distance based on a χ 2 distribution, with a critical α value of 0.05. We found that all populations were below the threshold value for outlier detection and thus all of populations were retained.

Testing for associations between ecological variation and (co)evolutionary trajectories.
We conducted two separate analyses to test for relationships between variation in disease coevolutionary trajectories and wider ecological variation. First, we tested whether pairwise differences in ecological conditions among populations were associated with pairwise differences in disease coevolutionary trajectories. We calculated population differences in ecological conditions (δ eco ), made up of the first four principal components (over 80% of combined variation), using the Mahalanobian distances between all of the possible pairwise comparisons of populations and the R package StatMatch v1.3.0 35 . We then calculated the overall multivariate distances for net disease coevolution (δ coevo ), that is, differences in change in parasite transmission rates as a composite for differences across three dimensions: host evolution, parasite evolution and coevolution. We then tested for a relationship between δ eco and δ coevo using a Mantel test fitted using the ecodist package 36 .
Second, we used SEM to dissect the various relationships between ecological variation, epidemic size and the components of coevolution. This was done using the piecewiseSEM package v2.0.2 in R 37 . SEM allows the evaluation of different causal pathways between variables, and therefore can evaluate support for alternative mediating variables that produce similar associations. We specified two global SEMs (Supplementary Fig. 2 Table 3) with the following variables: mixing, ecological variation (PC1 of the previously described PCA), epidemic size, change in host resistance (Δβ h ), change in parasite infectivity (Δβ p ) and coevolution (Δβ hp ). The hypothetical causal relationships between the variables included in these SEMs are outlined below.

and Supplementary
Mixing. Mixing was an experimental treatment whereby 6 of the 16 populations were stirred on a weekly basis. We predicted that this would have a significant effect on the ecological variables. For example, our previous work has shown that mixing significantly changes Daphnia host population densities and affects epidemic size 31 .
Ecology. Ecological variation was represented by PC1, which explained 36.0% of the overall variation, extracted from the PCA of the multiple environmental variables measured during the pond experiment. PC1 was mainly associated with low mean temperature, high chlorophyll concentrations and high predator density. The positive effects of temperature and negative effects of predation on parasite prevalence have been well documented in Daphnia disease systems 13,31,38,39 . Therefore, we predicted that our measure of ecological variation would be negatively associated with epidemic size and would be associated with the components of transmission rate evolution (changes in host resistance, parasite infectivity and coevolution).
Epidemic size. Epidemic size (integrated parasite prevalence, calculated by integrating the area under the time series of empirically determined prevalence for each mesocosm) could potentially be both a cause and a consequence of host evolution, parasite evolution and coevolution. There is ample evidence from previous studies that epidemics exert parasite-mediated selection and can cause the evolution of host resistance [40][41][42][43] , and that rapid host evolution of resistance can bring epidemics to an end 44 . Given the bidirectional relationship between these variables, we expected that there would be covariation between epidemic size and changes in host resistance, parasite infectivity and coevolution, but made no prediction about the direction of causality.
Change in Δβ h , Δβ p and Δβ hp . We developed two SEMs to test between two hypothetical relationships between epidemic size, ecology and different aspects of disease evolution. Hypothesis one is that ecology directly drives both epidemic size and all three components of disease evolution (Supplementary Fig. 2). Hypothesis two is that ecology affects epidemic size, host evolution of resistance and parasite evolution of infectivity, but that decreases in host resistance (that is, increased transmission rate) should negatively affect coevolution and increases in parasite infectivity should positively affect coevolution. Following our prediction that the wider environment has a greater impact on hosts compared with parasites, we expected that there would be asymmetry in the strength of the relationship between these different components of evolution with coevolution, such that hosts significantly affect coevolution more than parasites.
After fitting the two SEMs, we tested which provided the superior fit using the BIC. We chose the BIC over Akaike's information criterion and Akaike's information criterion corrected for small sample sizes because the BIC has been shown to better predict model performance when there is unobserved heterogeneity in the data 45 , which seems highly likely in both our genotype frequency and ecological variable data. We then conducted Fisher's C tests (Shipley's tests of directed separation 46 ) on the best-fitting model to discover potentially relevant relationships that had been excluded from the model. Finally, to achieve greater statistical power to test the significance of each of the proposed relationships, we divided the best performing global SEM into two submodels. It should be noted that the parameter estimates for each of the unidirectional relationships in the submodels were identical to the corresponding parameter estimates in the global model.
Reporting Summary. Further information on research design is available in the Nature Research Reporting Summary linked to this article.

code availability
All companion code is available on Dryad at https://doi.org/10.5061/dryad. qv9s4mwd6. As we are actively researching these datasets, we ask that researchers kindly contact us if they are planning to use the data for reasons other than reproducing the findings of our paper.

nature research | reporting summary
April 2020 Corresponding author(s): Stuart Auld Last updated by author(s): Jan 8, 2021 Reporting Summary Nature Research wishes to improve the reproducibility of the work that we publish. This form provides structure for consistency and transparency in reporting. For further information on Nature Research policies, see our Editorial Policies and the Editorial Policy Checklist.

Statistics
For all statistical analyses, confirm that the following items are present in the figure legend, table legend, main text, or Methods section.

n/a Confirmed
The exact sample size (n) for each experimental group/condition, given as a discrete number and unit of measurement A statement on whether measurements were taken from distinct samples or whether the same sample was measured repeatedly The statistical test(s) used AND whether they are one-or two-sided Only common tests should be described solely by name; describe more complex techniques in the Methods section.
A description of all covariates tested A description of any assumptions or corrections, such as tests of normality and adjustment for multiple comparisons A full description of the statistical parameters including central tendency (e.g. means) or other basic estimates (e.g. regression coefficient) AND variation (e.g. standard deviation) or associated estimates of uncertainty (e.g. confidence intervals) For null hypothesis testing, the test statistic (e.g. F, t, r) with confidence intervals, effect sizes, degrees of freedom and P value noted Data Policy information about availability of data All manuscripts must include a data availability statement. This statement should provide the following information, where applicable: All studies must disclose on these points even when the disclosure is negative.

Study description
This study tests how ecological differences among ponds affected the trajectories of host-parasite coevolution. Each pond was seeded with an identical suite of twelve host genotypes (the crustacean Daphnia magna), and the same initial dose of bacterial parasite (Pasteuria ramosa; from the same mastermix of parasite strains). Ponds were set to different depths in the ground and thus had different average temperatures. In addition, half of the ponds experienced a mixing treatment to simulate population disruption. We recorded biotic and abiotic ecological variation over the course of the epidemic. We sampled 20-30 hosts per pond at the end of the season, after the peak epidemic and genotyped them at 15 microsatellite loci. In addition, we sampled 90 infected Daphnia from each pond and stored the samples individually for a subsequent time-shift experiment.
Immediately prior to the time-shift experiment, Infected Daphnia were allocated to one of three experimental replicates per pond and homogenized (30 infected Daphnia per replicate). The experimental design consisted of a factorial manipulation of the 12 host genotypes and parasite samples collected from each pond plus three replicates of the original parasite mixed isolate used to seed the populations (hereafter referred to as the ancestral parasite).
Using both the host genotype frequency data, and infection outcome data in the time-shift experiment, we then calculated the evolution of parasite transmission in each pond due to host evolution of resistance to the ancestral parasite, parasite evolution of infectivity in a changing host population, and non additive evolution (coevolution), where parasite populations get proportionally better or worse at infecting specific genotypes. Using these three axes of evolution, we determined the overall coevolutionary trajectory for each pond population over its epidemic.
In addition, we conducted a principal components analysis of the ecological variables in order to determine multivariate ecological variation among ponds. By calculating the pairwise Mahalarobian differences in both ecological and coevolutionary variation, we were able to test how differences in ecology were associated with differences in coevolutionary trajectory.
Finally, using Structural Equation Modelling, we were able to dissect the mechanism through which ecological variation affected coevolutionary trajectory.

Research sample
The pond experiment comprised of 12 unique genotypes of the facultatively sexual crustacean Daphnia magna (Cladocera). We originally sampled 21 unique genotypes from Kaimes farm, Leitholm, Scotland. We genotyped each of the 21 Daphnia clonal lines using 15 microsatellite loci , and selected the 12 most dissimilar multilocus genotypes for the mesocosm experiment. Before the the pond experiment and time-shift experiement, replicate lines of each Daphnia of the 12 genotypes were maintained in a state of clonal reproduction for three generations to reduce variation due to maternal effects.
Meanwhile, we exposed ~20 Daphnia from each of the 21 Daphnia clonal lines to the original sediment samples and isolated those hosts that became infected with Pasteuria (total = 224 infected Daphnia, with a minimum of one infection per genotype). We then propagated these spores by exposing Pasteuria spores from each infected Daphnia to a further 80 healthy Daphnia of the same genotype. After 35 days, these Daphnia were homogenized, pooled and the density of spores was determined. We then performed a second round of propagation. After three rounds of infection (isolation followed by two rounds of propagation), all spore samples were pooled and the total number was determined. This final spore suspension was the parasite sample mastermix; it was subdivided and stored frozen. The parasite mastermix was used to seed the mesocosms and also used as the ancestral parasite samples in the time-shift experiment.
We chose the Daphnia-Pasteuria system because: (1) Daphnia naturally live in small bodies of water so our experimental ponds were biologically reasonable; (2) Infection is easy to determine by eye, meaning that parasite prevalence could be monitored non-invasively; and (3) Daphnia reproduce asexually throughout the season, so we were able to establish replicate ponds with an identical suite of Daphnia, track individual host genotypes over tim,e and also conduct lab-based experiments on the same suite of genotypes;

Sampling strategy
The pond experiment began on 2nd April 2015 (Julian day 98). Between the 2nd April and the 17th November 2015, we measured key abiotic and biotic ecological variables on a weekly basis. Twenty-thirty Daphnia were randomly sampled from each pond for genotyping, and a further 90 infected Daphnia were sampled for the time-shift experiment after peak epidemic (17th November 2015; Julian Day 321).

Data collection
Pond environmental data was collected weekly by June Brand. Daphnia demographic data was collected by Stuart Auld, also weekly, by subsampling each population with a net and determining the densities of healthy Daphnia, infected Daphnia, juveniles, and insect larvae predators. All microsatellite genotyping was performed by June Brand.The time-shift experiment was performed by Stuart
Timing and spatial scale The pond experiment began on 2nd April 2015 (Julian day 98). Between the 2nd April and the 17th November 2015, we measured key abiotic and biotic ecological variables on a weekly basis. Twenty-thirty Daphnia were randomly sampled from each pond for genotyping, and a further 90 infected Daphnia were sampled for the time-shift experiment after peak epidemic (17th November 2015; Julian Day 321). The pond experiment ended on this date.

Data exclusions
If no data were excluded from the analyses, state so OR if data were excluded, describe the exclusions and the rationale behind them, indicating whether exclusion criteria were pre-established.

Reproducibility
Describe the measures taken to verify the reproducibility of experimental findings. For each experiment, note whether any attempts to repeat the experiment failed OR state that all attempts to repeat the experiment were successful.

Randomization
Mixing and temperature treatments were haphazardly distributed across the experimental ponds and mean temperature was not different between mixing treatments (mean temperature: t = 0.04, df = 17.87, p = 0.97).
For the time-shift experiments, neonates from each maternal line were allocated to parasite treatments following a split-clutch design. Each of the replicates were exposed to one of three parasite isolates sampled from each pond. Once the replicates were assigned their unique identifying number, they were randomly allocated to different trays. Location within each tray and the tray location within the lab was then randomised on a daily basis.

Blinding
All experimental genotype analysis was performed double blind -each sampled Daphnia was allocated a unique identifier and the pond identification was only known after allele scoring had been performed. For the time-shift experiment, each experimental replicate was assigned a unique number following exposure to the allocated parasite treatment. The treatment details were only reconciled with this unique number after the experiment was concluded and all data was entered.