Generalized Functions for Viability Calibration and Growth Rate Extrapolation

Abraheem ‘Abe’ Khouqeer

2024-12-16

This document provides generalized R functions for viability calibration and growth rate extrapolation. These functions include explanations of the underlying mathematics and demonstrate their usage with examples.


Viability Calibration

Overview

Viability calibration involves converting a measured signal (e.g., luminescence as I used with CellTiterGlo) into the actual number of viable cells. I model the relationship using linear interpolation between known data points using approxfun().

Inputs

approxfun(x, y) takes two main arguments:

  • x: A numeric vector of x-coordinates of the given data points.
  • y: A numeric vector of y-coordinates of the given data points.

Linear Interpolation

Linear interpolation involves constructing new data points within the range of a discrete set of known data points. For two points \((x_i, y_i)\) and \((x_{i+1}, y_{i+1})\), the linear interpolation formula for a point \(x\) such that \(x_i \leq x \leq x_{i+1}\) is:

\[ y = y_i + \frac{(y_{i+1} - y_i)}{(x_{i+1} - x_i)} \cdot (x - x_i) \]

R Function for Viability Calibration

# Function to calculate the standard curve from raw cell counts and signal measurements
calculate_standard_curve <- function(cell_counts, signals) {
  # Create and return an interpolation function using approxfun
  approxfun(signals, cell_counts, rule = 2) # Linear interpolation with extrapolation
}

# Function to perform viability calibration using the interpolation function
viability_calibration <- function(signal_values, interpolation_func) {
  # Apply the interpolation function to the signal values
  calibrated_cells <- interpolation_func(signal_values)
  return(calibrated_cells)
}

Example Usage

# Standard curve data
cell_counts <- c(0, 1000, 5000, 10000, 20000)
signals <- c(0, 150, 750, 1500, 3000)

# Create the interpolation function
interpolation_func <- calculate_standard_curve(cell_counts, signals)

# Measured signals to be calibrated
measured_signals <- c(200, 1200, 2500)

# Convert signals to cell counts using the interpolation function
calibrated_cells <- viability_calibration(measured_signals, interpolation_func)

# Print the calibrated cell counts
print(calibrated_cells)
## [1]  1333.333  8000.000 16666.667

Growth Rate Calculation

Overview

Growth rate calculation determines the rate of population growth over a specific time interval. The doubling time, which represents the time required for the population to double, can also be derived.

Mathematical Model

The growth rate (\(\mu\)) and doubling time (\(t_d\)) are calculated using the following equations:

Growth Rate:

\[ \mu = \frac{ \ln \left( \frac{N_t}{N_0} \right) }{ \Delta t } \cdot 24 \text{h} \]

Where:

  • \(\mu\): growth rate [1/d]
  • \(N_t\): number of cells at time \(t\)
  • \(N_0\): initial number of cells
  • \(\Delta t\): duration of growth (in hours)

Doubling Time:

\[ t_d = \frac{\ln(2)}{\mu} \cdot 24 \text{h} \]

Where:

  • \(t_d\): doubling time [h]

R Function for Growth Rate and Doubling Time

calculate_growth_rate <- function(N0, Nt, delta_t) {
  # Calculate growth rate (mu)
  mu <- (log(Nt / N0) / delta_t) * 24

  # Calculate doubling time (td)
  td <- (log(2) / mu) * 24

  return(list(growth_rate = mu, doubling_time = td))
}

Example Usage

# Input values
N0 <- 1e5  # Initial cell count
Nt <- 8e5  # Final cell count
delta_t <- 48  # Growth duration in hours

# Calculate growth rate and doubling time
results <- calculate_growth_rate(N0, Nt, delta_t)
print(results)
## $growth_rate
## [1] 1.039721
## 
## $doubling_time
## [1] 16

Growth Rate and Slope Extrapolation at Inflection Point

Overview

In cases where cumulative population data is available over time, the slope at the inflection point can be used to assess the degree the challenge is affecting the growth rate. This function uses a smooth spline fit to the cumulative data and calculates the maximum of the first derivative to determine the slope at the inflection point.

Calculating the Slope

Given cumulative population data \((x, y)\): 1. Fit a smooth spline to \((x, y)\). 2. Compute the first derivative of the smooth spline. 3. Identify the point where the first derivative is maximized. 4. Extract the slope (value of the first derivative) at this point.

Formula

Let \(f(x)\) be the smooth spline fitted to the data. The slope at the inflection point is given by:

\[ \text{slope} = \max \left( \frac{d}{dx} f(x) \right) \]

R Function for Growth Rate Extrapolation

growth_rate_slope <- function(cumulative_data) {
  # Fit a smooth spline to the cumulative data
  fit <- smooth.spline(cumulative_data$x, cumulative_data$cumulative_y)

  # Find the maximum of the first derivative (slope at the inflection point)
  derivatives <- predict(fit, deriv = 1)
  inflection_slope <- max(derivatives$y)

  return(inflection_slope)
}

Example Usage

# Cumulative data
data <- data.frame(
  x = 1:10,
  cumulative_y = c(2, 5, 9, 15, 22, 31, 42, 55, 70, 87)
)

# Extract slope at the inflection point
inflection_slope <- growth_rate_slope(data)
print(inflection_slope)
## [1] 17.42154