Inferring Ancestral Recombination Graphs from Bacterial Genomic Data

Homologous recombination is a central feature of bacterial evolution, yet it confounds traditional phylogenetic methods. While a number of methods specific to bacterial evolution have been developed, none of these permit joint inference of a bacterial recombination graph and associated parameters. In this article, we present a new method which addresses this shortcoming. Our method uses a novel Markov chain Monte Carlo algorithm to perform phylogenetic inference under the ClonalOrigin model. We demonstrate the utility of our method by applying it to ribosomal multilocus sequence typing data sequenced from pathogenic and nonpathogenic Escherichia coli serotype O157 and O26 isolates collected in rural New Zealand. The method is implemented as an open source BEAST 2 package, Bacter, which is available via the project web page at http://tgvaughan.github.io/bacter.

R ECOMBINATION plays a crucial role in the molecular evolution of many bacteria, in spite of the clonal nature of bacterial reproduction. Indeed, for a large number of species surveyed in recent studies (Vos and Didelot 2009;Fearnhead et al. 2015), homologous recombination was found to account for a similar or greater number of nucleotide changes than point mutation.
However, many traditional phylogenetic methods (Huelsenbeck and Ronquist 2001;Drummond et al. 2002;Guindon and Gascuel 2003) do not account for recombination. This is regrettable for several reasons. First, ignoring recombination is known to bias phylogenetic analyses in various ways such as by overestimating the number of mutations along branches, artificially degrading the molecular clock hypothesis, and introducing apparent exponential population growth (Schierup and Hein 2000). Second, much of modern computational phylogenetics extends beyond the inference of phylogenetic relationships and instead focuses on the parametric and nonparametric inference of the dynamics governing the population from which the genetic data are sampled. In this context, the phylogeny is merely the glue that ties the data to the underlying population dynamics. Recombination events contain a strong phylogenetic signal, so incorporating recombination into the phylogenetic model can significantly improve analyses. For instance, Li and Durbin (2011) used a recombination-aware model to recover detailed ancestral population dynamics from pairs of human autosomes, a feat which would have been impossible without the additional signal provided by the recombination process.
The standard representation of the phylogenetic relationship between ancestral lineages when recombination is present is the ancestral recombination graph (ARG) (Griffiths 1981;Hudson 1983), a timed phylogenetic network describing the reticulated ancestry of a set of sampled taxa. Several expected result of the crossover resolution of the Holliday junction in eukaryotic recombination. This assumption, which is often anchored in the choice to base the inference on the coalescent with recombination (Wiuf and Hein 1999), is not generally appropriate for bacterial recombination, where there is usually a strong asymmetry between the quantity of genetic material contributed from each "parent." Alternatively, a series of methods introduced by Didelot and Falush (2007), Didelot et al. (2010), and Didelot and Wilson (2015) directly target bacterial recombination by employing models based on the coalescent with gene conversion (Hudson 1983;Wiuf 2000;Wiuf and Hein 2000). These models acknowledge that the asymmetry present in the bacterial context allows for the definition of a precisely defined clonal genealogy-the clonal frame (CF)-which represents not only the true reproductive genealogy of a given set of bacterial samples, but also the ancestry of the majority of their genetic material.
In the first article, Didelot and Falush (2007) presented a method for performing inference under a model of molecular evolution, which, in combination with a standard substitution model, includes effects similar to those resulting from gene conversion; instantaneous events that simultaneously produce character-state changes at multiple sites within a randomly positioned conversion tract. This model does not consider the origin of these changes: it dispenses entirely with the ARG and can be considered a rather peculiar substitution model applied to evolution of sequences down the CF. Despite this, it does allow the Markov chain Monte Carlo (MCMC) algorithm implemented in the associated ClonalFrame software package to jointly infer the bacterial CF, conversion rate, and tractlength parameters; neatly avoiding the branch-length bias described by Schierup and Hein (2000). Didelot and Wilson (2015) introduced a maximum likelihood method for performing inference under the same model, making it possible to infer CFs from whole bacterial genomes as opposed to the short sequences that the earlier Bayesian method could handle.
In a second article, Didelot et al. (2010) present a different approximation to the coalescent with gene conversion which retains the ARG but assumes that the ARG has the form of a tree-based network (Zhang 2015), with the CF taking on the role of the base tree. While acknowledging that their model could be applied to jointly infer the CF and the conversions, the algorithm they present is limited to performing inference of the gene conversion ARG given a separately inferred CF. This choice permitted the application of their model to relatively large genomic data sets.
This model was also used recently by Ansari and Didelot (2014), who exploit the Markov property of the model with regard to the active conversions at each site along an aligned set of sequences to enable rapid simulation under the model. These simulations were used in an approximate Bayesian computation scheme (Beaumont et al. 2002) to infer the homologous recombination rate, tract lengths, and scaled mutation rate from full genome data, as well as to assess the degree to which the recombination process favors DNA from donors closely related to the recipient. As with the earlier study, this method requires that the CF be separately inferred.
In this article we present a Bayesian method for jointly reconstructing the ARG, the homologous conversion events, the expected conversion rate and tract lengths, and the population history from genetic sequence data. Our approach assumes the ClonalOrigin model of Didelot et al. (2010), extended to allow for the piecewise-constant or piecewiselinear variations in population size. It relies upon a novel MCMC algorithm which uses a carefully designed set of proposal distributions to make traversing the vast state space of the model tractable for practical applications. Unlike earlier methods, our algorithm jointly infers the CF, meaning that the inference is a single-step process. This has a number of advantages such as improving the quality of the resulting uncertainty estimates when phylogenetic signal is poor, and allowing the CF itself to be inferred under a more realistic model of evolution under homologous gene conversion.
In addition to the inference method itself, we present a basic technique for summarizing the sampled ARG posterior. Our approach is an extension of the maximum clade credibility tree approach (as described by Heled and Bouckaert 2013) to summarizing phylogenetic tree posteriors in which a summary of the CF is annotated with well-supported conversion events.
We demonstrate that our method can accurately infer known parameters from simulated data and apply it to a set of Escherichia coli ribosomal multilocus sequence typing (rMLST) (Jolley et al. 2012) sequences derived from isolates collected from in and around the Manawatu region in New Zealand. The method reveals details of previously unobserved gene flow between pathogenic and nonpathogenic populations belonging to the serotype O157.
A software implementation of our method is distributed as a publicly available BEAST 2 (Bouckaert et al. 2014) package. This gives the sampler a substantial amount of flexibility, allowing it to be used in combination with complex substitution models and a wide variety of prior distributions. Details on how to obtain and use this package are given on the project website at http://tgvaughan.github.io/bacter.

The ClonalOrigin genealogical model
In contrast to eukaryotes where recombination primarily occurs during meiosis, bacteria generally undergo recombination due to mechanisms that are not directly related to the process of genome replication. These mechanisms generally only result in the transfer of small fragments of genetic material. A result of this is that every homologous recombination event in bacteria is comparable to a gene conversion event, regardless of the underlying molecular biology. A good model for the genealogy of bacterial genomes is therefore the coalescent with gene conversion: a straight-forward extension to the Kingman n-coalescent (Kingman 1982a,b) in which (a) lineages may bifurcate as well as coalesce, and (b) lineages are associated with a subset of sites on each of the sampled genetic sequences to which they are ancestral. At each bifurcation event, a contiguous range of sites is chosen for "conversion" by selecting a starting site uniformly at random and a tract length from a geometric distribution. The ancestry of the converted sites follows one parental lineage, while that of the unconverted sites follows the other.
The ClonalOrigin model is a simplification of the coalescent with gene conversion in which lineages are labeled as either clonal or nonclonal, with nonclonal lineages assumed to be free from conversion events (i.e., they may not bifurcate) and pairs of these lineages forbidden from coalescing. As Didelot et al. (2010) argue, this simplified process is a good approximation to the full model in the limit of small expected tract length (relative to genome length) and low recombination rate. It also possesses features that make it an attractive basis for practical inference methods. First among these is that, conditional on the CF, the conversion events are completely independent. In our context, this simplifies the process of computing the probability of a given ARG and proposing the modifications necessary when exploring ARG space using MCMC.
We briefly reiterate the mathematical details of the model described in Didelot et al. (2010) using terminology more appropriate for our purposes. We define the ClonalOrigin recombination graph G 5 ðC; RÞ where C represents the CF and R is a set of recombinant edges connecting pairs of points on C: The CF is assumed to be generated by an unstructured coalescent process governed by a time-dependent effective population size NðtÞ; where t measures time before the present. That is, the probability density of C can be written Here Y is the set of internal (coalescent) nodes between edges of C; including the root node o; and ft i j i 2 Yg are the ages of these nodes. The term kðtÞ represents the number of CF lineages extant at time t: Conversion events r 2 R appear at a constant rate on each lineage of C and thus their number jRj is Poisson distributed with mean rT P b2B ðL b 1 d 2 1Þ; with T being the sum of all branch lengths in C: Here r is the per-site, per-unit-time rate of homologous gene conversion, d is the expected conversion tract length and b 2 B are the loci for which length L b sequence alignments are available. Each conversion is defined by r 5 ðl; u; b; x; yÞ where l and u identify points on C at which the recombinant lineage attaches, with the age of l less than that of u: The element b indicates the locus to which the conversion applies, and x and y identify the start and end, respectively, of the range of sites affected by the conversion. The point l $ f ðl j CÞ is chosen uniformly over C; while u is drawn from the conditional coalescent distribution, f ðu j l; C; NÞ 5 exp 2 Z t u t l kðtÞ NðtÞ where t l and t u are the ages of points l and u; respectively. The locus b is chosen with probability Pðb j B; dÞ 5 ðL b 1 d 2 1Þ= P b92B ðL b9 1 d 2 1Þ; the site x is drawn from the distribution Pðx j b; dÞ 5 ½Iðx 5 1Þd 1 1=ðl 1 d 2 1Þ; and the site y is drawn from Pð y j x; b; dÞ 5 d 21 ð12d 21 Þ y2x 1 Ið y 5 L b Þð12d 21 Þ L b 2x : [In these equations IðÁÞ is the indicator function.] The full probability density for a ClonalOrigin ARG is then simply the product: where the jRj! accounts for independence with respect to label permutations of the recombination set R: Figure 1 illustrates the various elements of the ClonalOrigin model and associated notation.

