# biopython v1.71.0 Bio.HMM.MarkovModel.HiddenMarkovModel

Represent a hidden markov model that can be used for state estimation.

# Link to this section Summary

## Functions

Initialize a Markov Model

Return log transform of the given probability dictionary

Get the starting default emmissions for each sequence

Get the default transitions for the model

Get all destination states which can transition from source state_letter

Get all source states which can transition to destination state_letter

Calculate the most probable state path using the Viterbi algorithm

# Link to this section Functions

Initialize a Markov Model.

Note: You should use the MarkovModelBuilder class instead of initiating this class directly.

Arguments:

- initial_prob - A dictionary of initial probabilities for all states.
- transition_prob — A dictionary of transition probabilities for all possible transitions in the sequence.
- emission_prob — A dictionary of emission probabilities for all possible emissions from the sequence states.
- transition_pseudo — Pseudo-counts to be used for the transitions, when counting for purposes of estimating transition probabilities.
- emission_pseudo — Pseudo-counts to be used for the emissions, when counting for purposes of estimating emission probabilities.

Return log transform of the given probability dictionary.

When calculating the Viterbi equation, add logs of probabilities rather than multiplying probabilities, to avoid underflow errors. This method returns a new dictionary with the same keys as the given dictionary and log-transformed values.

Get the starting default emmissions for each sequence.

This returns a dictionary of the default emmissions for each letter. The dictionary is structured with keys as (seq_letter, emmission_letter) and values as the starting number of emmissions.

Get the default transitions for the model.

Returns a dictionary of all of the default transitions between any two letters in the sequence alphabet. The dictionary is structured with keys as (letter1, letter2) and values as the starting number of transitions.

Get all destination states which can transition from source state_letter.

This returns all letters which the given state_letter can transition to, i.e. all the destination states reachable from state_letter.

An empty list is returned if state_letter has no outgoing transitions.

Get all source states which can transition to destination state_letter.

This returns all letters which the given state_letter is reachable from, i.e. all the source states which can reach state_later

An empty list is returned if state_letter is unreachable.

Calculate the most probable state path using the Viterbi algorithm.

This implements the Viterbi algorithm (see pgs 55-57 in Durbin et al for a full explanation — this is where I took my implementation ideas from), to allow decoding of the state path, given a sequence of emissions.

Arguments:

- sequence — A Seq object with the emission sequence that we want to decode.
- state_alphabet — The alphabet of the possible state sequences that can be generated.