Skip to content

Commit

Permalink
Merge branch 'CW-4904' into 'dev'
Browse files Browse the repository at this point in the history
Path for SeqCompare to work with Bokeh plots [CW-4904]

Closes CW-4904

See merge request epi2melabs/ezcharts!199
  • Loading branch information
RenzoTale88 committed Sep 10, 2024
2 parents 1f5ee59 + 56ba2d7 commit 12e46d4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Transparent lines/points plotted in relational plots.
- Add `hover` back to bokeh toolbox.
- `SeqCompare` not working with histograms and line charts from `BokehPlots`.
### Removed
- BcftoolsStats component until it is updated to use BokehPlot.

Expand Down
41 changes: 31 additions & 10 deletions ezcharts/components/fastcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ezcharts.components.reports.comp import ComponentReport
from ezcharts.layout.base import Snippet
from ezcharts.layout.snippets import DataTable, Grid, Tabs
from ezcharts.plots import BokehPlot


FASTCAT_COLS_DTYPES = {
Expand Down Expand Up @@ -484,31 +485,51 @@ def _is_empty_plot(self, plot):
"""Check if the plot is empty."""
if not plot:
return True
if not plot.dataset:
return True
if isinstance(plot, BokehPlot):
if "_fig" not in dir(plot):
return True
for renderer in plot._fig.renderers:
if not hasattr(renderer, 'glyph'):
return True
else:
if not plot.dataset:
return True
return False

def _coordinate_plots(self, plots, labels=None):
"""Coordinate the axes between the plots."""
max_by_plot = []
for plot in plots:
if not self._is_empty_plot(plot):
dimensions = np.array(plot.dataset[0].dimensions)
if 'y' in dimensions:
y_col = np.where(dimensions == 'y')[0]
if isinstance(plot, BokehPlot):
dimensions = plot._fig.renderers[0].data_source.to_df()
if 'top' in dimensions.columns:
col = 'top'
else:
col = 'y'
y_val = dimensions[col].max()
else:
y_col = np.where(dimensions == 'height')[0]
max_by_plot.append(np.max(plot.dataset[0].source, axis=0)[y_col])
dimensions = np.array(plot.dataset[0].dimensions)
if 'y' in dimensions:
y_col = np.where(dimensions == 'y')[0]
else:
y_col = np.where(dimensions == 'height')[0]
y_val = np.max(plot.dataset[0].source, axis=0)[y_col]
max_by_plot.append(y_val)
# Set new values
if labels:
inputs = zip(plots, labels)
else:
inputs = zip(plots, [None] * len(plots))
for (plot, label) in inputs:
if not self._is_empty_plot(plot):
plot.yAxis.max = max(max_by_plot)
if label:
plot.title.text = label
plot._fig.y_range.end = max(max_by_plot)
if label:
plot._fig.add_layout(
Title(text=label, text_font_size="1.5em"), 'above')
else:
if label:
plot.title.text = label

def _draw_bamstat_table(self, data):
if not isinstance(data, pd.DataFrame):
Expand Down
6 changes: 3 additions & 3 deletions ezcharts/data/test/histogram_stats/sample_2/length.hist
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,10 @@
701 702 8
702 703 8
703 704 6
704 705 9
705 706 13
704 705 19
705 706 23
706 707 9
707 708 11
707 708 21
708 709 6
709 710 5
710 711 5
Expand Down
6 changes: 3 additions & 3 deletions ezcharts/data/test/histogram_stats/sample_2/quality.hist
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@
11.60 11.62 6
11.62 11.64 17
11.64 11.66 7
11.66 11.68 16
11.68 11.70 11
11.70 11.72 6
11.66 11.68 26
11.68 11.70 21
11.70 11.72 16
11.72 11.74 8
11.74 11.76 9
11.76 11.78 10
Expand Down
9 changes: 8 additions & 1 deletion ezcharts/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ezcharts.components.dss import load_dml, load_dmr
from ezcharts.components.ezchart import EZChart
from ezcharts.components.fastcat import load_bamstats_flagstat, load_stats
from ezcharts.components.fastcat import SeqSummary
from ezcharts.components.fastcat import SeqCompare, SeqSummary
from ezcharts.components.modkit import load_bedmethyl, load_modkit_summary
from ezcharts.components.mosdepth import load_mosdepth_regions, load_mosdepth_summary
from ezcharts.components.nextclade import NextClade, NXTComponent
Expand Down Expand Up @@ -164,6 +164,13 @@ def example_plot(style="line") -> Plot:
seq_summary=histogram_stats_dir,
color="#2a98b7",
sample_names=tuple(['sample_1', 'sample_2', 'sample_3']))
with report.add_section('Compare Summaries', 'Compare'):
SeqCompare(
histogram_stats_dir,
sample_names=tuple(['sample_1', 'sample_2', 'sample_3']),
alignment_stats=False,
color="#2a98b7",
)

# This also adds to main_content, but provides a nice
# container snippet as a starting context.
Expand Down

0 comments on commit 12e46d4

Please sign in to comment.