Skip to content

Commit

Permalink
reset index, and add_pheno_to_df index check (#117)
Browse files Browse the repository at this point in the history
Closes #116
  • Loading branch information
jgallowa07 authored Aug 13, 2023
1 parent 2cd1512 commit d954f00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com>`_.


main/HEAD
---------
- Fixed a `bug <https://github.com/matsengrp/multidms/issues/116>`_
caused by non-unique indicies in input variant functional score dataframes.


0.2.1
-----
- Made lineplot_and_heatmap() more private to remove from docs.
Expand Down
6 changes: 3 additions & 3 deletions multidms/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def __init__(
self._conditions = tuple(variants_df["condition"].astype(str).unique())

if str(reference) not in self._conditions:
if type(reference) != str:
if isinstance(reference, str):
raise ValueError(
"reference must be a string, note that if your "
"condition names are numeric, they are being"
Expand All @@ -223,7 +223,7 @@ def __init__(
raise ValueError("not enough `condition_colors`")
else:
self.condition_colors = dict(zip(self._conditions, condition_colors))
if not onp.all([type(c) == str for c in self.condition_colors.values()]):
if not onp.all([isinstance(c, str) for c in self.condition_colors.values()]):
raise ValueError("condition_color values must be hexidecimal")

# Check and initialize alphabet & mut parser attributes
Expand Down Expand Up @@ -259,7 +259,7 @@ def __init__(
)

else:
df = variants_df.copy()
df = variants_df[cols].reset_index(drop=True)

self._split_subs = partial(split_subs, parser=self._mutparser.parse_mut)
df["wts"], df["sites"], df["muts"] = zip(
Expand Down
15 changes: 9 additions & 6 deletions multidms/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ def __init__(
raise ValueError(
"softplus activation requires a lower bound be specified"
)
elif type(lower_bound) != float:
if not isinstance(lower_bound, float):
raise ValueError("lower_bound must be a float")
else:
output_activation = partial(
multidms.biophysical.softplus_activation, lower_bound=lower_bound
)

output_activation = partial(
multidms.biophysical.softplus_activation, lower_bound=lower_bound
)

for condition in data.conditions:
self._params[f"gamma_{condition}"] = jnp.zeros(shape=(1,))
Expand Down Expand Up @@ -493,7 +493,8 @@ def add_phenotypes_to_df(
----------
df : pandas.DataFrame
Data frame containing variants. Requirements are the same as
those used to initialize the `multidms.Data` object
those used to initialize the `multidms.Data` object - except
the indices must be unique.
substitutions_col : str
Column in `df` giving variants as substitution strings
with respect to a given variants condition.
Expand Down Expand Up @@ -537,6 +538,8 @@ def add_phenotypes_to_df(
raise ValueError("`df` lacks `substitutions_col` " f"{substitutions_col}")
if condition_col not in df.columns:
raise ValueError("`df` lacks `condition_col` " f"{condition_col}")
if not df.index.is_unique:
raise ValueError("`df` must have unique indices")

# return copy
ret = df.copy()
Expand Down

0 comments on commit d954f00

Please sign in to comment.