Giter Site home page Giter Site logo

blakeaw / pysb-pkpd Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 4.0 250 KB

PySB add-on providing domain-specific macros and models for empirical and mechanistic PK/PD modeling.

License: BSD 2-Clause "Simplified" License

Python 30.71% Jupyter Notebook 69.29%
pharmacodynamics pharmacokinetics pkpd quantitative-systems-pharmacology pharmacometrics pkpd-modelling systems-pharmacology mechanistic-modeling quantitative-systems-toxicology

pysb-pkpd's Introduction

pysb-pkpd

Python version badge PySB version badge license version release DOI

pysb-pkpd enables you to efficiently program and simulate dynamic PK/PD and QSP models in Python using the PySB modeling framework.

๐Ÿ’Š ๐Ÿ’ป

What's new in

version 0.3.0

  • Macro encoding a Fixed-effect PD model: fixed_effect
  • Macro encoding a Log-linear Effect PD model: loglinear_effect
  • simulate function to simplify the process of simulating models.
  • The macro encoding the Linear-effect PD model, linear_effect, has an optional intercept argument to allow users to set the y-intercept of the linear model.

Table of Contents

  1. Install
    1. Dependencies
    2. pip install
    3. Manual install
  2. License
  3. Change Log
  4. Documentation and Usage
    1. Quick Overview
    2. Example
    3. List of macros
    4. Simulating models
    5. Preconstructed models
  5. Contact
  6. Supporting
  7. Other Useful Tools

Install

! Note
psyb-pkpd is still in version zero development so new versions may not be backwards compatible.

pysb-pkpd installs as the pysb.pkpd Python (namespace) package. It is has been developed with Python 3.11.3 and PySB 1.15.0.

Dependencies

Note that pysb-pkpd has the following core dependencies:

  • PySB - developed using PySB version 1.15.0

pip install

You can install pysb-pkpd version 0.3.3 with pip sourced from the GitHub repo:

with git installed:

Fresh install:

pip install git+https://github.com/blakeaw/[email protected]

Or to upgrade from an older version:

pip install --upgrade git+https://github.com/blakeaw/[email protected]
without git installed:

Fresh install:

pip install https://github.com/blakeaw/pysb-pkpd/archive/refs/tags/v0.3.3.zip

Or to upgrade from an older version:

pip install --upgrade https://github.com/blakeaw/pysb-pkpd/archive/refs/tags/v0.3.3.zip

Manual install

First, download the repository. Then from the pysb-pkpd folder/directory run

pip install .

License

This project is licensed under the BSD 2-Clause License - see the LICENSE file for details


Change Log

See: CHANGELOG


Documentation and Usage

Quick Overview

pysb-pkpd is an add-on for the PySB modeling framework. Its key feature is a set of domain-specific PySB macros that facilitate the efficient and descriptive programmatic construction of PK/PD models in Python using the PySB framework. It also provides a limited set of pre-constructed one-, two-, and three-compartment PK and PK/PD models.

Additional details, such as examples and the list of available macros, can be found in the subsequent subsections of this README.

You can also check out my blog post, Modeling Drug Dynamics using Programmatic PK/PD Models in Python: An Introduction to PK/PD Modeling using PySB and pysb-pkpd, for an introduction to PK/PD modeling concepts and additional illustrative case studies of building PK/PD models with pysb and pysb-pkpd.

Example

Building a two-compartment PK model with a sigmoidal Emax PD function:

from pysb import Model
import pysb.pkpd as pkpd

# Initialize the PySB model:
Model()

# Add a Monomer for the drug:
pkpd.drug_monomer(name='Drug')

# Add the compartments for a two-compartment model:
pkpd.two_compartments(c1_name="CENTRAL",
                             c1_size=2.0,
                             c2_name="PERIPHERAL",
                             c2_size=1.0)


# Add a dose of the drug using an 
# instantaneous 'bolus' dose in the central
# compartment (initial amount of drug at time zero).
#   Note that dose is an amount such as weight, mass, or moles,
#     which will be converted automatically to an initial concentration
#     as: 
#         [Drug]_0 = dose / V_CENTRAL , 
#     where V_CENTRAL is the size (i.e., volume) of the central compartment.
pkpd.dose_bolus(Drug, CENTRAL, dose=100.)

# Add (1st order) distribution and re-distribution between the 
# central and peripheral compartments:
#    Note that klist is [k_distribute, k_redistribute]
pkpd.distribute(Drug, CENTRAL, PERIPHERAL, klist=[1.0, 1e-1])

# Include linear elimination of Drug from the central compartment 
# by processes like metabolism and renal excretion.
pkpd.eliminate(Drug, CENTRAL, kel=1e-2)

