Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in PolyclonalCollection.sites when models have different sequential integer sites #173

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4
---
- Fixed bug introduced in version 6.3 in ``PolyclonalCollection.sites`` when ``sites`` are integer.

6.3
---
- Ensure ``PolyclonalCollection.sites`` attribute is always defined.
Expand Down
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.3"
__version__ = "6.4"
__url__ = "https://github.com/jbloomlab/polyclonal"

from polyclonal.alphabets import AAS
Expand Down
20 changes: 15 additions & 5 deletions polyclonal/polyclonal_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,16 @@ class PolyclonalCollection:
... [("M3A", 1, 0), ("K5G", 1, 1)],
... columns=["aa_substitutions", "concentration", "prob_escape"],
... )
>>> data_to_fit2 = pd.DataFrame.from_records(
... [("M3A", 1, 0), ("K5G", 1, 1), ("L6T", 1, 0.5)],
... columns=["aa_substitutions", "concentration", "prob_escape"],
... )

>>> models_df = pd.DataFrame(
... {
... "model": [
... polyclonal.Polyclonal(data_to_fit=data_to_fit, n_epitopes=1),
... polyclonal.Polyclonal(data_to_fit=data_to_fit, n_epitopes=1),
... polyclonal.Polyclonal(data_to_fit=data_to_fit2, n_epitopes=1),
... ],
... "description": ["model_1", "model_2"],
... }
Expand All @@ -322,7 +326,7 @@ class PolyclonalCollection:
... models_df, default_avg_to_plot="mean",
... )
>>> model_collection.sites
(3, 5)
(3, 5, 6)

"""

Expand All @@ -349,18 +353,24 @@ def __init__(self, models_df, *, default_avg_to_plot):
raise ValueError("some models have the same descriptors")
self.model_descriptors = list(descriptors_df.to_dict(orient="index").values())

for attr in [
shared_attrs = [
"epitopes",
"epitope_colors",
"alphabet",
"sequential_integer_sites",
"sites",
]:
]
if all(not model.sequential_integer_sites for model in self.models):
shared_attrs.append("sites")
for attr in shared_attrs:
for model in self.models:
if not hasattr(self, attr):
setattr(self, attr, copy.copy(getattr(model, attr)))
elif getattr(self, attr) != getattr(model, attr):
raise ValueError(f"{attr} not the same for all models")
if "sites" not in shared_attrs:
sites = sorted(set().union(*[model.sites for model in self.models]))
assert all(type(r) == int for r in sites), sites
self.sites = tuple(sites)

@property
def activity_wt_df_replicates(self):
Expand Down