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   
13  from __future__ import print_function 
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 24 o emissions -- The sequence of emissions of the sequence you are 25 dealing with. 26 27 o real_state -- The actual state path that generated the emissions. 28 29 o predicted_state -- A state path predicted by some kind of HMM model. 30 """ 31 # calculate the length of the titles and sequences 32 title_length = max(len(emission_title), len(real_title), 33 len(predicted_title)) + 1 34 seq_length = line_width - title_length 35 36 # set up the titles so they'll print right 37 emission_title = emission_title.ljust(title_length) 38 real_title = real_title.ljust(title_length) 39 predicted_title = predicted_title.ljust(title_length) 40 41 cur_position = 0 42 # while we still have more than seq_length characters to print 43 while True: 44 if (cur_position + seq_length) < len(emissions): 45 extension = seq_length 46 else: 47 extension = len(emissions) - cur_position 48 49 print("%s%s" % (emission_title, 50 emissions[cur_position:cur_position + seq_length])) 51 print("%s%s" % (real_title, 52 real_state[cur_position:cur_position + seq_length])) 53 print("%s%s\n" % (predicted_title, 54 predicted_state[cur_position: 55 cur_position + seq_length])) 56 57 if (len(emissions) < (cur_position + seq_length)): 58 break 59 60 cur_position += seq_length
61