Skip to content

Commit 18a8135

Browse files
authored
Merge pull request #166 from biocircuits/dev
Enhanced documentation with Bioscrape v1.2.2
2 parents acb4734 + 1be7f3c commit 18a8135

19 files changed

+593
-440
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,4 @@ mcmc_results.txt
143143
lmfit_results.csv
144144
mcmc_results.txt
145145
unzip_dist.py
146+
pip-wheel-metadata/*

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ Further details about the installation process can be found in the [Bioscrape wi
9393
Please report any bugs that you find [here](https://github.com/biocircuits/bioscrape/issues).
9494
Or, even better, fork the repository on [GitHub](https://github.com/biocircuits/bioscrape),
9595
and create a pull request (PR). We welcome all changes, big or small, and we
96-
will help you make the PR if you are new to `git` (just ask on the issue). More details on contributing to bioscrape are available on the [`Contributing`](https://github.com/biocircuits/bioscrape/blob/master/contributing.md) page.
96+
will help you make the PR if you are new to `git` (just ask on the issue). The [CONTRIBUTING.md](https://github.com/biocircuits/bioscrape/blob/master/CONTRIBUTING.md) file has more detailed set of instructions on contributing to the software.
9797

9898
# Versions
9999

100100
Bioscrape versions:
101101

102-
* 1.2.1 (latest stable release): To install run `pip install bioscrape`
102+
* 1.2.2 (latest release): To install run `pip install bioscrape`
103103
* 1.2.0 (tagged stable release): To install run `pip install bioscrape==1.2.0`
104104
* 1.0.4 (beta release): To install run `pip install bioscrape==1.0.4`
105105

bioscrape/analysis.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from bioscrape.simulator import ModelCSimInterface, DeterministicSimulator
44
from scipy.integrate import odeint
55
import numpy as np
6+
from typing import List, Union
67

7-
def py_sensitivity_analysis(model, timepoints, normalize, **kwargs):
8+
def py_sensitivity_analysis(model: Model, timepoints: np.ndarray,
9+
normalize: bool, **kwargs) -> np.ndarray:
810
"""User interface function to perform sensitivity analysis
911
on a bioscrape model. The sensitivity coefficients are computed
1012
where each coefficient s_ij = rate of change of x_i with parameter p_j
@@ -22,15 +24,41 @@ def py_sensitivity_analysis(model, timepoints, normalize, **kwargs):
2224
numpy.ndarray: A numpy array of size:
2325
len(timepoints) x len(parameters) x len(states)
2426
"""
25-
sens_obj = SensitivityAnalysis(model)
26-
ans_df = sens_obj.propagator.py_simulate(sens_obj.sim_interface, timepoints).py_get_dataframe(sens_obj.M)
27+
dx = kwargs.get("dx", 0.01)
28+
precision = kwargs.get("precision", 10)
29+
sens_obj = SensitivityAnalysis(model, dx=dx, precision=precision)
30+
ans_df = sens_obj.propagator.py_simulate(sens_obj.sim_interface,
31+
timepoints).py_get_dataframe(sens_obj.M)
2732
solutions_array = np.array(ans_df.iloc[:,range(0,len(ans_df.T) - 1)])
2833
return sens_obj.compute_SSM(solutions_array, timepoints, normalize, **kwargs)
2934

30-
def py_get_jacobian(model, state, **kwargs):
35+
def py_get_jacobian(model: Model, state: Union[list, np.ndarray], **kwargs) -> np.ndarray:
36+
"""User interfacce function to compute Jacobian (df/dx) of the model.
37+
38+
Args:
39+
model (Model): Bioscrape Model
40+
state (Union[list, np.ndarray]): The state values (vector of length n)
41+
at which to compute the Jacobian
42+
43+
Returns:
44+
np.ndarray: A (n x n) Jacobian matrix, where n = len(state)
45+
"""
3146
return SensitivityAnalysis(model).compute_J(state, **kwargs)
3247

33-
def py_get_sensitivity_to_parameter(model, state, param_name, **kwargs):
48+
def py_get_sensitivity_to_parameter(model: Model, state: Union[list, np.ndarray],
49+
param_name: str, **kwargs) -> np.ndarray:
50+
"""User interface function to compute the sensitivity to parameter (df/dp)
51+
where p is the parameter and f is the model
52+
53+
Args:
54+
model (Model): Bioscrape Model
55+
state (Union[list, np.ndarray]): The state values (vector of length n)
56+
at which to compute df/dp
57+
param_name (str): The parameter name for which df/dp is computed
58+
59+
Returns:
60+
np.ndarray: A np.ndarray of size (n x 1), where n is the length of state
61+
"""
3462
return SensitivityAnalysis(model).compute_Zj(state, param_name, **kwargs)
3563

3664
class SensitivityAnalysis(Model):

bioscrape/inference.pyx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,54 @@ def py_inference(Model = None, params_to_estimate = None, exp_data = None, initi
579579
parameter_conditions = None, measurements = None, time_column = None, nwalkers = None,
580580
nsteps = None, init_seed = None, prior = None, sim_type = None, inference_type = 'emcee',
581581
method = 'mcmc', plot_show = True, **kwargs):
582-
582+
"""
583+
User level interface for running bioscrape inference module.
584+
Args:
585+
Model (bioscrape.types.Model): Bioscrape Model object
586+
params_to_estimate (List[str]): A list of parameter names in the Model to estimate
587+
exp_data (List[pd.DataFrame], pd.Dataframe): A pandas.DataFrame or a list of pandas.Dataframe
588+
that consists of the required experimental data\
589+
initial_conditions (List[dict], dict): A list of dictionaries of initial conditions corresponding to each
590+
data trajectory in exp_data or a single dictionary if one trajectory
591+
parameter_conditions (List[dict], dict): A list of dictionaries of parameter conditions corresponding to each
592+
data trajectory in exp_data or a single dictionary if one trajectory
593+
measurements (List[str], str): Names of species in the Model that are measured, either as a list if multiple outputs
594+
or a single measurement.
595+
time_column (str): The column name of the exp_data that contains the time points in the data, for time-series inference
596+
nwalkers (int): The number of walkers for the Markov Chain Monte Carlo sampling. See emcee.EnsembleSampler for more info.
597+
nsteps (int): The number of steps for the Markov Chain Monte Carlo sampling. See emcee.EnsembleSampler for more info.
598+
init_seed (Union[float, np.ndarray, list. "prior"]): The parameter that controls the initial parameter
599+
values for the sampling.
600+
If a float "r" is passed, then the initial values
601+
are sampled from a Gaussian ball of radius "r" around mean values
602+
set as Model parameter values
603+
If a np.ndarray or a list is passed, then the length must be same
604+
as the number of `params_to_estimate`. These values are then
605+
used as initial values for the sampler.
606+
If the keyword "prior" is passed, then the initial values are sampled
607+
from the prior distributions specified for each parameter value.
608+
prior (dict): The prior dict specifies the prior for each parameter in params_to_estimate. The syntax is
609+
{"parameter1": ["uniform", min_value, max_value],
610+
"parameter2": ["gaussian", mean, std, "positive"]}
611+
The "positive" keyword ensures that the prior rejects all negative values for the parameter.
612+
Refer to the full documentation on priors on our Wiki: https://github.com/biocircuits/bioscrape/wiki
613+
sim_type (Union["deterministic", "stochastic"]): A str that is either "deterministic" or "stochastic" to set the
614+
type of simulation for the inference run.
615+
inference_type (Union["emcee", "lmfit"]): A str that specifies the kind of inference to run. Currently, only two packages
616+
are supported: emcee and lmfit.
617+
method (str): For inference_type = emcee, this argument should not be used. For lmfit, method is passed into the method
618+
keyword of the lmfit call. More details here:
619+
https://lmfit.github.io/lmfit-py/fitting.html#choosing-different-fitting-methods
620+
plot_show (bool): If set to `True`, bioscrape will try to display the generated plots from the inference run.
621+
If set to `False`, not plots will be shown.
622+
Returns:
623+
for inference_type = "emcee":
624+
sampler, pid: A tuple consisting of the emcee.EnsembleSampler and the bioscrape pid object
625+
for inference_type = "lmfit":
626+
minimizer_result: A lmfit.MinimizerResult object that consists of the minimizer information.
627+
Raises:
628+
ValueError: When `inference_type` argument is set to something other than the currently supported modules.
629+
"""
583630
if Model is None:
584631
raise ValueError('Model object cannot be None.')
585632

bioscrape/simulator.pyx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,31 @@ cdef class DelayVolumeSSASimulator(DelayVolumeSimulator):
21032103
#A wrapper function to allow easy simulation of Models
21042104
def py_simulate_model(timepoints, Model = None, Interface = None, stochastic = False,
21052105
delay = None, safe = False, volume = False, return_dataframe = True, **keywords):
2106+
"""
2107+
User interface function to simulate a Bioscrape Model.
2108+
Args:
2109+
timepoints (np.ndarray): An array that contains the times for the simulation run.
2110+
Model (bioscrape.types.Model): The bioscrape Model object to run.
2111+
Interface (bioscrape.simulator.CSimInterface): Specifies particular model simulation interface to use.
2112+
Default: None, to create the interface automatically.
2113+
Developers may use this to pass existing interfaces to speed up simulations.
2114+
stochastic (bool): If `True`, a stochastic simulation using the Gillespie stochastic simulation algorithm is run.
2115+
If `False` (default), a deterministic simulation using python scipy.integrate.odeint is run.
2116+
delay (bool): If `True`, a delay simulator is initialized.
2117+
If `False` or None (default), delay simulator is not initialized.
2118+
safe (bool): If `True`, a safe model model simulation interface is initialized.
2119+
A safe model simulator issues warnings when ill-conditioned situations occur in simulation
2120+
(for example, a negative propensity of a reaction)
2121+
If `False` (default), normal model simulation interface is used.
2122+
volume (bool): If `True`, a volume is initialized for the simulation (relevant for lineage simulations)
2123+
If `False` (default), volume is not used in simulations.
2124+
Refer to the lineage module for more information.
2125+
return_dataframe (bool): If `True` (default), a Pandas dataframe with the simulation results is returned.
2126+
If `False`, a bioscrape simulation result object is returned.
2127+
Returns:
2128+
pandas.DataFrame with the simulation results if return_dataframe is set to `True`
2129+
or a bioscrape simulation result object is returned if it is set to `False`.
2130+
"""
21062131

21072132

21082133
#Check model and interface

bioscrape/types.pyx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,15 +1502,37 @@ cdef class StateDependentVolume(Volume):
15021502
############################## #############################
15031503

15041504
cdef class Model:
1505-
def __init__(self, filename = None, species = [], reactions = [],
1505+
def __init__(self, sbml_filename = None, filename = None, species = [], reactions = [],
15061506
parameters = [], rules = [], initial_condition_dict = None,
1507-
sbml_filename = None, input_printout = False,
1508-
initialize_model = True, **kwargs):
1507+
input_printout = False, initialize_model = True, **kwargs):
15091508
"""
15101509
Read in a model from a file using old bioscrape XML format (now deprecated), SBML format, or by
15111510
specifying the model programmatically using the API.
1511+
Model API documentation is available on bioscrape Wiki:
1512+
https://github.com/biocircuits/bioscrape/wiki
1513+
1514+
Args:
1515+
sbml_filename (str): The SBML filename to import the model.
1516+
Note that you cannot any other arguments when importing from SBML.
1517+
You can import the SBML model, then edit the model with the API.
1518+
filename (str): The (old bioscrape XML) file to read the model. Recommended way to import
1519+
a model is by importing an SBML using `sbml_filename` argument
1520+
species (List[str]): A list of species names, when constructing the model.
1521+
reaction (List[tuple]): A list of reaction tuples. Each reaction tuple includes a list
1522+
of reactants, a list of products, a propensity string,
1523+
and the propensity dict.
1524+
Refer to the documentation on bioscrape Wiki for more information.
1525+
parameters (List[tuples]): A list of tuples where each tuple specifies the parameter name
1526+
and a value for the parameter.
1527+
rules (List[(tuples)]): A list of tuples where each tuple describe a model rule.
1528+
initial_condition_dict (dict): A dictionary of initial conditions where each key is a species name
1529+
and the value is the initial condition value.
1530+
input_printout (bool, default: False): If True, verbose print statements are printed out.
1531+
If False, the print statements are silenced.
1532+
initial_model (bool, default: True): If True, the model is initialized =>
1533+
Model arrays are created and basic validity checks are run.
1534+
If False, the model is not initialized.
15121535
1513-
:param filename: (str) the file to read the model
15141536
"""
15151537

15161538
########################################################################

examples/Advanced Examples and Developer Overview.ipynb

Lines changed: 12 additions & 21 deletions
Large diffs are not rendered by default.

examples/Basic Examples - START HERE.ipynb

Lines changed: 32 additions & 30 deletions
Large diffs are not rendered by default.

examples/Benchmarking bioscrape performance.ipynb

Lines changed: 62 additions & 29 deletions
Large diffs are not rendered by default.

examples/Fast Statistics for SSA Trajectories.ipynb

Lines changed: 13 additions & 16 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)