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.1.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.1-py3-none-any.whl (36.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gdebs-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 76808b918f0694c98fac5ae170333701f1e6ca1f2ee7bc75610a5c345c6b12a9
MD5 34358138228f09a5014cdd2ac4878cb6
BLAKE2b-256 771987671d8cb55c7a75108e496051099be1a0d68c832328de50dd44eb53dd9a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gdebs-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b31dc482d4f5b51730c864c7cc660e414de86014a126531776dfb9f091d6ecb
MD5 cff3b5834d2376fd977833a8d488713c
BLAKE2b-256 640e11b7da7c6348d3dd9c4ac1fa2edc0f753254a7fa03b93baec686279ff5a7

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