Skip to content

feat(hmm): add profile hidden Markov models - #705

Open
SahilRajputdotexe wants to merge 1 commit into
rust-bio:masterfrom
SahilRajputdotexe:feat/profile-hmm
Open

SahilRajputdotexe wants to merge 1 commit into
rust-bio:masterfrom
SahilRajputdotexe:feat/profile-hmm

Conversation

@SahilRajputdotexe

Copy link
Copy Markdown

This adds bio::stats::hmm::profile, a profile hidden Markov model with match, insert and delete states per position (the Plan 7 layout from Durbin et al. and Eddy 1998). The generic discrete and Gaussian models in bio::stats::hmm are untouched, and this one sits next to them as a submodule.

A ProfileHmm is built from equal-length aligned rows, where - marks a gap. Columns that hold a residue in at least half of the weighted rows become positions, and a pseudocount smooths the counts. It then offers Viterbi alignment, forward/backward and match posteriors, maximum expected accuracy decoding, null-corrected bit scores with a ranked search, local alignment and scan, Baum-Welch and Viterbi re-estimation, sampling, consensus and information content, a rectangular align_all layout, and a text form that round-trips.

use bio::alphabets::Alphabet;
use bio::stats::hmm::profile::ProfileHmm;

let mut builder = ProfileHmm::builder(&Alphabet::new(b"ACGT"));
builder.add_row(b"ACGT");
builder.add_row(b"ACGT");
builder.add_row(b"AC-T");
let profile = builder.build().unwrap();

let alignment = profile.best_alignment(b"ACGT").unwrap();
let bits = profile.bit_score(b"ACGT").unwrap();

Hidden Markov models are one of the open items on the roadmap in #3.

There are unit tests next to each part (forward equals backward, posteriors in range, insert and delete runs, search ordering and ties, non-decreasing re-estimation traces, text round trip, error cases) and a doctest in the module docs. All of them pass on my fork's CI, and cargo clippy is clean for the new files.

The diff is large, about 2000 lines of code across 12 new files plus tests. I am happy to split it into smaller PRs, for example builder and Viterbi first, then forward/backward and decoding, then training and the rest, if that is easier to review.

Add bio::stats::hmm::profile, a Plan 7 style profile HMM built from a block of aligned rows. It provides Viterbi, forward/backward and maximum expected accuracy decoding, bit-score search, local alignment and scanning, Baum-Welch and Viterbi re-estimation, sampling, and a text form that round-trips.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant