#NEWLINE# def gcdist( counts , filename , fig_kw ) : #NEWLINE# #INDENT# m = int ( ( sum ( [ ( k * v ) for ( k , v ) in zip ( counts . keys ( ) , counts . values ( ) ) ] ) / sum ( counts . values ( ) ) ) ) #NEWLINE# variances = [ ( ( k - m ) ** 2 ) for k in counts . keys ( ) ] #NEWLINE# variance = int ( ( sum ( [ ( k * v ) for ( k , v ) in zip ( variances , counts . values ( ) ) ] ) / sum ( counts . values ( ) ) ) ) #NEWLINE# sigma = math . sqrt ( variance ) #NEWLINE# x = np . linspace ( 0 , 100 , 100 ) #NEWLINE# ( fig , axes ) = plt . subplots ( nrows = 1 , ** fig_kw ) #NEWLINE# ( x_vals , y_vals ) = zip ( * sorted ( counts . items ( ) , key = ( lambda x : x [ 0 ] ) ) ) #NEWLINE# axes . scatter ( x_vals , y_vals , color = ( 0.1 , 0.6 , 0.8 ) , marker = 'o' ) #NEWLINE# ( x1 , x2 , y1 , y2 ) = axes . axis ( ) #NEWLINE# axes . axis ( ( x1 , x2 , 0 , y2 ) ) #NEWLINE# axes2 = axes . twinx ( ) #NEWLINE# axes2 . plot ( x , mlab . normpdf ( x , m , sigma ) , color = 'red' ) #NEWLINE# axes2 . get_yaxis ( ) . set_visible ( False ) #NEWLINE# ( handles , labels ) = axes . get_legend_handles_labels ( ) #NEWLINE# display = ( 0 , 1 , 2 ) #NEWLINE# a = plt . Line2D ( ( 0 , 1 ) , ( 0 , 0 ) , color = ( 0.1 , 0.6 , 0.8 ) ) #NEWLINE# b = plt . Line2D ( ( 0 , 1 ) , ( 0 , 0 ) , color = 'red' ) #NEWLINE# axes . legend ( ( [ handle for ( i , handle ) in enumerate ( handles ) if ( i in display ) ] + [ a , b ] ) , ( [ label for ( i , label ) in enumerate ( labels ) if ( i in display ) ] + [ 'Actual' , 'Theoretical' ] ) ) #NEWLINE# axes . yaxis . grid ( b = True , which = 'major' , ** { #NEWLINE# #INDENT# 'color' : 'gray' , #NEWLINE# 'linestyle' : ':' , #NEWLINE# #UNINDENT# } ) #NEWLINE# axes . set_axisbelow ( True ) #NEWLINE# axes . set_title ( 'Read GC content distribution' ) #NEWLINE# axes . set_xlabel ( 'Mean read GC content (%)' ) #NEWLINE# axes . set_ylabel ( 'Number of reads' ) #NEWLINE# add_figure_to_archive ( fig , filename , 'gc_distribution.png' )