Bayesian inference
Performing Bayesian inference under the ClonalOrigin model shares many similarities with the process of performing inference under the standard coalescent. The goal is to characterize the joint posterior density: f ðG; N; d; r; m j DÞ } P lik ðD j G; mÞf CO ðG j N; d; r; BÞ 3 f prior ðN; d; r; mÞ; where D represents multiple sequence alignments for each locus in B and m represents one or more parameters of the chosen substitution model. The distributions on the righthand side include P lik ; the likelihood of the recombination graph; f CO ; the probability density of the graph under the ClonalOrigin model discussed above; and f prior ; the joint prior density of the model parameters.
To define the ARG likelihood, first consider that every ARG may be mapped onto a set T of "local" trees describing the ancestry of contiguous ranges of completely linked sites in the alignment. The likelihood of G is expressed in terms of local trees as the following product where D i is the portion of the alignment whose ancestry is described by local tree T i 2 T and P F ðD i j T i ; mÞ is the standard phylogenetic tree likelihood (Felsenstein 2003).
Since it is possible for conversions to have no effect on T ; there is no one-to-one correspondence between G and T : This suggests that certain features of G may be strictly nonidentifiable in terms of the likelihood function. As Bayesian inference deals directly with the posterior distribution, this nonidentifiability will not invalidate any analysis, provided that f prior is proper. However, the existence of nonidentifiability has practical implications for the design of sampling algorithms, as we discuss in the following section.

