# A retrospective look at our models First we saw the finite state automaton The rigid non-stochastic nature of these structures ultimately limited their.

## Presentation on theme: "A retrospective look at our models First we saw the finite state automaton The rigid non-stochastic nature of these structures ultimately limited their."— Presentation transcript:

A retrospective look at our models First we saw the finite state automaton The rigid non-stochastic nature of these structures ultimately limited their usefulness to us as models of DNA 12345678 S  ggggcgctc c a The finite state automaton above is non- deterministic, but is NOT probabilistic Sequences under test are either elements of the set of accepted sequences, or are rejected

Markov Model What do we need to probabilistically model DNA sequences? A C G T States Transition probabilities Here each observation necessarily corresponded to the underlying biological state…which also limited the usefulness and generality of the concept as a model for DNA or amino acid sequences

HMM Topology Many different HMM topologies are possible…   R S  Careful selection of alternative HMM topologies will allow us to address a variety of different problems using essentially the same algorithmic toolkit

HMM Topology Duration modeling with HMMs Consider our C p G island model with two underlying states…. How long does our model dwell in a particular state? This should be familiar as an exponentially decaying value CpG +CpG + S  C p G - P(L residues) = (1-p)·p L-1 p

HMM Topology Duration modeling with HMMs What if this doesn’t accurately reflect the real distribution of lengths? CpG +CpG + S  C p G - P(L residues) = (1-p)·p L-1 p P L

HMM Topology Duration modeling with HMMs Assuming that each state shown here has the same emission frequencies, this forms an example of a submodel topology that will guarantee a minimum of four symbols drawn from the same underlying emission distribution, but with a length distribution that is still geometric. The duration of the model has been tweaked. There are many more complex possibilities depending on the properties of the length distribution you seek to model etc. Note: this and numerous other figures that follow in this presentation are after Durbin et al. etc.

HMM Topology Duration modeling with HMMs The topology shown in this variation can model any desired distribution of lengths varying between 2 and 6 etc.

HMM Topology Duration modeling with HMMs Without belaboring the derivation, we’ll just mention that this negative binomial distribution offers a great deal of flexibility in modeling length distributions p etc. ppp 1-p Where n = number of repetitive states, so here n = 4

HMM Topology Duration modeling with HMMs By selecting appropriate values for the number of repeating states and the probability of re-entering each state, you can flexibly model the length distribution http://www.boost.org/doc/libs/1_40_0/libs/math/doc/sf_and_dist/html/ math_toolkit/dist/dist_ref/dists/negative_binomial_dist.html

HMM Topology Duration modeling with HMMs In practical HMMs we would probably use n much smaller than in these examples, but with probability of state re-entry much closer to 1 http://www.boost.org/doc/libs/1_40_0/libs/math/doc/sf_and_dist/html/ math_toolkit/dist/dist_ref/dists/negative_binomial_dist.html http://www.boost.org/doc/libs/1_40_0/libs/math/doc/sf_and_dist/html/ math_toolkit/dist/dist_ref/dists/negative_binomial_dist.html

HMM Topology A trivial HMM is equivalent to a Position Specific Scoring Matrix... M1M1 M2M2 MLML S  The transitions are deterministic and Pr{a Mi→Mi+1 }= 1 but the emissions correspond to the estimated amino acid or nucleotide frequencies in the columns of a PSSM We refer collectively to M 1 …M j as match states This simple model cannot account for indels and does not capture all of the information present in a multiple alignment

HMM Topology Insertions are handled with special states with background-like emission M1M1 MjMj M j+1 S  Insertion states correspond to states that do not match anything in the model. They almost always have emission probabilities matching the background distribution We still need a way to deal with deletions…... IjIj

HMM Topology How do insertions affect the overall probability of a sequence? M1M1 MjMj M j+1 S  Assuming log-odds scoring relative to some background distribution, emissions from I j will not contribute to the overall score, and only the transitions will matter... IjIj log a M j →I j + (k-1)·log a I j →I j + log a I j →M j+1 For an insertion of length k:

HMM Topology How do insertions affect the overall probability of a sequence? M1M1 MjMj M j+1 S  This is equivalent to the familiar gap opening + gap extension penalties used in many sequence alignment methods. This is therefore a form of affine gap scoring... IjIj log a Mj→Ij + (k-1)·log a Ij→Ij + log a Ij→Mj+1 For an insertion of length k:

HMM Topology How best to handle deletions? S  The problem with allowing arbitrarily long gaps in any practically sized model is that we would need to estimate far too many transition probabilities Estimation is the hardest HMM problem, so we should avoid an unnecessary proliferation of transitions wherever possible!

HMM Topology In general we handle deletions by adding silent states… S  We can use a sequence of silent-state transitions to move from any match state to any other match state! Note that not all D j →D j+1 transitions need have the same probability MjMj DjDj

The Profile HMM If we combine all these features, we have the famous profile HMM S  We can use a sequence of silent-state transitions to move from any match state to any other match state! Profile HMMs fully generalise the concept of pairwise alignment! MjMj DjDj IjIj

The Profile HMM If we combine all these features, we have the famous profile HMM S  Profile HMMs are extensively used for the identification of new members of conserved sequence families This relies on the ability to estimate parameters for the profile HMM on the basis of multiple sequence alignments MjMj DjDj IjIj

Basic estimation for profile HMMs We can now count simply count the transitions and emissions to calculate our maximum likelihood estimators from frequencies. But what about missing observations? Consider a multiple sequence alignment #pos 01234567890 >glob1 VGA--HAGEY >glob2 V----NVDEV >glob3 VEA--DVAGH >glob4 VKG------D >glob5 VYS--TYETS >glob6 FNA--NIPKH >glob7 IAGADNGAGV *** ***** First heuristic: positions with more than 50% gaps will be modeled as inserts, the remainder as matches. In this example only the starred columns will correspond to matches

Basic estimation for profile HMMs Let’s start by simply applying Laplace’s rule: add one pseudocount to every frequency calculation Parameter estimation from multiple alignments Second heuristic: use pseudocounts to fill in missing observations.. Here B is the total number of pseudocounts, and q represents the fraction of the total number that have been allocated to that particular transition or emission

Basic estimation for profile HMMs These are the estimates when we apply Laplace’s rule for adding pseudocounts.. Consider a multiple sequence alignment #pos 01234567890 >glob1 VGA--HAGEY >glob2 V----NVDEV >glob3 VEA--DVAGH >glob4 VKG------D >glob5 VYS--TYETS >glob6 FNA--NIPKH >glob7 IAGADNGAGV *** ***** e M1 (V) = 6/27, e M1 (I) = e M1 (F) = 2/27, e M1 (all other aa) = 1/27 a M1→M2 = 7/10, a M1→D2 = 2/10, a M1→I1 = 1/10, etc.

Scoring with profile HMMs We could calculate separate scores for the models, then combine, but this is inefficient Since the state path is unknown we have two basic options: Employ the Viterbi algorithm to determine the joint probability of the observed sequence and the most probable state path Employ the forward (or backward) algorithm to determine the full probability summed over all possible state paths The state path of sequences under test are always unknown Either way, one fly in the ointment is that we are usually interested in a score expressed as a log-odds ratio relative to our random model:

Scoring with profile HMMs In other words, we need only adjust and “ log_floatize ” our emissions, which is something we can do up front in the self.emissions dict rather than in the algorithms We could rewrite the recurrences to accommodate log-odds scoring. For example, Viterbi might look like this: Modifying Viterbi and Forward for profile HMMs This would be a serious nuisance except we already have a log_float class!!! So, we can instead just alter our emission terms to the form below:

Handling multiple sequences in Python class FastA(list): # note derivation from list, not object def __init__(self): #stuff def read_file(self, filepath): # stuff def calculate_MLE(self, pseudocounts) # stuff return (transitions, emissions) I’ll provide more information about the key methods in the form of a Python docstring Inheritance is a powerful tool for deriving new classes Our goal is to develop a class, FastA, that behaves like a python list that serves as a container for sequences read from a file. Each element will contain a tuple of the annotation and the sequence stored as a string. It should also be able to use these sequences to then calculate “dict-of-dict” transition and emission distributions suitable for use in our increasingly sophisticated HMM class

Download ppt "A retrospective look at our models First we saw the finite state automaton The rigid non-stochastic nature of these structures ultimately limited their."

Similar presentations