Skip to main content

Draw interaction graphs from systems biology reaction models

Project description

model-graph-drawer

Automatically draw interaction graphs for systems biology models.

Species (states) are rendered as bold text labels. Reactions are drawn as direct arrows between species, labelled with their rate constants. Modifier arrows (dashed red, + at the tip) are drawn from a species to the midpoint of the reaction whose rate it influences.

Installation

Source: https://gitlab.liu.se/ISBgroup/projects/model-graph-drawer

pip install model-graph-drawer
# or with uv
uv add model-graph-drawer

Requires Python ≥ 3.10.

Dependencies

Package Version Role
matplotlib ≥ 3.5 Rendering arrows, labels, and axes
networkx ≥ 3.0 Graph data structure and layout algorithms (Kamada–Kawai, spring, circular, spectral)
numpy ≥ 1.20 Vector geometry for arc midpoints, perpendicular calculations, and curvature

Quick start

Reaction-string format

from model_graph_drawer import Model, draw
import matplotlib.pyplot as plt

model = Model.from_reactions([
    "-> A   : k1",      # synthesis  (source)
    "A -> B : k2*A*C",  # A→B, rate depends on C  →  C is a modifier
    "B -> C : k3*B",
    "C ->   : k4*C",    # degradation (sink)
])

draw(model, title="A → B → C with C as modifier")
plt.show()

Or load from a multi-line string:

model = Model.from_text("""
    -> A   : k1
    A -> B : k2*A*C
    B -> C : k3*B
    C ->   : k4*C
""")

The shortcut model.draw(...) is equivalent to draw(model, ...).

sund model files

model = Model.from_sund("path/to/model.txt")
model.draw(title="My model")
plt.show()

Reaction format

[reactants] -> [products] : rate_expression
Example Meaning
-> A : k1 Source — A is produced at rate k1
A -> B : k2*A*C A is converted to B; C is a modifier
B -> C : k3*B Simple first-order conversion
C -> : k4*C Sink — C is degraded
A + B -> C : k*A*B Bimolecular reaction

Modifier detection — any species that appears in the rate expression but is not a reactant is automatically detected as a modifier and drawn with a dashed arrow.


Relationship to sund

model-graph-drawer is a generic visualisation library — it works with any reaction network you can express in the reaction-string format. It also has first-class support for sund model files, developed by the same team.

When a sund .txt file is loaded, the parser extracts not only the reaction stoichiometry but also the INPUTS, OUTPUTS, and FEATURES sections, which are reflected in the graph as distinct visual styles:

Role Visual style
Input (external signal) Dashed green border
Output (exposed to other models) Solid orange border
Feature (observable quantity) Pale yellow background
model = Model.from_sund("path/to/model.txt")
model.draw(title="My sund model")

sund file format

The parser reads the STATES and VARIABLES sections of a .txt sund model file.

########## STATES
d/dt(R)  = r2 - r1
d/dt(Rp) = r1 - r2
...

########## VARIABLES
r1 = R*A*k1
r2 = Rp*k2

Stoichiometry is inferred from the signs in each d/dt expression. Identifiers in the rate expression that are neither species nor mathematical operators are used as reaction labels.


API

Model.from_reactions(reactions: list[str]) -> Model
Model.from_text(text: str) -> Model
Model.from_sund(path: str) -> Model

draw(
    model,
    *,
    ax=None,         # matplotlib Axes; created automatically when None
    figsize=(10, 7), # inches, used only when ax is None
    layout="kamada_kawai",
    title=None,
) -> plt.Axes

Layout options

Value Description
"kamada_kawai" (default) Minimises edge crossings
"spring" Force-directed
"circular" All nodes on a circle
"spectral" Eigenvector-based

Programmatic access

import networkx as nx
from model_graph_drawer import build_graph

G = build_graph(model)   # nx.DiGraph with species + reaction nodes
# node attribute  node_type : 'species' | 'reaction'
# edge attribute  edge_type : 'consumption' | 'production' | 'modifier'

AI disclosure

This project was developed with the assistance of Claude (Anthropic). Parts of the code, documentation, and tests were written or refined using AI-assisted pair programming.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

model_graph_drawer-0.1.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

model_graph_drawer-0.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file model_graph_drawer-0.1.0.tar.gz.

File metadata

  • Download URL: model_graph_drawer-0.1.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for model_graph_drawer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6f3c881a3ec390327d39d7e6beb55fd8a4dd6cb605a2d55010f9eae0f2784af2
MD5 c4630c0056e8fb86d94111f82ad82493
BLAKE2b-256 1ad221951a1dc028faa50ee6797d7ef0613ca8b26a205e115a7dc49ecd110fe4

See more details on using hashes here.

File details

Details for the file model_graph_drawer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: model_graph_drawer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for model_graph_drawer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36fe71089ce0b12cbdba54b4cde7c67c7ca4a5eab1c345d776e230ea2f783f7e
MD5 70ecf4853f0668aacf33f35978bb25d9
BLAKE2b-256 d9b879ad4cc8203dc3f2e64022a4296d79e725b4e62c590edbe95be23055702a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page