A collection of classes that solve common quantitative biology problems.
- numpy
- plotly
- scipy
All of the classes assume online plotting, which requires initialization. To switch to offline plotting use a find and replace on QBioPlots.py: py.plotly.plot -> py.offline.plot
This class can be used to solve and plot a NxN system of IVP ODEs
An example can be viewed with:
from qbioplots import PlotSystemWRTTime as ode22
ode22.demo1()
This example solves and plots a competition model. An additional demo can be seen with ode22.demo2()
that plots the seven equation system (Model A) defined by Dunster et al. (2015). The plot from demo2 can be seen here.
r_1 = 0.15 r_2 = 0.3
k_1 = 50 k_2 = 60
a = 0.2 b = 0.6
To solve an ode system, the following parameters are necessary
x_start - (int) First value of your domain
x_end - (int) Last value of your domain
steps - (int) Number of intervals over your domain
figure_title - (string) Title for the plot
x_label - (string) Label for the x-axis
y_label - (string) Label for the y-axis
var_labels - (list) List of dependent variable labels
eqn_list - (list) List of equations
init_conds - (list) List of initial values
Example:
from qbioplots import PlotSystemWRTTime as ode22
# Solution Parameters
x_start = 0
x_end = 100
steps = 200
# y_1
r_1 = 0.15
k_1 = 50
a = 0.2
# y_2
r_2 = 0.3
k_2 = 60
b = 0.6
# Plot Labels
figure_title = "2x2 Nonlinear ODE System"
x_label = "time (days)"
y_label = "population"
var_labels = ["Population 1", "Population 2"]
# Equations
eqn1 = lambda x1,x2: r_1*x1 * (k_1 - x1 - a*x2) / k_1
eqn2 = lambda x1,x2: r_2*x2 * (k_2 - b*x1 - x2) / k_2
eqn_list = [eqn1, eqn2]
# Initial Conditions
init_conds = [1,1]
ode22(x_start, x_end, steps, figure_title, x_label, y_label, var_labels, eqn_list, init_conds)
NOTE: Equations one and two must defined using lambda x1, x2:
before your expression. The lambda functions are required to pass the expressions as parameters.
This class can be used to plot the phase plane of a 2x2 ODE system with carry capacities. These equations should be of the form:
An example can be viewed with:
from qbioplots import PhasePlaneTwoByTwoWithCarry as phase
phase.demo()
The example plots a phase plane with the following parameters:
r_1 = 0.15 r_2 = 0.3
k_1 = 50 k_2 = 60
a = 0.2 b = 0.6
To solve a 2x2 system, the following parameters are necessary
x_start - First value for x-axis
x_end - Last value for x-axis
x_steps - Number of intervals for x-axis
y_start - First value for y-axis
y_end - Last value for y-axis
y_steps - Number of intervals for y-axis
figure_title - (string) Title for the plot
x_label - (string) Label for the x-axis
y_label - (string) Label for the y-axis
carry1 - Carry capacity for the first equation
carry2 - Carry capacity for the second equation
a - Interaction coefficient for the first equation
b - Interaction coefficient for the second equation
eqn1 - (lambda) First equation of the system
eqn2 - (lambda) Second equation of the system
Example:
from qbioplots import PhasePlaneTwoByTwoWithCarry as phase
# Solution Parameters
x_start = 0
x_end = 100
x_steps = 200
y_start = 0
y_end = 100
y_steps = 200
# y_1
r_1 = 0.15
k_1 = 50
a = 0.2
# y_2
r_2 = 0.3
k_2 = 60
b = 0.6
# Plot Labels
figure_title = "2x2 Phase Plane with Carry Capacity"
x_label = "population size, N1"
y_label = "population size, N2"
# Equations
eqn1 = lambda x1,x2: r_1*x1 * (k_1 - x1 - a*x2) / k_1
eqn2 = lambda x1,x2: r_2*x2 * (k_2 - b*x1 - x2) / k_2
phase(x_start, x_end, x_steps, y_start, y_end, y_steps, figure_title,
x_label, y_label, k_1, k_2, a, b, eqn1, eqn2)
NOTE: Equations one and two must defined using lambda x1, x2:
before your expression. The lambda functions are required to pass the expressions as parameters.