# Add the sigmoidal Emax PD function for Drug in the
# central compartment:
pkpd.sigmoidal_emax(Drug, CENTRAL, emax=1.,
                                   ec50=10.,
                                   n=1.7)
               

PKRO Example

See this notebook for another example using PySB with the psyb-pkpd add-on to build a simple semi-mechanistic pharmacokinetic and receptor occupancy (PKRO) model.

List of macros

The pysb.pkpd.macros module currently defines the following macros encoding PK, PD, and dosing functions:

PK functions:

  • drug_monomer - adds a simple monomer species for the drug to the model. If the drug needs binding sites or other state variables then you should directly use the PySB Monomer class instead.
  • one_compartment - adds one compartment to the model for a one-comaprtment PK model. Alternatively, it could be used to add a new compartment to a multi-compartment model.
  • two_compartments - adds two compartments to the model for a two-comaprtment PK model.
  • three_compartments - adds three compartments to the model for a three-compartment PK model.
  • eliminate - adds linear (1st-order) elimination of the specified drug/species from a compartment.
  • eliminate_mm - add non-linear, Michaelis-Menten, elimination of the specified drug/species from a compartment.
  • clearance - adds linear (1st-order) elimination of the specified drug/species from a compartment by systemic clearance.
  • distribute - adds distribution/redistribution of the specified drug/species between two compartments.
  • transfer - adds one-way transfer (distribution with no redistribution) of the specified drug/species from one compartment to another.

PD functions:

  • emax - Adds an Emax model expression for the specified drug/species in a given compartment. Generates a PySB Expression with name: 'Emax_expr_DrugName_CompartmentName'
  • sigmoidal_emax - Adds a sigmoidal Emax model expression for the specified drug/species in a given compartment. Generates a PySB Expression with name: 'Emax_expr_DrugName_CompartmentName'
  • linear_effect - Adds a linear effect model expression for the specified drug/specis in a given compartment. Generates a PySB Expression with name: 'LinearEffect_expr_DrugName_CompartmentName'
  • loglinear_effect - Adds a log-linear effect model expression for the specified drug/specis in a given compartment. Generates a PySB Expression with name: 'LogLinearEffect_expr_DrugName_CompartmentName'
  • fixed_effect - Adds a fixed-effect model expression for the specified drug/specis in a given compartment. Generates a PySB Expression with name: 'FixedEffect_expr_DrugName_CompartmentName'

Dosing functions:

  • dose_bolus - adds an instantaneous bolus dose of the specified drug/species which defines the initial concentration at time zero; e.g., to model IV bolus.
  • dose_infusion - adds a continous (zero-order) infusion of the specified drug/species; e.g., to model continuous IV infusion.
  • dose_absorbed - adds a dose of the specified drug which is absorbed into the specified compartment via first-order kinetics, including a bioavailibity factor; e.g., to model oral dosing or a subcutaneous depot.

Simulating models

pysb-pkpd provides a simulate function that can be used to easily execute a simulation of your PK/PD model as below:

import numpy as np
import pysb.pkpd as pkpd
from my_pkpd_model import model

# Simulate the PKPD/PySB model.
## Set the timespan for the simulation:
tspan = np.arange(241) # 0-240 seconds at 1 second intervals
## Execute the simulation:
simulation_trajectory = pkpd.simulate(model, tspan)

Preconstructed models

Another feature of pysb-pkpd are a limited set of pre-constructed two-compartment and three-compartment models which can be used for empirical fitting of PK data or as base models for more complex semi-mechanistic PK/PD mdoels.

PK/PD models

Two-compartment and three-compartment PK models with Emax PD function for the drug in the central compartment:

from pysb.pkpd.models import twocomp_emax, threecomp_emax

PK-only models

Two-compartment and three-compartment PK models:

from pysb.pkpd.pk_models import twocomp, threecomp

Contact

  • Issues ๐Ÿ› : Please open a GitHub Issue to report any problems/bugs with the code or its execution, or to make any feature requests.

  • Discussions โ” : If you have questions, suggestions, or want to discuss anything else related to the project, feel free to use the pysb-pkpd Discussions board.


Supporting

I'm very happy that you've chosen to use pysb-pkpd. This add-on is a project that I develop and maintain on my own time, independently of the core PySB library, and without external funding. If you've found it helpful, here are a few ways you can support its ongoing development:

  • Star โญ : Show your support by starring the pysb-pkpd GitHub repository. It helps increase the project's visibility and lets others know it's useful. It also benefits my motivation to continue improving the package!
  • Share ๐Ÿ“ฃ : Sharing pysb-pkpd on your social media, forums, or with your network is another great way to support the project. It helps more people discover pysb-pkpd, which in turn motivates me to keep developing!
  • Cite ๐Ÿ“š : Citing or mentioning this software in your work, publications, or projects is another valuable way to support it. It helps spread the word and acknowledges the effort put into its development, which is greatly appreciated!
  • Sponsor ๐Ÿ’ต : Even small financial contributions, such as spotting me the cost of a tea through Ko-fi so I can get my caffeine fix, can make a big difference! Every little bit can help me continue developing this and other open-source projects.

ko-fi


Other Useful Tools

Parameter estimation

Please see packages such as simplePSO, PyDREAM, Gleipnir, or GAlibrate for tools to do PySB model parameter estimation using stochastic optimization or Bayesian Monte Carlo approaches.

PD response models

If you want to separately fit response data independetly of PK data, then the pharmacodynamic-response-models package may also be useful.

PySB model visualization

pyvipr can be used for static and dynamic PySB model visualizations.


pysb-pkpd's People

Contributors

blakeaw avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

pysb-pkpd's Issues

Make the macros module into a subpackage

Maybe it would be cleaner or easier to understand if the macros were organized into their own type-specific modules. Something like macros.pk, macros.pd, and macros.dose for PK, PD, and dosing functions respectively.

In this case, the current macros module under pysb.pkpd.macros would be converted into a sub-package. The modules inside that sub-package could then be imported in the pkpd level __init__.py to give a shortcut where they could be imported like from pysb.pkpd import pk, pd, dose. Then users could call those like pk.clearance(...), pd.emax(...), or dose.bolus(...) when building their own model, which may make it more readable and easier to differentiate the PD and dose functions from the PK ones.

Compartmental model schematic generator

It may be nice to implement a function that can parse a model and generate a compartmental model schematic like that in https://github.com/blakeaw/pysb-pkpd/blob/main/example-notebooks/1_simple-PKRO.ipynb.

Although there are some existing tools in PySB to render reactions and species visualization (https://pysb.readthedocs.io/en/stable/modules/tools/render.html), as well as other tools like pyvipr, it might be nice to have something more PK/PD focused and generate the type of schematic used more commonly to show one-, two-, and three-compartment models with the dosing, PK processes, and PD function: similar to the one in https://github.com/blakeaw/pysb-pkpd/blob/main/example-notebooks/1_simple-PKRO.ipynb.

Maybe something that directly renders a schematic as a matplotlib graph? That should at least make it easy to use in notebooks.

Problem with bioavalibility parameter in dose_absorb macro

I get an error when the input bioavailability (f=) to the dose_absorb macro is already a Parameter.

Offending code:

    if not isinstance(f, Parameter):
        F = Parameter("F_{0}_{1}".format(monomer_name, comp_name), f)
        params_created.add(F)
    pre_0_expr = Expression('precursor_0', (dose_expr * F))

When the argument f is a Parameter, the variable F is not created and the pre_0_expr expression errors out.

Problem with the dose_absorbed macro.

I'm pretty sure the current version of the dose_absorbed macro doesn't work as expected, particularly when there are other processes that affect the free drug concentration. As is, the generated rule would add or remove drug in a way that the model would have a steady-state around the given dose.

I think a better way to handle this is probably to create a pre-cursor monomer and then have a first-order reaction that converts the pre-cursor to free drug in the designated compartment.

Idea: Auto fitting functionality/parameter estimation

It might be nice if the package included/added some functionality to abstract away fitting a PK/PD model to data and estimate the associated model parameters. Maybe something akin to the sklearn style .fit function where you could call something like model.fit(observable, data) and the PK/PD model would train to fit the data.

Way to simulate multiple doses

I think it would be nice to have a feature that facilitates executing simulations with multiple doses over time (i.e., dosage).

Implementation ideas

i. One way to do this might be to wrap a PySB simulator, such as the ScipyOdeSimulator, and have the dosage simulator execute multiple runs of the simulator and then stitch together the multiple trajectories; for each run, you would adjust the initials/parameters to implement another dose.

ii. I guess it might also be possible to use complex Expression(s) to implement a dosage macro that periodically adjusts the drug concentration during the simulation to implement multiple dosages.

Function to abstract setting up and running the ScipyOdeSimulator with PK/PD models

I think in typical cases the PK/PD models will be executed using ODEs. Therefore, a default function, such as simulate or run_model, that abstracts setting up and pulling results from PySB's ScipyOdeSimulator might be useful.

Instead of having to do something like:

sim = ScipyOdeSimulator(model)
simres = sim.run(tspan=tspan)
simtraj = simres.all

You could just do something like:

simtraj = pkpd.simulate(model, tspan)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.