Back to index

python-biopython  1.60
Utilities.py
Go to the documentation of this file.
00001 """Generic functions which are useful for working with HMMs.
00002 
00003 This just collects general functions which you might like to use in
00004 dealing with HMMs.
00005 """
00006 
00007 def pretty_print_prediction(emissions, real_state, predicted_state,
00008                             emission_title = "Emissions",
00009                             real_title = "Real State",
00010                             predicted_title = "Predicted State",
00011                             line_width = 75):
00012     """Print out a state sequence prediction in a nice manner.
00013 
00014     Arguments:
00015     
00016     o emissions -- The sequence of emissions of the sequence you are
00017     dealing with.
00018 
00019     o real_state -- The actual state path that generated the emissions.
00020 
00021     o predicted_state -- A state path predicted by some kind of HMM model.
00022     """
00023     # calculate the length of the titles and sequences
00024     title_length = max(len(emission_title), len(real_title),
00025                        len(predicted_title)) + 1
00026     seq_length = line_width - title_length
00027 
00028     # set up the titles so they'll print right
00029     emission_title = emission_title.ljust(title_length)
00030     real_title = real_title.ljust(title_length)
00031     predicted_title = predicted_title.ljust(title_length)
00032 
00033     cur_position = 0
00034     # while we still have more than seq_length characters to print
00035     while 1:
00036         if (cur_position + seq_length) < len(emissions):
00037             extension = seq_length
00038         else:
00039             extension = len(emissions) - cur_position
00040         
00041         print "%s%s" % (emission_title,
00042                         emissions[cur_position:cur_position + seq_length])
00043         print "%s%s" % (real_title,
00044                         real_state[cur_position:cur_position + seq_length])
00045         print "%s%s\n" % (predicted_title,
00046                           predicted_state[cur_position:
00047                                           cur_position + seq_length])
00048 
00049         if (len(emissions) < (cur_position + seq_length)):
00050             break
00051 
00052         cur_position += seq_length
00053 
00054     
00055         
00056         
00057