Pedigree-based recombination simulation with explicit homolog tracking.
Project description
pedigraph-sim
Pedigree-based recombination simulation with explicit homolog tracking
pedigraph-sim simulates recombination along user-defined pedigrees while explicitly tracking the ancestry of chromosome segments through time. Currently pedigraph-sim implements diploid inheritance and a Haldane map function. I plan to introduce additional models in future updates.
Unlike coalescent-based simulators, pedigraph-sim operates directly on pedigrees and produces interval-specific local genealogies (i.e. a tree sequence).
My goal in developing pedigraph-sim was to bridge a gap between two approaches to modeling recombination. On one hand, there is the mechanistic process of meiosis: e.g. thinking in terms of bivalents, crossing over, and how ancestry is physically sorted over a small number of generations. On the other hand, there is the more abstract, deep-time view of the coalescent with recombination (e.g. as implemented in msprime).
These models can ultimately produce the same type of output (a tree sequence partitioned by historical recombination events) but the connection between them is not always intuitive... I sometimes find myself scribbling genealogy cartoons to try to relate patterns in msprime outputs back to the underlying generation-by-generation crossing over process.
By grounding ancestry in explicit pedigrees and mechanistic models of recombination, my hope with pedigraph-sim is to make this connection more transparent, making it easy to build intuition about tree sequence variation, to explore sensitivity in this variation to deviations from coalescent assumptions, and to study processes not included in more phenomenological models.
pedigraph-sim is designed for:
- simulating inheritance under explicit pedigrees
- benchmarking ancestry and ARG inference methods
- generating ground-truth local ancestry under recombination
pedigraph-sim is inspired by PedigreeSim (https://github.com/PBR/pedigreeSim), and future work will prioritize incorporating the additional models featured there.
Features
- Flexible diploid pedigree specification
- Explicit segment-level ancestry tracking:
- parent homolog IDs
- founder homolog IDs
- Multiple chromosomes
- Built-in pedigree visualization
- Reconstruction of ARG-like local ancestry graphs
- Export to Newick or
tskit
Priority improvements
- Additional map functions
- Ploidy variation
- Performance improvements
Installation
Currently: source install
pip install git+https://github.com/pmckenz1/pedigraph-sim.git
[Coming soon] PyPI install:
pip install pedigraph-sim # core simulation
pip install "pedigraph-sim[dataframe]" # adds pandas helpers
pip install "pedigraph-sim[tskit]" # adds tskit export
pip install "pedigraph-sim[all]" # everything
Optional extras:
dataframe: enables.individuals_dataframe(),.homologs_dataframe(),.segments_dataframe()tskit: enablespg.to_tskit(...)
Quick Start
import pedigraph_sim as pg
gen_list = [
['P0', 'NA', 'NA'],
['P1', 'NA', 'NA'],
['P2', 'NA', 'NA'],
['P3', 'NA', 'NA'],
['P4', 'NA', 'NA'],
['F1_0', 'P3', 'P1'],
['F1_1', 'P0', 'P0'],
['F1_2', 'P0', 'P3'],
['F1_3', 'P4', 'P3'],
['F1_4', 'P1', 'P2'],
['F2_0', 'F1_4', 'F1_3'],
['F2_1', 'F1_1', 'F1_3'],
['F2_2', 'F1_2', 'F1_4'],
['F2_3', 'F1_1', 'F1_1'],
['F2_4', 'F1_3', 'F1_4'],
['F3_0', 'F2_1', 'F2_2'],
['F3_1', 'F2_1', 'F2_2'],
['F3_2', 'F2_0', 'F2_4'],
['F3_3', 'F2_0', 'F2_0'],
['F3_4', 'F2_2', 'F2_2'],
]
model = pg.PedigreeModel(
pedigree=gen_list,
chromosomes={"A": 100.0, "B": 50.0},
seed=123,
)
model.draw_pedigree()
Run a simulation
result = model.simulate()
# inspect individuals
result
result.individuals["F3_0"]
Example output: result.individuals["F3_0"]
SimIndividual(
individual_id='F3_0',
time=3,
homologs_by_chromosome={
'A': [
Homolog(
homolog_id=60,
chromosome='A',
individual_id='F3_0',
time=3,
length=100.0,
segments=[
Segment(left=0.0, right=66.31224791052625, parent_homolog_id=45, founder_homolog_id=13),
Segment(left=66.31224791052625, right=100.0, parent_homolog_id=45, founder_homolog_id=12)
]
),
Homolog(
homolog_id=61,
chromosome='A',
individual_id='F3_0',
time=3,
length=100.0,
segments=[
Segment(left=0.0, right=74.53017446460717, parent_homolog_id=49, founder_homolog_id=8),
Segment(left=74.53017446460717, right=74.98318679719566, parent_homolog_id=49, founder_homolog_id=4),
Segment(left=74.98318679719566, right=100.0, parent_homolog_id=49, founder_homolog_id=5)
]
)
],
'B': [
Homolog(
homolog_id=62,
chromosome='B',
individual_id='F3_0',
time=3,
length=50.0,
segments=[
Segment(left=0.0, right=40.93653676280072, parent_homolog_id=46, founder_homolog_id=2),
Segment(left=40.93653676280072, right=50.0, parent_homolog_id=47, founder_homolog_id=14)
]
),
Homolog(
homolog_id=63,
chromosome='B',
individual_id='F3_0',
time=3,
length=50.0,
segments=[
Segment(left=0.0, right=23.757990827567365, parent_homolog_id=51, founder_homolog_id=6),
Segment(left=23.757990827567365, right=38.768579535484946, parent_homolog_id=51, founder_homolog_id=7),
Segment(left=38.768579535484946, right=50.0, parent_homolog_id=51, founder_homolog_id=6)
]
)
]
}
)
For easy inspection:
result.individuals_dataframe()
result.homologs_dataframe()
result.segments_dataframe()
Local ancestry / ARG reconstruction
A central feature of pedigraph-sim is reconstruction of local genealogies along the chromosome.
sample_hids = result.final_generation_homolog_ids("A")
seq = result.local_forests("A", sample_hids)
Check out local forests:
for forest in seq[:3]:
print(forest.left, forest.right)
print("roots:", forest.roots())
print("edges:", sorted(forest.edges))
Export to Newick
records = pg.to_newick_records(result, seq)
for rec in records[:3]:
print(rec["left"], rec["right"])
print(rec["newicks"])
Or as a dataframe:
df = pg.to_dataframe(result, seq)
df.head()
Convert to tskit
ts = pg.to_tskit(result, seq)
print(ts)
print("num_trees:", ts.num_trees)
Inspect trees:
from itertools import islice
for tree in islice(ts.trees(), 3):
print("\ninterval:", tree.interval)
print(tree.draw_text())
This makes pedigraph-sim compatible with the broader tskit ecosystem.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pedigraph_sim-0.1.0.tar.gz.
File metadata
- Download URL: pedigraph_sim-0.1.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b34d92a29bbff4a7c6ccfe52d8654a5f800e6588e97be652e71283d38ef93927
|
|
| MD5 |
827720a9fd10c6e03797f394ce48cf24
|
|
| BLAKE2b-256 |
4f4318cd4b05a1e7d34a144caa6a28d7db1c2450baa7a9d6a98e4b1fc7151982
|
Provenance
The following attestation bundles were made for pedigraph_sim-0.1.0.tar.gz:
Publisher:
python-publish.yml on pmckenz1/pedigraph-sim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pedigraph_sim-0.1.0.tar.gz -
Subject digest:
b34d92a29bbff4a7c6ccfe52d8654a5f800e6588e97be652e71283d38ef93927 - Sigstore transparency entry: 1186312867
- Sigstore integration time:
-
Permalink:
pmckenz1/pedigraph-sim@a97c8250a18f7823719e84f001322113f658f56c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/pmckenz1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a97c8250a18f7823719e84f001322113f658f56c -
Trigger Event:
release
-
Statement type:
File details
Details for the file pedigraph_sim-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pedigraph_sim-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1d3d814688e75e6c7e950af6efaf424f5ec54b99f4c7094233509e9b7cafcac
|
|
| MD5 |
5508c1c4096c976a6e648bce74a5c6fc
|
|
| BLAKE2b-256 |
2b459003710311addb6ec1feeac90330c1b829fc78aa7aadb0ad12cce957b664
|
Provenance
The following attestation bundles were made for pedigraph_sim-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on pmckenz1/pedigraph-sim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pedigraph_sim-0.1.0-py3-none-any.whl -
Subject digest:
d1d3d814688e75e6c7e950af6efaf424f5ec54b99f4c7094233509e9b7cafcac - Sigstore transparency entry: 1186312873
- Sigstore integration time:
-
Permalink:
pmckenz1/pedigraph-sim@a97c8250a18f7823719e84f001322113f658f56c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/pmckenz1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a97c8250a18f7823719e84f001322113f658f56c -
Trigger Event:
release
-
Statement type: