Briefly, the model is defined in terms of a simple switching process along the branches of the phylogeny. It has separate parameters for the rates of gain and loss of positive selection at several switch points on the tree, with two switch points per internal branch and one per external branch (see Figure 4A and Methods). The joint posterior distribution of these parameters and of all selection histories is inferred from the data by a Gibbs sampling algorithm (see Methods and Text S1). The inference procedure is computationally intensive, so it was applied only to the 544 genes identified by one or more LRTs as showing significant evidence of positive selection. Because in these cases the null model of no positive selection had already been rejected by a conservative test, the history without selection on any branch was excluded, leaving 2 9 21 = 511 possible histories for the nine-branch (unrooted) phylogeny. To reduce computational cost, the inference of selection histories was conditioned on the maximum likelihood estimates of the parameters of the codon models (see Methods).