Section: Computational Biology

Hidden Markov Models in Biological Sequence Analysis

Introduction

Hidden Markov models (HMMs) are probabilistic frameworks that have become foundational in computational biology for the analysis of linear biological sequences such as DNA, RNA, and protein primary structures [1, 2]. An HMM models a sequence of observable events (e.g., nucleotide bases or amino acid residues) as being generated by an unobserved (hidden) Markov process. The model consists of a set of states, transition probabilities between states, and emission probabilities that define the likelihood of observing a particular symbol from a given state. This architecture enables HMMs to capture positional dependencies and conservation patterns within sequence families, making them particularly suited for tasks including remote homology detection, multiple sequence alignment, gene prediction, and functional annotation.

The application of HMMs in bioinformatics has expanded substantially since their introduction, aided by algorithmic improvements and integration with other computational techniques [3, 1]. In the context of veterinary medicine and animal diagnostics, HMM-based methods are increasingly used to characterize pathogen genomes, detect antimicrobial resistance determinants, and annotate emerging viral variants. This article provides a detailed technical exposition of HMMs in biological sequence analysis, with emphasis on profile HMMs, architectural extensions, and computational implementations that are relevant to veterinary virology and diagnostics.

Mathematical and Algorithmic Foundations

The Hidden Markov Model

An HMM is defined by a set of N hidden states S = {s₁, s₂, ..., sₙ}, a transition probability matrix A = {aᵢⱼ} where aᵢⱼ = P(state j at time t+1 | state i at time t), an emission probability matrix B = {bᵢ(k)} where bᵢ(k) = P(observing symbol k in state i), and an initial state probability vector π = {πᵢ} where πᵢ = P(state i at time 1). The observed sequence O = (o₁, o₂, ..., o_T) is modeled as a realization of the stochastic process defined by these parameters. The fundamental algorithms associated with HMMs are the forward algorithm (for computing the likelihood of a sequence given the model), the Viterbi algorithm (for finding the most probable path of hidden states), and the Baum-Welch algorithm (for parameter estimation via expectation-maximization) [1].

Profile HMMs for Sequence Families

A profile HMM is a specialized architecture designed to represent a multiple sequence alignment of related sequences. The profile consists of three types of states: match states (M) that model conserved positions, insert states (I) that model gaps within aligned regions, and delete states (D) that model positions where a residue is absent in a given sequence relative to the consensus [4]. Transitions among these states are trained using a set of aligned sequences, typically via the HMMER software suite [3]. The resulting profile HMM can then be used to search a database for new members of the sequence family, yielding a score that reflects the likelihood of homology.

Profile HMMs have been shown to be non-identifiable under certain conditions, meaning that different parameter sets can produce the same distribution of sequences [4]. Despite this limitation, they remain highly effective for remote homology detection because they capture position-specific conservation patterns that are more sensitive than simple pairwise similarity methods.

Architectural Variants

Several extensions to the basic HMM framework have been developed for specific biological problems.

Hierarchical HMMs: In a hierarchical HMM, the hidden states themselves are modeled as sub-HMMs, enabling the representation of sequence motifs at multiple scales. This architecture has been applied to the detection of antimicrobial resistance sequences, where the hierarchical structure captures both class-level and gene-level signatures [5].

Ordered HMMs with emission densities (oHMMed): This variant relaxes the assumption of a fixed number of states by allowing the ordering of states along a genomic coordinate and using continuous emission densities. It has been used to infer genomic landscapes, such as recombination rate variation and GC content domains, from population sequencing data [6].

Circular profile HMMs (cpHMMs): Designed for tandem repeat detection, cpHMMs allow the model to wrap around at the ends of a repeat unit, capturing the periodic nature of tandem arrays. The TRAL 2.0 system employs circular profile HMMs to detect and align tandem repeats across genomes [7].

Hidden Markov models with explicit duration (duration HMMs): Standard HMMs assume a geometric distribution for state duration (the number of consecutive time steps spent in a state). Duration HMMs incorporate explicit state duration distributions, which are beneficial for applications such as nanopore base calling where the time spent in a conductance level relates to the number of bases [8].

Triplet HMMs: These models extend the HMM to handle triplets of observations, which is useful for covariate-assisted genome-wide association studies as implemented in the CARLIS framework [9]. Triplet HMMs can jointly model genotype, phenotype, and covariate information to improve replicability of association signals.

Non-homogeneous HMMs: In non-homogeneous HMMs, transition probabilities are allowed to vary along the sequence, which is particularly useful for modeling DNA methylation patterns that change across genomic regions. This approach was applied to detect differentially methylated regions from bisulfite sequencing data [10].

Coalescent HMMs: These are used in population genomics to infer ancestral recombination graphs and demographic history. The Jocx software implements a coalescent HMM that efficiently computes likelihoods for multiple genomes [11].

Bayesian phylogenetic HMMs: This hybrid framework combines a phylogenetic tree with an HMM over sites to model heterogeneity in evolutionary rates. It has been applied to B cell receptor sequence analysis to identify lineages of affinity maturation [12].

Hybrid deep learning and HMM models: Recent work combines deep neural networks (e.g., residual LSTMs or convolutional networks) with HMM layers to leverage both representational learning and interpretable state transitions. Lokatt uses a residual LSTM to produce emission probabilities for a duration HMM in nanopore base calling [8]. Helixer employs a deep learning pipeline followed by an HMM to predict eukaryotic gene models ab initio [13]. learnMSA2 integrates large language models (protein language models) with profile HMMs for deep multiple sequence alignment [14].

Applications in Biological Sequence Analysis

Remote Homology Detection and Sequence Database Searching

Profile HMMs are the primary method for identifying distantly related members of protein families. The HMMER web server provides a user-friendly interface to search protein and nucleotide databases using profile HMMs [3]. The sensitivity of profile HMMs over position-specific scoring matrices (PSSMs) used in PSI-BLAST is well established, especially for sequences with lower sequence identity. Accordingly, HMMER tools (hmmbuild, hmmsearch, hmmscan) are widely used in genome annotation pipelines for function prediction of hypothetical proteins.

Ab initio Gene Prediction

Gene prediction requires distinguishing protein-coding regions from non-coding DNA. HMMs can model the statistical properties of coding sequences, splice sites, and intergenic regions. The Helixer method uses a deep learning model to produce a per-base probability of being in a particular genic state, followed by an HMM that imposes biologically realistic constraints such as continuity of open reading frames and acceptable splice signals [13]. This hybrid approach improves accuracy in compact genomes with limited training data, such as those of many veterinary pathogens.

Antimicrobial Resistance Gene Detection

The detection of antimicrobial resistance (AMR) gene sequences is critical for managing infections in livestock and companion animals. Hierarchical HMMs, as implemented in the HAMMER system, enable the classification of resistance sequences into functional classes (e.g., beta-lactamases, tetracycline efflux pumps) and the identification of novel variants within each class [5]. This approach is more accurate than simple BLAST-based methods because it models the conserved structural features of AMR determinants.

Viral Genome Characterization and Variant Detection

Veterinary virology relies heavily on sequencing for pathogen surveillance. HMMs are used in the analysis of viral genomes for several tasks:

  • Base calling from nanopore sequencing: HMMs modeled electrical current signals from ion channels as hidden states, with explicit duration to handle homopolymer regions. The Lokatt base caller achieves high accuracy for viral genomes including those of economically important viruses affecting poultry and livestock [8].
  • Mutation signature analysis: HMMs are used to segment cancer genomes (for comparative oncology) into regions with distinct mutational signatures, such as those caused by exposure to environmental mutagens or viral integrations [15].
  • Viral subtype classification: Profile HMMs for major capsid proteins can classify viral isolates into serotypes or genotypes more reliably than simple k-mer based methods. This is applicable to the classification of canine parvovirus variants (CPV-2a, CPV-2b, CPV-2c) and feline calicivirus strains.

Tandem Repeat Detection and Genotyping

Tandem repeats are common in prokaryotic and eukaryotic genomes and often affect virulence, antigenic variation, or as molecular markers. The circular profile HMM approach in TRAL 2.0 allows detection of both perfect and imperfect repeats without prior knowledge of repeat unit length [7]. This has applications in genotyping bacteria and parasites for epidemiological studies.

Methylation Analysis

DNA methylation patterns are important epigenetic markers in development and disease. Non-homogeneous HMMs can identify differentially methylated regions (DMRs) from bisulfite sequencing data by modeling the spatial correlation of methylation states [10]. In veterinary contexts, methylation analysis has been used to study the effects of nutrition and environment on livestock health.

Multiple Sequence Alignment

Profile HMMs are inherently alignment algorithms. The learnMSA2 system combines large protein language models with profile HMMs to produce alignments that incorporate deep evolutionary and structural information [14]. This method improves alignment quality for divergent proteins, such as those from rapidly evolving RNA viruses infecting avian or mammalian hosts.

Phylogenetic and Population Genomics

Coalescent HMMs infer ancestral population parameters from whole-genome sequences. The Jocx software uses a framework that models the correlated coalescence times across chromosomes, enabling estimation of effective population size, recombination rates, and gene flow between populations [11]. These models are applicable to studies of livestock breeds and pathogen population structure.

Veterinary and Diagnostic Relevance

The application of HMMs in veterinary medicine spans multiple domains, from basic research to clinical diagnostics.

Pathogen Detection and Identification

Direct sequencing of clinical samples yields metagenomic data that must be screened for pathogen sequences. Profile HMMs offer higher sensitivity than nucleotide BLAST for detecting distantly related viral sequences. For example, in a sample from a chicken with respiratory disease, a profile HMM built on conserved RNA-dependent RNA polymerase domains can detect a novel paramyxovirus even when most of the genome is unalignable. This is critical for early detection of emerging pathogens such as highly pathogenic avian influenza (H5N1) or lumpy skin disease virus.

Antimicrobial Resistance Surveillance

Livestock-associated Staphylococcus aureus and Escherichia coli from poultry harbor resistance genes that can transfer to human pathogens. Hierarchical HMMs provide a rapid and accurate method for profiling resistance gene content from whole-genome sequencing data [5]. This allows veterinarians to guide antimicrobial use and monitor the emergence of new resistance mechanisms in production animals.

Host-Virus Interaction Studies

HMM-based annotation of viral genomes aids in identifying proteins involved in host immune evasion, such as the NS1 protein of influenza A virus or the p15E protein of feline leukemia virus. Understanding these interactions is important for vaccine design and development of antiviral strategies.

Diagnostic Assay Design

Profile HMMs can inform the design of PCR primers or hybridization probes for conserved regions across a viral family. By identifying positions that are highly conserved across diverse strains, one can target diagnostic assays to minimize false negatives due to sequence variation. This is particularly relevant for pathogens with high mutation rates, such as West Nile virus or canine coronavirus.

Computational Implementations and Hardware Acceleration

The core HMM algorithms (forward, Viterbi, Baum-Welch) have a time complexity of O(N²T) for N states and T observations. For profile HMMs with hundreds of states and databases containing billions of residues, this computational cost is substantial. Hardware acceleration using field-programmable gate arrays (FPGAs) has been developed to accelerate profile HMM filtering. The accelerator described in [16] implements the Viterbi algorithm on an FPGA, achieving about 100-fold speedup over CPU implementations while retaining sensitivity. This enables real-time analysis of sequences generated in field-deployable nanopore sequencing instruments, which is relevant for point-of-care diagnostics in veterinary settings.

A Workflow for HMM-Based Pathogen Sequence Analysis

flowchart TD
    A[Raw sequencing reads] --> B[Base calling using duration HMM<br>e.g., Lokatt]
    B --> C[Assembly and contig generation]
    C --> D[Gene prediction using hybrid<br>deep learning + HMM e.g., Helixer]
    D --> E[Functional annotation using<br>profile HMMs e.g., HMMER]
    E --> F[AMR gene detection using<br>hierarchical HMMs e.g., HAMMER]
    E --> G[Viral subtype classification<br>using subtype-specific profiles]
    F --> H[Reporting of resistance determinants<br>and virulence factors]
    G --> H
    H --> I[Epidemiological tracking and<br>outbreak response]

The flowchart above illustrates a typical bioinformatics pipeline that integrates multiple HMM-based tools for pathogen characterization from raw sequence data through to actionable intelligence for veterinary diagnostics.

Limitations and Considerations

Despite their power, HMMs have limitations. Profile HMMs assume that each position in the alignment is independent given the state, ignoring structural context (e.g., residue-residue contacts). The use of large language models and deep learning has mitigated this limitation by providing context-rich embeddings that are fed into the HMM [14]. Parameter identifiability is another concern, as multiple HMM parameterizations can yield the same observational distribution [4]. Practitioners must also be aware of overfitting when training HMMs on small datasets common in veterinary studies of low-prevalence pathogens.

Conclusion

Hidden Markov models remain a cornerstone of biological sequence analysis, offering a mathematically rigorous and interpretable framework for modeling sequence variability and conservation. Their ability to capture positional dependencies, handle gaps, and incorporate prior biological knowledge makes them ideal for applications from gene prediction to viral diagnostics. The integration of HMMs with deep learning methods and hardware acceleration ensures their relevance in the era of high-throughput sequencing and point-of-care molecular diagnostics. In veterinary medicine, these techniques are essential for pathogen surveillance, antimicrobial resistance monitoring, and vaccine development.


References

[1] Ma Y, Chen H, Kang J et al. The hidden Markov model and its applications in bioinformatics analysis. Genes Dis. 2026. URL: https://pubmed.ncbi.nlm.nih.gov/41069576/

