Package Bio :: Package HMM :: Module Utilities
[hide private]
[frames] | no frames]

Source Code for Module Bio.HMM.Utilities

 1  """Generic functions which are useful for working with HMMs. 
 2   
 3  This just collects general functions which you might like to use in 
 4  dealing with HMMs. 
 5  """ 
 6  # standard modules 
 7  import string 
 8   
9 -def pretty_print_prediction(emissions, real_state, predicted_state, 10 emission_title = "Emissions", 11 real_title = "Real State", 12 predicted_title = "Predicted State", 13 line_width = 75):
14 """Print out a state sequence prediction in a nice manner. 15 16 Arguments: 17 18 o emissions -- The sequence of emissions of the sequence you are 19 dealing with. 20 21 o real_state -- The actual state path that generated the emissions. 22 23 o predicted_state -- A state path predicted by some kind of HMM model. 24 """ 25 # calculate the length of the titles and sequences 26 title_length = max(len(emission_title), len(real_title), 27 len(predicted_title)) + 1 28 seq_length = line_width - title_length 29 30 # set up the titles so they'll print right 31 emission_title = string.ljust(emission_title, title_length) 32 real_title = string.ljust(real_title, title_length) 33 predicted_title = string.ljust(predicted_title, title_length) 34 35 cur_position = 0 36 # while we still have more than seq_length characters to print 37 while 1: 38 if (cur_position + seq_length) < len(emissions): 39 extension = seq_length 40 else: 41 extension = len(emissions) - cur_position 42 43 print "%s%s" % (emission_title, 44 emissions.data[cur_position:cur_position + seq_length]) 45 print "%s%s" % (real_title, 46 real_state.data[cur_position: 47 cur_position + seq_length]) 48 print "%s%s\n" % (predicted_title, 49 predicted_state.data[cur_position: 50 cur_position + seq_length]) 51 52 if (len(emissions) < (cur_position + seq_length)): 53 break 54 55 cur_position += seq_length
56