A Python library for compartmental pharmacokinetic analysis of drug concentration-time data. It performs non-linear regression to fit one-compartment and two-compartment models, and calculates relevant PK parameters, both for intravenous (IV) and extravascular (oral) scenarios.
For an in-depth understanding of the CPK analysis performed here, refer to our published article Large-Scale Compartmental Model-Based Study of Preclinical Pharmacokinetic Data and Its Impact on Compound Triaging in Drug Discovery.
- Compartmental Analysis: Supports one-compartment and two-compartment pharmacokinetic models
- Multiple Routes: Handles both intravenous (IV) and extravascular (EV) administration routes
- Model Selection: Automatically selects best-fitting model based on Akaike Information Criterion (AICc)
- Uncertainty Analysis: Calculates parameter standard errors and identifies high-uncertainty parameters
- Outlier Detection: Implements outlier detection and removal with automatic reprocessing
- Command Line Interface: Easy-to-use CLI for analysis of CSV data files
- Python API: Comprehensive programmatic interface for integration into workflows
# Analyze data from CSV file
cpk run --csv-path data.csv --dose 10 --parent-weight 500 --route IV
# Analyze data directly from command line
cpk run --sample-times 0.083 0.25 0.5 1 2 4 8 24 --concentrations 2.28 1.35 1.08 0.82 0.45 0.20 0.08 0.04 --dose 1 --parent-weight 564.55
# Run demo analysis
cpk demoimport pandas as pd
from cpk import IvPkAnalysis, EvPkAnalysis, load_samples
# Load data
df = pd.DataFrame({
'sample_time': [0.083, 0.25, 0.5, 1, 2, 4, 8, 24],
'concentration': [2.28, 1.35, 1.08, 0.82, 0.45, 0.20, 0.08, 0.04]
})
# Create analysis object
iv_cpk = IvPkAnalysis.from_df(
samples_df=df,
dose=1.0, # mg/kg
parent_weight=564.55 # g/mol
)
# Run analysis
iv_cpk.run_pk_analysis()
# Get results
results_df = iv_cpk.get_samples_dataframe()
best_model = iv_cpk.get_best_model()
model_result = iv_cpk.get_result_by_model(best_model)
print(f"Best model: {best_model}")
print(f"Clearance: {model_result.cl:.3f} L/min/kg")
print(f"Volume: {model_result.V1:.3f} L/kg")-
One-compartment model:
C(t) = A × e^(-α×t) -
Two-compartment model:
C(t) = A × e^(-α×t) + B × e^(-β×t)
- One-compartment with absorption: Solved using ODE integration
- Two-compartment with absorption: Solved using ODE integration
The library automatically selects the best model based on:
- Akaike Information Criterion corrected (AICc)
- Parameter uncertainty assessment
- Goodness of fit statistics
CSV files or DataFrames must contain:
sample_time: Time points (hours)concentration: Drug concentrations (μM)
dose: Administered dose (mg/kg)parent_weight: Molecular weight of parent compound (g/mol)route: Administration route ('IV' or 'EV')
- Clearance (CL): Rate of drug elimination
- Volume of distribution (V1, V2): Apparent distribution volumes
- Rate constants (k10, k12, k21): Transfer rate constants
- Inter-compartmental clearance (Q): Distribution clearance
- AUC: Area under the concentration-time curve
- Half-life: Terminal elimination half-life
- Mean residence time (MRT): Average time drug remains in body
- Bioavailability: Fraction of dose reaching systemic circulation (EV only)
The library provides several quality indicators:
- Parameter standard errors
- Parameter uncertainty flags (>40% relative standard error)
- Outlier detection and removal
- Model selection confidence
IvPkAnalysis: Intravenous pharmacokinetic analysisEvPkAnalysis: Extravascular pharmacokinetic analysisIvCpkResult: Results container for IV analysisEvCpkResult: Results container for EV analysisSample: Individual concentration-time data point
load_samples(): Load data from various sourcesvalidate_study_parameters(): Input validation
We welcome contributions from the community! Here's how you can help:
If you encounter bugs, have feature requests, or need help:
- Open an issue on the GitHub repository
- Provide a clear description of the problem or suggestion
- Include relevant details:
- Python version
- Operating system
- Code snippet to reproduce (if applicable)
- Error messages
- GitHub Issues: For bug reports and feature requests
- Email: Contact us at the address in the Contact section
- Documentation: Check QUICKSTART.md for usage examples
- Fork the repository
- Create a feature branch
- Make your changes with clear commit messages
- Add tests if applicable
- Update documentation
- Submit a pull request
If you use CPK in your research, please cite our paper:
@article{ADP2024,
title={Large-Scale Compartmental Model-Based Study of Preclinical Pharmacokinetic Data and Its Impact on Compound Triaging in Drug Discovery},
journal={Molecular Pharmaceutics},
year={2024},
doi={10.1021/acs.molpharmaceut.4c00813},
url={https://pubs.acs.org/doi/10.1021/acs.molpharmaceut.4c00813}
}This project is licensed under the MIT License - see the LICENCE file for details.
- Code Maintainer: Facundo Esquivel Fagiani (esqufacu@msd.com)
- Scientific Inquiries: Peter Zhiping Zhang (zhiping.peter.zhang@msd.com)
Version: 1.0.0