Back to index

python-biopython  1.60
Classes | Functions
Bio.HMM.MarkovModel Namespace Reference

Classes

class  MarkovModelBuilder
class  HiddenMarkovModel

Functions

def _gen_random_array
def _calculate_emissions
def _calculate_from_transitions
def _calculate_to_transitions

Detailed Description

Deal with representations of Markov Models.

Function Documentation

def Bio.HMM.MarkovModel._calculate_emissions (   emission_probs) [private]
Calculate which symbols can be emitted in each state

Definition at line 23 of file MarkovModel.py.

00023 
00024 def _calculate_emissions(emission_probs):
00025     """Calculate which symbols can be emitted in each state
00026     """
00027     # loop over all of the state-symbol duples, mapping states to
00028     # lists of emitted symbols
00029     emissions = dict()
00030     for state, symbol in emission_probs:
00031         try:
00032             emissions[state].append(symbol)
00033         except KeyError:
00034             emissions[state] = [symbol]
00035 
00036     return emissions

Here is the caller graph for this function:

def Bio.HMM.MarkovModel._calculate_from_transitions (   trans_probs) [private]
Calculate which 'from transitions' are allowed for each state

This looks through all of the trans_probs, and uses this dictionary
to determine allowed transitions. It converts this information into
a dictionary, whose keys are source states and whose values are
lists of destination states reachable from the source state via a
transition.

Definition at line 37 of file MarkovModel.py.

00037 
00038 def _calculate_from_transitions(trans_probs):
00039     """Calculate which 'from transitions' are allowed for each state
00040 
00041     This looks through all of the trans_probs, and uses this dictionary
00042     to determine allowed transitions. It converts this information into
00043     a dictionary, whose keys are source states and whose values are
00044     lists of destination states reachable from the source state via a
00045     transition.
00046     """
00047     transitions = dict()
00048     for from_state, to_state in trans_probs:
00049         try:
00050             transitions[from_state].append(to_state)
00051         except KeyError:
00052             transitions[from_state] = [to_state]
00053 
00054     return transitions

Here is the caller graph for this function:

def Bio.HMM.MarkovModel._calculate_to_transitions (   trans_probs) [private]
Calculate which 'to transitions' are allowed for each state

This looks through all of the trans_probs, and uses this dictionary
to determine allowed transitions. It converts this information into
a dictionary, whose keys are destination states and whose values are
lists of source states from which the destination is reachable via a
transition.

Definition at line 55 of file MarkovModel.py.

00055 
00056 def _calculate_to_transitions(trans_probs):
00057     """Calculate which 'to transitions' are allowed for each state
00058 
00059     This looks through all of the trans_probs, and uses this dictionary
00060     to determine allowed transitions. It converts this information into
00061     a dictionary, whose keys are destination states and whose values are
00062     lists of source states from which the destination is reachable via a
00063     transition.
00064     """
00065     transitions = dict()
00066     for from_state, to_state in trans_probs:
00067         try:
00068             transitions[to_state].append(from_state)
00069         except KeyError:
00070             transitions[to_state] = [from_state]
00071 
00072     return transitions

Return an array of n random numbers, where the elements of the array sum
to 1.0

Definition at line 14 of file MarkovModel.py.

00014 
00015 def _gen_random_array(n):
00016     """ Return an array of n random numbers, where the elements of the array sum
00017     to 1.0"""
00018     randArray = [random.random() for i in range(n)]
00019     total = sum(randArray)
00020     normalizedRandArray = [x/total for x in randArray]
00021     
00022     return normalizedRandArray

Here is the caller graph for this function: