Skip to content

Commit

Permalink
Upgrade bokeh to 3.1 (#400)
Browse files Browse the repository at this point in the history
* upgrade bokeh to 3.1

* rework plotting show and return values

* update poetry
  • Loading branch information
alimanfoo authored May 19, 2023
1 parent bd62d00 commit c3e76e2
Show file tree
Hide file tree
Showing 21 changed files with 23,149 additions and 55,080 deletions.
44 changes: 22 additions & 22 deletions malariagen_data/ag3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,8 +1867,9 @@ def plot_cnv_hmm_coverage_track(

if show:
bkplt.show(fig)

return fig
return None
else:
return fig

def plot_cnv_hmm_coverage(
self,
Expand Down Expand Up @@ -1914,11 +1915,6 @@ def plot_cnv_hmm_coverage(
show : bool, optional
If true, show the plot.
Returns
-------
fig : Figure
Bokeh figure.
"""
debug = self._log.debug

Expand Down Expand Up @@ -1961,8 +1957,9 @@ def plot_cnv_hmm_coverage(

if show:
bkplt.show(fig)

return fig
return None
else:
return fig

def plot_cnv_hmm_heatmap_track(
self,
Expand Down Expand Up @@ -2113,7 +2110,9 @@ def plot_cnv_hmm_heatmap_track(
fig.yaxis.major_label_text_font_size = f"{row_height}px"

debug("add color bar")
color_bar = bkmod.ColorBar(
# For some reason, mypy reports: Module has no attribute "ColorBar"
# ...but this works fine, so ignore for now.
color_bar = bkmod.ColorBar( # type: ignore
title="Copy number",
color_mapper=color_mapper,
major_label_overrides={
Expand All @@ -2126,8 +2125,9 @@ def plot_cnv_hmm_heatmap_track(

if show:
bkplt.show(fig)

return fig
return None
else:
return fig

def plot_cnv_hmm_heatmap(
self,
Expand Down Expand Up @@ -2171,13 +2171,6 @@ def plot_cnv_hmm_heatmap(
row_height.
genes_height : int, optional
Height of genes track in pixels (px).
show : bool, optional
If true, show the plot.
Returns
-------
fig : Figure
Bokeh figure.
"""
debug = self._log.debug
Expand Down Expand Up @@ -2220,8 +2213,9 @@ def plot_cnv_hmm_heatmap(

if show:
bkplt.show(fig)

return fig
return None
else:
return fig

def _view_alignments_add_site_filters_tracks(
self, *, contig, visibility_window, tracks
Expand Down Expand Up @@ -2349,6 +2343,8 @@ def plot_aim_heatmap(
colors="T10",
xgap=0,
ygap=0.5,
show=True,
renderer=None,
):
"""Plot a heatmap of ancestry-informative marker (AIM) genotypes.
Expand Down Expand Up @@ -2547,7 +2543,11 @@ def plot_aim_heatmap(
height=max(300, row_height * len(samples) + 100),
)

return fig
if show:
fig.show(renderer=renderer)
return None
else:
return fig


@numba.njit("Tuple((int8, int64))(int8[:], int8)")
Expand Down
25 changes: 16 additions & 9 deletions malariagen_data/anoph/genome_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class gplt_params:
genes_height_default: genes_height = 120
show: TypeAlias = Annotated[
bool,
"If true, show the plot.",
"If true, show the plot. If False, do not show the plot, but return the figure.",
]
toolbar_location: TypeAlias = Annotated[
Literal["above", "below", "left", "right"],
Expand All @@ -79,8 +79,8 @@ class gplt_params:
# Use quite a broad type here to accommodate both single-panel figures
# created via bokeh.plotting and multi-panel figures created via
# bokeh.layouts.
bokeh.model.Model,
"A bokeh figure.",
Optional[bokeh.model.Model],
"A bokeh figure (only returned if show=False).",
]


Expand Down Expand Up @@ -234,6 +234,11 @@ def plot_transcript(
if title is True:
title = f"{transcript} ({parent.strand})"

if x_range is None:
x_range = bokeh.models.Range1d(
parent.start - 2_000, parent.end + 2_000, bounds="auto"
)

debug("Define tooltips for hover.")
tooltips = [
("Type", "@type"),
Expand All @@ -255,6 +260,7 @@ def plot_transcript(
active_drag="xpan",
tooltips=tooltips,
x_range=x_range,
y_range=bokeh.models.Range1d(-0.6, 0.6),
)

debug("Find child components of the transcript.")
Expand Down Expand Up @@ -333,13 +339,13 @@ def plot_transcript(

debug("Tidy up the figure.")
fig.yaxis.ticker = []
fig.y_range = bokeh.models.Range1d(-0.6, 0.6)
self._bokeh_style_genome_xaxis(fig, parent.contig)

if show:
bokeh.plotting.show(fig)

return fig
return None
else:
return fig

@check_types
@doc(
Expand Down Expand Up @@ -412,6 +418,7 @@ def plot_genes(
active_drag="xpan",
tooltips=tooltips,
x_range=x_range,
y_range=bokeh.models.Range1d(-0.4, 2.2),
)

debug("add functionality to click through to vectorbase")
Expand All @@ -431,7 +438,6 @@ def plot_genes(
)

debug("tidy up the plot")
fig.y_range = bokeh.models.Range1d(-0.4, 2.2)
fig.ygrid.visible = False
yticks = [0.4, 1.4]
yticklabels = ["-", "+"]
Expand All @@ -441,8 +447,9 @@ def plot_genes(

if show:
bokeh.plotting.show(fig)

return fig
return None
else:
return fig

def _plot_genes_setup_data(self, *, region):
attributes = [a for a in self._gff_default_attributes if a != "Parent"]
Expand Down
12 changes: 7 additions & 5 deletions malariagen_data/anoph/snp_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,9 @@ def plot_snps(

if show:
bokeh.plotting.show(fig)

return fig
return None
else:
return fig

@check_types
@doc(
Expand Down Expand Up @@ -1198,7 +1199,7 @@ def plot_snps_track(
tooltips=tooltips,
)
hover_tool = fig.select(type=bokeh.models.HoverTool)
hover_tool.names = ["snps"]
hover_tool.name = "snps"

# Plot gaps in the reference genome.
df_n_runs = pd.DataFrame(
Expand Down Expand Up @@ -1247,8 +1248,9 @@ def plot_snps_track(

if show:
bokeh.plotting.show(fig)

return fig
return None
else:
return fig

@check_types
@doc(
Expand Down
Loading

0 comments on commit c3e76e2

Please sign in to comment.