11
11
"""
12
12
from pylab import *
13
13
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' ,
15
15
'r7' : 'GT' , 'r8' : 'TG' , 'r9' : 'CT' , 'r10' : 'TC' , 'r11' : 'GC' , 'r12' : 'CG' }
16
16
numbered_bases_to_rates = dict ([(v , k ) for k , v in rates_to_bases .items ()])
17
17
lettered_bases_to_rates = dict ([(v , 'r' + v ) for k , v in rates_to_bases .items ()])
@@ -24,10 +24,10 @@ def add_dicts(d1, d2):
24
24
return result
25
25
26
26
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 ,
31
31
** kwargs ):
32
32
"""Makes an arrow plot.
33
33
@@ -53,11 +53,11 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
53
53
max_text_size = size * 12
54
54
min_text_size = size
55
55
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' ,
57
57
'fontweight' : 'bold' }
58
58
r2 = sqrt (2 )
59
59
60
- deltas = {\
60
+ deltas = {
61
61
'AT' : (1 , 0 ),
62
62
'TA' : (- 1 , 0 ),
63
63
'GA' : (0 , 1 ),
@@ -72,7 +72,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
72
72
'CG' : (- 1 , 0 )
73
73
}
74
74
75
- colors = {\
75
+ colors = {
76
76
'AT' : 'r' ,
77
77
'TA' : 'k' ,
78
78
'GA' : 'g' ,
@@ -87,7 +87,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
87
87
'CG' : 'b'
88
88
}
89
89
90
- label_positions = {\
90
+ label_positions = {
91
91
'AT' : 'center' ,
92
92
'TA' : 'center' ,
93
93
'GA' : 'center' ,
@@ -103,7 +103,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
103
103
}
104
104
105
105
def do_fontsize (k ):
106
- return float (clip (max_text_size * sqrt (data [k ]),\
106
+ return float (clip (max_text_size * sqrt (data [k ]),
107
107
min_text_size , max_text_size ))
108
108
109
109
A = text (0 , 1 , '$A_3$' , color = 'r' , size = do_fontsize ('A' ), ** text_params )
@@ -117,7 +117,7 @@ def do_fontsize(k):
117
117
max_arrow_width = max_arrow_width
118
118
max_head_width = 2.5 * max_arrow_width
119
119
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 ,
121
121
'head_starts_at_zero' : head_starts_at_zero }
122
122
ax = gca ()
123
123
sf = 0.6 # max arrow size represents this in data coords
@@ -126,7 +126,7 @@ def do_fontsize(k):
126
126
r2v = arrow_sep / r2 # offset for diags
127
127
128
128
# tuple of x, y for start position
129
- positions = {\
129
+ positions = {
130
130
'AT' : (arrow_h_offset , 1 + arrow_sep ),
131
131
'TA' : (1 - arrow_h_offset , 1 - arrow_sep ),
132
132
'GA' : (- arrow_sep , arrow_h_offset ),
@@ -179,8 +179,8 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
179
179
180
180
x_scale , y_scale = deltas [pair ]
181
181
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 ,
184
184
head_length = head_length , ** arrow_params )
185
185
186
186
# figure out coordinates for text
@@ -209,14 +209,14 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
209
209
orig_label = rate_labels [pair ]
210
210
label = '$%s_{_{\mathrm{%s}}}$' % (orig_label [0 ], orig_label [1 :])
211
211
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' ,
213
213
color = labelcolor or fc )
214
214
215
215
for p in positions .keys ():
216
216
draw_arrow (p )
217
217
218
218
# test data
219
- all_on_max = dict ([(i , 1 ) for i in 'TCAG' ] + \
219
+ all_on_max = dict ([(i , 1 ) for i in 'TCAG' ] +
220
220
[(i + j , 0.6 ) for i in 'TCAG' for j in 'TCAG' ])
221
221
222
222
realistic_data = {
0 commit comments