- Research
- Open Access

# A polynomial time algorithm for calculating the probability of a ranked gene tree given a species tree

- Tanja Stadler
^{1}Email author and - James H Degnan
^{2, 3}

**7**:7

https://doi.org/10.1186/1748-7188-7-7

© Stadler and Degnan; licensee BioMed Central Ltd. 2012

**Received:**30 September 2011**Accepted:**2 April 2012**Published:**30 April 2012

## Abstract

### Background

The ancestries of genes form gene trees which do not necessarily have the same topology as the species tree due to incomplete lineage sorting. Available algorithms determining the probability of a gene tree given a species tree require exponential computational runtime.

### Results

In this paper, we provide a polynomial time algorithm to calculate the probability of a *ranked* gene tree topology for a given species tree, where a ranked tree topology is a tree topology with the internal vertices being ordered. The probability of a gene tree topology can thus be calculated in polynomial time if the number of orderings of the internal vertices is a polynomial number. However, the complexity of calculating the probability of a gene tree topology with an exponential number of rankings for a given species tree remains unknown.

### Conclusions

Polynomial algorithms for calculating ranked gene tree probabilities may become useful in developing methodology to infer species trees based on a collection of gene trees, leading to a more accurate reconstruction of ancestral species relationships.

## Keywords

- Incomplete lineage sorting
- Coalescent history
- Anomalous gene tree
- Dynamic programming

## Background

*A*and

*B*in Figure 1b do not coalesce until the population ancestral to species

*A*,

*B*, and

*C*, thus allowing the

*B*and

*C*lineages in the gene tree to have a more recent common ancestor than lineages

*A*and

*B*.

Given a fixed species tree, and assuming the gene tree evolved under the multi-species coalescent [1], the most probable gene tree topology can have a different topology from that of the species tree. Such a gene tree topology is called an anomalous gene tree. In fact, for every species tree topology with at least 5 leaves, we can choose edge lengths in the species tree topology such that anomalous gene trees exist [2]. This implies that the gene tree topology appearing most often when considering different genes might not agree with the species tree topology, thus we cannot use a simple majority-heuristic to infer the species tree from a collection of gene trees. Instead we need statistical tools rather than majority rule heuristics for inferring the species tree based on gene trees.

Current methods for inferring species trees from gene trees in this setting can be divided into topology-based and genealogy-based methods, in which the input for a reconstruction algorithm accepts either gene tree topologies or genealogies, i.e., gene trees with branch lengths (coalescence times). Topology-based methods include Minimize Deep Coalescence (MDC) [3, 4], STAR [5], STELLS [6], rooted triple consensus [7] and other consensus and supertree methods [8, 9]. Genealogy-based methods include Bayesian and likelihood methods such as BEST, *BEAST, and STEM [10–12] and clustering and distance-based methods [5, 13–15]. Possible pros and cons of the two approaches are that topology-based methods can be computationally faster and less sensitive to errors in estimating gene trees (and gene tree branch lengths) from sequence data [16], while methods that use coalescence times, particularly using Bayesian modelling, can be the most accurate when model assumptions are correct [17].

Another possibility that has been so far unexplored in methods for inferring species trees from gene trees is to use *ranked* gene trees, in which the temporal order of the nodes of the gene tree (the coalescence times) is used, but not the continuous-valued branch lengths. This approach might therefore be intermediate between purely topology-based methods and genealogy-based methods. By preserving more of the temporal information in the gene tree nodes, the hope is to develop methods that are more powerful than purely topology-based methods and that are still computationally efficient and robust to errors in estimating gene trees and gene tree branch lengths from sequence data.

In [18], a first step toward developing methods that use ranked gene trees for inferring species trees was taken by providing formulae to calculate the probability of a ranked gene tree given a species tree. The previous work, however, was based on an exponential enumeration of what were called *ranked coalescent histories* and did not provide an algorithm for computing some of the key terms in the probability of individual ranked histories. In this paper, we improve this previous (computationally inefficient) approach, by providing a method for computing probabilities of ranked gene trees given species trees which is polynomial in the number of leaves using a dynamic programming approach.

Methods for computing probabilities of ranked gene trees efficiently may also be of interest in the context of computing probabilities of unranked gene trees, particularly because no polynomial time algorithm has been found for calculating the probability of a gene tree topology given a species tree under the multispecies coalescent [6, 19–21]. The probability of an unranked gene tree topology can be obtained by summing over all ranked gene tree topologies with the same topology. Thus, for unranked gene trees with particular shapes where the number of rankings increases in polynomial time, using ranked gene trees can potentially increase the speed of computing probabilities of unranked gene trees as well. We note that a completely unbalanced gene tree has only one ranking, while the number of rankings can be exponential in the number of leaves when gene trees become more balanced. Thus, our approach for calculating unranked gene tree probabilities will be most useful for less balanced ranked gene trees.

The bulk of the paper consists of the derivation of the polynomial time method for computing ranked gene tree probabilities. The algorithm is summarized in section ‘An algorithm’. This is followed by a discussion of applications to computing probabilities of unranked gene tree topologies and to inferring ranked species trees under maximum likelihood and a modification to the MDC criterion.

## Calculating the probability of a ranked gene tree topology

In the following, we will derive the probability of a ranked gene tree topology given a species tree, $\mathbb{P}\left[\mathcal{G}\right|\mathcal{T}]$. Equations (1, 2, 3, 4, 8, 10) allow the calculation of $\mathbb{P}\left[\mathcal{G}\right|\mathcal{T}]$ in time *O*(*n*^{5}). The model giving rise to the gene tree is the multi-species coalescent with constant population sizes [1]. Each species consists of a population of constant size where lineages merge according to the coalescent. Thus, lineages from two different species may coalesce any time previous to the split of the two species.

*n*species, and thus

*n*− 1 speciation events (denoted by 1,…,

*n*− 1) occurring at times

*s*

_{1}>⋯>

*s*

_{n−1}. Denote the interval between speciation event

*i*− 1 and speciation event

*i*by

*τ*

_{ i }, see Figure 1.

**Notation used in the paper**

Symbol | Meaning |
---|---|

$\mathcal{T}$ | Species tree with real-valued divergence times |

$\mathcal{G}$ | Ranked gene tree (real-valued coalescence times not specified) |

| The number of leaves of $\mathcal{T}$ and $\mathcal{G}$ |

| Speciation times, with |

| Intervals between speciation times, |

| The number of gene tree lineages at time |

| The number of coalescence events in interval |

${\mathcal{G}}_{i,{\ell}_{i}}$ | The ranked gene tree observed from time 0 to time |

| The minimum number of gene tree lineages at time |

| Population |

| Internal node (coalescence) with rank |

| The number of lineages available for coalescence in population |

| The set of leaves descended from a node of the species tree or gene tree, respectively |