MCMC
We use MCMC to sample from the joint posterior given in Equation 4. This algorithm explores the state space of x 5 ðG; N; d; r; mÞ (or some subspace thereof) using a random walk in which steps from x to x9 are drawn from some proposal distribution qðx9 j xÞ and accepted with a probability that depends on the relative posterior densities at x9 and x: In practice, qðx9 j xÞ is often expressed as a weighted sum of proposal densities q i ðx9 j xÞ (also known as proposals or moves) which individually proposes alterations to some small part of x: While there is considerable freedom in choosing a set of moves, their precise form can dramatically influence the convergence and efficiency of the sampling algorithm. Proposals should not generate new states that are too bold (accepted with very low frequency) nor too timid (accepted with very high frequency): both extremes tend to lead to chains with long autocorrelation periods. In this section we present an informal outline of the moves used in our algorithm. (Refer to the Appendix for a detailed description.) For the subspace made up of the continuous model parameters d; r; m; and N; choosing appropriate proposals is relatively trivial as standard proposals for sampling from ℝ n are sufficient. In our algorithm we use the univariate scaling operator described by Drummond et al. (2002), which can be made more or less bold simply by altering the size of the scaling operation.
For the ARG itself, assembling an appropriate set of moves is more difficult. Even determining exactly what constitutes a timid or bold move in G space is hard to determine without detailed knowledge of the target density. Our general approach here is to design proposals that (a) only minimally affect the likelihood of G where possible, and (b) draw any significant changes from the prior that the ClonalOrigin model places on G: The design of these proposals is assisted by our knowledge of the identifiability issue considered in the previous section: there is a many-to-one mapping from G to the local tree set T ; and the ARG likelihood depends only on T : Thus, ARG proposals that minimally effect the likelihood are those that propose a G9 that maps to the same or similar T : The proposals for G fall into two groups, the first of which deals exclusively with the set of conversions R: These include all three moves described by Didelot et al. (2010) (we consider the conversion add/remove pair to be two halves of a single proposal), along with six additional simple moves aimed at quickly exploring the ARG state space conditional on C: Examples include a conversion merge/split proposal that merges pairs of conversions between the same pair of edges on the CF that affect nearby ranges of sites or splits single conversions into such pairs, a proposal which reversibly replaces a single conversion between two edges with a pair involving a third intermediate edge, and a proposal which adds or removes conversions that do not alter the topology of the CF.
Proposals in the second group propose joint updates to both the CF C and the conversions R: Some of these moves are quite bold (and thus tend to be accepted rarely), but are very important for dealing with topological uncertainty in the CF. The general strategy for each move is to apply one of the tree proposals from Drummond et al. (2002) to C and to simultaneously modify the conversions in R to ensure both compatibility with the C9 and to minimize the effect of the proposal on both the likelihood and the ARG prior. The changes to C can for the most part be decomposed into primitive operations that involve selecting a subtree, deleting the edge e attaching that subtree to the rest of the CF at time t i ; then reconnecting the subtree via a new edge e9 to a new point on C at time t 9 i : Modification of R is done using an approach (depicted in Figure 2) that consists of two distinct forms. The first form, the "collapse," is applied whenever t 9 i , t i and involves finding conversions for which u or v are on the edge above the subtree and attach at times t l or t u greater than t 9 i : These attachment points are moved from their original position to contemporaneous points on the C lineage ancestral to e9. The second form, the "expansion," is applied when t 9 i . t i and is the inverse of the first: conversion attachments u or v at times t i , t fl;ug , t 9 i are moved with some probability to contemporaneous positions on e9.
In concert, these proposals allow us to effectively explore the entire state space of x: Summarizing the ARG posterior Bayesian MCMC algorithms produce samples from posterior distributions rather than point estimates of inferred quantities. These approaches are superior because they give us the Figure 1 Schematic representation of a recombination graph G for a single locus b; with CF C and j R j 5 1 conversion r: The conversion attaches to C at points l and u and affects sites x through y of the L b sites belonging to locus b: The horizontal bars represent ancestral sequences belonging to each lineage and colors are used to denote which samples each site is ancestral to, with white indicating sites ancestral to no samples. The graph on the right displays the associated CF lineagesthrough-time function kðtÞ; together with the times used in computing f ðG j N; d; r; BÞ: These include the conversion attachment times t l and t u ; together with ages of coalescent nodes i and i9. ðHere i9 5 o:Þ means to directly quantify the uncertainty inherent in the inference. For the very high dimensional state space that ARGs (even the ClonalOrigin model's tree-based networks) occupy, actually visualizing this uncertainty and extracting an overall picture of the likely ancestral history of the sequence data are nontrivial.
A similar problem exists for Bayesian phylogenetic tree inference. Given the maturity of that field, it should not be surprising that a large number of solutions exist. The majority of these solutions involve the assembly of some kind of summary or consensus tree (see chapter 30 of Felsenstein 2003 for an overview, or Heled and Bouckaert 2013 for a recent discussion). While conceptually appealing, the replacement of a posterior distribution with a single tree can very easily lead to the appearance of signal where there is none, so care must be taken. At least one method exists that avoids this problem: the DensiTree software (Bouckaert 2010) simply draws all of the trees in a given set with some degree of transparency, making it possible to actually visualize the distribution directly.
Unfortunately, the approach taken by DensiTree cannot be easily applied to ARGs, since the recombinant edges introduce significant visual noise, making patterns difficult to discern. Nor can any of the standard summary methods be applied directly.
Instead, we use a summary of the CF posterior as a starting point to produce summary ARGs, as described in Algorithm 1. In the algorithm, MCC refers to the maximal clade credibility tree (see, for instance, Heled and Bouckaert 2013), and the value of a in step 3(c) imposes a threshold on the posterior support necessary for a conversion to appear in the summary. The relationship between the sampled conversions and the summary conversions is illustrated in Figure 3. Testing with simulated data demonstrates that the method is capable of recovering useful summaries. However, one significant drawback is that the algorithm only groups together sampled conversions that appear between identical (in the sense described in the algorithm) pairs of CF edges. This means that a single conversion with significant uncertainty in either of its attachment points u or l may appear as multiple conversions in the summary. As a result, we still consider the problem of how best to summarize the posterior distribution over ARGs a target for future research.

Data availability
The methods presented in this article are implemented in the open source BEAST 2 package, Bacter (http://tgvaughan. github.io/bacter). The BEAST 2 XML files necessary to reproduce both the simulated and real data analyses are provided as Supplemental Material, File S2.  Figure 2 Schematic representation of the collapse/expand strategy used by the MCMC algorithm to update conversions following the movement of a CF edge. (A) Illustrates a proposal to replace the thick black edge portion of the CF edge joined to p with the thick gray edge portion joint to q: Since t q , t p the collapse procedure is applied by moving affected conversion attachment points, highlighted with •, to contemporaneous points on the lineage ancestral to q: Any conversion with a new arrival point above the root is deleted from the new ARG. (B) Illustrates the reverse situation, where a CF edge attached at q is reattached at p: Since t p . t q the expand procedure is applied by moving any attachment points contemporaneous with a point on the newly extended portion of the CF edge to that point with some probability. Since p becomes the new CF root, new conversions with arrival points on the new CF edge at times older than the previous CF root are drawn from the ClonalOrigin prior.

Implementation and validation
The methods described here are implemented as a BEAST 2 package. This allows the large number of substitution models, priors, and other phylogenetic inference methods already present in BEAST 2 to be used with the ClonalOrigin model.
Despite the reuse of an existing phylogenetic toolkit, the implementation is still complex. As such, the importance of validating the implementation cannot be overstated. Our validation procedure involved two distinct phases: sampling from the ARG prior and performing inference of known parameter values from simulated data.
Sampling from the ARG prior: This first phase of the validation involves using the MCMC algorithm to generate samples from f CO ðG j N; r; dÞ; i.e., the prior distribution over ARG space implied by the ClonalOrigin model. Unlike the full posterior density, we can also sample from this distribution via direct simulation of ARGs. Statistical comparisons between these two distributions should yield perfect agreement. Assuming that errors in both the MCMC algorithm implementation and the ARG simulation algorithm are unlikely to produce identically erroneous results, this is a stringent test of all aspects of our implementation besides calculation of the ARG likelihood. Figure 4 displays a comparison between the histograms for a number of summary statistics computed from ARGs with five (noncontemporaneous) leaves sampled using our implementation of each method. The MCMC chain was allowed to run for 10 8 iterations with ARGs sampled every 10 4 steps, while the simulation method was used to generate 10 5 independent ARGs. The close agreement between the two sets of histograms is very strong evidence that our implementation of both algorithms is correct.
Inference from simulated data: A common way to determine the validity and usefulness of an inference algorithm is to assess its ability to recover known truths from simulated data. In contrast with sampling from the prior, inference from simulated data is sensitive to the implementation of the ARG likelihood. Here we use a well-calibrated (Dawid 1982) form of the test, which requires that known true values fall within the estimated 95% highest posterior density (HPD) interval 95% of the time.
The details of the validation procedure are as follows. First, 100 distinct 10-leaf ARGs were simulated under the Clona-lOrigin model with parameters r 5 0:01; d 5 500; and N 5 0:05: These ARGs were then used to produce an equivalent number of two-locus alignments, with each locus containing 5 3 10 3 sites. Finally, each simulated alignment was used as the basis for inference of the ARG using the MCMC algorithm described above, conditional on the known true parameters.
The circles in the graphs shown as Figure 5 display the fraction of the sampled marginal MCMC posteriors for the CF time to most recent common ancestor (tMRCA) and recombination event count which included the known true values as a function of the relative HPD interval width. The dashed lines indicate the fractions expected of a well-calibrated analysis. This close agreement therefore suggests that our analysis method is internally consistent in this regard, a result which strongly implies that our implementation is correct.

Example: E. coli
We applied our new method to the analysis of sequence data collected from a set of 23 E. coli isolates. The isolates were derived from from both humans and cattle and include both Shiga toxin-producing E. coli (STEC) and non-STEC representatives of the O26 and O157 serotypes. The analysis focused on the 53 loci targeted by rMLST (Jolley et al. 2012).
The analysis was performed under the assumption of a constant population, the size of which was given a lognormal prior ln N ð0; 2Þ: The Hasegawa-Kishino-Yano substitution model (Hasegawa et al. 1985) was used, with uniform priors placed on the relative site frequencies and a log-normal prior ln N ð1; 1:25Þ placed on the transition/ transversion relative rate parameter k: We also infer the relative substitution rate r=u with u being the average substitution rate per site. For this we use an informative lognormal prior ln N ð22:3; 1:5Þ; whose 95% HPD includes a previously published estimate of 1.024 (Didelot et al. 2012). The expected tract length parameter was fixed at d 5 10 3 sites.
Six unique instances of the MCMC algorithm were run in parallel. Five of these were run for 2:5 3 10 7 iterations while the sixth was run for 5 3 10 7 iterations, the longest of these taking $1 week to run on a modern computer. Comparison of the posteriors sampled by each of these chains demonstrated that convergence had been achieved. Final results were obtained by removing the first 10% of samples from each chain to account for burn-in and then concatenating the results. Once complete, the effective sample size for every model parameter and summary ARG statistic recorded surpassed 200.
The final results of this analysis are presented as Figure 6. First, Figure 6A displays a summary ARG produced from the sampled ARG posterior using a conversion posterior cutoff threshold of 0.4. This summary shows that four conversion events have posterior support exceeding this threshold. Three of these depict gene conversion events that transfer nucleotides between lineages ancestral to samples with O157 serotype. More specifically, the conversions result in gene flow from lineages ancestral to pathogenic (1STEC) samples to lineages ancestral to nonpathogenic (2STEC) samples. The remaining conversion event is indicative of a recent introgression from the O26 serotype into 2STEC O157.
This overall pattern is also reflected in Figure 6B, which displays the posterior distributions for the total number of nucleotides transferred by conversion events between 1/2STEC O157 ancestral lineages: the gene flow from 1STEC to 2STEC O157 is on average greater than that in the reverse direction. This asymmetry is, however, very slight-a fact that may be attributed to the presence of a large number of "background" conversions which individually lack the posterior support to be included in the summary, but which nevertheless contribute to the particular gene flow metric we have chosen.
Finally, Figure 6C displays the posterior distribution for the relative recombination rate parameter, giving a 95% HPD interval of [0.21, 1.44]. The log-normal prior density for the recombination rate is also shown and indicates that the data are informative for this parameter.

Discussion
Dealing appropriately with recombination in a phylogenetic setting is a difficult task for a number of reasons. First, the progressive bifurcation of lineages with increasing age steadily decrease the signal for these features in a given data set. Furthermore, the possibility of these bifurcations drastically increases the size of the state space occupied by the genealogy. Indeed, even for a small number of aligned sequences, the upper bound of the number of coalescent events influencing the evolution of those sequences is potentially huge: the total number of nucleotide sites in the alignment. Considering that the superexponential rate at which the number of binary trees grows as a function of sample size already presents complexity problems for computational phylogenetics, it is no surprise that models that explicitly consider recombination are not as widely used in genealogical inference.
Despite these challenges, Didelot and coauthors have shown repeatedly that traditional coalescent-based phylogenetic inference methods can be applied to such models, by applying carefully chosen simplifications to the coalescent with gene conversion which reduce the state space while maintaining sufficient realism in the important context of Figure 5 Coverage fraction vs. HPD interval width for (A) the CF tMRCA and (B) the recombination event count posteriors inferred from simulated sequence data. The s represents the observed coverage fraction, while the dashed lines indicate the coverage fraction to be expected from a well-calibrated analysis. bacterial evolution. In our article we have sought to continue in this tradition, and have demonstrated that one can indeed perform full joint inference of tree-based ARGs using a carefully constructed MCMC algorithm. Also, in our effort to narrow the technological gap between inference using the ClonalOrigin model and Bayesian inference performed using common nonrecombination-aware models, we have introduced a means of summarizing sampled tree-based ARG posteriors that is reminiscent of the methods often employed to summarize sampled tree posteriors.
Our joint approach has several advantages over the earlier method described by Didelot et al. (2010). That method involves separately inferring a point estimate of the CF under the model described by Didelot and Falush (2007) and conditioning inference of the rest of the ARG on this point estimate. First, as it does not rely on a point estimate of the CF, the joint approach more accurately characterizes the posterior for the ARG (and associated model parameters) and should yield more accurate estimates of statistical uncertainty when the statistical signal for the CF is weak. Properly representing this uncertainty is extremely important, as it is used to assess the strength of biological conclusions drawn from the inference.
Second, our joint estimation algorithm allows the CF, the recombinant edges, and the parameters to be inferred under a single self-consistent model (the ClonalOrigin model); a model which is a good approximation to a well-known mathematical model for bacterial evolution in the presence of homologous gene conversion (Hudson 1983;Wiuf 2000;Wiuf and Hein 2000). In contrast, the earlier method of Didelot et al. (2010) relies on a distinctly different model (the ClonalFrame model) of sequence evolution that does not allow for topological differences in marginal trees. It is therefore unsurprising that the joint method recovers the truth more often than the earlier approach (see File S1, and Figures S1 and S2 in particular, for details).
We must emphasize, however, that despite making significant headway we do not consider either the ClonalOrigin inference problem nor the problem of summarizing posterior distributions over tree-based networks to be in any way "solved." In the case of the inference problem, computational challenges relating to the way the algorithm scales with increasing frequency of recombination remain. This problem is tied directly to the large amount of computation required to calculate the ARG likelihood (Equation 5). The tree likelihood calculation is often the most computationally expensive calculation even in standard phylogenetic analyses, and recombination only multiplies this expense. It may be the case that improving this situation will require replacing the mathematically exact likelihood evaluation under a given substitution model with a carefully chosen approximation, but the feasibility and usefulness of this approach has yet to be fully investigated.
The problem of summarizing posterior distributions over tree-based networks would seem to be a fruitful line of future research. The algorithm presented here does seem to perform relatively well from an empirical standpoint, and to our knowledge is the first of its kind. However, it does have drawbacks relating to its propensity to misclassify conversions for which topological uncertainty exists (i.e., uncertainty in the CF edge to which one or both of its end-points attach) as multiple distinct conversions with a proportionally smaller posterior support. Solving this problem would seem to be nontrivial, as it requires the algorithm to identify a conversion in one sampled ARG with a conversion in a second ARG even when those conversions join distinct pairs of edges on the CF. However, we feel that tackling these and other related problems is a worthwhile endeavor, and one which should encourage mainstream adoption of recombination-aware Bayesian phylogenetic inference methods. In this appendix we lay out the details of the proposal operators used by the MCMC algorithm implemented described in the article. To do this, we require some additional nomenclature. We decompose the CF using the tuple C 5 ðV; E; tÞ: Here V 5 I [ Y with I being the set of leaf nodes and Y being the set of internal nodes, which contains the root node o: The set E contains the directed edges between nodes i; j 2 V; where an edge from i to j is written hi; ji: We use t 5 ft i j i 2 Vg to denote a set of node ages. The direction of an edge hi; ji is such that t i , t j : As noted in the manuscript, MCMC is an iterative algorithm for sampling from some target probability density pðxÞ by iteratively modifying the state x: At each step in the iteration, a specific proposal kernel q w ðx9 j xÞ is chosen from a fixed weighted distribution of such kernels, and a new value for the state x9 is drawn using that proposal. This new value is accepted with probability If the value is accepted it is assigned to x; otherwise x remains unchanged. The process then repeats. The term h w ðx9 j xÞ is a function which we refer to as the Hastings-Green factor or HGF for the proposal distribution, and ensures that the Markov chain defined by the MCMC algorithm is reversible. The HGF is uniquely defined by the proposal, but is often nontrivial to derive. Thus, each operator is presented below alongside its corresponding HGF.

ARG Scale Proposal
This operator selects a scaling factor f uniformly at random from ½a; a 21 where a 2 ð0; 1Þ is a tuning parameter for which smaller values yield bolder proposals. The age of every entity in the ARG, excluding leaf ages, is scaled by this one factor. The HGF for this proposal is where n is the number of entities scaled by the move.

Conversion Add/Remove
With probability 1=2; this operator either deletes a randomly selected conversion or creates a new conversion r 5 ðl; u; b; x; yÞ drawn directly from the prior f ðr j C; B; N; dÞ 5 f ðl j CÞf ðu j l; C; NÞ 3 Pðb j B; dÞPðx j b; dÞPð y j x; b; dÞ; where the terms on the right-hand side are those described in the manuscript. The HGF for the deletion form of the proposal is where r is the conversion selected for deletion. The HGF for the addition form is simply h cadd ðG9 j GÞ 5 1=h cdel ðG j G9Þ:

Detour Add/Remove
This operator improves mixing by allowing the sampler to transition directly between ARGs that have very similar local tree sets. It does this by proposing the addition or deletion of "detours": pairs of conversions ðr 1 ; r 2 Þ for which u 1 and l 2 lie on the same edge of C and for which the attachment times satisfy t u 1 , t l2 : With probability 1=2; either the deletion or the addition form of the operator is selected. For addition, a conversion r is selected uniformly at random from R: Two times t d1 and t d2 are drawn from Unifðt l ; t u Þ and labeled so that t d1 , t d2 : A nonroot node i is then chosen uniformly at random from V. Let i p be the parent of i: If u or l lie on hi; i p i; or it is not the case that both t d1 ; t d2 2 ½t i ; t ip ; then the proposal is immediately rejected. Otherwise, r is replaced with a pair of conversions r 9 1 5 ðl; u9; b; x; yÞ and r 9 2 5 ðl9; u; b; x9; y9Þ; where l9 and u9 are the points on hi; i p i with times t d1 and t d2 ; respectively, and x9, 9y, and b9 are drawn from the affected site region boundary priors Pðb j B; dÞ; Pðx j b; dÞ; and Pð y j x; b; dÞ: For deletion, a nonroot node i is chosen uniformly at random from V, and i p is defined as its parent. A pair of conversions, r 1 and r 2 ; are chosen uniformly at random satisfying the requirements u 1 6 ¼ l 1 ; u 2 6 ¼ l 2 ; u 1 lies on hi; i p i; and l 2 lies on hi; i p i: This pair is replaced by a single conversion r9 5 ðl 1 ; u 2 ; b 1 ; x 1 ; y 1 Þ: The HGF for the addition form is hi;i p i ðG9Þ is the number of conversions with u$ and l$ on distinct edges and where l$ lies on hi; i p i: For the deletion form the HGF is hi;ipi ðGÞQ ð2Þ hi;ipi ðGÞ À t u 2 2t l 1 Á 2 j R9 j Á Pðx 2 ; y 2 ; b 2 j B; dÞ: (A6)

Redundant Conversion Add/Remove
This operator adds or removes a conversion that mirrors an existing edge in C; meaning that the conversion does not introduce a change in the local tree topology. The boldness of the move is adjustable via the tuning parameter l: With probability 1=2; the addition or removal form of the operator is selected. For addition, a nonroot node i is drawn uniformly at random from V, and i p is defined as its parent. A new conversion r 5 ðl; u; b; x; yÞ is created with x; y; and b drawn from the prior Pðx; y; b j B; dÞ: The departure point l is drawn uniformly from the portions of edges around i with an age difference of at most l from t i : Similarly, u is drawn from the portions of edges around i p that differ in age by at most l from t i p : For removal, a nonroot node i is also drawn uniformly from V, with i p again defined as its parent. The subset S l hi;ipi of R consisting of those conversions which could have been generated by the addition form of the move applied to the same CF edge hi; i p i with a given l is constructed. A member r of this set is selected uniformly at random and is deleted.
The HGF for the addition form is where L l i is the sum of the lengths of the CF edge portions around i from which l is drawn. Similarly, L l i p is the sum of the lengths of the CF edge portions around i p from which u is drawn. The primed S l9 hi;i p i is the subset of R9 of conversions, including r; which could have been produced by this proposal.
For deletion, the HGF is

Merge/Split Conversion
This operator reversibly merges two conversions whose arrival and departure points share the same pair of CF edges. A locus b is drawn from the prior Pðb j B; dÞ: With probability 1=2; the merge or split form of the operator is selected. For merging, two conversions r 1 and r 2 are sampled without replacement from the subset R b & R containing only those conversions affecting locus b: This pair of conversions is replaced by a new conversion r9 5 ðl 1 ; u 1 ; b; x 1 _ x 2 ; y 1^y 2Þ: For splitting, conversion r is drawn from R b : Let i be the CF node below the edge containing l and j be the CF node below the edge containing u; and define i p and j p to be the parents of these nodes (in the instance that j is the root CF node, j p is not defined). Two sites m 1 and m 2 are drawn uniformly from the site range [x,y]. With probability 1=2; we either define x 1 9 5 x and x 2 9 5 m 1 or x 1 9 5 m 1 and x 2 9 5 x: Similarly, with probability 1=2 we either define y 1 9 5 y and y 2 9 5 m 2 or y 1 9 5 m 2 and y 2 9 5 y: Additionally, l 9 2 is a uniformly sampled point on the edge hi; i p i: In the case that j is not the root, u 9 2 is sampled uniformly from h j; j p i: Otherwise, the difference between the age of u9, t u9 ; and the age of the root, t j ; is drawn from the exponential distribution Exp½1=ðt u 2 t j Þ: Conversion r is then replaced by a pair of conversions r 1 9 5 ðl; u; b; x 1 9 ; y 1 9 Þ and r 2 9 5 ðl 2 9 ; u 2 9 ; b; x 2 9 ; y 2 9 Þ: The HGF for the merge form is and for the split form is

Converted Edge Hop
This operator simply repositions the arrival or departure point of a randomly chosen conversion to be a new point on the tree. It proceeds by choosing a conversion r uniformly at random from R: Then, if u is above the root of C or with probability 1=2; l9 is drawn from a uniform density over C and u9 is set to u: Otherwise, l9 is set to l and u9 is drawn from a uniform density over C: In either case, if t u9 . t l9 then r is replaced by a new conversion r9 5 ðl9; u9; b; x; yÞ: If this condition is not met, the proposal is rejected.
The HGF for this move is unity.

Converted Edge Flip
This is a simple proposal which reverses the direction of gene flow resulting from a given conversion. It is especially useful when this direction is not informed strongly (or at all) by the data. It involves firstly selecting a conversion r uniformly from R and defining e l as the CF edge containing the departure point l; and e u as the CF edge containing the arrival point u: If t u falls outside of the time interval spanned by e l ; or t l falls outside of the time interval spanned by e u ; the proposal is immediately rejected. Otherwise, we then define new departure and arrival points l9 and u9 such that t l9 5 t l and t u9 5 t u ; but with e l9 5 e u and e u9 5 e l : Finally, we replace the conversion r with r95 ðl9; u9; b; x; yÞ: The HGF for this move is unity.

Converted Edge Slide
This proposal "slides" a randomly selected arrival or departure point up or down the CF, where the maximum size of the slide relative to the height of C; t o ; is fixed by a tuning parameter b 2ð0; 1Þ: Firstly, the conversion is selected uniformly from R and a CF attachment point p is chosen uniformly from fl; ug An age increment Dt is then drawn uniformly from ½2bt 0 ; bt 0 : In the instance that Dt . 1; the new attachment point p9 (i.e., l9 or u9 depending on the choice of l or u for p) is chosen to be that point on the lineage ancestral to p with t p9 5 t p 1 Dt: (If p 5 l and t p9 . t u^to the move is immediately rejected.) On the other hand, if Dt , 0; the new attachment point p9 is chosen to be a point on a descendant lineage with t p9 5 t p 1 Dt: (If p 5 u and t p9 , t l ; the move is immediately rejected.) In the instance that t p9 is smaller than the age of the node below the CF edge containing p; there are multiple points on descendant lineages that satisfy this requirement. A particular point is chosen by tracing the CF lineage down from p and uniformly selecting the left-or right-child lineage of any CF node that is passed along the way to the final point p9. (If a leaf CF node is passed during this procedure the move is rejected immediately.) In either case, the original conversion r is replaced by a new conversion r9, defined as either ðl9; u; b; x; yÞ or ðl; u9; b; x; yÞ depending on whether p represents an arrival or departure point, respectively.
The HGF for the move is where sgnðDtÞ is the sign of Dt and where nðp; p9Þ is the number of nodes on the CF on the lineage between points p and p9.

Converted Region Swap
This proposal simply involves drawing two conversions r 1 and r 2 uniformly without replacement from R and swapping the loci and site ranges they affect. That is, the pair is replaced by a new pair r 1 9 5 ðl 1 ; u 1 ; b 2 ; x 2 ; y 2 Þ and r 2 9 5 ðl 2 ; u 2 ; b 1 ; x 1 ; y 1 Þ: The HGF for this move is unity.

Converted-Region (Boundary) Shift
The converted-region shift and converted-region boundary shift propose adjustments to the region affected by a given conversion. Both use a tuning parameter g that defines the maximum size of the adjustment that can be made. The proposals begin by a conversion r being selected uniformly at random from R: A shift amount D is then drawn uniformly from ½2l b g=2; l b g=2: In the case of the region shift proposal, x9 5 x 1 D and y9 5 y 1 D: In the case of the region boundary shift proposal, either x9 5 x 1 D and y9 5 y or x9 5 x and y9 5 y 1 D with probability 1=2: The proposal is immediately rejected if either x9 or y9 lie outside of the allowed site range ½1; l b for locus b: The conversion r is then replaced by a new conversion r9 5 ðl; u; b; x9; y9Þ: The HGF for this move is unity.

CF Operators
With the exception of the topology-preserving temporal scaling operator, every move described thus far has proposed changes only to the set of conversions R applied to C; not C itself. Operators which propose changes to C are clearly of central importance to an algorithm designed to explore the joint ðR; CÞ state space. As explained in the main text, our strategy for exploring this space is to employ each of the tree operators described in Drummond et al. (2002) to propose changes to C; updating R concurrently to maintain compatibility between the conversions and the CF. This is managed by expressing each of these operators primarily in terms of two primitive operations: expand and collapse. Understanding each operation requires considering a nonroot node i; its parent i p ; grandparent i g (if it exists), and sibling i s in C; as well as a distinct node j and its parent j p (if it exists) in C chosen so that j;fi; i p g and j is not included in the subtree below i: Each operation involves "disconnecting" the subtree rooted by i from the rest of the CF and "reconnecting" it to the edge above j: That is, (Edges involving j p and i g are only included if these nodes exist.) This rearrangement is of course only valid if t is also updated so that t 9 ip 2 ½t j ; t j p if j p exists or t 9 ip 2 ½t j ; NÞ if j is the root in C: If such a modification is impossible, the proposal invoking the expansion or collapse is rejected immediately.
In terms of their effect on the CF, the only difference between the two operations is the sign of the difference t 9 ip 2 t i p : expansions increase the age of i p while collapses decrease this age. The effects on the set R of conversions are quite different, however.
For expansion, the set of conversion connections X t ip ; t 9 ip containing only those connections with t fl;ug 2 ½t ip ; t 9 i p is constructed. Each of these attachment points are, with probability 1=2; moved in R9 to the contemporaneous point on the newly lengthened edge hi; i p i: Additionally, in the case that j is the root of C (making i p the root of C9), a set Z9 of new conversions are initiated along edges hj; i p i and hi; i p i; with arrival points uniformly distributed among the portion of these edges at ages greater than t j _ t ip : The expansion operation makes the following contribution to the HGF: where L 5 2ðt 9 ip 2 t j _ t i p Þ and V 5 P b2B ðrL b 1 d 2 1Þ: For collapse, the set of conversion connections X t ip ;t 9 ip containing only those connections which lie on hi; i p i which have t fl;ug 2 ½t 9 ip ; t i p is constructed. Note that in the case that i p is the root of C; this set omits any attachment points belonging to conversions with arrival points t l 2 ½t i s _ t 9 ip ; t i p Such conversions are assigned to the set Z; along with conversions with arrival times in the same interval which lie on hi s ; i p i: Each attachment in X ti p ;t 9 ip is moved to the lineage ancestral to j: Every conversion in Z is removed. The collapse operation makes the following contribution to the HGF: j D j Pðx; y; b j B; dÞ j D9 j Pðx9; y9; b9 j B; dÞ h op G9 j G ; where h op ðG9 j GÞ represents the HGF contribution of the particular expand/collapse operation performed.