1111"""
1212from pylab import *
1313
14- rates_to_bases = {'r1' : 'AT' , 'r2' : 'TA' , 'r3' : 'GA' , 'r4' : 'AG' , 'r5' : 'CA' , 'r6' : 'AC' , \
14+ rates_to_bases = {'r1' : 'AT' , 'r2' : 'TA' , 'r3' : 'GA' , 'r4' : 'AG' , 'r5' : 'CA' , 'r6' : 'AC' ,
1515 'r7' : 'GT' , 'r8' : 'TG' , 'r9' : 'CT' , 'r10' : 'TC' , 'r11' : 'GC' , 'r12' : 'CG' }
1616numbered_bases_to_rates = dict ([(v , k ) for k , v in rates_to_bases .items ()])
1717lettered_bases_to_rates = dict ([(v , 'r' + v ) for k , v in rates_to_bases .items ()])
@@ -24,10 +24,10 @@ def add_dicts(d1, d2):
2424 return result
2525
2626
27- def make_arrow_plot (data , size = 4 , display = 'length' , shape = 'right' , \
28- max_arrow_width = 0.03 , arrow_sep = 0.02 , alpha = 0.5 , \
29- normalize_data = False , ec = None , labelcolor = None , \
30- head_starts_at_zero = True , rate_labels = lettered_bases_to_rates ,\
27+ def make_arrow_plot (data , size = 4 , display = 'length' , shape = 'right' ,
28+ max_arrow_width = 0.03 , arrow_sep = 0.02 , alpha = 0.5 ,
29+ normalize_data = False , ec = None , labelcolor = None ,
30+ head_starts_at_zero = True , rate_labels = lettered_bases_to_rates ,
3131 ** kwargs ):
3232 """Makes an arrow plot.
3333
@@ -53,11 +53,11 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
5353 max_text_size = size * 12
5454 min_text_size = size
5555 label_text_size = size * 2.5
56- text_params = {'ha' : 'center' , 'va' : 'center' , 'family' : 'sans-serif' ,\
56+ text_params = {'ha' : 'center' , 'va' : 'center' , 'family' : 'sans-serif' ,
5757 'fontweight' : 'bold' }
5858 r2 = sqrt (2 )
5959
60- deltas = {\
60+ deltas = {
6161 'AT' : (1 , 0 ),
6262 'TA' : (- 1 , 0 ),
6363 'GA' : (0 , 1 ),
@@ -72,7 +72,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
7272 'CG' : (- 1 , 0 )
7373 }
7474
75- colors = {\
75+ colors = {
7676 'AT' : 'r' ,
7777 'TA' : 'k' ,
7878 'GA' : 'g' ,
@@ -87,7 +87,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
8787 'CG' : 'b'
8888 }
8989
90- label_positions = {\
90+ label_positions = {
9191 'AT' : 'center' ,
9292 'TA' : 'center' ,
9393 'GA' : 'center' ,
@@ -103,7 +103,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
103103 }
104104
105105 def do_fontsize (k ):
106- return float (clip (max_text_size * sqrt (data [k ]),\
106+ return float (clip (max_text_size * sqrt (data [k ]),
107107 min_text_size , max_text_size ))
108108
109109 A = text (0 , 1 , '$A_3$' , color = 'r' , size = do_fontsize ('A' ), ** text_params )
@@ -117,7 +117,7 @@ def do_fontsize(k):
117117 max_arrow_width = max_arrow_width
118118 max_head_width = 2.5 * max_arrow_width
119119 max_head_length = 2 * max_arrow_width
120- arrow_params = {'length_includes_head' : True , 'shape' : shape , \
120+ arrow_params = {'length_includes_head' : True , 'shape' : shape ,
121121 'head_starts_at_zero' : head_starts_at_zero }
122122 ax = gca ()
123123 sf = 0.6 # max arrow size represents this in data coords
@@ -126,7 +126,7 @@ def do_fontsize(k):
126126 r2v = arrow_sep / r2 # offset for diags
127127
128128 # tuple of x, y for start position
129- positions = {\
129+ positions = {
130130 'AT' : (arrow_h_offset , 1 + arrow_sep ),
131131 'TA' : (1 - arrow_h_offset , 1 - arrow_sep ),
132132 'GA' : (- arrow_sep , arrow_h_offset ),
@@ -179,8 +179,8 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
179179
180180 x_scale , y_scale = deltas [pair ]
181181 x_pos , y_pos = positions [pair ]
182- arrow (x_pos , y_pos , x_scale * length , y_scale * length , \
183- fc = fc , ec = ec , alpha = alpha , width = width , head_width = head_width , \
182+ arrow (x_pos , y_pos , x_scale * length , y_scale * length ,
183+ fc = fc , ec = ec , alpha = alpha , width = width , head_width = head_width ,
184184 head_length = head_length , ** arrow_params )
185185
186186 # figure out coordinates for text
@@ -209,14 +209,14 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
209209 orig_label = rate_labels [pair ]
210210 label = '$%s_{_{\mathrm{%s}}}$' % (orig_label [0 ], orig_label [1 :])
211211
212- text (x , y , label , size = label_text_size , ha = 'center' , va = 'center' , \
212+ text (x , y , label , size = label_text_size , ha = 'center' , va = 'center' ,
213213 color = labelcolor or fc )
214214
215215 for p in positions .keys ():
216216 draw_arrow (p )
217217
218218# test data
219- all_on_max = dict ([(i , 1 ) for i in 'TCAG' ] + \
219+ all_on_max = dict ([(i , 1 ) for i in 'TCAG' ] +
220220 [(i + j , 0.6 ) for i in 'TCAG' for j in 'TCAG' ])
221221
222222realistic_data = {
0 commit comments