Tutorials › High-Dimensional Genomic Data Analysis › Hidden Markov Models For Phasing

Genotype Imputation · Tutorial 48 of 795

Hidden Markov Models For Phasing

Learn how a simplified hidden Markov model represents phase orientation, incorporates recombination between markers, and combines local evidence across a chromosome.

Intermediate 12 min read

What You'll Learn

  • Define hidden phase-orientation states and genotype-compatible emissions.
  • Explain how recombination determines probabilities of staying in or changing state.
  • Derive the forward recursion for calculating state probabilities from observed data.
  • Distinguish the most likely complete state path from the most probable final state.
  • Recognize when genotype data alone cannot resolve phase and identify basic model diagnostics.

Why Represent Phase With Hidden States?

At a heterozygous marker, an unphased genotype records one reference and one alternate allele but does not say which allele lies on which homologous chromosome. Across several markers, those assignments form a phase pattern. Statistical phasing uses information across markers to assess which patterns are plausible; a hidden Markov model (HMM) provides a compact way to express how the pattern may change along the chromosome.

The model below is deliberately simplified. Its hidden state records the orientation of a phase pattern, while the observations provide local evidence about that orientation. Recombination makes a change in orientation more plausible between markers than within a tightly linked interval. Importantly, an unphased genotype by itself generally does not distinguish the two orientations of a heterozygote. Local phase-informative evidence, such as a compatible observed haplotype pattern, is needed to favor one orientation over another.

Definition: At marker \(i\), let \(Z_i\in\{0,1\}\) be a hidden phase-orientation state. For a heterozygous genotype, state 0 means the alternate allele is assigned to one designated homolog and state 1 means it is assigned to the other. Let \(G_i\) be the observed unphased genotype, coded as the number of alternate alleles, and let \(Y_i\) denote the local observed evidence used to assess phase. The emission probability is \(e_i(z)=P(Y_i\mid Z_i=z,G_i)\). The transition probability \(P(Z_i\mid Z_{i-1})\) describes how orientation changes between adjacent markers.

Model Assumptions and Recombination Transitions

This formulation assumes markers are ordered along the chromosome and that the hidden state at a marker depends on the preceding state through a first-order Markov transition. Conditional on the hidden states and genotypes, the local evidence \(Y_i\) is assumed independent across markers. These are modeling assumptions, not biological certainties; dependence in the evidence or an incomplete state description can make computed probabilities overconfident or misleading.

For a simple symmetric model, let \(r_i\) be the probability that the phase orientation changes between markers \(i-1\) and \(i\). Then the transition matrix is:

$$ P(Z_i=z'\mid Z_{i-1}=z)= \begin{cases} 1-r_i,&z'=z,\\ r_i,&z'\ne z. \end{cases} $$

Usually \(0\le r_i\le 0.5\) in this simplified model: nearby markers have a small chance of a change, while widely separated markers carry less information about a shared orientation. For genetic distance \(d_i\) in Morgans, a common illustrative mapping assumption is the Haldane model, which treats crossovers as a Poisson process. The probability of an odd number of crossovers, and hence a change in orientation, is \(r_i=(1-e^{-2d_i})/2\). This is a modeling approximation; the tutorial’s numerical examples also specify \(r_i\) directly.

The genotype constrains which states are possible. A genotype \(G_i=0\) or \(G_i=2\) is homozygous, so swapping homolog labels does not create a distinct local allele assignment. A heterozygous genotype \(G_i=1\) is compatible with either orientation. If only unphased hard genotypes are observed, the emission likelihoods for these two orientations are equal: the genotype says one allele of each type is present, not which homolog carries which. Phase-informative evidence can make \(e_i(0)\) and \(e_i(1)\) differ. A model should not silently treat an unphased genotype as if it supplied that information.

Worked Example: Setting a Transition Probability From Distance

Suppose adjacent markers are separated by \(d_i=0.01\) Morgans, or 1 centimorgan. Under the Haldane mapping assumption, calculate the probability of an orientation change.

Substitute the distance into \(r_i=(1-e^{-2d_i})/2\):

$$ r_i=\frac{1-e^{-2(0.01)}}{2} =\frac{1-e^{-0.02}}{2} \approx \frac{1-0.9802}{2} =0.009901. $$

Thus the probability of a change is about 0.009901, and the probability of staying in the same state is \(1-r_i\approx0.9901\). These are transition probabilities for this simplified model under the stated mapping assumption; they are not a direct observation that a crossover occurred in a particular individual.

Emissions, Forward Probabilities, and Path Inference

An emission probability measures how compatible the local evidence is with a state. It is a likelihood conditional on that state, not automatically a posterior probability that the state is true. At a heterozygous marker, a read-backed or other phase-informative observation may favor one assignment; a hard unphased genotype alone does not. Emissions must also respect genotype compatibility: an observation describing a homozygous call should not be assigned a positive likelihood under an incompatible allele configuration.

The forward algorithm sums over possible paths rather than selecting one. Define \(\alpha_i(z)=P(Y_1,\ldots,Y_i,Z_i=z\mid G_1,\ldots,G_i)\). With initial state probabilities \(\pi(z)=P(Z_1=z)\), the initialization and recursion are:

$$ \alpha_1(z)=\pi(z)e_1(z),\qquad \alpha_i(z)=e_i(z)\sum_{z'\in\{0,1\}}\alpha_{i-1}(z')P(Z_i=z\mid Z_{i-1}=z'). $$

The sum of the two forward values at the last marker is the likelihood of the observed evidence under the model. Dividing \(\alpha_i(z)\) by \(\alpha_i(0)+\alpha_i(1)\) gives the state probability conditional on the evidence through marker \(i\), provided the model and its likelihoods are specified. This is a marginal state probability: it sums the probabilities of every path that ends in that state.

A different question is which complete state sequence has the largest joint probability with the observations. The Viterbi algorithm answers this by replacing the sum in the forward recursion with a maximum and storing the maximizing predecessor at each step. The most likely complete path need not end in the state with the largest marginal probability, because the marginal sums many possible paths while the Viterbi result selects just one.

Worked Example: A Tie Between the Best Complete Paths

Consider three markers with equal initial probabilities, \(\pi(0)=\pi(1)=0.5\), and transition probabilities \(P(\text{stay})=0.9\), \(P(\text{change})=0.1\). Suppose the local evidence has emissions \(e_1(0)=0.9,e_1(1)=0.05\), \(e_2(0)=0.8,e_2(1)=0.05\), and \(e_3(0)=0.1,e_3(1)=0.9\). Treat these as hypothetical likelihoods conditional on each orientation and the observed genotypes.

For the path \(000\), the initial state probability is 0.5, the first two emissions are 0.9 and 0.8, both transitions stay, and the final emission is 0.1. Therefore:

$$ P(000,Y\mid G)=0.5(0.9)(0.9)(0.8)(0.9)(0.1)=0.02916. $$

For \(001\), the first two states and emissions are unchanged, but the last transition changes state and the final emission is 0.9:

$$ P(001,Y\mid G)=0.5(0.9)(0.9)(0.8)(0.1)(0.9)=0.02916. $$

The other paths have lower joint probabilities under these specified emissions, so \(000\) and \(001\) tie as the most likely complete paths. Yet the marginal probability of ending in state 1 is larger. The forward values at marker 2 are \(\alpha_2(0)=0.326\) and \(\alpha_2(1)=0.003375\). Applying the transition and final emissions gives:

$$ \alpha_3(0)=(0.326(0.9)+0.003375(0.1))(0.1)=0.02937375, $$ $$ \alpha_3(1)=(0.326(0.1)+0.003375(0.9))(0.9)=0.03207375. $$

Since \(0.03207375>0.02937375\), the marginal probability of final state 1 is larger: its normalized value is \(0.03207375/(0.02937375+0.03207375)\approx0.5220\). This does not contradict the Viterbi tie. The marginal sums all paths ending in each state, whereas the complete-path comparison considers one path at a time.

A Short Derivation of the Forward Recursion

To calculate the probability of reaching state \(z\) at marker \(i\) with all evidence through that marker, consider the possible state \(z'\) at marker \(i-1\). The events for the two predecessor states are disjoint. For each predecessor, the probability of the preceding evidence and state is \(\alpha_{i-1}(z')\); multiply by the transition probability to \(z\), then by the likelihood \(e_i(z)\) of the current evidence. Summing over the two predecessors gives:

$$ \begin{aligned} P(Y_1,\ldots,Y_i,Z_i=z\mid G_1,\ldots,G_i) &=\sum_{z'\in\{0,1\}}P(Y_1,\ldots,Y_{i-1},Z_{i-1}=z'\mid G_1,\ldots,G_{i-1})\\ &\quad\times P(Z_i=z\mid Z_{i-1}=z')e_i(z)\\ &=e_i(z)\sum_{z'\in\{0,1\}}\alpha_{i-1}(z')P(Z_i=z\mid Z_{i-1}=z'). \end{aligned} $$

The factorization uses the Markov assumption for transitions and the conditional-independence assumption for emissions. If local observations remain dependent after conditioning on the hidden states, this recursion does not represent their joint likelihood correctly without an expanded model.

Worked Example: Updating State Probabilities Across Two Markers

At the first marker, let \(\pi(0)=\pi(1)=0.5\) and emissions be \(e_1(0)=0.8\), \(e_1(1)=0.2\). At the second marker, let \(r_2=0.1\), with emissions \(e_2(0)=0.3\), \(e_2(1)=0.9\). Calculate the forward values and the probability of state 1 at marker 2 conditional on the evidence.

Initialization gives \(\alpha_1(0)=0.5(0.8)=0.4\) and \(\alpha_1(1)=0.5(0.2)=0.1\). For state 0 at marker 2, either state 0 stays or state 1 changes:

$$ \alpha_2(0)=0.3\{0.4(0.9)+0.1(0.1)\} =0.3(0.37)=0.111. $$

For state 1, state 0 changes or state 1 stays:

$$ \alpha_2(1)=0.9\{0.4(0.1)+0.1(0.9)\} =0.9(0.13)=0.117. $$

The total evidence likelihood is \(0.111+0.117=0.228\). Thus the conditional probability of state 1 at marker 2 is \(0.117/0.228\approx0.5132\); that of state 0 is \(0.111/0.228\approx0.4868\). The local emission favors state 1, and the transition-weighted information from marker 1 is incorporated rather than discarded.

Diagnostics, Alternatives, and Limitations

Before interpreting an HMM output, check that marker order and genetic distances are correct, transition probabilities are in range, and each emission corresponds to the stated observation model. A useful basic diagnostic is to inspect whether emissions actually distinguish the states. If \(e_i(0)=e_i(1)\) at every marker and the initial probabilities are symmetric, the observed data provide no preference for either globally swapped orientation. Transitions can favor persistence relative to switching, but cannot create phase evidence absent from the observations.

Other warning signs include abrupt state changes across very short distances, emissions that assign substantial likelihood to genotype-incompatible configurations, and highly decisive results driven by a single questionable observation. These may indicate data errors, a mis-specified likelihood, incorrect marker spacing, or unmodeled dependence. They do not, by themselves, prove which assumption failed. Scaling forward probabilities during long sequences may also be needed in computation to prevent numerical underflow; the same scale factor must be tracked if the overall likelihood is required.

A maximum-likelihood or maximum a posteriori phase assignment reports a selected configuration, while the HMM forward calculation retains uncertainty by summing paths. Independent marker-by-marker assignment is simpler but ignores linkage and transition structure. The simplified two-state model is interpretable and useful for illustrating phase continuity, but it cannot represent every possible haplotype configuration or realistic population-level structure. More elaborate models can use richer latent states and additional data, at the cost of more assumptions and computation. A result from this model should therefore be read as conditional on its states, emissions, transition model, and observed data—not as a guarantee that the inferred phase is correct.

Common Mistake

  • Wrong reasoning: “The best complete path ending in state 0 is more likely, so state 0 must also have the larger probability at the final marker.”
  • Correction: A best-path probability is the probability of one sequence. A marginal state probability adds the probabilities of all sequences ending in that state. Compare the quantities being asked for and calculate them accordingly; as the three-marker example shows, two best paths can even tie while one final-state marginal is larger.
  • Another pitfall: Treating an unphased heterozygous genotype as evidence favoring one orientation. The genotype alone is compatible with both assignments; unequal emissions require additional phase-informative observations or an explicitly stated model.
Key takeaway: In a phasing HMM, hidden states encode phase orientation, emissions quantify compatibility with local observations, and recombination controls the chance of a state change between markers. The model can combine local evidence across a chromosome, but it cannot recover orientation from uninformative genotypes alone.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. If the probability of changing state between adjacent markers is 0.03, what is the probability of staying in the same state in the symmetric two-state model?
  2. Why can an unphased heterozygous genotype alone not distinguish the two orientations?
  3. With equal initial state probabilities and equal emissions in both states at every marker, what can the observations establish about the absolute orientation?
  4. Explain why the most likely complete path and the most probable state at the final marker can differ.

Solutions. (1) The stay probability is \(1-0.03=0.97\). (2) Both orientations contain one reference and one alternate allele, so the unphased genotype records the same allele count under either assignment. (3) The observations cannot favor one absolute orientation over the other; with symmetric transitions and initialization, the two global orientations remain equally supported. (4) The best complete path selects one sequence, while the final-state marginal sums the probabilities of every sequence ending in that state; many individually weaker paths can make that sum larger.

Clinical Biostats