kinetics_kalculator package

Submodules

kinetics_kalculator.kinetics_kalculator module

class kinetics_kalculator.kinetics_kalculator.KineticsKalculator(data_path: Path | PathLike | DataFrame | None, standard_curve_parameters: dict | None = None)[source]

Bases: object

adjust_rates_for_background(rate_column: str, sample_type_column: str = 'sample_type', negative_control: str = 'negative_control', remove_negative_controls: bool = True)[source]

Adjust the rates in the DataFrame by subtracting the provided background value. Adds a new column containing the adjusted rates, ‘{rate_column}_minus_background’, to the DataFrame.

Parameters:
  • rate_column (str) – The name of the column containing the rates to adjust. Defaults to "rate."

  • sample_type_column (str) – The name of the column containing the sample type information. Defaults to “sample_type”.

  • negative_control (str) – The value to use as the negative control. Defaults to “negative_control”.

  • remove_negative_controls (bool) – Whether to remove the negative control rows after adjusting the rates. Defaults to True.

Returns:

The DataFrame is modified in-place.

Return type:

None

calculate_rates(time_column: str, value_column: str, group_by_columns: list[str], print_fit_summary: bool = True, sample_type_column: str = 'sample_type', negative_control: str = 'negative_control', poor_fit_threshold: float = 0.5)[source]

Calculate the rates of change in the ‘value’ column over time, and add a new column to the DataFrame containing the calculated rates.

NOTE: The rates are calculated as the first derivative of the values with respect to time. We assume that the “value” column represents the appropriate unit (e.g., concentration).

Parameters:
  • time_column (str) – The name of the column containing the time values.

  • value_column (str) – The name of the column containing the values to calculate rates from.

  • group_by_columns (list[str]) – The names of the columns to group the data by before calculating rates. E.g., “well” or “replicate”.

  • sample_type_column (str) – The name of the column containing the sample type information. Defaults to “sample_type”. Used for validation of results.

  • negative_control (str) – The value to use as the negative control. Defaults to “negative_control”. Used for validation of results.

  • poor_fit_threshold (float) – The threshold for determining a poor fit. Defaults to 0.5.

Returns:

The DataFrame is modified in-place.

Return type:

None

convert_values_to_concentration_with_standard_curve()[source]

Convert the ‘value’ column in the DataFrame to concentration units using the provided slope and y-intercept of the standard curve.

NOTE: Only supports linear standard curves of the form y = mx + c.

Returns:

The DataFrame is modified in-place.

Return type:

None

label_replicates_and_conditions(condition_columns: list[str], well_column: str = 'well')[source]

Label rows in the dataframe that represent the same experimental conditions; e.g., replicates.

plot_concentration_vs_time_for_each_condition(time_column: str = 'time', value_column: str = 'value', condition_column: str = 'condition', time_units: str = 's', concentration_units: str = 'M')[source]

Plot measured target concentration over time for each experimental condition in the DataFrame.

Parameters:
  • time_column (str) – The name of the column containing the time values. Defaults to ‘time’.

  • value_column (str) – The name of the column containing the concentration values. Defaults to ‘value’.

  • condition_column (str) – The name of the column containing the condition labels. Defaults to ‘condition’.

  • time_units (str) – The units of time to display on the x-axis. Defaults to ‘s’.

  • concentration_units (str) – The units of concentration to display on the y-axis. Defaults to ‘M’.

Returns:

Displays a plot for each condition showing substrate concentration over time.

Return type:

None

Raises:

AssertionError – If any of the specified columns do not exist in the DataFrame.

plot_michaelis_menten_curve(substrate_concentration_column: str = 'substrate_concentration') None[source]

Plot the Michaelis-Menten curve using Seaborn.

subset_dataframe_to_time_range(lower_bound: float, upper_bound: float)[source]

Subset the underlying DataFrame to only include rows where the ‘time’ column is within the specified range.

Parameters:
  • lower_bound (float) – The lower bound of the time range.

  • upper_bound (float) – The upper bound of the time range.

Returns:

The DataFrame is modified in-place.

Return type:

None

Raises:

ValueError – If the DataFrame does not contain the required ‘time’ column.

kinetics_kalculator.utils module

kinetics_kalculator.utils.add_rate_column(df: DataFrame, x_column: str, y_column: str, group_by_columns: list[str]) DataFrame[source]

Adds specified columns to the DataFrame by fitting a linear model to the specified x and y columns for each group.