lca( | For a node |

| For a node |

| The overall coalescence rate in interval |

| Number of sequences of coalescences above the root of the species tree starting with |

| The joint density of coalescence times in interval |

Let $\mathcal{G}$ be a ranked gene tree topology. It is convenient to use the same labels for the leaves of $\mathcal{G}$ and of $\mathcal{T}$. This is a slight abuse of notation, as leaf *A* of $\mathcal{T}$ refers to a population (or species), and *A* of $\mathcal{G}$ refers to a gene sampled from population *A*. We denote the nodes of $\mathcal{G}$ (which are coalescence events) by *u*_{1},…,*u*_{n−1}, where node *u*_{
j
} has rank *j*, and where higher rank indicates a more recent coalescence. A ranked tree topology can be notated similarly to Newick notation, putting the rank as a subscript for each node, see also Figure 1.

Let ${\mathcal{G}}_{i,{\ell}_{i}}$ be part of a ranked gene tree evolving on a species tree between time *s*_{
i
} and time 0 (i.e. the present). ${\mathcal{G}}_{i,{\ell}_{i}}$ consists of *ℓ*_{
i
} gene tree lineages at speciation time *s*_{
i
} and the coalescent history of ${\mathcal{G}}_{i,{\ell}_{i}}$ in time interval (0,*s*_{
i
}) is consistent with the ranked gene tree $\mathcal{G}$. Let *g*_{
i
} be the minimum number of lineages required in the ranked gene tree at time *s*_{
i
} such that $\mathcal{G}$ can be embedded into the species tree $\mathcal{T}$. Note that *n* ≥ *ℓ*_{
i
}≥ *g*_{
i
}> *i*. Next we provide a dynamic programming approach for calculating the probability of a ranked gene tree given a species tree. An efficient way to determine the required quantities *g*_{1},…,*g*_{n−1} is provided in Section ‘Calculation of *g*_{
i
} and *k*_{i,j,z}’.

Essentially, in our approach, we traverse the intervals between speciation events going back in time, *τ*_{n−1},…,*τ*_{2} (formalized in Theorem 2), and calculate the probability of the appropriate coalescent events occurring in interval *τ*_{
i
} based on how many coalescent events happened in the later intervals *τ*_{i+1},…,*τ*_{n−1} (Theorem 3). Finally with Theorem 1, we account for the most ancestral time interval *τ*_{1}.

### Theorem 1

*The probability of a ranked gene tree given a species tree is,*

*where*

*is the probability for the coalescences above the root appearing in the right order*[22].

For precalculated $\mathbb{P}\left[{\mathcal{G}}_{1,{\ell}_{1}}\right|\mathcal{T}]$ (*ℓ*_{1} = 2,…,*n*) the complexity of calculating $\mathbb{P}\left[\mathcal{G}\right|\mathcal{T}]$ is thus *O*(*n*). Next, we will provide a recursive way to calculate $\mathbb{P}\left[{\mathcal{G}}_{1,{\ell}_{1}}\right|\mathcal{T}]$ for *ℓ*_{1} = 2,…,*n* in polynomial time, thus $\mathbb{P}\left[\mathcal{G}\right|\mathcal{T}]$ can be calculated in polynomial time.

### Theorem 2

*The probability*$\mathbb{P}\left[{\mathcal{G}}_{i,{\ell}_{i}}\right|\mathcal{T}]$

*can be calculated for all*

*i*

*recursively (with*

*l*

_{ i }≥

*g*

_{ i }),

*with*

*The complexity of calculating*$\mathbb{P}\left[{\mathcal{G}}_{1,{\ell}_{1}}\right|\mathcal{T}]$*for* *ℓ*_{1} = 2,…,*n* *is* *O*(*n*^{3}), *given we know*$\mathbb{P}\left[{\mathcal{G}}_{i,{\ell}_{i}}\right|{\mathcal{G}}_{i+1,{\ell}_{i+1}},\mathcal{T}]$*for all* *i*,*ℓ*_{
i
},*ℓ*_{i+1}.

### Proof

*s*

_{n−1}, we have

*n*lineages with probability 1, which is the initial value of the recursion. Calculating $\mathbb{P}\left[{\mathcal{G}}_{i,{\ell}_{i}}\right|\mathcal{T}]$ for

*i*<

*n*− 1 can be done in the following way,

Suppose $\mathbb{P}\left[{\mathcal{G}}_{i,{\ell}_{i}}\right|{\mathcal{G}}_{i+1,{\ell}_{i+1}},\mathcal{T}]$ is known. Given we calculated the probability $\mathbb{P}\left[{\mathcal{G}}_{i+1,{\ell}_{i+1}}\right|\mathcal{T}]$ for *ℓ*_{i+1}= *i* + 2,…,*n*, then calculating $\mathbb{P}\left[{\mathcal{G}}_{i,{\ell}_{i}}\right|\mathcal{T}]$ for *ℓ*_{
i
}= *i* + 1,…,*n* requires $O\left(\sum _{j=1}^{n-i}j\right)=O\left(\left(\genfrac{}{}{0ex}{}{n-i+1}{2}\right)\right)$ calculations. Summing up over *i* = 1,…,*n* − 1 yields a complexity of $O\left(\sum _{i=2}^{n}\left(\genfrac{}{}{0ex}{}{i}{2}\right)\right)=O\left(\left(\genfrac{}{}{0ex}{}{n+1}{3}\right)\right)=O\left({n}^{3}\right)$. □

It remains to determine $\mathbb{P}\left[{\mathcal{G}}_{i-1,{\ell}_{i-1}}|{\mathcal{G}}_{i,{\ell}_{i}},\mathcal{T}\right]$. Note that during the interval *τ*_{
i
}, we have *i* branches in the species tree. Let *m*_{
i
} be the number of coalescent events in *τ*_{
i
}, so *m*_{
i
}= *ℓ*_{
i
}− *ℓ*_{i−1}. Let the number of lineages on branch *z* just after the *j* th coalescent event (going forward in time) in *τ*_{
i
} be *k*_{i,j,z}. Calculation of *k*_{i,j,z} can be done efficiently as shown in Section ‘Calculation of *g*_{
i
} and *k*_{i,j,z}’.

### Theorem 3

*We have,*

*where*${\lambda}_{i,j}=\sum _{z=1}^{i}\left(\genfrac{}{}{0ex}{}{{k}_{i,j,z}}{2}\right)$ and $\left(\genfrac{}{}{0ex}{}{1}{2}\right):=0$.

### Proof

The density for the coalescence events in interval *τ*_{
i
} can be obtained by considering the waiting time to the “next” coalescent event (going backwards in time) as being due to competing exponentials in the different branches, where the coalescence rate within branch *z* is $\left(\genfrac{}{}{0ex}{}{{k}_{i,j,z}}{2}\right)$. Thus, the waiting time until the next coalescent event has rate ${\lambda}_{i,j}=\sum _{z=1}^{i}\left(\genfrac{}{}{0ex}{}{{k}_{i,j,z}}{2}\right)$.

We denote the time between the *j* th and (*j* + 1)st coalescent event as *v*_{
j
}, where *v*_{0} is the time between *s*_{i−1} and the first (least recent) coalescent event in *τ*_{
i
} and with ${v}_{{m}_{i}}$ being the time between *s*_{
i
} and coalescent event *m*_{
i
}.

*τ*

_{ i }is [18],

It remains to integrate over *v*, for which we distinguish between case (i) *λ*_{i,0}= 0, and case (ii) *λ*_{i,0}> 0.

*λ*

_{i,0}= 0 (which occurs if

*ℓ*

_{i−1}=

*i*, i.e., all lineages within each population coalesce), then we rewrite

*f*

_{ i }as,

*m*

_{ i }exponential random variables [23] (with density functions ${\lambda}_{i,j}{e}^{-{\lambda}_{i,j}{v}_{j}}$,

*j*= 1,…,

*m*

_{ i }), the probability of the coalescent events in the interval is the

*cumulative distribution function*of the hypoexponential distribution evaluated at ${s}_{i-1}-{s}_{i}=\sum _{j=0}^{{m}_{i}}{v}_{i}$. Thus, with

*λ*

_{i,j}<

*λ*

_{i,j+1},

where the second line follows because −*λ*_{i,j}= *λ*_{i,0}− *λ*_{i,j}.

*λ*

_{i,0}> 0, then we rewrite

*f*

_{ i }as,

*f*

_{ i }, we use the fact that the integral of the numerator in Equation (7) is the convolution of

*m*

_{ i }+ 1 exponential random variables with parameters ${\lambda}_{i,0},\dots ,{\lambda}_{i,{m}_{i}}$, which is the hypoexponential distribution. Now, since

*λ*

_{i,j}<

*λ*

_{i,j+1}, we observe, using the

*probability density function*of the hypoexponential distribution,

which is the same expression as for the *λ*_{i,0}= 0 case (6). Note that for case (i) we made use of the cumulative distribution function of the hypoexponential distribution, while for case (ii) we made use of the density function of the hypoexponential distribution. Both cases yield the same final expression for $\mathbb{P}\left[{\mathcal{G}}_{i-1,{\ell}_{i-1}}\right|{\mathcal{G}}_{i,{\ell}_{i}},\mathcal{T}]$, which establishes the proof. □

### Corollary 4

*The probabilities*$\mathbb{P}\left[{\mathcal{G}}_{i-1,{\ell}_{i-1}}\right|{\mathcal{G}}_{i,{\ell}_{i}},\mathcal{T}]$*for all possible* *i*, *m*_{
i
}*and* *ℓ*_{
i
}*(recall that* *m*_{
i
}= *ℓ*_{
i
}− *ℓ*_{i−1}) *are calculated in* *O*(*n*^{5}), *given all* *λ*_{i,j}.

### Proof

*i*,

*m*

_{ i }and

*ℓ*

_{ i }, we require $O\left({m}_{i}^{2}\right)$ calculations to evaluate $\mathbb{P}\left[{\mathcal{G}}_{i-1,{\ell}_{i-1}}\right|{\mathcal{G}}_{i,{\ell}_{i}},\mathcal{T}]$. We need to determine $\mathbb{P}\left[{\mathcal{G}}_{i-1,{\ell}_{i-1}}\right|{\mathcal{G}}_{i,{\ell}_{i}},\mathcal{T}]$ for all possible

*i*,

*m*

_{ i }and

*ℓ*

_{ i }. First, we observe that

*i*≤

*ℓ*

_{i−1}≤

*n*, and thus for a fixed

*ℓ*

_{ i }, we have, 0 ≤

*m*

_{ i }≤

*ℓ*

_{ i }−

*i*. Second,

*i*<

*ℓ*

_{ i }≤

*n*. And third, 2 ≤

*i*≤

*n*− 1. Thus, the number of calculations needed to calculate $\mathbb{P}\left[{\mathcal{G}}_{i-1,{\ell}_{i-1}}\right|{\mathcal{G}}_{i,{\ell}_{i}},\mathcal{T}]$ for all possible

*i*,

*m*

_{ i }and

*ℓ*

_{ i }is,

□

### Corollary 5

*The quantities* *λ*_{i,j}*can be calculated for all possible* *i*, *m*_{
i
}, *ℓ*_{
i
}*and* *j* *in* *O*(*n*^{5}), *given all* *k*_{i,j,z}.

### Proof

*i*,

*m*

_{ i },

*ℓ*

_{ i }and

*j*, we require

*O*(

*i*) calculations to evaluate

*λ*

_{i,j}. As

*j*= 0,…,

*m*

_{ i }, with the same arguments as in Corollary 4, we obtain,

□

*g*

_{i,j}defined in [24]

*,*[25], which give the probability that

*i*lineages coalesce into

*j*within time

*t*in a single population and are used extensively in computing probabilities related to unranked gene trees [6]

*,*[19]

*,*[26, 27]. In particular, if only one population, say

*z*

^{∗}, has coalescence events, then we have r

*g*

_{i,j}functions with the denominator counting the number of sequences in which

*m*

_{ i }coalescences could have occurred. The terms $\mathbb{P}\left[{\mathcal{G}}_{i-1,{\ell}_{i-1}}\right|{\mathcal{G}}_{i,{\ell}_{i}},\mathcal{T}]$ allow for the coalescences to occur in separate populations, however, and are constrained by the ranking of the gene tree. For example, in interval

*τ*

_{3}of Figure 1c, there are two coalescences which occur in different populations. If the ranking of the gene tree were not important, the branches could be considered independent, and the probability of this event would be

*g*

_{2,1}(

*s*

_{2}−

*s*

_{3})

*g*

_{2,1}(

*s*

_{2}−

*s*

_{3}). However, the gene tree ranking constrains the coalescence of

*A*and

*B*to be less recent than that of

*D*and

*E*, so the probability for events in this interval is, r

*τ*

_{3}, so we use

*j*= 0,1,2, and calculate

### Remark 6

*The probability of a gene tree topology is the sum of the probabilities of each ranked gene tree with the given topology. A given tree topology has*$(n-1)!/\prod _{i=1}^{n-1}({c}_{i}-1)$

*rankings, where*

*c*

_{ i }

*is the number of descendant leaves of interior vertex*

*i*.

*A proof can be found in*[28].

*For a completely balanced tree on*

*n*= 2

^{ k }

*leaves, the number of rankings grows faster than polynomial: the numerator can be approximated by,*

*and the denominator can be approximated by,*

*showing that the ratio grows faster than polynomial in* *n*.

### Calculation of *g*_{
i
} and *k*_{i,j,z}

