7
7
from bokeh .models import HoverTool
8
8
9
9
from .. import config
10
+ from ..plot_helpers import center_plot_title
10
11
from ..plot_helpers import customise_ticks
11
12
from ..plot_helpers import filter_points
12
13
from ..plot_helpers import hover_points
@@ -124,9 +125,10 @@ def get_mut_data(x_range, y_range, index):
124
125
def update_pop_freq_plot (x_range , y_range , index ):
125
126
if not index :
126
127
return hv .Bars ([], "population" , "frequency" ).opts (
127
- title = "Population frequencies " ,
128
+ title = "Tap on a mutation " ,
128
129
default_tools = [],
129
130
tools = ["hover" ],
131
+ hooks = [center_plot_title ],
130
132
)
131
133
132
134
mut_data = get_mut_data (x_range , y_range , index )
@@ -141,49 +143,53 @@ def update_pop_freq_plot(x_range, y_range, index):
141
143
"frequency" : [mut_data [col ] for col in pops ],
142
144
}
143
145
)
146
+ df = df [df ["frequency" ] > 0 ]
147
+
144
148
bars = hv .Bars (df , "population" , "frequency" ).opts (
145
149
framewise = True ,
146
- title = "Population frequencies " ,
150
+ title = f"Mutation { mut_data [ 'id' ] } " ,
147
151
ylim = (0 , max (df ["frequency" ]) * 1.1 ),
148
152
xrotation = 45 ,
149
153
tools = ["hover" ],
150
154
default_tools = [],
155
+ yticks = 3 ,
156
+ yformatter = "%.3f" ,
157
+ hooks = [center_plot_title ],
151
158
)
152
159
return bars
153
160
else :
154
161
return hv .Bars ([], "population" , "frequency" ).opts (
162
+ title = "Tap on a mutation" ,
155
163
default_tools = [],
156
164
tools = ["hover" ],
165
+ hooks = [center_plot_title ],
157
166
)
158
167
159
168
def update_mut_info_table (x_range , y_range , index ):
160
169
if not index :
161
- return hv .Table ([], kdims = ["Detail" ], vdims = ["value" ]).opts (
162
- title = "Tap on a mutation"
163
- )
170
+ return hv .Table ([], kdims = ["mutation" ], vdims = ["value" ])
164
171
mut_data = get_mut_data (x_range , y_range , index )
165
172
pops = [col for col in mut_data .index if "pop_" in col ]
166
173
mut_data = mut_data .drop (pops )
167
- return hv .Table (mut_data .items (), kdims = ["Column" ], vdims = ["Value" ]).opts (
168
- title = f"Mutation { mut_data ['id' ]} "
169
- )
174
+ mut_data ["time" ] = mut_data ["time" ].round (2 )
175
+ if "log_time" in mut_data :
176
+ mut_data ["log_time" ] = mut_data ["log_time" ].round (2 )
177
+ return hv .Table (mut_data .items (), kdims = ["mutation" ], vdims = ["value" ])
170
178
171
179
pop_data_dynamic = hv .DynamicMap (
172
180
update_pop_freq_plot , streams = [range_stream , selection_stream ]
173
181
)
182
+ pop_data_dynamic .opts (align = ("center" ))
174
183
mut_info_table_dynamic = hv .DynamicMap (
175
184
update_mut_info_table , streams = [range_stream , selection_stream ]
176
185
)
177
-
178
- tap_widgets_layout = (mut_info_table_dynamic + pop_data_dynamic ).cols (1 )
186
+ tap_widgets_layout = (pop_data_dynamic + mut_info_table_dynamic ).cols (1 )
179
187
180
188
return pn .Row (
181
- pn . Column ( layout .opts (shared_axes = True ).cols (1 ) ),
182
- pn .panel (
189
+ layout .opts (shared_axes = True ).cols (1 ),
190
+ pn .Column (
183
191
tap_widgets_layout ,
184
192
align = "center" ,
185
- sizing_mode = "stretch_width" ,
186
- margin = (0 , 0 , 0 , 200 ),
187
193
),
188
194
)
189
195
0 commit comments