Note
Archive Notice: This project is an educational and reference implementation of profile Hidden Markov Model (HMM) search in Rust. It is finished and archived; no active maintenance or feature development is planned.
viterbi is a high-performance profile Hidden Markov Model (HMM) search and alignment engine written in pure Rust. It implements HMMER3-compatible profile modeling, fast log-space arithmetic with a 4,096-entry
-
Precomputed Branchless
$\ln(1 + e^{-\Delta})$ Table:- 4,096-entry lookup table for high-speed
log_sum_exp(a, b)evaluations, enabling fast Forward scoring without callingf32::exporf32::lnin the inner loop.
- 4,096-entry lookup table for high-speed
-
Dual DP Engines (Scalar & Striped):
-
Scalar Viterbi: Full local profile HMM recurrence with state backtrace (
M,I,D), yielding domain boundaries and state alignments. -
Farrar-Style Striped Viterbi: Parallelized model states into striped lanes of width
$W = 8$ , boosting cache locality and SIMD auto-vectorization across query sequences.
-
Scalar Viterbi: Full local profile HMM recurrence with state backtrace (
-
HMMER3 ASCII Format (
.hmm) & MSA Builder:- Parses standard ASCII HMMER3/f model files (
NAME,LENG,ALPH,STATS, match/insert/transition matrices). - Builds calibrated profile HMMs directly from multi-sequence alignment (MSA) FASTA files with Laplace pseudocounts.
- Parses standard ASCII HMMER3/f model files (
-
Statistical Significance:
- Computes log-odds bit-scores and statistical E-values calibrated via Gumbel extreme value distribution parameters (
$\mu, \lambda$ ). - Generates tabular domain hit tables (
--domtblout).
- Computes log-odds bit-scores and statistical E-values calibrated via Gumbel extreme value distribution parameters (
Multiple Sequence Alignment (MSA)
|
[ viterbi build ]
|
Laplace Pseudocounts + Background Normalization
|
Profile HMM (.hmm)
|
v
[ Target Sequences FASTA ]
|
+------+------+
| |
[ Striped DP ] [ Scalar DP ] (W=8 vectorization & backtrace)
| |
+------+------+
|
[ Gumbel Extreme Value Statistics ]
- Bit-Score S = (Raw / ln 2)
- E-value E = N * exp(-lambda * (S - mu))
|
+-------+-------+
| |
Standard Output Tabular Hits (domtblout)
cargo build --release
cargo test --releasemake test # Runs unit tests or standalone verification suite
make all # Builds release binarycargo run --release -- build --msa data/sample_msa.fa --output kinase.hmmcargo run --release -- search --hmm kinase.hmm --targets data/sample_targets.fa --domtblout hits.tsv --show-alignmentOutput:
Target Length Score E-value hmm_from hmm_to ali_from ali_to
------------------------------------------------------------------------------------------
target_kinase_true 59 152.1 1.42e-44 0 41 4 45
States: MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
target_kinase_variant 50 84.3 2.15e-23 0 41 4 45
States: MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
Run automated verification:
./scripts/test_example.sh
./scripts/benchmark_compare.sh| Target Length | Viterbi Latency |
|---|---|
| 200 aa | 4.88 ms |
| 500 aa | 12.76 ms |
| 1,000 aa | 26.74 ms |
MIT License. Copyright (c) 2026 Andreas Sagen.