#### Calculation of *g*_{
i
}

*g*

_{ i }=

*i*+ 1. In general, to compute

*g*

_{ i }, we let lca (

*u*

_{ j }) be the

*least common ancestor*node on the species tree for a node

*u*

_{ j }on the ranked gene tree – i.e., the node with the largest rank on the species tree which is ancestral to all species represented in

*u*

_{ j }. For a node

*y*on the species tree, let

*τ*(

*y*) be the interval immediately above

*y*. For example, in Figure 1c,

*τ*(lca(

*u*

_{4})) =

*τ*

_{3}where

*u*

_{4}is the gene tree node with rank 4 — the node ancestral to D and E only. In order to compute

*g*

_{ i }, we count the number of gene tree nodes which may occur closer to the present than

*s*

_{ i }. These are precisely all gene tree nodes

*u*

_{ j }where lca (

*u*

_{ j }) is in any of the intervals

*τ*

_{i+1},…,

*τ*

_{n−1}. Since at the present,

*n*lineages are able to coalesce, we can express

*g*

_{ i }as,

where *τ*_{
j
}< *τ*_{
i
} iff *j* < *i*, and where *I*(·) is an indicator function taking the value 1 if the condition holds and otherwise 0. Assuming each lca() operation is *O*(1) [29, 30], preprocessing allows all lca terms to be computed in *O*(*n*) time. Thus, calculating *g*_{1},…,*g*_{n−1} can be done, based on Equation 8, in *O*(*n*^{3}).

#### Calculation of *k*_{i,j,z}

*y*

_{i,j}be the

*j*th population (read left to right) in interval

*τ*

_{ i }(equivalently, the

*j*th branch or

*j*th node subtending the branch). In order to label every population before and after a speciation time

*s*

_{ i }uniquely, extra nodes can be added to the species tree to form a

*beaded species tree*(Figure 2), so that there are

*i*nodes at time

*s*

_{ i }, $i=1,\dots ,n-1$. For each

*i*∈ {1,…,

*n*−1}, there is one node of outdegree 2, and

*i*− 1 nodes of outdegree 1. Thus, population

*y*

_{i,j}corresponds to a branch (equivalently, a node) in the beaded species tree. We denote the outdegree of a node

*y*by

*outdeg*(

*y*).

*k*

_{i,j,z}, i.e. the number of lineages on branch

*y*

_{i,z}of the beaded species tree during the interval immediately after the

*j*th coalescence event (going forward in time), with

*k*

_{i,0,z}being the number of lineages “exiting” the branch at time

*s*

_{i−1}. For example, in Figure 1b, we have

The value of *k*_{i,j,z} depends on the number of lineages entering branch *i*, *ℓ*_{
i
}, as well as the number of lineages exiting the branch, and not just on the number of coalescence events in the interval. For example, in Figure 1c, *k*_{2,0,1} = 1 and *k*_{2,1,1} = 2, while in Figure 1d, *k*_{2,0,1} = 2 and *k*_{2,1,1} = 3, although the two gene trees have the same ranked topology and *m*_{2} = 1 for both cases.

To determine the terms *k*_{i,j,z} we note that the number of coalescences that have occurred more recently than interval *τ*_{
i
} is *n* − *ℓ*_{
i
}. In a given interval *τ*_{
i
}, we let *z*^{(1)} and *z*^{(2)} be the left and right children, respectively, of population *z* of outdegree 2, and let *z*^{(1)} = *z*^{(2)} be the only child of a node *z* of outdegree 1.

*z*of interval

*τ*

_{ i }is

*z*

^{(j)}are the daughter populations (one or two) of

*z*. Further,

*k*

_{n,0,z}= 0 for all

*z*. Since the beaded species tree has

*n*

^{2}/2 nodes, precalculating

*outdeg*(

*y*

_{i,z}) requires

*O*(

*n*

^{2}). For 0 ≤

*j*<

*m*

_{ i }, we have

*k*

_{i,j,z}is

*O*(1). Thus determining

*k*

_{i,j,z}for all possible

*i*,

*m*

_{ i }and

*ℓ*

_{ i }is (see also Corollary 4),

Note that taking the sum over all *z* is not necessary, as in all but one branch the *k*_{i,j,z} equals the *k*_{i,j+1,z}.

