โ† Wiki Index / Genetics & Evolution / Felsenstein's Tree-Pruning Algorithm
๐Ÿงฌ Genetics & Evolution

Felsenstein's Tree-Pruning Algorithm

Felsenstein's tree-pruning algorithm is a post-order dynamic programming recursion that computes the phylogenetic likelihood of a sequence alignment in linear time with respect to taxon count.

Felsenstein's tree-pruning algorithm is a foundational dynamic-programming algorithm introduced by Joseph Felsenstein in 1973 and popularized for nucleotide sequences in 1981 that computes the exact likelihood of a molecular sequence alignment on a fixed phylogenetic tree topology and branch-length vector. In maximum-likelihood phylogenetics and Bayesian inference, the characters observed at the tips (leaves) of an evolutionary tree are known from DNA sequencing, whereas the ancestral character states at the N โˆ’ 1 internal nodes of a rooted binary tree of N taxa are unobserved latent variables.

Calculating the marginal probability P(xh | ฯ„, t) of observing alignment column xh requires summing the joint probability over all ANโˆ’1 possible combinations of ancestral character states at the internal nodes, where A is the alphabet size (A = 4 for nucleotides, A = 20 for amino acids, or A = 61 for sense triplets in codon substitution models). Naive brute-force summation over all ANโˆ’1 ancestral state histories grows according to an exponential function exp((N โˆ’ 1) ln A), reaching 499 โ‰ˆ 4.0 ร— 1059 terms for a modest 100-taxon DNA tree. Felsenstein's pruning algorithm exploits the conditional independence of evolutionary lineages under a Markov chain model to move summation signs inward across the tree hierarchy, reducing the computational complexity per site from O(AN) to linear time O(N ยท A2).

Mathematical Formulation of the Pruning Recursion

Conditional Subtree Likelihood Vectors Lv(s)

Consider a rooted binary phylogenetic tree ฯ„ with branch lengths t and a continuous-time Markov substitution model defined by equilibrium state frequencies ฯ€s and branch transition probability matrices P(t) = exp(Qt), where Psx(t) is the probability that state s โˆˆ {1, ..., A} at a parent node evolves into state x โˆˆ {1, ..., A} at a child node separated by branch length t. Assume that sites h = 1, ..., L evolve independently and identically, so that the total log-likelihood of the alignment X is the sum over unique site patterns:

โ„“(ฯ„, t) = ln P(X | ฯ„, t) = โˆ‘h=1L ln P(xh | ฯ„, t)

For a single site h and any node v in the tree, Felsenstein defined the conditional subtree likelihood Lv(h)(s) as the probability of observing all tip character states at or below node v (in the clade rooted at v), given that node v itself is in character state s โˆˆ {1, ..., A}.

Initialization at Tip Nodes and Post-Order Internal Recursion

Felsenstein's algorithm evaluates the conditional likelihood vector Lv(h) = [Lv(h)(1), ..., Lv(h)(A)]T from the tips down to the root via a bottom-up post-order tree traversal (visiting both child nodes u and w before visiting their parent node v):

  1. Initialization at Leaf (Tip) Nodes: For any external tip node k โˆˆ {1, ..., N} where the observed character in alignment column h is xk:
  • Unambiguous Character: Lk(h)(s) = 1 if s = xk, and Lk(h)(s) = 0 for all s โ‰  xk. (For example, if tip k has nucleotide A in state order {A, C, G, T}, its tip vector is [1, 0, 0, 0]).
  • Missing Data, Gap (-), or IUPAC Ambiguity Code: Because missing data or ambiguity codes represent uncertainty about which state is observed at tip k, Lk(h)(s) = 1 for every state s compatible with the symbol (e.g., [1, 1, 1, 1] for N or -, and [1, 0, 1, 0] for purine R).
  1. Post-Order Recursion at Internal Nodes: For an internal node v with left child u (connected by branch length tu) and right child w (connected by branch length tw), evolution along branch tu and its descendant clade is conditionally independent of evolution along branch tw and its descendant clade once the ancestral state s at parent node v is specified. Therefore, for each possible parent state s โˆˆ {1, ..., A}:

Lv(h)(s) = [ โˆ‘x=1A Psx(tu) Lu(h)(x) ] ร— [ โˆ‘y=1A Psy(tw) Lw(h)(y) ]

Once Lv(h) is computed from Lu(h) and Lw(h), the descendant subtrees below u and w have been algebraically "pruned" into the A-element vector at node v.

  1. Marginal Termination at the Root Node (r): When the post-order traversal reaches the root node r, the unconditional site likelihood P(xh | ฯ„, t) is obtained by weighting each possible root state s by its prior equilibrium frequency ฯ€s:

P(xh | ฯ„, t) = โˆ‘s=1A ฯ€s Lr(h)(s)

Sequence AlphabetAlphabet Size (A)Matrix-Vector Cost per Node (2A2)Brute-Force States for N = 50 Taxa (A49)Felsenstein Pruning Operations per Site for N = 50
Binary / Restriction SitesA = 28 FLOPs249 โ‰ˆ 5.63 ร— 101449 ร— 8 = 392 FLOPs
DNA / RNA NucleotidesA = 432 FLOPs449 โ‰ˆ 3.17 ร— 102949 ร— 32 = 1,568 FLOPs
Translated Amino AcidsA = 20800 FLOPs2049 โ‰ˆ 5.63 ร— 106349 ร— 800 = 39,200 FLOPs
Universal Sense CodonsA = 617,442 FLOPs6149 โ‰ˆ 4.90 ร— 108749 ร— 7,442 = 364,658 FLOPs

Pulley Principle, Rate Heterogeneity, and Numerical Optimizations

Felsenstein's Pulley Principle for Unrooted Trees

When the underlying substitution model Q is time-reversibleโ€”satisfying the detailed balance condition ฯ€i qij = ฯ€j qji, which in turn ensures ฯ€i Pij(t) = ฯ€j Pji(t)โ€” combined with the Chapman-Kolmogorov semigroup property P(t1 + t2) = P(t1)P(t2), the site likelihood P(xh | ฯ„, t) is completely invariant to the placement of the root node r anywhere along any branch of the tree. Felsenstein termed this invariance the Pulley Principle.

Because of the Pulley Principle, maximum-likelihood phylogenetics searches operate on unrooted trees (which have 2N โˆ’ 3 branches for N taxa) and place a virtual root on any internal branch being optimized during Nearest-Neighbor Interchange or Subtree Pruning and Regrafting. By caching the partial likelihood vectors pointing into both ends of an edge, the branch length te of any single edge e can be optimized by Newton-Raphson iteration in O(L ยท A2) time without recomputing the conditional likelihoods of the rest of the tree.

Discrete Gamma (+ฮ“4) Rate Heterogeneity Across Sites

In real biological sequences, functional constraints cause substitution rates to vary substantially across alignment positions (for example, between first, second, and third codon positions, or between catalytic active sites and solvent-exposed loops). Following Ziheng Yang (1994), rate heterogeneity across sites is modeled by multiplying all branch lengths at site h by a relative rate factor rk drawn from a continuous Gamma(ฮฑ, ฮฑ) distribution of mean 1 and variance 1/ฮฑ, approximated by K = 4 equal-probability discrete categories (+ฮ“4) with rates r1, r2, r3, r4 (each having prior weight 1/K = 0.25).

To evaluate the likelihood under a +ฮ“K model, Felsenstein's pruning algorithm is executed independently for each rate multiplier rk (replacing P(t) with P(rk t)), and the site likelihood is averaged across the K rate categories before taking the logarithm:

P(xh | ฯ„, t, ฮฑ) = โˆ‘k=1K (1 / K) [ โˆ‘s=1A ฯ€s Lr(h,k)(s) ]

