Skip to main content

pg-phenotype

Phenotypes in the context of a pedigree, as an extension of pedigree-graph: a Rust core with Python and R bindings. Relationships and kinship come from pedigree-graph's core; each method is a module on top.

Method Module Status
PA-FGRS family genetic risk scores (Dybdahl Krebs et al., Am J Hum Genet 2024, doi:10.1016/j.ajhg.2024.09.009) pg_phenotype.pafgrs available
Assortative mating: the Mate Correlation of one or two traits, ported from pedsum #13 pg_phenotype.assortative available

Python

import pg_phenotype as pgp
from pg_phenotype import pafgrs

trait = pgp.Trait(dx, kind="binary")  # one value per pedigree row
prep = pafgrs.prepare(pedigree, ndegree=2)  # once per pedigree
cip = pafgrs.Cip(ages, cip_values)  # K is the last value
scores = pafgrs.score_univariate(prep, trait, age=dx_age, cip=cip, h2=0.4)
scores.est, scores.var, scores.n_relatives, scores.metadata

both = pafgrs.score_bivariate(prep, (t1, t2), age=(a1, a2), cip=(c1, c2), h2=(0.4, 0.6), rg=0.5)
  • pedigree: columns id, mother, father (-1 or NA when missing) and optional twin, sex (0 female, 1 male), as a polars or pandas frame or a mapping of arrays. It is validated by pedigree-graph's rules.
  • Trait(values, kind=None): one phenotype column on the pedigree's rows, NA where unknown. The kind is continuous, binary, ordinal or categorical, inferred when unambiguous.
  • PA-FGRS takes a binary trait. age is the onset age for a case and the last observed age for a control; a control without an age is unobserved and counted.
  • probands= restricts the scored rows; relatives are drawn from the whole pedigree. Output is one record per proband in input-row order.
  • configure_threads(n) or PG_PHENOTYPE_THREADS sets the thread budget (default 1). Results are identical for every budget.

Errors are pg_phenotype.ValidationError, ParameterError and ResourceError, each with a stable .code and .fields.

Assortative mating

from pg_phenotype.assortative import mate_correlation

res = mate_correlation(pedigree, [pgp.Trait(liab), pgp.Trait(dx)], stratum=birth_decade, bootstrap=1000, seed=1)
cell = res.cell(0, 1)  # mothers' trait 0 x fathers' trait 1
cell.primary.value, cell.primary.ci, cell.primary.permutation.p
cell.stratified.result.value  # within birth-decade strata
res.within_person["mothers"]

The Mate Correlation is the correlation between the mother's and the father's value of a trait over a pedigree's Mating Pairs. Each cell uses the estimators its trait kinds call for (Pearson, tetrachoric, polychoric, biserial or polyserial, with their closed-form companions), a Mate Network sandwich SE, an optional Mate Network bootstrap, and a sequential father-permutation p-value. docs/assortative-mating.md describes the inputs, rules and every result field, and docs/assortative-mating-design.md explains the design.

R

library(pgphenotype)

dx <- trait(ped$dx, kind = "binary")
prep <- pafgrs_prepare(ped, ndegree = 2L)
cip <- pafgrs_cip(ages, cip_values)
scores <- pafgrs_score_univariate(prep, dx, age = ped$dx_age, cip = cip, h2 = 0.4)
both <- pafgrs_score_bivariate(prep, list(t1, t2), ages = list(a1, a2),
                               cips = list(c1, c2), h2 = c(0.4, 0.6), rg = 0.5)
am <- assortative_mate_correlation(ped, list(trait(ped$liab), trait(ped$dx)),
                                   stratum = ped$birth_decade, bootstrap = 1000, seed = 1)

The R package runs the same core as Python and returns the same scores bit for bit. Errors are conditions of class pgphenotype_error (with pgphenotype_validation_error and friends) carrying $code and $fields, positions 1-based.