### An algorithm

*O*(

*n*

^{5}) for calculating the probability of a ranked gene tree given a species tree on

*n*tips:

- 1.
Calculate

*g*_{1},…*g*_{n−1}using Equation (8). - 2.
- 3.
Calculate ${\lambda}_{i,j}=\sum _{z=1}^{i}\left(\genfrac{}{}{0ex}{}{{k}_{i,j,z}}{2}\right)$ (for

*i*,*j*= 1,…,*n*). - 4.
Calculate $\mathbb{P}\left[{\mathcal{G}}_{i-1,{\ell}_{i-1}}\right|{\mathcal{G}}_{i,{\ell}_{i}},\mathcal{T}]$ (for

*i*= 2,…,*n*;*ℓ*_{i−1}=*g*_{i−1},…,*n*;*ℓ*_{ i }=*g*_{ i },…,*n*), using Theorem 3. - 5.
Calculate $\mathbb{P}\left[{\mathcal{G}}_{1,{\ell}_{1}}\right|\mathcal{T}]$ using Theorem 2.

- 6.
Calculate $\mathbb{P}\left[\mathcal{G}\right|\mathcal{T}]$ using Theorem 1.

## Conclusions

In this paper, we provide a polynomial-time algorithm (*O*(*n*^{5}) where *n* is the number of species) to calculate the probability of a ranked gene tree topology given a species tree, summarized in Section ‘An algorithm’. We now discuss applying these results to computing probabilities of unranked gene tree topologies and to inferring ranked species trees.

### Computing probabilities of unranked gene tree topologies

Previous work on computing probabilities of unranked gene tree topologies used the concept of *coalescent histories*, which specify the branches in the species tree in which each node of the gene tree occurs. An unranked gene tree probability can then be computed by enumerating all coalescent histories and computing the probability of each. The number of coalescent histories grows at least exponentially when the (unranked) gene tree matches the species tree, making this approach computationally intensive. Coalescent histories can be enumerated either recursively (e.g., in PHYLONET [31] or [20]) or nonrecursively (COAL [19]).

A much faster approach using dynamic programming similar to that used in this paper is implemented in STELLS [6], which conditions on the ancestral configuration in each branch rather than the number of lineages. Here an ancestral configuration keeps track not only of the number of lineages in a branch in the species tree, but also the particular nodes of the gene tree. Different ancestral configurations can potentially have the same number of lineages within a population. Enumerating ancestral configurations turns out to have exponential running time for arbitrarily shaped trees, but the number of ancestral configurations is still much smaller than the number of coalescent histories. When computing probabilities of ranked gene tree topologies, however, the ranking specifies the sequence of coalescence events, leading to a unique ancestral configuration given the number of lineages in a time interval. This fortuitously enables probabilities of ranked gene tree topologies to be computed in polynomial time.

We note that although the number of rankings for a gene tree is not polynomial in the number of leaves in general, the number of rankings can be small for certain tree shapes. For example, if the gene tree has a *caterpillar* shape, in which each internal node has a leaf as a descendant, then there is only one ranking, and thus computing the ranked and unranked gene tree are equivalent. For a *pseudo-caterpillar*, a tree made by replacing the subtree with four leaves of a caterpillar with a balanced tree on four leaves [20], there are only two rankings possible, and for a *bicaterpillar*[20], for which the left subtree is a caterpillar with *n*_{
L
} leaves and the right subtree is a caterpillar with *n* − *n*_{
L
} leaves, there are $\left(\genfrac{}{}{0ex}{}{n-2}{{n}_{L}-1}\right)$ rankings. Thus computing unranked gene tree probabilities by summing ranked gene tree probabilities can be done in polynomial time for some tree shapes. We note that for the approach used by STELLS, some tree shapes can also be computed in polynomial time, including the cases we mentioned with a polynomial number of rankings (caterpillar and pseudo-caterpillar). An open question is whether there are any classes of unranked gene trees which have a polynomial number of rankings but an exponential number of ancestral configurations, or vice versa.

### Inferring species trees from ranked gene trees

*N*ranked gene trees (i.e.,

*N*loci). Now the maximum likelihood species tree ${\mathcal{T}}_{\mathit{\text{ML}}}$ (with branch lengths on internal branches) is

is a multinomial likelihood. Here $\mathbb{P}\left[{\mathcal{G}}_{k}\right|\mathcal{T}]$ can be determined with our polynomial-time algorithm, we let ${\mathcal{G}}^{\left(i\right)}$ denote the *i* th ranked topology, and *n*_{
i
} is the number of times ranked topology *i* is observed, with $\sum _{i=1}^{{H}_{n}}{n}_{i}=N$. Note in particular that the ranked topology of ${\mathcal{T}}_{\mathit{\text{ML}}}$ might differ from the most frequent ranked gene tree topology [18].

*τ*

_{ i }. The total number of extra lineages in this sense is

