The competitions module contains functions for predicting
the results of competitions between different species or strains
and analysing the competitions results to extract the fitness
or selection coefficients of the competing strains.
The model contains:
Competition function (compete()) performs a numerical simulation of a competition.
Competition models (dobule_*_ode*) are Python implementations of ODE systems, consistent with Scipy’s odeint requirement. These ODE systems define competition models in which two strains/species compete for resources while growing in a well-mixed homogeneous vessel.
Fitness and selection coefficient analysis (fitness_*, selection_coefs_*) are functions for infering fitness and selection coefficients from competitions time-series.
Consider the following double logistic competition model in the form of a system of ordinary differential equations:
: population size of strain i.
: initial per capita growth rate of strain i
: maximum population size of strain i
To simulate a competition between two strains we need to set the values of
for
where 1 and 2 define two strains.
These values can be estimated from growth curve data using curveball.models.fit_model(),
which fits growth models to data and returns model fit results.
These model fit results can be passed to the compete() function to simulate a competition:
The result of compete(), t and y are the time array and the frequencies array of the competition:
specifically, y is a 2-dimensional array, containing the frequency of each strain at each time point.
Fig. 8 Fig. 1 - Competition simulation. The figure is the result of calling fig.savefig() on the result of the above example code.¶
Fujikawa, Hiroshi, and Mohammad Z Sakha. 2014. Prediction of Microbial Growth in Mixed Culture with a Competition Model. Biocontrol Science 19 (2): 89-92.
Fujikawa, Hiroshi, and Mohammad Z Sakha. 2014. Prediction of Microbial Growth in Mixed Culture with a Competition Model. Biocontrol Science 19 (2): 89-92.
Simulate competitions between two strains using growth parameters estimated
by fitting growth models to growth curves data.
Integrates a 2-dimensional ODE system given by ode
with parameters extracted from lmfit.model.ModelResult instances m1 and m2.
This implementation includes plotting (if required by PLOT);
resampling from the distribution of model parameters (when nsamples > 1);
changing the ODE system (by providing a different function in ode);
and more.
The function competes two strains/species;
therefore it expects two lmfit.model.ModelResult objects,
two initial values in y0, etc.
model fitting results of growth models defined in curveball.models.
p0, y0tuple, optional
p0 is the initial relative frequencies; y0 is the initial population sizes.
if y0 is given than y0[0] and y0[0] are the initial population size for m1 and m2, respectively.
if y0 is not given, then it will be set to the average estimated y0 in m1 and m2 multiplied by p0.
tnumpy.ndarray or None, optional
array of time points in which to calculate the population sizes.
hoursint, optional
if t is not given, determines how many hours should the competition proceed, defaults to 24.
num_of_pointsint, optional
if t is not given, determines the number of time points to use, defaults to 100.
nsamplesint, optional
how many replicates of the competition should be simulated;
if nsamples = 1, only one competition is simulated with the estimated parameters;
otherwise nsamples competitions are simulated with parameters drawn from a parameter distribution
determined by sampler. Defaults to 1.
lag_phasebool, optional
if True, use lag phase as given by m1 and m2. Otherwise, override the lag phase parameters to prevent a lag phase. Defaults to True.
odefunc, optional
an ordinary differential systems system defined by a function that accepts y, t, and additional arguments, and returns the derivate of y with respect to t. Defaults to double_baranyi_roberts_ode0().
params1, params2dict, optional
dictionaries of model parameter values; if given, overrides values from m1 and m2.
cifloat, optional
confidence interval size, in (0, 100), only applicable when PLOT is True, defaults to 95%.
colorssequence of str, optional
if PLOT is True, this sets the colors of the drawn lines. colors[0] will be used for m1; colors[1] for m2. If not provided, defaults to the current pallete.
axmatplotlib.axes.Axes, optional
if PLOT is True, an axes to plot into; if not provided, a new one is created.
PLOTbool, optional
if True, the function will plot the curves of y as a function of t. Defaults to False.
A two species Baranyi-Roberts model with competition model inspired by Gimenez and Delgado (2004).
The function calculates the population growth rate at given time points.
Calculate relative fitness according to the definition used in the Long Term Evolutionary Experiment (LTEE) [3],
where are population densities of assay strain A and reference strain B at time t:
If ci > 0, treats the third axis of y as replicates (from a parameteric boostrap) to calculate the confidence interval on the fitness.
array of population densities, as produced by compete(), where the first axis is time and the second axis is strain. A third axis is also applicable if ci>0.
ref_strainint, optional
the index of the reference strain within y. This strain’s fitness is set to 1 by definition. Defaults to 0 (first).
assay_strainint, optional
the index of the assay strain within y. The result will be the fitness of this strain relative to the fitness of the reference strain. Defaults to 1 (second).
t0int, optional
the index of the time point from which to start the calculation of the relative fitness, defaults to 0 (first).
t1int, optional
the index of the time point at which to end the calculation of the relative fitness, defaults to -1 (last).
cifloat between 0 and 1, optional
if not zero, a confidence interval will be calculated using the third axis of y as replicates.
curveball.competitions.selection_coefs_ts(t, y, ax=None, PLOT=False)[source]¶
Calculate selection coefficient according to the following formula[2]_,
where are population densities of assay strain A and reference strain B at time t:
This formula assumes that the frequencies of the strains follow a logistic curve.
Lag phases, interactions, etc. may cause this formula to become irrelevant.