celltx.odelayer package¶
Submodules¶
celltx.odelayer.odelayer module¶
- class celltx.odelayer.odelayer.ODELayer(equations)¶
Bases:
object- chunks(lst, nChunks)¶
Divide a list into n lists where all chunks have even size, except for the last one, which is smaller.
- display_args()¶
- display_equations(display_func, substitute=False)¶
Print out the model equations. Display_func is IPython.display.display. If substituting, for each differential equation, substitute the X in dX/dt in the rhs with ‘X’ for concision.
- execute_argspace_search(t, n_samples, parallel, method='LHS', quash_species=None)¶
Explore the space of parameter values and initial conditions specified via self.set_param_search_range and self.set_x0_search_range. First, generate n_samples sets of input values using method, and then simulate (possibly in n-parallel), the model timecourse for each sample.
- Parameters
t (np.ndarray) – The timeframe over which to integrate for each set
n_samples (int) – How many samples to generate
parallel (int) – Number of processing cores to use
method (str) – Sampling method
quash_species (None or int) – Index of a species to quash during the simulation (same functionality as self.integrate_quash_species).
- Returns
Returns a list of length n_simulations where each element is a 2-lists where 0 is a dictionary of
x0 and parameter values and 1 is a numpy array of result timecourses X.
- execute_paramspace_search(t, n_samples, parallel, method='LHS', quash_species=None)¶
Sample parameter values from parameter-specific ranges specified in self.search_ranges (dict) and simulate. Parameters that don’t have an entry in self.search_ranges are not to be sampled.
- Parameters
t (np.ndarray) – space of timepoints to profile
- Returns
list of 2-lists, where list[0] is parameter values (in same order as self.params), and list[1] is a timecourse
from self.integrate()
- gen_argspace_samples(n_samples)¶
Use Latin Hypercube Sampling to generate samples of the parameter space (looking at self.param_search_ranges and self.x0_search_ranges)
- gen_ode_model()¶
Generate a lambda (self.f_model) from the Sympy expressions in self.equations that takes the values for all species and parameters and returns dX/dt.
- Returns
- Return type
None
- gen_paramspace_samples(n_samples)¶
Use Latin Hypercube Sampling to generate samples of the parameter space (looking at self.search_ranges)
- get_param_value(name)¶
- index_of_parameter(parameter_name)¶
Get the index within self.parameters of the parameter named parameter_name
- Parameters
parameter_name –
- Returns
- Return type
int
- index_of_species(species_name)¶
Get the index within self.species of the species named species_name.
- Parameters
species_name –
- Returns
- Return type
int
- inspect_terms_for_simulation(idx, X, t)¶
Given the output X of a simulation (e.g. from self.integrate), and the index of an equation in self.equations, return a dictionary keyed by the args of the equation (linearly combined terms) and with values that are arrays with the numerical values of the arg for every timepoint represented in X.
- Parameters
idx (int) – the index of the equation whose args to examine
X (list) – list (1 x n) of lists (m x 1) where n is the number of timepoints and m is the number of equations This has the same format as is returned by self.integrate.
t (numpy.ndarray(float64)) – 1 x n array describing the time at each of the timepoints in X. Only really needed if the model takes time as an argument.
- Returns
List of 2-tuples, in which the first value is the arg and the second is a list of values (1 x n)
- Return type
list[tuple]
- integrate(t, override_x0=None, override_params=None)¶
Integrate the model at timepoints in t using literal parameter values.
- integrate_quash_species(t, species_idxs, start_from=None, override_params=None, override_x0=None, r=1)¶
Goal is to account for the fact that species in a model should not be able to resurge from a value less than 1. In addition, since species at the odelayer abstraction level often actually represent individual states of true biological species (e.g. activated and unactivated T cells), it may be important to consider multiple species when attempting to quash a biological species.
- Recursive algorithm:
Integrate self.model over timespace t.
- Find (if it exists) the first timeopint t_crit at which all species in a group S (from species_idxs)
have fallen below 1.
Recurse, but start the simulation at t_crit and feed a modified x0 where species in S are set to 0.
Return the result if there is no t_crit.
- Parameters
t (np.linspace) – The timeframe to integrate.
species_idxs (list[tuple]) – List of tuples, where each tuple defines a group of species (addressed by indices in self.species) that should be quashed together.
start_from (np.ndarray or None) – Numpy array with a row for each species and a column for each timepoint. If it is provided, the simulation will start at timepoint t[start_from.shape[0]] and the first start_from.shape[0] cols will be pasted in.
- Returns
- Return type
np.ndarray with a row for each species in the model and a column for each timepoint (in t).
- model(X, t, args)¶
Return the derivative of the system based on current state, desired timepoint, and param values. Effectively a wrapper for the lambda self.f_model that, for instance, prevents species from having negative values.
- Parameters
X (list[float]) – List of values for all species in the model, in the same order as self.species.
t (float) – Time at which the differential is being evaluated.
args (list[float]) – List of values for all parameters in the model, in the same order as self.params.
- Returns
Derivative of the value of each species in the model, in the same order as self.species.
- Return type
list[float]
- pin_params_for_search(param_names)¶
Create pairs of parameters which will have the same value when samples are created, e.g. by self.gen_argspace_samples.
- Parameters
params (tuple of parameters to pin (should correspond to elements of self.params.) –
- Returns
- Return type
None
- process_argspace_chunk(chk, out, t, i, quash_species)¶
Process a chunk of argspace samples. This function is used for parallelizations.
- Parameters
chk (list) – list of lists, where each list has a value for each species and each parameter (in order of self.x)
out (multiprocess.reservoir) – reservoir to send the outputs
t (np.ndarray) – timeframe to integrate
i (int) – Index of the processor (for reporting realtime progress)
quash_species (list of lists) – groups of species to quash
- process_paramset_chunk(chk, out, t, i, quash_species)¶
- profile_parameter(param_name, values, t)¶
Profile the model behavior for timeframe t across values of a parameter in values array.
- Parameters
param_name (str) – Name of the parameter to investigate
values (numpy.ndarray[numpy.float64]) – Values of the parameter to investigate
t (np.ndarray[numpy.float64]) – Timepoint(s) at which to report the state of the model
- Returns
Array of arrays, one for each parameter value in values, reporting the model state at times in t.
- Return type
np.ndarray[np.ndarray]
- ravel_expression(expr)¶
Given a Sympy expression, return an array of all arguments (selectors and constant) in the expression.
- set_initial_value(idx, val)¶
- set_initial_value_byname(name, val)¶
- set_param_search_range(param_name, rnge)¶
- set_param_value(name, val)¶
- set_x0_search_range(x0_idx, rnge)¶