Skip to content

Commit

Permalink
add min_times_seen to PolyclonalCollection.mut_escape_corr
Browse files Browse the repository at this point in the history
  • Loading branch information
jbloom committed Aug 13, 2023
1 parent 3c2dc6e commit ec06a32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on `Keep a Changelog <https://keepachangelog.com>`_.
6.6
---
- Fix bug where ``scale_stat_col`` to per-model values in tooltips when using ``PolyclonalCollection.mut_escape_plot`` and ``PolyclonalCollections.mut_escape_icXX``.
- Add ``min_times_seen`` filter to ``PolyclonalCollection.mut_escape_corr`` and ``PolyclonalCollection.mut_escape_corr_heatmap``.

6.5
---
Expand Down
20 changes: 16 additions & 4 deletions polyclonal/polyclonal_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,13 +776,15 @@ def mut_icXX_df_w_model_values(self, **kwargs):
validate="one_to_one",
)

def mut_escape_corr(self, method="pearson"):
def mut_escape_corr(self, method="pearson", min_times_seen=1):
"""Correlation of mutation escape values across models for each epitope.
Parameters
----------
method : str
A correlation method passable to `pandas.DataFrame.corr`.
min_times_seen : int
Only include mutations with a *times_seen* >= this value.
Returns
-------
Expand All @@ -805,7 +807,9 @@ def mut_escape_corr(self, method="pearson"):

corr = (
polyclonal.utils.tidy_to_corr(
self.mut_escape_df_replicates.merge(
self.mut_escape_df_replicates.query(
"times_seen >= @min_times_seen"
).merge(
ids,
on=self.descriptor_names,
validate="many_to_one",
Expand All @@ -826,13 +830,21 @@ def mut_escape_corr(self, method="pearson"):

return corr

def mut_escape_corr_heatmap(self, method="pearson", plot_corr2=True, **kwargs):
def mut_escape_corr_heatmap(
self,
method="pearson",
min_times_seen=1,
plot_corr2=True,
**kwargs,
):
"""Heatmap of mutation-escape correlation among models at each epitope.
Parameters
----------
method : str
A correlation method passable to `pandas.DataFrame.corr`.
min_times_seen : int
Only include mutations with a *times_seen* >= this value.
plot_corr2 : bool
Plot squared correlation (eg, :math:`R^2` rather :math:`R`).
**kwargs
Expand All @@ -841,7 +853,7 @@ def mut_escape_corr_heatmap(self, method="pearson", plot_corr2=True, **kwargs):
corr_label = {"pearson": "r", "kendall": "tau", "spearman": "rho"}[method]
corr2_label = f"{corr_label}2"
corr_df = (
self.mut_escape_corr(method)
self.mut_escape_corr(method, min_times_seen)
.assign(correlation2=lambda x: x["correlation"] ** 2)
.rename(columns={"correlation": corr_label, "correlation2": corr2_label})
)
Expand Down

0 comments on commit ec06a32

Please sign in to comment.