Minimizing (12) as a criterion for the ranked species tree will tend to penalize long edges of the species tree which have multiple lineages persisting through multiple species divergence events. As an example, in Figure 1b, the gene tree has a MDC cost of 1 since there are two lineages exiting the population immediately ancestral to *A* and *B*; however the cost according (12) is 2 because there are two edges on the beaded version of the species tree (Figure 2) that each have an extra lineage. In Figure 1c, the gene tree has a MDC cost of 0 for the species tree since it has the matching unranked topology; however, the number of extra lineages from equation (12) is 1. We note that in Figure 1c, interval *τ*_{3}, incomplete lineage sorting (and deep coalescence) have not occurred as these concepts are normally used. To capture the idea that coalescence has nevertheless occurred in a more ancient time interval than allowed, we might refer to the coalescence of *A* and *B* in Figure 1c as an “ancient lineage sorting” event (rather than incomplete lineage sorting event) or an ancient coalescence rather than a deep coalescence. We could therefore refer to minimizing equation (12) as the Minimize Ancient Coalescence (MAC) criterion, which would provide an interesting comparison to the usual topology-based MDC criterion.

In practice, a method of inferring a species tree from ranked gene trees would require estimating the ranked gene trees. This would require clock-like gene trees, or trees with times estimated for nodes, which can also be inferred under relaxed clock models in BEAST [32]. To account for the uncertainty in the gene trees, the counts for different ranked gene trees could be weighted by their posterior probabilities obtained from Bayesian estimation of the gene trees [33]. Thus, in equation (11), we would let *n*_{
i
k
} be the posterior probability of ranked topology *i* at locus *k*, and use ${n}_{i}=\sum _{k=1}^{{H}_{n}}{n}_{\mathit{\text{ik}}}$ as the estimated number of times that ranked topology *i* was observed. Similarly, for equation (12), the coalescence cost at a locus could be distributed over multiple topologies weighted by their posterior probabilities.

## Declarations

### Acknowledgements

We thank David Bryant for suggesting the dynamic programming approach to this problem and two anonymous referees for valuable comments, particularly on calculating *g*_{
i
} and *k*_{i,j,z}. JHD was funded by the New Zealand Marsden fund and by a Sabbatical Fellowship at the National Institute for Mathematical and Biological Synthesis, an Institute sponsored by the National Science Foundation, the U.S. Department of Homeland Security, and the U.S. Department of Agriculture through NSF Award #EF-0832858, with additional support from The University of Tennessee, Knoxville. TS was funded by the Swiss National Science Foundation.

## Authors’ Affiliations

## References

