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

Source Code for Module Bio.HMM.Utilities

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