Skip to main content

An event based simulation package for observing the spread of a gene drive in an animal population

Project description

gdebs - Gene Drive Simulation Package

An event-based simulation package for observing the spread of a gene drive in animal populations.

Description

The gdebs library simulates the spread of gene drives in animal populations. Gene drives are genetic modifications that can be inherited and affect reproduction or survival, specifically:

  1. Female Sterility Drive: Females cannot mate and have offspring
  2. Female Lethality Drive: Females die at birth

Males are unaffected by these gene drives but can pass them down to their offspring. This library provides tools for simulating, analyzing, and visualizing the spread of these gene drives in populations over time.

Installation

Requirements

  • Python 3.13 or higher
  • Dependencies:
    • numpy
    • pandas
    • matplotlib
    • streamlit (for web interface)

Installing from PyPI

pip install gdebs

Installing from Source

  1. Clone the repository:
git clone https://github.com/rsnarang/gdebs.git
cd gdebs
  1. Install the package:
pip install -e .

Usage

Basic Simulation

Here's a simple example to run a gene drive simulation:

import numpy as np
from time import time
from gdebs import PigPatch, Boar, Sow, simulate_n_years, get_default_settings

# Get default settings
settings = get_default_settings()

# Customize settings
settings["number_of_simulations"] = 10
settings["starting_males"] = 500
settings["starting_females"] = 500
settings["starting_ge_males"] = 50  # Start with gene-edited males
settings["gene_edit_success_rate"] = 0.9  # Success rate for passing gene drive

# Run simulation
np.random.seed(42)  # Set seed for reproducibility
result = simulate_n_years(PigPatch, settings, Boar, Sow)

# Access results
for year, stats in enumerate(result):
    print(f"Year {year}:")
    print(f"  Total population: {stats['Total_Population']}")
    print(f"  Gene-edited animals: {stats['Gene_Edit_Males'] + stats['Gene_Edit_Females']}")

Analyzing and Visualizing Results

The library provides tools for analyzing and visualizing simulation results:

from gdebs import analyze_simulation, display_graphs
import pandas as pd

# Run multiple simulations
sim_array = []
for i in range(settings["number_of_simulations"]):
    np.random.seed(1000 + i)
    result = simulate_n_years(PigPatch, settings, Boar, Sow)
    sim_array.append(result)

# Analyze results
mean_array, std_array = analyze_simulation(sim_array)

# Create DataFrame for visualization
column_names = [
    "Normal_Males", "Normal_Females", 
    "Gene_Edit_Males", "Gene_Edit_Females",
    "Young_Population", "Adult_Population", 
    "Total_Population", "Effective_Adult_Population"
]

mean_df = pd.DataFrame(mean_array, columns=column_names)
mean_df['Year'] = mean_df.index.astype(int)

# Move Year to first column
cols = mean_df.columns.tolist()
cols = cols[-1:] + cols[:-1]
mean_df = mean_df[cols]

# Display graphs
display_graphs(mean_df)

Web Interface

The package includes a Streamlit web interface for easy interaction:

cd examples
streamlit run app.py

This will launch a web application where you can:

  • Configure all simulation parameters
  • Run simulations with different settings
  • Visualize and analyze results
  • Save simulation data for further analysis

Settings Configuration

The simulation is highly configurable through settings:

from gdebs import get_default_settings, save_settings, load_settings

# Get default settings
settings = get_default_settings()

# Modify settings
settings["starting_males"] = 1000
settings["starting_females"] = 1000
settings["gene_edit_success_rate"] = 0.75

# Save settings to file
save_settings(settings, "my_simulation_settings.json")

# Load settings from file
settings = load_settings("my_simulation_settings.json")

Key Settings Parameters

  • Population Parameters:

    • starting_males: Initial male population
    • starting_females: Initial female population
    • starting_ge_males: Initial gene-edited male population
    • starting_child_males: Initial male child population
    • starting_child_females: Initial female child population
  • Rate Parameters:

    • sex_rate: Ratio of male to female birth (0.5 = equal)
    • adult_survival_rate: Probability of adults surviving each year
    • newborn_survival_rate: Probability of newborns surviving first year
    • gene_edit_success_rate: Probability of passing gene drive to offspring
  • Simulation Parameters:

    • number_of_litters: Maximum number of litters per female per year
    • number_of_years: Duration of simulation in years
    • number_of_simulations: Number of simulation trials to run
  • Gene Drive Introduction:

    • artificial_insemination: Enable artificial insemination
    • targeted_hunting: Enable targeted hunting
    • added_ge_carriers: Add new gene drive carriers each year

Project Structure

  • core: Core classes for animals and population dynamics
  • simulation: Simulation engine and algorithms
  • utils: Utility functions and settings management
  • visualization: Data analysis and visualization tools
  • examples: Example scripts and applications
  • tests: Test suite for the library

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Author

Rocky Sam Narang (rnarang@uoguelph.ca; rssnarang@gmail.com)

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

gdebs-1.0.2.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

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

gdebs-1.0.2-py3-none-any.whl (36.6 kB view details)

Uploaded Python 3

File details

Details for the file gdebs-1.0.2.tar.gz.

File metadata

  • Download URL: gdebs-1.0.2.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gdebs-1.0.2.tar.gz
Algorithm Hash digest
SHA256 83940a20fbbe8a264a7988c00efc9b32398dce0b5b4096d05ff052114b881284
MD5 81e9983fa30098e8a30b85d87a558cbb
BLAKE2b-256 a7b9a4637eb60e64e7aa2f3a7b945aed1755c55d50ff135460cc85621b3247bc

See more details on using hashes here.

File details

Details for the file gdebs-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: gdebs-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 36.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gdebs-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 994a7d7efe52c2c6856cae23a3d2d5f0a5ea8934228d054e1e28d1487e0e0c2e
MD5 5eadac81a2729109b7023bc77afea57e
BLAKE2b-256 75636ce6d4017c8524776265baa30690b8c22826e0e1234bdab7e30561dd7a3a

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