Welcome to PK project’s documentation!¶
API for PK project modules and readme
# Pharmacokinetic Modelling Group Project
A PharmacoKinetic (PK) modelling function for analysis of injected solute dynamics over time, developed by Group 6 of the 2021 Software Engineering course. This model has been developed with the end-user in mind, and includes an easy-to-use interface to guide refinement of tissue models.
https://software-engineering-bbsrc-group-6.github.io/PK_modelling/
# Authors
Amit Halkhoree - amit.halkhoree@dtc.ox.ac.uk Cameron Anderson - cameron.anderson@dtc.ox.ac.uk Dan Hudson - alexander.hudson@dtc.ox.ac.uk Ishaan Kapoor - ishaan.kapoor@dtc.ox.ac.uk Joseph Pollacco - joseph.pollacco@dtc.ox.ac.uk Samuel Johnson - samuel.johnson@dtc.ox.ac.uk
Indices and tables¶
- class definitions.Compartment(volume, transrate_out)¶
Compartment describes an individual compartment in either model type.
- Parameters
volume (float) – Volume of compartment
transrate (float) – Transition rate out of a given compartment
- definitions.form_rhs_ib(maincmpt, peripherals, dose, clearance)¶
Function factory to form the right-hand side of the PK ODE for IB model.
- Parameters
maincmpt (compartment) – Object corresponding to the main compartment
peripherals (list, each listem item is Compartment.) – List containing each peripheral compartment object
dose (Function) – Function, one argument (time), describes dosing protocol.
clearance (float) – Clearance rate from the main compartment.
- Return rhs_ib
RHS of the PK ODE for the IB model, taking parameters t (time) and an N-dimensional vector of q (floats).
- definitions.form_rhs_sc(subcmpt, maincmpt, peripherals, dose, clearance)¶
Function factory to form the right-hand side of the PK ODE for IB model.
- Parameters
subcmpt (Compartment object) – Object corresponding to the subcutaneous compartment
maincmpt (Compartment object) – Object corresponding to the main compartment
peripherals (list, each listem item is Compartment.) – List containing each peripheral compartment object
dose (Function) – Function, one argument (time), describes dosing protocol.
clearance (float) – Clearance rate from the main compartment.
- definitions.write_solution_file(solution, model, timestamp)¶
Puts the scipy solution into a data file for reading by the visualiser.
- Parameters
solution (bunch) – solution from scipy solve_ivp().
model (string) – type of model, one of ‘sc’ or ‘ib’ as defined earlier by the user.
timestamp (string) – time at which the solver was run, used to identify a given run.
- Return solutionmat
Contains timeseries data, and solutions for each compartment.
- class dosing.ConstantDose(num_applications, interval, rate)¶
ConstantDose describes a dose with constant application rate.
Inherits from Dose.
- Parameters
num_applications (int) – Number of applications of the drug
interval (float) – Time applications given over.
rate (float) – Rate of drug application (ng/hr)
- class dosing.Dose(num_applications, interval)¶
Dose describes a generic dosing protocol.
Protocol has a number of applications (one unless repeated dosage), and a time between applications.
- Parameters
num_applications (int) – Number of applications of the drug
interval (float) – Time applications given over.
- class dosing.InstantDose(num_applications, interval, mass)¶
InstantDose describes a single instant dose.
Inherits from Dose.
- Parameters
num_applications (int) – Number of applications of the drug
interval (float) – Time applications given over.
mass (float) – Mass of the drug to apply (ng)
- solver.build_and_solve_model(filename, dosing_function)¶
Opens a file containing model parameters, builds a model, solves it, and writes the output to file.
- Parameters
filename (string) – Name of .json file containing program parameters (see ux for details).
dosing_function (function object) – Describes the dosing protocol as a function of time (in hours)
- Return datafile
Name of the file where the solution is stored.
- solver.generate_compartments(parameterdict)¶
Turns a list of compartment parameters into a set of compartment objects.
- Parameters
parameterdict (dictionary) – Dictionary containing a list with key ‘compartments’, formatted as [Volume Transition Rate Type Name], and a second key ‘model_type’ which is either ‘ib’ or ‘sc’.
- solver.generate_times(tmax, check_interval)¶
Generates an array of times to be checked by the solver.
- Parameters
tmin (float) – Time of start of assay (hours)
tmax (float) – Time of end of assay (hours)
check_interval (float) – Time interval between data points (hours).
- Return times
Contains the times at which data points are wanted from the solver.
- solver.get_solution(model, subcmpt, maincmpt, peripherals, dose, clearance, times)¶
Finds solution of drug dosage over time for a given set of compartments, dose and clearance rate
- Parameters
model (string) – the input model, subcutaneous (sc) or IV bolus (ib)
subcompt – subcompartment
maincmpt – main compartment
peripheral – the peripheral compartments added
dose – dose function
clearance – clearance rate
times – time points to solve model
- ux.num_models()¶
Defines how many modeles will be tested
- ux.param_to_file()¶
Writes dictionary generated from user_input() and generates .json file
- ux.user_input()¶
This requests user input via the command line, and then returns the requested arguments in a dictionary
- Parameters
model_type (string) – Decides which model is build. This should return either intravenous bolous, subcutaenous or both
compound – Allows the user to specify what the compound is. Useful for reporting back and for ease of understandingx
dose – Dose of compound used in ng per hour
len_assay – Length of time should the simulation be computed across in hours
len_interval – Granularity of time series in hours
clearance – Time for drug to clear the system in hours
compartments – A list of lists containing the desired compartments
vis – Specifies if the user wants a graph generated or just a table output
- visualiser.collate_data(run)¶
Collate the lists returned by single_plot to return a list of lists for all simulations in a run :param run: list formatted as [[json1.json, csv1.csv], [json2.json, csv2.csv]…]
- Return collated_list
matrix containing data matrices for all simulations
- visualiser.make_plots(filenames)¶
Combine multiplot and collate_data functions to produce overlayed plots of drug concentration against time for all user specified compartments.
- Parameters
filenames – Simulation filename list formatted as [[json1, csv1], [json2, csv2]…]
- visualiser.multiplot(collated_list)¶
Plot overlayed simulation data from multiple runs using collated data matrix
- Parameters
collated_list – matrix containing data matrices for all simulations
- Returns
display overlayed plots for each compartment
- visualiser.single_plot_data(json_file, csv_file)¶
Read parameters and data from models to generate a list of model parameters, data array and its dimensions
- Parameters
json_file (string) – Name of the json file to be opened
csv_file (string) – Name of the csv file to be opened
- Return plot_value
list containing [parameters, data_array, num_rows, num_columns]