Hidden Markov Model for Biological Sequence
By: Mattia Cinelli
Tags: Getting Started, Markov Chains, Bioinformatics, Editors Pick, Machine Learning

Application on Biological sequences

Let’s consider a set of functionally related DNA sequences. Our objective is to characterise them as a “family”, and consequently identify other sequences that might belong to the same family.

We start by creating a multiple sequence alignment to highlight conserved positions:

Five related sequences are aligned with a multiple sequence alignment (Image by Author)

It is possible to express this set of sequences as a regular expression. The family pattern for this set of sequences is:

[AT][CG][AC][ACGT]∗A[TG][GC]

Each position in the regular expression represents the nucleotides in the chain. Multiple options for each position are gathered in a bracket: thus, the first element could equally be an A or a T, the second one a C or G, and so on. The element indicated with a * represents a gap area: only the A is not bracketed, because it is the only possible option of that position.

The regular expression is useful because it allows us to spot the pattern of this family of sequences in a visual and simple compact view. However, the regular expression is not an adequate method when establishing whether other sequences are part of this family.

As an example, let’s consider two new sequences 1 and 2:

TGCA–AGG ACAC–ATC

Both sequences fit the regular expression given above and, based on that alone, they could be considered part of the family. However, we can see that the first sequence is formed by the nucleotides occurring the fewest times in the multiple sequence alignment, while the second is formed by those most common. Indeed, in the first position, the T is present only once in the multiple sequence alignment, while A in all other sequences, similarly for the in the second position, the G only once and C, for all remaining sequences.

We need a way to measure the “distance” between a new sequence and the original set of family sequences. To solve this problem, we can use the MC and HMM:

Using Markov Chain

From the multiple sequence alignment, we can start computing the probability of transition following the alignment seen previously. As such, we can begin calculating the probability of passing from the nucleotide A to G or from G to T, for example, and forming a transition matrix.

Graphical representation of a Markov chain model for DNA: Each circle represents a state of the chain: four states connected with the DNA nucleotides (A, C, G, T). Each edge is the probability of transition from one state to another or to itself. (Image by Author)

Using the transition matrix, it is possible to obtain the probability of a new sequence through the following relation:

The formula of the Transition Matrix. Side note: I’ve met quite a few people that never saw the symbol on the right that is a multiplier (Image by Author)

Where the probability of a sequence concerning a transition matrix (Mt) is given by the product of the transition probability from one state to another of the sequence.

The result obtained through this equation is an indication of how much a sequence can be considered part of a family: the higher the value obtained, the greater the extent to which a sequence can be considered part of the family. However, the transition matrix is being obtained regardless of the positions of the states within the sequences. This aspect is not negligible, particularly regarding the study of DNA and protein sequences, where undeniably the position of a nucleotide is more important than its numeric presence.

To adapt the Markov Model to the study of sequences, the concept of Profile HMM has been introduced.

Using Profile HMM

The Profile HMM is a variation of the Hidden Markov Chain in which the position of a multiple sequence alignment becomes the states of the model; the transition matrix is the probability to pass from one state/position to the next.

In this way, the probability of emission for each state is introduced, and thus the probability to have a particular nucleotide on that state of the Markov Chain.

We can rewrite the regular expression presented in the previous section (and above), delivering the assumption of the previous paragraph.

The figure below clarifies this concept:

[AT][CG][AC][ACGT]∗A[TG][GC]

Scheme of a Profile HMM: In this plot, the multiple sequence alignment taken as the example above, has been represented as a Profile HMM, each position of the multiple sequence alignment is a state, for each amino acid are reported the probability of emission of a nucleotide in that state and, the arrows are the transition probability between the state. Source for this example (Image by Author)

Each of the boxes is a state of the HMM, corresponding to the position of the multiple sequence alignment or each group of the regular expression. Inside the boxes are the possible emissions of the state and the probability of each one, while the external arrows exemplify the probability of transition from one state to the other.

The state on the top of the figure above is the only one with the property to stay still, rather than to move to a different state. This property can be used to model an insertion state.

To generalise the scheme even further, more states can be added with different properties until a Profile HMM is formed. The general standard architecture of a Profile HMM is presented in the figure below:

General representation of the structure of a Profile HMM: This is a general representation of the structure of a Profile HMM. There is both a begin and end state. The square represents the matches’ states (M), and the circles and diamonds represent deletion (D) and insertion states (I). The addition of insertion and deletion states make it possible to train and test sequences of different length. The arrows are the transition probability and because for each position, except for the Begin and End state. Because there are nine arrows, this type of Profile HMM is called Plan 9. (Image by Author)

In the figure above the Profile-HMM has three hidden states, plus a “Begin” and “End” state.

The squares are the “matches” states, which represent the frequency (emission) of the amino acid or nucleotides.

The diamonds are called the “insert state”. They are used to model the gap insertions of the alignment. They are usually used to test sequences longer than the consensus sequences.

The circles are the “deletion states”. They play the role of the silent or null state. They do not match residues or gaps and are used to jump from one column to another. These are usually used for sequences shorter than the consensus sequences.

Begin and End states have been introduced to help the transaction at the beginning and the end of the Profile HMM. They do not produce any emissions.

The arrows represent the transition probabilities. In the figure above, nine arrows are presented in a module (M, I, D states). This configuration is named Plan 9. Sometimes, a variation of this is present, like Plan 7, etch.

Profile HMM are widely used in biological sequences analysis. They have been proven to be useful for protein classification, motif detection, multiple sequences alignment, and protein secondary structure prediction. In general, all of them can be summarised in terms of their major uses: aligning a sequence to a profile and scoring a sequence against a profile.

To evaluate a sequence against a profile and obtain a score, more efficient dynamic programming methods than the ones presented above are available. The Forward algorithm identifies the likelihood of a sequence; the Viterbi algorithm identifies the most probable “path” to generate a given sequence; and the Forward-Backward (Baum-Welch) algorithm, used also to train the Profile HMM.

In Conclusion

I hope this article has helped you understand the concepts behind Markov Chains and Hidden Markov Models. These models have a surprisingly high number of applications and they deserve to be better known and applied.

I kept this article light on the math and focus on a general overview but it contains enough links to sources to deepening your understanding of MC and HMM.

For who wants to know more, I strongly recommend this article from Anders Krogh that was inspirational for this article and also the book “Hidden Markov Models for Bioinformatics” by Timo Kosk that presents a formal and thought mathematical explanation of the MC/HMM.