Skip to main content

Stochastic and Deterministic Simulation Methods Used in Computational Biology

Project description

BioStoch

Simulation in Biology

ssa1.png

Simulated with GillespySimulator: Concentration trajectories of species A and B over time. Ten independent simulations were performed, each represented by a different line color

Overview

biostoch is a Python library for simulating chemical and biological models using various deterministic and stochastic methods. It provides implementations of methods such as Euler's method, the Runge-Kutta algorithm, the Stochastic Simulation Algorithm (SSA), Tau-Leaping, and the Chemical Langevin Equation (CLE). These methods can be used to model and analyze the dynamics of biochemical reactions, gene regulatory networks, and other biological systems.

Installation

Install biostoch and its dependencies using pip:

pip install numpy matplotlib 
pip install biostoch

Usage

import numpy
import matplotlib
import time
from biostoch.model import Model
from biostoch.ode import EulerSimulator, RungeKuttaSimulator
from biostoch.ssa import GillespieSimulator
from biostoch.tau_leaping import TauLeaping
from biostoch.cle import ChemicalLangevin
from biostoch.visualization import Visualization

# Define a system of reactions, in this case, a simple system with two reactions: A <-> B; with rate constants K1 = 0.1, K2 = 0.05
model = Model() 

# Add rate constants for each reaction in the system
model.parameters({
    "K1": 0.1, 
    "K2": 0.05
})

# Add species and rate of change for each of them
model.species(
    components={
        "A": 100.0, 
        "B": 0.0
    }, 
    rate_change={
        "A": "K2 * B - K1 * A", 
        "B": "K1 * A - K2 * B"
    }
)

# Add reactions and rate for each of them
model.reactions(
    reacts={
        "reaction1": "A -> B", 
        "reaction2": "B -> A"
    },
    rates={
        "reaction1": "K1 * A", 
        "reaction2": "K2 * B"
    }
)

# Simulate the model using ordinary differential equations (ODE) with the Euler method
euler_model = EulerSimulator(
    model=model, 
    start=0, 
    stop=100, 
    epochs=1000
)
euler_model.reset() # Reset the model to initialize if it has been used before
euler_model.simulate() # Simulate the model 
euler_model.species # Print the model species after the simulation, a dictionary containing the change in species concentration during the simulation time
euler_model.time # Show how long the simulation took to complete

# Simulate the model using ordinary differential equations (ODE) with the Runge-Kutta method
runge_model = RungeKuttaSimulator(
    model=model, 
    start=0, 
    stop=100, 
    epochs=1000
)

runge_model.simulate()
runge_model.species
runge_model.time

# Simulate the model using the Stochastic Simulation Algorithm (SSA)
ssa_model = GillespieSimulator(
    model=model, 
    start=0, 
    stop=100, 
    max_epochs=1000
)

ssa_model.simulate()
ssa_model.species
ssa_model.time

# Simulate the model using the Tau-Leaping method
tau_model = TauLeaping(
    model=model, 
    start=0, 
    stop=100, 
    max_epochs=100
)

tau_model.simulate()
tau_model.species
tau_model.time

# Simulate the model using the Chemical Langevin Equation method
cle_model = ChemicalLangevin(
    model=model,
    start=0,
    stop=100, 
    max_epochs=1000
)

cle_model.simulate()
cle_model.species
cle_model.time

# Visualize the simulated models using integrated matplotlib.pyplot in biostoch
euler_plot = Visualization(euler_model)
runge_plot = Visualization(euler_model)
ssa_plot = Visualization(euler_model)
tau_plot = Visualization(euler_model)
cle_plot = Visualization(euler_model)

euler_plot.plot()
runge_plot.plot()
ssa_plot.plot()
tau_plot.plot()
cle_plot.plot()

License

This project is licensed under the MIT License

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

biostoch-0.0.3.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

biostoch-0.0.3-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file biostoch-0.0.3.tar.gz.

File metadata

  • Download URL: biostoch-0.0.3.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for biostoch-0.0.3.tar.gz
Algorithm Hash digest
SHA256 462e9c15ef22f9ee309ccf2884c4a1355d4727c987515319e1579c27cb99cf0e
MD5 922a3160125a1b264757c20ae2bbaa49
BLAKE2b-256 197f9a4b0e60ff44dfaf136cd9f2ac443085070b0e4c456f21c0eb4857e294ad

See more details on using hashes here.

File details

Details for the file biostoch-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: biostoch-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for biostoch-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ab0f6baed5d6153b1480eba49289111157e57f2408217f495a7e30b24e8da837
MD5 d7534430ba4d441626936c4a7e9e351b
BLAKE2b-256 2329b221e963dd5d9525e53c63a384ddb0d67fc83f6b9dc9f7e381793c0adf94

See more details on using hashes here.

Supported by

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