pedigree-graph
Pedigree relationship extraction and kinship on a Rust core, with Python and R bindings.
A row-streaming engine classifies every relationship pair up to the fifth
degree one individual at a time, so its working memory is linear in the
pedigree size; pair lists, counts, and per-person burden all come from it.
Each relationship type is parameterised by (up, down, n_ancestors):
up: meioses from the first member (the junior role: offspring, descendant, niece_nephew, junior_cousin) up to the common ancestor(s); collateral categories are storedup ≥ downdown: meioses from common ancestor(s) down to individual Bn_ancestors: 1 (half/lineal) or 2 (full, i.e. mated pair)kinship = n_ancestors × (1/2)^(up + down + 1)
Install
pip install pedigree-graph
Binary wheels cover manylinux x86-64 and AArch64, macOS x86-64 and Apple
Silicon, and Windows x86-64 (one abi3 wheel per platform for CPython >= 3.13).
Elsewhere pip builds the sdist, which needs a Rust toolchain (rustc >= 1.85).
For development the locked pixi environment carries Python, Rust, and maturin
and installs the package editable (the extension module is rebuilt with
pixi run maturin develop --release after a Rust change):
git clone https://github.com/rwaples/pedigree-graph.git
cd pedigree-graph
pixi install --locked
pixi run test # inner loop: everything but the `slow` tests, about 45 s
pixi run test-all # before a commit: the full suite, about 100 s
pixi run test-rust # the Rust core
Six of the ten slow tests are the random_30k integration gates, which run
the kernels over the whole 30,300-row pedigree. One of them, the frozen
v0.7.1 parity gate, takes most of the slow tier's time (about 80 s of 88 s
measured on 2026-09-24); the rest take 2 to 14 s each. The other four are the
N=2000 effective-size scaling tests in tests/test_effective_size_scaling.py.
Requires Python ≥ 3.13. Runtime deps: numpy and scipy. Construction,
relationships, topology, pairwise kinship, the kinship matrices, the
generation kinship summary, inbreeding, the lineage counts and the Ne
prerequisites are compiled Rust (pedigree_graph._native, sources under
crates/). numba is only a test extra, for the retired kernels the test
suite keeps as oracles.
Pandas is optional and only needed if you pass DataFrames to the
constructors.
R
The R package pedigreegraph (under r/) runs the same Rust core. Each
GitHub release from v0.10.0 carries its source tarball, which bundles every
Rust dependency and builds offline given a Rust toolchain (rustc >= 1.85):
install.packages(
"https://github.com/rwaples/pedigree-graph/releases/download/v0.10.0/pedigreegraph_0.10.0.tar.gz",
repos = NULL, type = "source"
)
library(pedigreegraph)
pg <- pedigree_graph(data.frame(
id = 1:6, mother = c(NA, NA, 1, 1, NA, 3), father = c(NA, NA, 2, 2, NA, 5)
))
pairs <- relationship_pairs(pg, max_degree = 3) # one row per pair
pairs$kinship <- pair_kinship(pg, pairs$first, pairs$second)
K <- kinship_matrix(pg) # Matrix::dsCMatrix
F <- inbreeding(pg)
counts <- relationship_counts(pg, max_degree = 3) # pairs per category
m <- relationship_moments(pg, categories = c("MO", "FO", "FS"),
values = list(x = c(0.1, -0.4, 0.7, 0.3, 1.2, -0.2)))
as.data.frame(m, stats = c("n", "pearson")) # bit-identical to Python
It covers construction, relationship pairs, counts, burden, per-person
relative counts and moments, pairwise kinship, the complete kinship matrix
and inbreeding; views, lineage and effective size are Python-only for now.
For development, the r pixi environment carries R:
pixi run -e r r-test installs r/ in place and runs its tests,
pixi run -e r r-doc regenerates r/man/, and
pixi run -e r tools/r_build_tarball.sh builds the source tarball.
Usage
import numpy as np
from pedigree_graph import RELATIONSHIPS, PedigreeGraph
# Construct from arrays (no pandas needed)
pg = PedigreeGraph.from_arrays(
ids=np.array([0, 1, 2, 3, 4]),
mother_ids=np.array([-1, -1, 0, 0, 0]),
father_ids=np.array([-1, -1, 1, 1, 1]),
)
# Or from a table: a dict of columns (pandas-free), or any pandas/polars frame
pg = PedigreeGraph.from_frame(
{
"id": np.array([0, 1, 2, 3]),
"mother": np.array([-1, -1, 0, 0]),
"father": np.array([-1, -1, 1, 1]),
"twin": np.array([-1, -1, -1, -1]),
"sex": np.array([0, 1, 0, 1], dtype=np.int8),
"generation": np.array([0, 0, 1, 1], dtype=np.int32),
}
)
# pg = PedigreeGraph.from_frame(df)
# Pairs by relationship category, up to a given degree; each block holds
# read-only int32 first_rows / second_rows in the category's role orientation.
# execution="memory" returns the same blocks at the lowest peak memory
# (the result plus engine state) for about twice the wall time.
pairs = pg.relationship_pairs(max_degree=3)
first, second = pairs["FS"] # full sibs
print(len(pairs["1C"])) # 1st cousins (degree 3)
print(RELATIONSHIPS["FS"].nominal_kinship) # 0.25
# Pedigree-expected kinship for those pairs, or for any two row arrays
kin = pg.pair_kinship(pairs) # {code: float32 array}
kin_fs = pg.pair_kinship(first, second)
# Exact counts in O(N) memory (no pair lists), and the three kinship-matrix families
counts = pg.relationship_counts(max_degree=3)
K = pg.kinship_matrix() # complete, CSC float32
# One O(N)-memory pass for full-graph category counts and per-person
# degree-1..5 burden, without materializing pair lists.
burden = pg.relationship_burden()
print(burden.category_counts["FS"])
print(burden.per_person[2, 0]) # degree-1 relatives of graph row 2
# Scalar counts for MZ, MO, FO, FS, MHS and PHS only, also exact
close = pg.close_relative_counts() # no degree/category selector
assert close["FS"] == counts["FS"]
assert close["GP"] is None # not computed, not zero
Absent optional columns read as absent: there is no sex default and no
generation fallback. Effective-size estimators live in
pedigree_graph.effective_size; the FrameLike protocol in
pedigree_graph.typing. Migrating from 0.7.1: see the old-to-new table in
CHANGELOG.md.
close_relative_counts() is full-graph only. Its requested and exact
sets contain the six codes above; all other registry keys map to None.
It counts parent edges and sibling groups without pair lists or adjacency
powers. For grandparents, avuncular pairs, cousins, or a pedigree view, use
relationship_counts() instead. The former estimate_relationship_counts
method and the result fields approximate and clamped have been removed.
Relationship registry
Codes follow the convention up_down_n_anc:
| Code | Label | up | down | n_anc | Kinship | Degree |
|---|---|---|---|---|---|---|
MZ |
MZ twin | 0 | 0 | 0 | 0.5 | 0 |
MO |
Mother–offspring | 1 | 0 | 1 | 0.25 | 1 |
FO |
Father–offspring | 1 | 0 | 1 | 0.25 | 1 |
FS |
Full sib | 1 | 1 | 2 | 0.25 | 1 |
MHS |
Maternal half sib | 1 | 1 | 1 | 0.125 | 2 |
PHS |
Paternal half sib | 1 | 1 | 1 | 0.125 | 2 |
GP |
Grandparent | 2 | 0 | 1 | 0.125 | 2 |
Av |
Avuncular | 2 | 1 | 2 | 0.125 | 2 |
1C |
1st cousin | 2 | 2 | 2 | 0.0625 | 3 |
| ... | (full registry up to 2nd cousin / kinship 1/64) |
See RELATIONSHIPS for the complete list; each RelationshipCategory
carries code, label, degree, nominal_kinship, up, down,
ancestor_count, and the two positional roles.
Architecture
For contributors: docs/architecture.md maps the
module layout and the hidden contracts (coordinate space, exact count
coverage, sparse-ID handling, default sex), each with its source
of truth and regression test.
The relationship/coordinate vocabulary is in CONTEXT.md;
design decisions are in docs/adr/.
License
MIT — see LICENSE.
Metadata
Release files for pedigree-graph 0.12.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pedigree_graph-0.12.4.tar.gz | 714.8 kB | With provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pedigree_graph-0.12.4-cp313-abi3-win_amd64.whl | CPython 3.13 | abi3 | Windows x86-64 | Details |
| pedigree_graph-0.12.4-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.13 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| pedigree_graph-0.12.4-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.13 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| pedigree_graph-0.12.4-cp313-abi3-macosx_11_0_arm64.whl | CPython 3.13 | abi3 | macOS 11.0+ ARM64 | Details |
| pedigree_graph-0.12.4-cp313-abi3-macosx_10_12_x86_64.whl | CPython 3.13 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 4.4 MB
Release files / pedigree_graph-0.12.4.tar.gz
| Download URL | pedigree_graph-0.12.4.tar.gz |
|---|---|
| Size | 714.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c249a5c93c439e392bb5c11fca2c0c6963e31b3b990d2178222dbf2fb2601422
|
|
BLAKE2b-256 checksum How to use checksums |
51b440017c46aafde109c97d503a67bb05a6f87e4bcb24d483d18137d1ab7909
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / pedigree_graph-0.12.4-cp313-abi3-win_amd64.whl
| Download URL | pedigree_graph-0.12.4-cp313-abi3-win_amd64.whl |
|---|---|
| Size | 686.4 kB |
| Tags | CPython 3.13 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
111d0c95785fc75775be4ff2e550f2dd06a116d58e285d4db2d1770b5aa5c023
|
|
BLAKE2b-256 checksum How to use checksums |
00238b248e53b0eeda4b21f665bffba06e380d6fa7904cafc22e37c5e20115d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / pedigree_graph-0.12.4-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pedigree_graph-0.12.4-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 771.0 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
9c4c552dc6bd15655028159115dca00ed916cb2f2c29216370343bf91e5ff239
|
|
BLAKE2b-256 checksum How to use checksums |
2c6cc84014bf21cdb15693c94c95e8374e800f7738b86482377ac920a9dc5fa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / pedigree_graph-0.12.4-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pedigree_graph-0.12.4-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 737.2 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
34a682ae0a62ef55d13d077bc2a38f7f2d479aaba84b3ec4002646e2a412a04b
|
|
BLAKE2b-256 checksum How to use checksums |
f4d15d0b5b4ecac905af80c905f3fb022148b8d1bd9c3dbd9ced54239370b456
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / pedigree_graph-0.12.4-cp313-abi3-macosx_11_0_arm64.whl
| Download URL | pedigree_graph-0.12.4-cp313-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 708.8 kB |
| Tags | CPython 3.13 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6274d0e8483d8e450264e53ee89600f2f60d773eb214a4a44e8aa4ffa3f0ef7b
|
|
BLAKE2b-256 checksum How to use checksums |
1a424fe2b2f8b1f59740859504345803a1b149e4217394631b88eb0375dda6ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / pedigree_graph-0.12.4-cp313-abi3-macosx_10_12_x86_64.whl
| Download URL | pedigree_graph-0.12.4-cp313-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 735.8 kB |
| Tags | CPython 3.13 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
415ac4940f0d4e9a2066732c2b98b73e023d54492c4b0836b635ca58e7e72275
|
|
BLAKE2b-256 checksum How to use checksums |
0e60d072fc12d4463c769f11db2e2ec82bb37b1d592a7cffe9adea86a33b5a6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logSecurity for pedigree-graph 0.12.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for pedigree_graph-0.12.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.