- Degnan JH, Rosenberg NA: Gene tree discordance, phylogenetic inference, and the multispecies coalescent. Trends Ecol Evol. 2009, 24: 332-340. 10.1016/j.tree.2009.01.009PubMedView ArticleGoogle Scholar
- Degnan JH, Rosenberg NA: Discordance of species trees with their most likely gene trees. PLoS Genet. 2006, 2: 762-768.View ArticleGoogle Scholar
- Maddison WP, Knowles LL: Inferring phylogeny despite incomplete lineage sorting. Syst Biol. 2006, 55: 21-30. 10.1080/10635150500354928PubMedView ArticleGoogle Scholar
- Than C, Nakhleh L: Species tree inference by minimizing deep coalescences. PLoS Comput Biol. 2009, 5: e1000501- 10.1371/journal.pcbi.1000501PubMedPubMed CentralView ArticleGoogle Scholar
- Liu L, Yu L, Pearl DK, Edwards SV: Estimating species phylogenies using coalescence times among sequences. Syst Biol. 2009, 58: 468-477. 10.1093/sysbio/syp031PubMedView ArticleGoogle Scholar
- Wu Y: Coalescent-based species tree inference from gene tree topologies under incomplete lineage sorting by maximum likelihood. Evolution. 2011, , 10.1111/j.1558-5646.2011.01476.x.Google Scholar
- Ewing GB, Ebersberger I, Schmidt HA, von Haeseler A: Rooted triple consensus and anomalous gene trees. BMC Evol Biol. 2008, 8: 118- 10.1186/1471-2148-8-118PubMedPubMed CentralView ArticleGoogle Scholar
- Degnan JH, DeGiorgio M, Bryant D, Rosenberg NA: Properties of consensus methods for inferring species trees from gene trees. Syst Biol. 2009, 58: 35-54. 10.1093/sysbio/syp008PubMedPubMed CentralView ArticleGoogle Scholar
- Wang Y, Degnan JH: Performance of matrix representation with parsimony for inferring species from gene trees. Stat Appl Genet Mol Biol. 2011, 10: 21-Google Scholar
- Heled J, Drummond AJ: Bayesian inference of species trees from multilocus data. Mol Biol Evol. 2010, 27: 570-580. 10.1093/molbev/msp274PubMedPubMed CentralView ArticleGoogle Scholar
- Kubatko LS, Carstens BC, Knowles LL: STEM: Species tree estimation using maximum likelihood for gene trees under coalescence. Bioinformatics. 2009, 25: 971-973. 10.1093/bioinformatics/btp079PubMedView ArticleGoogle Scholar
- Liu L, Pearl DK: Species trees from gene trees: Reconstructing bayesian posterior distributions of a species phylogeny using estimated gene tree distributions. Syst Biol. 2007, 56: 504-514. 10.1080/10635150701429982PubMedView ArticleGoogle Scholar
- Liu L, Yu L: Estimating species trees from unrooted gene trees. Syst Biol. 2011, 60: 661-667. 10.1093/sysbio/syr027PubMedView ArticleGoogle Scholar
- Liu L, Yu L, Pearl DK: Maximum tree: a consistent estimator of the species tree. J Math Biol. 2010, 60: 95-106. 10.1007/s00285-009-0260-0PubMedView ArticleGoogle Scholar
- Mossel E, Roch S: Incomplete lineage sorting: consistent phylogeny estimation from multiple loci. IEEE/ACM Trans Comp Biol Bioinf. 2010, 7: 166-171.View ArticleGoogle Scholar
- Huang H, He Q, Kubatko LS, Knowles LL: Sources of error for species-tree estimation: Impact of mutational and coalescent effects on accuracy and implications for choosing among different methods. Syst Biol. 2009, 59: 573-583.View ArticleGoogle Scholar
- Liu L, Yu L, Kubatko LS, Pearl DK, Edwards SV: Coalescent methods for estimating phylogenetic trees. Mol Phylogenet Evol. 2009, 53: 320-328. 10.1016/j.ympev.2009.05.033PubMedView ArticleGoogle Scholar
- Degnan JH, Rosenberg N, Stadler T: The probability distribution of ranked gene trees on a species tree. Math Biosci. 2012, 235: 45-55. 10.1016/j.mbs.2011.10.006PubMedView ArticleGoogle Scholar
- Degnan JH, Salter LA: Gene tree distributions under the coalescent process. Evolution. 2005, 59: 24-37.PubMedView ArticleGoogle Scholar
- Rosenberg NA: Counting coalescent histories. J Comput Biol. 2007, 14: 360-377. 10.1089/cmb.2006.0109PubMedView ArticleGoogle Scholar
- Than C, Ruths D, Innan H, Nakhleh L: Confounding factors in HGT detection: statistical error, coalescent effects, and multiple solutions. J Comput Biol. 2007, 14: 517-535. 10.1089/cmb.2007.A010PubMedView ArticleGoogle Scholar
- Edwards AWF: Estimation of the branch points of a branching diffusion process. J R Stat Soc Ser B. 1970, 32: 155-174.Google Scholar
- Ross S: Introduction to Probability Models. 2007, San Diego: Academic PressGoogle Scholar
- Tavaré S: Line-of-descent and genealogical processes, and their applications in population genetics models. Theor Popul Biol. 1984, 26: 119-164. 10.1016/0040-5809(84)90027-3PubMedView ArticleGoogle Scholar
- Wakeley J: Coalescent Theory. 2008, Greenwood Village: Roberts & CompanyGoogle Scholar
- Pamilo P, Nei M: Relationships between gene trees and species trees. Mol Biol Evol. 1988, 5: 568-583.PubMedGoogle Scholar
- Rosenberg NA: The probability of topological concordance of gene trees and species trees. Theor Pop Biol. 2002, 61: 225-247. 10.1006/tpbi.2001.1568View ArticleGoogle Scholar
- Semple C, Steel M: Phylogenetics, vol. 24 of Oxford Lecture Series in Mathematics and its Applications. 2003, Oxford: Oxford University PressGoogle Scholar
- Harel D, Tarjan RE: Fast algorithms for finding nearest common ancestors. SIAM J Comput. 1984, 13: 338-355. 10.1137/0213024View ArticleGoogle Scholar
- Schiever B, Vishkin U: On finding lowest common ancestors: simplification and parallelization. SIAM J Comput. 1988, 17: 1253-1262. 10.1137/0217079View ArticleGoogle Scholar
- Than C, Ruths D, Nakhleh L: Phylonet: A software package for analyzing and reconstructing reticulate evolutionary relationships. BMC Bioinformatics. 2008, 9: 322- 10.1186/1471-2105-9-322PubMedPubMed CentralView ArticleGoogle Scholar
- Drummond AJ, Rambaut A: Beast: Bayesian evolutionary analysis by sampling trees. BMC Evolut Biol. 2007, 7: 214-10.1186/1471-2148-7-214. 10.1186/1471-2148-7-214View ArticleGoogle Scholar
- Allman ES, Degnan JH, Rhodes JA: Identifying the rooted species tree from the distribution of unrooted gene trees under the coalescent. J Math Biol. 2011, 62: 833-862. 10.1007/s00285-010-0355-7PubMedView ArticleGoogle Scholar

## Copyright

This article is published under license to BioMed Central Ltd. This is an Open Access article distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/by/2.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.