Correctness (PA-FGRS)

  • Rust against NumPy reference cores (fitACE's, verbatim) given the same covariance and order: within 1e-10.
  • Against BioPsyk/PAFGRS's own pa_fgrs on stored fixtures: within 1e-10 (1.1e-15 observed).
  • Every kinship value bit-identical to pedigree-graph's pair_kinship.

Correctness (assortative mating)

  • Against pedsum #13 at 142adf3 on 74 stored cases (28 fixtures, pedsum's own benchmark pedigrees at 10^4 pairs, and 40 random pedigrees), every count, reason, flag and p-value is identical. Closed-form estimates agree within 4.5e-15, and latent ones within 3.2e-10, inside Brent's 1e-7 tolerance. One case differs on float noise in pedsum. The gate report has the details.
  • On pedsum's benchmark pedigrees at 10^4 to 10^6 pairs and up to 12 threads, pg-phenotype's median wall time and peak memory are at most 0.994 and 0.981 of pedsum's (benchmark report).
  • The SciPy and C-library functions pedsum calls are ported bit for bit (ADR 0005).

Design decisions are in docs/adr/; vocabulary in CONTEXT.md.

Development

pixi run test        # rebuilds the extension with test hooks, then pytest (no slow tests)
pixi run test-all    # the same with the slow tests, as CI runs it
pixi run test-rust
pixi run -e r r-test
pixi run test-against-pg ../pedigree-graph   # every suite against a pg checkout

To release a version, follow How to release pg-phenotype.

Metadata

Release files for pg-phenotype 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pg-phenotype 0.2.0
File Size Uploaded Provenance
pg_phenotype-0.2.0.tar.gz 112.0 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for pg-phenotype 0.2.0
File
pg_phenotype-0.2.0-cp313-abi3-win_amd64.whl CPython 3.13 abi3 Windows x86-64 Details
pg_phenotype-0.2.0-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 abi3 Linux glibc 2.17+ x86-64 Details
pg_phenotype-0.2.0-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 abi3 Linux glibc 2.17+ ARM64 Details
pg_phenotype-0.2.0-cp313-abi3-macosx_11_0_arm64.whl CPython 3.13 abi3 macOS 11.0+ ARM64 Details
pg_phenotype-0.2.0-cp313-abi3-macosx_10_12_x86_64.whl CPython 3.13 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.6 MB

Release files / pg_phenotype-0.2.0.tar.gz

Download URL pg_phenotype-0.2.0.tar.gz
Size 112.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4d9af1193f316e83b564dbd4afedf0b700bddca6a4639dfe27b5ed1730c53a72
BLAKE2b-256 checksum
How to use checksums
52a3ce372a452285cc022da8b42a9447fc17e8a07cfef31ddd2abcddc5d7fb93
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 9, 2026.

Transparency log

Release files / pg_phenotype-0.2.0-cp313-abi3-win_amd64.whl

Download URL pg_phenotype-0.2.0-cp313-abi3-win_amd64.whl
Size 672.9 kB
Tags CPython 3.13 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
515499fc9e1ba8f233986d85cf50b0f5296d036c2b6a56b29ba100610c1ed2b1
BLAKE2b-256 checksum
How to use checksums
d1ce24a395ffec93e14c3e2e19f9d1c3b6b1a2ba254024f4600adcf4fc1277bd
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 9, 2026.

Transparency log

Release files / pg_phenotype-0.2.0-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pg_phenotype-0.2.0-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 749.0 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
b2f2a805057abd18c4ded7e3c7407e0ab7e18f88986f825fd962a8b109e09c09
BLAKE2b-256 checksum
How to use checksums
c61504deb5e7d5c38203b6bdb1bd66680cb7f441d70d709913a8216794e32241
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 9, 2026.

Transparency log

Release files / pg_phenotype-0.2.0-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pg_phenotype-0.2.0-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 690.0 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
7d45b4b424eba29f2b3068b15195bbc2fb2345aba14047d2dddec92524be3eef
BLAKE2b-256 checksum
How to use checksums
e7f6587f64969514bf5f9aea0a4368111375a7f3f2e72472e17d2f423ae73aaa
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 9, 2026.

Transparency log

Release files / pg_phenotype-0.2.0-cp313-abi3-macosx_11_0_arm64.whl

Download URL pg_phenotype-0.2.0-cp313-abi3-macosx_11_0_arm64.whl
Size 660.2 kB
Tags CPython 3.13 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8121336f7a64241a272f30a6e6e71dd47954d4d093f9869f7909d70ee1e3247a
BLAKE2b-256 checksum
How to use checksums
6e5c68ba2ee25a71d96cdb3e57dc3f6b5c32dbd54f6e6ecd408cb892c755875c
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 9, 2026.

Transparency log

Release files / pg_phenotype-0.2.0-cp313-abi3-macosx_10_12_x86_64.whl

Download URL pg_phenotype-0.2.0-cp313-abi3-macosx_10_12_x86_64.whl
Size 697.6 kB
Tags CPython 3.13 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
64d01c585a382ea79772b60d5c7032182896cb14b228a01e4f2741131b6135c9
BLAKE2b-256 checksum
How to use checksums
0f2f07e60d9993f5fcd9cef8f5533ea38544ff13807d488e955274be2aa741e5
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 9, 2026.

Transparency log

Security for pg-phenotype 0.2.0

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.

Select from 6 files

Attestation for pg_phenotype-0.2.0.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 9, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page