Site-Pattern Compression and Floating-Point Underflow Scaling

Modern phylogenetic engines (such as RAxML, IQ-TREE, and PhyML) accelerate Felsenstein's pruning algorithm via two essential engineering techniques:

  1. Site-Pattern Compression (Aliasing): Any two alignment columns xh and xm that display the exact same pattern of characters across all N tips have identical conditional likelihood vectors at every node of the tree. Compressing L total alignment columns into Lu โ‰ค L unique site patterns with integer multiplicity weights wp reduces the total runtime to O(N ยท Lu ยท K ยท A2).
  2. Floating-Point Underflow Rescaling: On trees containing hundreds or thousands of taxa, multiplying probabilities Psx(t) < 1 across hundreds of internal nodes causes the conditional likelihoods Lv(s) to decay exponentially toward zero as exp(โˆ’cN), eventually underflowing double-precision IEEE 754 floating-point representation (~2.2 ร— 10โˆ’308). Whenever maxs Lv(s) falls below a safety threshold (such as 2โˆ’256), the vector Lv is divided by its maximum element Mv = maxs Lv(s) (or scaled by a power of 2), and ln(Mv) is accumulated into a per-site log-scaling ledger added back to the final log-likelihood at the root.

Frequently Asked Questions

Why is Felsenstein's pruning algorithm O(N ยท A2) per site instead of O(N ยท A)?

At each of the N โˆ’ 1 internal nodes of a binary tree, the algorithm must evaluate the conditional likelihood Lv(s) for each of the A possible parent states s โˆˆ {1, ..., A}. For each parent state s, it computes the inner product โˆ‘x=1A Psx(t) Lu(x) over all A possible child states x on both the left and right branches, requiring 2A2 floating-point multiplications per node and O(N ยท A2) operations across the entire tree.

How does Felsenstein's pruning algorithm handle gaps (-) and missing data (N)?

Under standard time-reversible Markov substitution models that do not explicitly model insertion-deletion events as an extra state, a gap (-) or unknown nucleotide (N) at tip k is treated as missing data (complete uncertainty about which character state is present). Its tip conditional likelihood vector is initialized to all ones, Lk(s) = 1 for all s โˆˆ {1, ..., A}, which algebraically prunes away a terminal branch Containing only missing data without biasing the remaining tree likelihood.

What is Felsenstein's Pulley Principle and when does it break down?

Felsenstein's Pulley Principle states that the likelihood of an alignment on a tree is unchanged when the root is moved along any branch, so long as the sum of the two sub-branch lengths attached to the root stays constant. It holds whenever the substitution model satisfies time-reversibility (ฯ€i qij = ฯ€j qji) and stationarity; it breaks down under non-reversible substitution models (such as general non-reversible 12-rate DNA matrices) or non-stationary base-composition models across lineages.

References

  1. Felsenstein, J. (1981). "Evolutionary trees from DNA sequences: A maximum likelihood approach." Journal of Molecular Evolution, 17(6), 368โ€“376. https://doi.org/10.1007/BF01734359
  2. Felsenstein, J. (1973). "Maximum likelihood and minimum-steps methods for estimating evolutionary trees from data on discrete characters." Systematic Zoology, 22(3), 240โ€“249. https://doi.org/10.2307/2412304
  3. Yang, Z. (1994). "Maximum likelihood phylogenetic estimation from DNA sequences with variable rates over sites: Approximate methods." Journal of Molecular Evolution, 39(3), 306โ€“314. https://doi.org/10.1007/BF00160154
  4. Felsenstein, J. (2004). Inferring Phylogenies. Sinauer Associates. https://doi.org/10.1086/424804
๐Ÿงฌ Support Open Science
Explore interactive science games on LowKey Games or browse scientific apparel & accessories in the CRV Science Shop.
๐Ÿ’ก Spot an inaccuracy or have primary literature to expand this article?
Submit a citation or revision note using your shared CRV Science / LowKey Games profile ID.
Suggest Revision