Skip to content

Commit

Permalink
add mean_abs and sum_abs to lineplot_and_heatmap (#183)
Browse files Browse the repository at this point in the history
Allows display of site statistics reflecting the mean and sum of the absolute values of the mutation values.

Also, update GitHub actions and lint/format with newer versions of `black` and `ruff`.
  • Loading branch information
jbloom committed Jan 30, 2024
1 parent 917a080 commit 82b3923
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 165 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
timeout-minutes: 60
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: install python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file.

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

6.11
----
- In ``lineplot_and_heatmap``, add ``mean_abs`` and ``sum_abs`` as possible site statistics, reflecting the mean and sum of the absolute values of the mutation values.

6.10
----
- In ``lineplot_and_heatmap``, mutations that are hidden are by one slider filtered even if they fail other sliders. Addresses `this issue <https://github.com/dms-vep/dms-vep-pipeline-3/issues/96>`_
Expand Down
220 changes: 159 additions & 61 deletions notebooks/real_LyCoV1404.ipynb

Large diffs are not rendered by default.

196 changes: 98 additions & 98 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.10"
__version__ = "6.11"
__url__ = "https://github.com/jbloomlab/polyclonal"

from polyclonal.alphabets import AAS
Expand Down
14 changes: 11 additions & 3 deletions polyclonal/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def lineplot_and_heatmap(
they fail other filters in `addtl_slider_stats`.
init_floor_at_zero : bool
Initial value for option to put floor of zero on value is `stat_col`.
init_site_statistic : {'sum', 'mean', 'max', 'min'}
init_site_statistic : {'sum', 'mean', 'max', 'min', 'mean_abs', 'sum_abs'}
Initial value for site statistic in lineplot, calculated from `stat_col`.
cell_size : float
Size of cells in heatmap
Expand Down Expand Up @@ -594,6 +594,7 @@ def lineplot_and_heatmap(
-------
altair.Chart
Interactive plot.
"""
if addtl_tooltip_stats is None:
addtl_tooltip_stats = []
Expand Down Expand Up @@ -978,7 +979,7 @@ def replace_std(col):
)

# make the site chart
site_statistics = ["sum", "mean", "max", "min"]
site_statistics = ["sum", "mean", "max", "min", "sum_abs", "mean_abs"]
if init_site_statistic not in site_statistics:
raise ValueError(f"invalid {init_site_statistic=}")
if set(site_statistics).intersection(req_cols):
Expand All @@ -998,8 +999,15 @@ def replace_std(col):
base_chart.transform_filter(
(alt.datum.wildtype != alt.datum.mutant) & ~alt.datum["_stat_hide"]
)
.transform_calculate(_stat_abs=alt.expr.abs(alt.datum["_stat"]))
.transform_aggregate(
**{f"_stat_{stat}": f"{stat}(_stat)" for stat in site_statistics},
**{
f"_stat_{stat}": (
stat.split("_")[0]
+ f"({'_stat_abs' if stat.endswith('_abs') else '_stat'})"
)
for stat in site_statistics
},
groupby=[*site_prop_cols, category_col],
)
.transform_fold(
Expand Down
2 changes: 2 additions & 0 deletions polyclonal/polyclonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2867,6 +2867,7 @@ def filter_variants_by_seen_muts(
variants_df : pandas.DataFrame
Copy of input dataframe, with rows of variants
that have unseen mutations removed.
"""
variants_df = variants_df.copy()

Expand Down Expand Up @@ -3154,6 +3155,7 @@ def mut_escape_corr(self, ref_poly):
-------
corr_df : pandas.DataFrame
Pairwise epitope correlations for escape.
"""
if self.mut_escape_df is None or ref_poly.mut_escape_df is None:
raise ValueError("Both objects must have `mut_escape_df` initialized.")
Expand Down
1 change: 1 addition & 0 deletions polyclonal/polyclonal_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ def mut_escape_corr_heatmap(
Plot squared correlation (eg, :math:`R^2` rather :math:`R`).
**kwargs
Keyword args for :func:`polyclonal.plot.corr_heatmap`
"""
corr_label = {"pearson": "r", "kendall": "tau", "spearman": "rho"}[method]
corr2_label = f"{corr_label}2"
Expand Down

0 comments on commit 82b3923

Please sign in to comment.