[2] Husi H, Saeed U, Usman Z. Biological Sequence Analysis. 2019. URL: https://pubmed.ncbi.nlm.nih.gov/31815401/

[3] Rajković A, Beracochea M, Rogers AB et al. HMMER web server: 2026 update. Nucleic Acids Res. 2026. URL: https://pubmed.ncbi.nlm.nih.gov/42037125/

[4] Pattabiraman S, Warnow T. Profile Hidden Markov Models Are Not Identifiable. IEEE/ACM Trans Comput Biol Bioinform. 2021. URL: https://pubmed.ncbi.nlm.nih.gov/31425043/

[5] Lakin SM, Kuhnle A, Alipanahi B et al. Hierarchical Hidden Markov models enable accurate and diverse detection of antimicrobial resistance sequences. Commun Biol. 2019. URL: https://pubmed.ncbi.nlm.nih.gov/31396574/

[6] Vogl C, Karapetiants M, Yıldırım B et al. Inference of genomic landscapes using ordered Hidden Markov Models with emission densities (oHMMed). BMC Bioinformatics. 2024. URL: https://pubmed.ncbi.nlm.nih.gov/38627634/

[7] Delucchi M, Näf P, Bliven S et al. TRAL 2.0: Tandem Repeat Detection With Circular Profile Hidden Markov Models and Evolutionary Aligner. Front Bioinform. 2021. URL: https://pubmed.ncbi.nlm.nih.gov/36303789/

[8] Xu X, Bhalla N, Ståhl P et al. Lokatt: a hybrid DNA nanopore basecaller with an explicit duration hidden Markov model and a residual LSTM network. BMC Bioinformatics. 2023. URL: https://pubmed.ncbi.nlm.nih.gov/38062356/

[9] Li Y, Ma H, Li Y et al. CARLIS: covariate-assisted replicability analysis for genome-wide association studies via triplet hidden Markov models. Genetics. 2026. URL: https://pubmed.ncbi.nlm.nih.gov/41354059/

[10] Chen Y, Kwok CK, Jiang H et al. Detect differentially methylated regions using non-homogeneous hidden Markov model for bisulfite sequencing data. Methods. 2021. URL: https://pubmed.ncbi.nlm.nih.gov/32949692/

[11] Cheng JY, Mailund T. Ancestral Population Genomics with Jocx, a Coalescent Hidden Markov Model. Methods Mol Biol. 2020. URL: https://pubmed.ncbi.nlm.nih.gov/31975168/

[12] Dhar A, Ralph DK, Minin VN et al. A Bayesian phylogenetic hidden Markov model for B cell receptor sequence analysis. PLoS Comput Biol. 2020. URL: https://pubmed.ncbi.nlm.nih.gov/32804924/

[13] Holst F, Bolger AM, Kindel F et al. Helixer: ab initio prediction of primary eukaryotic gene models combining deep learning and a hidden Markov model. Nat Methods. 2026. URL: https://pubmed.ncbi.nlm.nih.gov/41286201/

[14] Becker F, Stanke M. learnMSA2: deep protein multiple alignments with large language and hidden Markov models. Bioinformatics. 2024. URL: https://pubmed.ncbi.nlm.nih.gov/39230690/

[15] Wojtowicz D, Sason I, Huang X et al. Hidden Markov models lead to higher resolution maps of mutation signature activity in cancer. Genome Med. 2019. URL: https://pubmed.ncbi.nlm.nih.gov/31349863/

[16] Anderson T, Wheeler TJ. An FPGA-based hardware accelerator supporting sensitive sequence homology filtering with profile hidden Markov models. BMC Bioinformatics. 2024. URL: https://pubmed.ncbi.nlm.nih.gov/39075359/

[17] Shirsath A, Khairnar SV, Anand A et al. Hidden Markov Model-Based Prokaryotic Genome Space Mining Reveals the Widespread Pervasiveness of Complex I and Its Potential Evolutionary Scheme. Genome Biol Evol. 2025. URL: https://pubmed.ncbi.nlm.nih.gov/40795046/

[18] Kalal V, Jha BK. Cancer detection with various classification models: A comprehensive feature analysis using HMM to extract a nucleotide pattern. Comput Biol Chem. 2024. URL: https://pubmed.ncbi.nlm.nih.gov/39378821/


Disclaimer: This article is for educational and informational purposes only. It is not intended to substitute for professional veterinary advice, diagnosis, treatment, or regulatory guidance. Always consult a licensed veterinarian or qualified specialist regarding animal health, disease diagnosis, and therapeutic decisions.