#NEWLINE# def qualmap( qualities , filename , fig_kw ) : #NEWLINE# #INDENT# fig = plt . figure ( ** fig_kw ) #NEWLINE# ax = fig . add_subplot ( 111 ) #NEWLINE# values = map ( Counter , tuple ( qualities . values ( ) ) ) #NEWLINE# counts = Counter ( ) #NEWLINE# for value in values : #NEWLINE# #INDENT# counts = ( counts + value ) #NEWLINE# #UNINDENT# max_qual = max ( tuple ( counts . keys ( ) ) ) #NEWLINE# max_pos = max ( tuple ( qualities . keys ( ) ) ) #NEWLINE# heat_map = np . zeros ( ( max_qual , max_pos ) ) #NEWLINE# for p in range ( max_pos ) : #NEWLINE# #INDENT# for q in range ( max_qual ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# heat_map [ q ] [ p ] = qualities [ ( p + 1 ) ] [ ( q + 1 ) ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# imax = ax . imshow ( np . array ( heat_map ) , cmap = viridis_cm , origin = 'lower' , interpolation = 'none' , aspect = 'auto' ) #NEWLINE# ax . axhline ( y = 10 , linestyle = ':' , color = 'gray' ) #NEWLINE# ax . axhline ( y = 20 , linestyle = ':' , color = 'gray' ) #NEWLINE# ax . axhline ( y = 30 , linestyle = ':' , color = 'gray' ) #NEWLINE# cbar = fig . colorbar ( imax , orientation = 'horizontal' , shrink = 0.5 ) #NEWLINE# cbar_labels = [ item . get_text ( ) for item in cbar . ax . get_xticklabels ( ) ] #NEWLINE# cbar . ax . set_xticklabels ( cbar_labels , rotation = 45 ) #NEWLINE# cbar . ax . set_title ( '' ) #NEWLINE# ax . set_title ( 'Quality score heatmap' ) #NEWLINE# ax . set_xlabel ( 'Cycle' ) #NEWLINE# ax . set_ylabel ( 'Sum of Phred qualities' ) #NEWLINE# add_figure_to_archive ( fig , filename , 'quality_score_heatmap.png' )