Back to index

python-biopython  1.60
Functions
Bio.HMM.Utilities Namespace Reference

Functions

def pretty_print_prediction

Detailed Description

Generic functions which are useful for working with HMMs.

This just collects general functions which you might like to use in
dealing with HMMs.

Function Documentation

def Bio.HMM.Utilities.pretty_print_prediction (   emissions,
  real_state,
  predicted_state,
  emission_title = "Emissions",
  real_title = "Real State",
  predicted_title = "Predicted State",
  line_width = 75 
)
Print out a state sequence prediction in a nice manner.

Arguments:

o emissions -- The sequence of emissions of the sequence you are
dealing with.

o real_state -- The actual state path that generated the emissions.

o predicted_state -- A state path predicted by some kind of HMM model.

Definition at line 11 of file Utilities.py.

00011 
00012                             line_width = 75):
00013     """Print out a state sequence prediction in a nice manner.
00014 
00015     Arguments:
00016     
00017     o emissions -- The sequence of emissions of the sequence you are
00018     dealing with.
00019 
00020     o real_state -- The actual state path that generated the emissions.
00021 
00022     o predicted_state -- A state path predicted by some kind of HMM model.
00023     """
00024     # calculate the length of the titles and sequences
00025     title_length = max(len(emission_title), len(real_title),
00026                        len(predicted_title)) + 1
00027     seq_length = line_width - title_length
00028 
00029     # set up the titles so they'll print right
00030     emission_title = emission_title.ljust(title_length)
00031     real_title = real_title.ljust(title_length)
00032     predicted_title = predicted_title.ljust(title_length)
00033 
00034     cur_position = 0
00035     # while we still have more than seq_length characters to print
00036     while 1:
00037         if (cur_position + seq_length) < len(emissions):
00038             extension = seq_length
00039         else:
00040             extension = len(emissions) - cur_position
00041         
00042         print "%s%s" % (emission_title,
00043                         emissions[cur_position:cur_position + seq_length])
00044         print "%s%s" % (real_title,
00045                         real_state[cur_position:cur_position + seq_length])
00046         print "%s%s\n" % (predicted_title,
00047                           predicted_state[cur_position:
00048                                           cur_position + seq_length])
00049 
00050         if (len(emissions) < (cur_position + seq_length)):
00051             break
00052 
00053         cur_position += seq_length
00054 
00055     
00056         
00057         
00058