Kappa integration (pysb.kappa
)¶
Wrapper functions for running the Kappa programs KaSim and KaSa.
The path to the directory containing the KaSim and KaSa executables can be specified in one of three ways:
- set the KAPPAPATH environment variable to the KaSim directory
- move Kappa to /usr/local/share/KaSim (macOS, Linux) or c:Program FilesKaSim (Windows)
- set the path using the
pysb.pathfinder.set_path()
function at runtime
-
class
pysb.kappa.
SimulationResult
¶ -
flux_map
¶ Alias for field number 1
-
timecourse
¶ Alias for field number 0
-
-
class
pysb.kappa.
StaticAnalysisResult
¶ -
contact_map
¶ Alias for field number 0
-
influence_map
¶ Alias for field number 1
-
-
pysb.kappa.
contact_map
(model, **kwargs)[source]¶ Generates the contact map via KaSa.
Parameters: - model : pysb.core.Model
The model for generating the influence map.
- **kwargs : other keyword arguments
Any other keyword arguments are passed to the function
run_static_analysis()
.
Returns: - networkx MultiGraph object containing the contact map. For details on
- viewing the contact map graphically see :func:`run_static_analysis` (notes
- section).
-
pysb.kappa.
influence_map
(model, **kwargs)[source]¶ Generates the influence map via KaSa.
Parameters: - model : pysb.core.Model
The model for generating the influence map.
- **kwargs : other keyword arguments
Any other keyword arguments are passed to the function
run_static_analysis()
.
Returns: - networkx MultiGraph object containing the influence map. For details on
- viewing the influence map graphically see :func:`run_static_analysis`
- (notes section).
-
pysb.kappa.
run_simulation
(model, time=10000, points=200, cleanup=True, output_prefix=None, output_dir=None, flux_map=False, perturbation=None, seed=None, verbose=False)[source]¶ Runs the given model using KaSim and returns the parsed results.
Parameters: - model : pysb.core.Model
The model to simulate/analyze using KaSim.
- time : number
The amount of time (in arbitrary units) to run a simulation. Identical to the -u time -l argument when using KaSim at the command line. Default value is 10000. If set to 0, no simulation will be run.
- points : integer
The number of data points to collect for plotting. Note that this is not identical to the -p argument of KaSim when called from the command line, which denotes plot period (time interval between points in plot). Default value is 200. Note that the number of points actually returned by the simulator will be points + 1 (including the 0 point).
- cleanup : boolean
Specifies whether output files produced by KaSim should be deleted after execution is completed. Default value is True.
- output_prefix: str
Prefix of the temporary directory name. Default is ‘tmpKappa_<model name>_’.
- output_dir : string
The directory in which to create the temporary directory for the .ka and other output files. Defaults to the system temporary file directory (e.g. /tmp). If the specified directory does not exist, an Exception is thrown.
- flux_map: boolean
Specifies whether or not to produce the flux map (generated over the full duration of the simulation). Default value is False.
- perturbation : string or None
Optional perturbation language syntax to be appended to the Kappa file. See KaSim manual for more details. Default value is None (no perturbation).
- seed : integer
A seed integer for KaSim random number generator. Set to None to allow KaSim to use a random seed (default) or supply a seed for deterministic behaviour (e.g. for testing)
- verbose : boolean
Whether to pass the output of KaSim through to stdout/stderr.
Returns: - If flux_map is False, returns the kasim simulation data as a Numpy ndarray.
- Data is accessed using the syntax::
results[index_name]
- The index ‘time’ gives the time coordinates of the simulation. Data for the
- observables can be accessed by indexing the array with the names of the
- observables. Each entry in the ndarray has length points + 1, due to the
- inclusion of both the zero point and the final timepoint.
- If flux_map is True, returns an instance of SimulationResult, a namedtuple
- with two members, `timecourse` and `flux_map`. The `timecourse` field
- contains the simulation ndarray, and the `flux_map` field is an instance of
- a networkx MultiGraph containing the flux map. For details on viewing
- the flux map graphically see :func:`run_static_analysis` (notes section).
-
pysb.kappa.
run_static_analysis
(model, influence_map=False, contact_map=False, cleanup=True, output_prefix=None, output_dir=None, verbose=False)[source]¶ Run static analysis (KaSa) on to get the contact and influence maps.
If neither influence_map nor contact_map are set to True, then a ValueError is raised.
Parameters: - model : pysb.core.Model
The model to simulate/analyze using KaSa.
- influence_map : boolean
Whether to compute the influence map.
- contact_map : boolean
Whether to compute the contact map.
- cleanup : boolean
Specifies whether output files produced by KaSa should be deleted after execution is completed. Default value is True.
- output_prefix: str
Prefix of the temporary directory name. Default is ‘tmpKappa_<model name>_’.
- output_dir : string
The directory in which to create the temporary directory for the .ka and other output files. Defaults to the system temporary file directory (e.g. /tmp). If the specified directory does not exist, an Exception is thrown.
- verbose : boolean
Whether to pass the output of KaSa through to stdout/stderr.
Returns: - StaticAnalysisResult, a namedtuple with two fields, `contact_map` and
- `influence_map`, each containing the respective result as an instance
- of a networkx MultiGraph. If the either the contact_map or influence_map
- argument to the function is False, the corresponding entry in the
- StaticAnalysisResult returned by the function will be None.
Notes
To view a networkx file graphically, use draw_network:
import networkx as nx nx.draw_networkx(g, with_labels=True)
You can use graphviz_layout to use graphviz for layout (requires pydot library):
import networkx as nx pos = nx.drawing.nx_pydot.graphviz_layout(g, prog='dot') nx.draw_networkx(g, pos, with_labels=True)
For further information, see the networkx documentation on visualization: https://networkx.github.io/documentation/latest/reference/drawing.html