Parameters:
  • df (pd.DataFrame) – A DataFrame containing the data to fit.

  • x_column (str) – The name of the column to use as the independent variable.

  • y_column (str) – The name of the column to use as the dependent variable.

  • group_by_columns (list) – A list of columns to group the data by before fitting the model. E.g., “well”, or “replicate”.

Returns:

A new DataFrame with specified columns added, representing the results of the linear fit for each group. The new columns include:
  • ”rate”: The slope of the fitted line.

  • ”intercept”: The y-intercept of the fitted line.

  • ”r_value”: The correlation coefficient.

  • ”p_value”: The two-sided p-value for a hypothesis test whose null hypothesis is that the slope is zero.

  • ”std_err”: The standard error of the estimated gradient.

Return type:

pd.DataFrame

kinetics_kalculator.utils.adjust_rates_for_background(df: DataFrame, negative_control: str, epsilon: float, rate_column: str = 'rate', sample_type_column: str = 'sample_type') None[source]

Adjusts the rates in the DataFrame to account for background rates using a specified negative control.

Parameters:
  • df (pd.DataFrame) – A DataFrame containing a sample type column and a column for rates.

  • negative_control (str) – The value in the sample type column to identify negative control samples.

  • epsilon (float) – A small positive value to replace any negative rates after background adjustment.

  • rate_column (str) – The name of the column containing the rates to be adjusted. Default is ‘rate’.

  • sample_type_column (str) – The name of the column containing the sample type information. Default is ‘sample_type’.

Returns:

The DataFrame is modified in-place.

Return type:

None

Raises:

ValueError – If the DataFrame does not contain the required columns.

kinetics_kalculator.utils.calculate_michaelis_menten_constants(df: DataFrame, substrate_concentration_column: str = 'substrate_concentration') dict[source]

Calculate Michaelis-Menten constants Vmax and Km.

Parameters:
  • df (pd.DataFrame) – A DataFrame containing columns for substrate concentration and initial rates.

  • substrate_concentration_column (str) – The name of the column containing the substrate concentrations. Default is ‘substrate_concentration’.

Returns:

A dictionary containing Vmax and Km.

Return type:

dict

kinetics_kalculator.utils.convert_to_concentration_using_linear_standard_curve(df: DataFrame, slope: float, y_intercept: float) None[source]

Converts generic values to concentrations.

Convert the ‘value’ column in the DataFrame to concentration units using the provided slope and y-intercept of the standard curve.

NOTE: Only support linear standard curves of the form y = mx + c.

Parameters:
  • df (pd.DataFrame) – A DataFrame containing a ‘value’ column.

  • slope (float) – The slope of the standard curve.

  • y_intercept (float) – The y-intercept of the standard curve.

Returns:

The DataFrame with the ‘value’ column converted to concentration units.

Return type:

DataFrame

Raises:

ValueError – If the DataFrame does not contain the required ‘value’ column.

Example

>>> df = pd.DataFrame({"value": [1, 2, 3, 4, 5]})  # E.g., units of absorbance
>>> convert_to_concentration_using_standard_curves(df, 2, 1)
>>> df
   value
0    0.5
1    1.0
2    1.5
3    2.0
4    2.5
kinetics_kalculator.utils.filter_by_time_range(df: DataFrame, lower_bound: float, upper_bound: float) DataFrame[source]

Filter the DataFrame to only include rows where the ‘time’ column is within the specified range.

Parameters:
  • df (pd.DataFrame) – A DataFrame containing a ‘time’ column.

  • lower_bound (float) – The lower bound of the time range.

  • upper_bound (float) – The upper bound of the time range.

Returns:

A new DataFrame containing only the rows within the specified time range.

Return type:

pd.DataFrame

Raises:

ValueError – If the DataFrame does not contain the required ‘time’ column.

kinetics_kalculator.utils.fit_line(group: DataFrame, x_column: str, y_column: str) Series[source]

Fits a linear model to the data in the specified group using the given x and y columns.

Parameters:
  • group (pd.DataFrame) – A DataFrame group containing the data to fit.

  • x_column (str) – The name of the column to use as the independent variable.

  • y_column (str) – The name of the column to use as the dependent variable.

Returns:

A Series containing the slope (rate), intercept, and other statistics from the linear regression.
  • ”rate”: The slope of the fitted line.

  • ”intercept”: The y-intercept of the fitted line.

  • ”r_value”: The correlation coefficient.

  • ”p_value”: The two-sided p-value for a hypothesis test whose null hypothesis is that the slope is zero.

  • ”std_err”: The standard error of the estimated gradient.

Return type:

pd.Series

Module contents