Skip to content

Commit

Permalink
improve heatmap limits (#177)
Browse files Browse the repository at this point in the history
* Add `heatmap_lims_from_slider_init` option to `lineplot_and_heatmap`

* Set default `floor_at_zero` for `mut_icXX_plot` to be `True` like for other plots

* code formatting

* re-run notebooks
  • Loading branch information
jbloom authored Aug 18, 2023
1 parent 049419c commit 241a801
Show file tree
Hide file tree
Showing 8 changed files with 565 additions and 359 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.

The format is based on `Keep a Changelog <https://keepachangelog.com>`_.

6.7
---
- Add ``heatmap_lims_from_slider_init`` option to ``lineplot_and_heatmap`` so that by default heatmap range is set by data shown with initial slider stats. Set this option to ``False`` if you want old behavior for plot limits
- Set default ``init_floor_at_zero`` for ``mut_icXX_plot`` to be ``True`` like for other plots.

6.6
---
- Change ``lineplot_and_heatmap`` parameter ``addtl_slider_stats_hide_not_filter`` (which is used to make the escape heatmaps) so that mutations that have null escape but a non-null but hidden value are shown as grayed out (hidden) rather than missing. The use case is so that deleterious mutations that don't have escape measured but fail the functional effects filter are shown grayed out to indicate that they were measured and are deleterious, rather than leaving them out which implies they were not measured.
Expand Down
469 changes: 279 additions & 190 deletions notebooks/RBD_average.ipynb

Large diffs are not rendered by default.

242 changes: 122 additions & 120 deletions notebooks/real_LyCoV1404.ipynb

Large diffs are not rendered by default.

174 changes: 141 additions & 33 deletions notebooks/visualize_RBD.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion polyclonal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

__author__ = "`the Bloom lab <https://research.fhcrc.org/bloom/en.html>`_"
__email__ = "[email protected]"
__version__ = "6.6"
__version__ = "6.7"
__url__ = "https://github.com/jbloomlab/polyclonal"

from polyclonal.alphabets import AAS
Expand Down
26 changes: 17 additions & 9 deletions polyclonal/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ def lineplot_and_heatmap(
heatmap_negative_color=None,
heatmap_color_scheme=None,
heatmap_color_scheme_mid_0=True,
heatmap_lims_from_slider_init=True,
heatmap_max_at_least=None,
heatmap_min_at_least=None,
heatmap_max_fixed=None,
Expand Down Expand Up @@ -540,6 +541,11 @@ def lineplot_and_heatmap(
rather than `category_colors` and `heatmap_negative_color`.
heatmap_color_scheme_mid_0 : bool
Set the heatmap color scheme so the domain mid is zero.
heatmap_lims_from_slider_init : bool
Do we set the heatmap limits to span just the range of values that are
shown given the initial values for any sliders in `addtl_slider_stats`, or
do we include all values including ones that might be filtered or hidden
by the initial slider values.
heatmap_max_at_least : None or float
Make heatmap color max at least this large.
heatmap_min_at_least : None or float
Expand Down Expand Up @@ -613,12 +619,6 @@ def lineplot_and_heatmap(
# filter `data_df` by any minimums in `slider_binding_range_kwargs`
if slider_binding_range_kwargs is None:
slider_binding_range_kwargs = {}
for col, col_kwargs in slider_binding_range_kwargs.items():
if "min" in col_kwargs:
data_df = data_df[
(data_df[col] >= col_kwargs["min"])
| (data_df["wildtype"] == data_df["mutant"])
]

categories = data_df[category_col].unique().tolist()
show_category_label = show_single_category_label or (len(categories) > 1)
Expand All @@ -638,7 +638,7 @@ def lineplot_and_heatmap(
[data_df[c].notnull() for c in ["site", "mutant", category_col]],
)
]
# not defined for one of the stats or one of the hiding columns
# not defined for at least one of the stats or one of the hiding columns
data_df = data_df[
functools.reduce(
operator.or_,
Expand Down Expand Up @@ -690,12 +690,20 @@ def lineplot_and_heatmap(
]

# make floor at zero selection, setting floor to either 0 or min in data (no floor)
min_stat = data_df[stat_col].min() # used as min in heatmap when not flooring at 0
if heatmap_lims_from_slider_init:
df_for_lims = data_df.copy()
for slider_stat, init_stat in addtl_slider_stats.items():
if init_stat is not None:
df_for_lims = df_for_lims[df_for_lims[slider_stat] >= init_stat]
min_stat = df_for_lims[stat_col].min()
max_stat = df_for_lims[stat_col].max()
else:
min_stat = data_df[stat_col].min()
max_stat = data_df[stat_col].max() # used as max in heatmap
if heatmap_min_at_least is not None:
min_stat = min(min_stat, heatmap_min_at_least)
if heatmap_min_fixed is not None:
min_stat = heatmap_min_fixed
max_stat = data_df[stat_col].max() # used as max in heatmap
if heatmap_max_at_least is not None:
max_stat = max(max_stat, heatmap_max_at_least)
if heatmap_max_fixed is not None:
Expand Down
3 changes: 0 additions & 3 deletions polyclonal/polyclonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2697,9 +2697,6 @@ def mut_icXX_plot(
kwargs["addtl_tooltip_stats"] = []
kwargs["addtl_tooltip_stats"].append(icXX_col)

if "init_floor_at_zero" not in kwargs:
kwargs["init_floor_at_zero"] = False

if "heatmap_min_at_least" not in kwargs:
kwargs["heatmap_min_at_least"] = -2
if "heatmap_max_at_least" not in kwargs:
Expand Down
3 changes: 0 additions & 3 deletions polyclonal/polyclonal_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,6 @@ def mut_icXX_plot(
if "times_seen" not in kwargs["addtl_slider_stats"]:
kwargs["addtl_slider_stats"]["times_seen"] = 1

if "init_floor_at_zero" not in kwargs:
kwargs["init_floor_at_zero"] = False

if "heatmap_min_at_least" not in kwargs:
kwargs["heatmap_min_at_least"] = -2
if "heatmap_max_at_least" not in kwargs:
Expand Down

0 comments on commit 241a801

Please sign in to comment.