Skip to content

Commit

Permalink
add option for response_col to be str or list
Browse files Browse the repository at this point in the history
  • Loading branch information
tlint101 committed Nov 29, 2024
1 parent 2497f78 commit d305a32
Showing 1 changed file with 72 additions and 12 deletions.
84 changes: 72 additions & 12 deletions py50/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def calculate_ic50(
self,
name_col: str = None,
concentration_col: str = None,
response_col: str = None,
response_col: Union[str, list] = None,
input_units: str = None,
verbose: bool = None,
):
Expand All @@ -71,8 +71,9 @@ def calculate_ic50(
Name column from DataFrame
:param concentration_col: str
Concentration column from DataFrame
:param response_col: str
Response column from DataFrame
:param response_col: Union[str, list]
Response column from DataFrame. Can be a single column (i.e. already a calculated average) or a list of
columns to be averaged. The columns will be averaged internally within the function.
:param input_units: str
Units of input dataset. Default is nM.
:param verbose: bool
Expand All @@ -81,6 +82,26 @@ def calculate_ic50(
:return: DataFrame generated from the list from the relative_calculation method
"""

# set instance variables
if name_col is None:
name_col = self.name_col
if concentration_col is None:
concentration_col = self.concentration_col
if response_col is None:
response_col = self.response_col

# if response_col is a list, table will be reformated to produce a column with average values
if isinstance(response_col, list):
reshape_data = pd.melt(
self.data,
id_vars=[name_col, concentration_col],
value_vars=response_col,
value_name="inhibition_average",
)
# drop the variable column
self.data = reshape_data.drop(columns=["variable"])
response_col = "inhibition_average" # reset response_col input

# Set variables from function and convert name_col to np array
values = self._relative_calculation(
name_col, concentration_col, response_col, input_units, verbose
Expand All @@ -95,7 +116,7 @@ def calculate_absolute_ic50(
self,
name_col: str = None,
concentration_col: str = None,
response_col: str = None,
response_col: Union[str, list] = None,
input_units: str = None,
verbose: bool = None,
):
Expand All @@ -107,15 +128,35 @@ def calculate_absolute_ic50(
Name column from DataFrame
:param concentration_col: str
Concentration column from DataFrame
:param response_col: str
Response column from DataFrame
:param response_col: Union[str, list]
Response column from DataFrame. Can be a single column (i.e. already a calculated average) or a list of
columns to be averaged. The columns will be averaged internally within the function.
:param input_units: str
Units of input dataset. Default is nM.
:param verbose: bool
Output drug concentration units.
:return: DataFrame generated from the list from the absolute_calculation method
"""
# set instance variables
if name_col is None:
name_col = self.name_col
if concentration_col is None:
concentration_col = self.concentration_col
if response_col is None:
response_col = self.response_col

# if response_col is a list, table will be reformated to produce a column with average values
if isinstance(response_col, list):
reshape_data = pd.melt(
self.data,
id_vars=[name_col, concentration_col],
value_vars=response_col,
value_name="inhibition_average",
)
# drop the variable column
self.data = reshape_data.drop(columns=["variable"])
response_col = "inhibition_average" # reset response_col input

values = self._absolute_calculation(
name_col=name_col,
Expand All @@ -133,7 +174,7 @@ def calculate_pic50(
self,
name_col: str = None,
concentration_col: str = None,
response_col: str = None,
response_col: Union[str, list] = None,
input_units: str = None,
verbose: bool = None,
):
Expand All @@ -146,15 +187,37 @@ def calculate_pic50(
Name column from DataFrame
:param concentration_col: str
Concentration column from DataFrame
:param response_col: str
Response column from DataFrame
:param response_col: Union[str, list]
Response column from DataFrame. Can be a single column (i.e. already a calculated average) or a list of
columns to be averaged. The columns will be averaged internally within the function.
:param input_units: str
Units of input dataset. Default is nM.
:param verbose: bool
Output drug concentration units.
:return: DataFrame from calculate_absolute_ic50 along with the pIC50 values
"""

# set instance variables
if name_col is None:
name_col = self.name_col
if concentration_col is None:
concentration_col = self.concentration_col
if response_col is None:
response_col = self.response_col

# if response_col is a list, table will be reformated to produce a column with average values
if isinstance(response_col, list):
reshape_data = pd.melt(
self.data,
id_vars=[name_col, concentration_col],
value_vars=response_col,
value_name="inhibition_average",
)
# drop the variable column
self.data = reshape_data.drop(columns=["variable"])
response_col = "inhibition_average" # reset response_col input

values = self._absolute_calculation(
name_col=name_col,
concentration_col=concentration_col,
Expand Down Expand Up @@ -314,9 +377,6 @@ def _relative_calculation(
query = drug_query.copy()
query.sort_values(by=concentration_col, inplace=True)

# todo Calculate standard deviations from the covariance matrix
# std_dev = np.sqrt(np.diag(covariance))

# tag response col to determine direction of fourpl equation and fit to 4PL equation
reverse, params, covariance = self._calc_logic(
data=query,
Expand Down

0 comments on commit d305a32

Please sign in to comment.