Topkappy - Reference manual¶
Kappa Models¶
-
class
topkappy.KappaModel.
KappaModel
(agents, rules, initial_quantities, snapshot_times=None, plots=(), plot_time_step=0.1, duration=None, stop_condition=None)[source]¶ Class to represent Kappa models and create corresponding Kappa scripts.
See the README example for a quick intro.
- Parameters
- agents
List of all KappaAgent in the model.
- rules
List of all KappaRule in the model.
- initial_quantities
Either a dict {agent_name: initial_quantity} or a single integer if all agents start with the same initial quantity. Note that the more initial agents, the less noisy the simulation results/
- duration
Virtual duration of the simulation, in seconds/
- snapshot_times
A dict {snapshot_name: time}, e.g. {‘end’: 10}. The snapshot can then be accessed as simulation_results[‘snapshots’][‘end’].
- plots
List of Kappa expressions to plot. Each list element can be either a string (a Kappa expression like
|A(.)|
) or a KappaSiteState like[KappaSiteState('B', 'b', '.'), KappaSiteState('C', 'c', '.')]
.- plot_time_step
Time interval between two points when gathering data for plotting.
- stop_condition
String representing a Kappa stopping condition. If none is provided, the simulation stops after the provided
duration
is reached.
Methods
get_simulation_results
()Run a simulation of the model and return results as a dict.
set_parameters
([duration, stop_condition, …])(Re-)set some parameters of the model.
-
class
topkappy.KappaClasses.
KappaAgent
(name, sites)[source]¶ Class to represent a Kappa agent.
- Parameters
- name
Agent name, e.g. ‘A’.
- sites
List of sites, e.g. [‘a1’, ‘a2’].
-
class
topkappy.KappaClasses.
KappaSiteState
(agent, site, state='.')[source]¶ Class to represent a Kappa site state like ‘A(x[.])’.
- Parameters
- agent
A KappaAgent object.
- site
Name of the site. Should be a name in agent.sites.
- state
The site state, e.g. ‘.’, ‘1’, 2, etc.
-
class
topkappy.KappaClasses.
KappaRule
(name, reactants, sense, products, rate)[source]¶ Class to represent a Kappa rule. Possibly very incomplete.
- Parameters
- name
Name of the rule.
- reactants
List of KappaSiteState that are consumed by the rule.
- sense
String arrow like ‘->’ or ‘<->’.
- products
List of KappaSiteState that are produced by the rule.
- rate
Value indicating the frequency at which the rule happens. (or pair of values if sense is ‘<->’.
-
class
topkappy.FormattedKappaError.
FormattedKappaError
[source]¶ Class to raise and pretty-print Kappa script syntax errors.
When Kappa complains that the script doesn’t make sense (through kappy), you can catch the error, pass it to FormattedKappaError.from_kappa_error() and reraise it. The resulting error will nicely print the errors in context.
Examples
>>> kappa_client = kappy.KappaStd() >>> kappa_client.add_model_string(model_string) >>> try: >>> kappa_client.project_parse() >>> except kappy.KappaError as kappa_error: >>> raise FormattedKappaError.from_kappa_error(kappa_error, >>> model_string)
- Attributes
- args
Methods
formatted_string
(error_items, model_string)Create a FormattedKappaError from a Kappy project parsing error.
from_kappa_error
(kappa_error, model_string)Create a FormattedKappaError from a Kappy project parsing error.
with_traceback
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Result analysis¶
-
topkappy.agents_graphs.
plot_snapshot_agents
(agents, with_ports=True, columns='auto', ax_inches=3, layout_method='FR', freq_cutoff=0)[source]¶ Plot graph representations of all complexes in a multi-ax figure.
- Parameters
- agents
Snapshot agents as provided in the result of
get_simulation_results()
bysimulation_results['snapshots']['SNAP_NAME']['snapshot_agents']
.- with_ports
If true, ports (= agents binding sites) will be represented on the figure.
- columns
How many columns (= plots by lines) in the figure ? Keep to “auto” for a more-or-less squared figure.
- ax_inches
Size of one figure in inches.
- layout_method
Networkx layout method for the graph drawing. Either ‘FR’ (fruchterman_reingold), ‘spectral’ or ‘spring’.
- freq_cutoff
All complexes with a number of occurences lower than frew_cutoff in the snapshot will be ignored.
- Returns
- fig, axes
Matplotlib “figure” and “axes” list of the multi-ax figure generated.
-
topkappy.plot_simulation_time_series.
plot_simulation_time_series
(plots_data, ax=None)[source]¶ Plot the time series data from a KappaModel simulation.
Examples
>>> model = KappaModel(...) >>> simulation_results = model.get_simulation_results() >>> ax = plot_simulation_time_series(simulation_results['plots']) >>> ax.figure.savefig('basic_example_time_series.png')