Skip to main content

Python implementation of core rrBLUP workflows with R-aligned baselines

Project description

pyrrBLUP

Python implementation of core rrBLUP workflows with numeric checks against the R package.

Installation

pip install pyrrblup

Quick Start

import numpy as np
import pandas as pd

from pyrrblup import amat, kin_blup, mixed_solve

markers = pd.DataFrame(
    {
        "m1": [0, 0, 2, 2],
        "m2": [0, 2, 0, 2],
        "m3": [0, 1, 1, 2],
    },
    index=["s1", "s2", "s3", "s4"],
)

kinship = amat(markers).matrix
y = np.array([1.0, 2.0, 1.5, 2.5])
X = pd.DataFrame(
    {
        "Intercept": [1.0, 1.0, 1.0, 1.0],
        "covariate": [0.0, 1.0, 0.5, 1.5],
    }
)
Z = pd.DataFrame(
    {
        "line_A": [1.0, 0.0, 1.0, 0.0],
        "line_B": [0.0, 1.0, 0.0, 1.0],
    }
)
K = np.array(
    [
        [1.0, 0.2],
        [0.2, 1.0],
    ]
)

print(kinship.shape)
fit = mixed_solve(y, X=X, Z=Z, K=K)
print(fit.beta_terms, fit.beta)
print(fit.Vu, fit.Ve)

Run kin_blup from file paths:

from pyrrblup import kin_blup

result = kin_blup("genotype.csv", "phenotype.csv", "loc_BeiJ")
print(result.predictions.head())

mixed_solve follows an rrBLUP-like matrix interface:

result = mixed_solve(y, Z=None, K=None, X=None)

kin_blup accepts either:

  • genotype and phenotype file paths
  • genotype and phenotype pandas.DataFrame objects

Both inputs must be the same kind. Mixed input types are rejected.

Real Data Examples

This repository also includes deterministic subsets cut from the real loc_BeiJ data.

  • examples/minimal_real_data/

    • 32 samples
    • 64 markers
    • intended for quick README-scale runs
  • examples/medium_real_data/

    • 256 samples
    • 512 markers
    • intended for more realistic local demonstrations

Build or refresh the example data:

python scripts/build_examples.py

Run the minimal real-data example:

python examples/minimal_real_data/run_example.py

More detail:

  • docs/mixed_solve.md
  • examples/README.md

Development

Install from source:

pip install -e .

Run the test suite with:

OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 python -m pytest -v

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

pyrrblup-1.0.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

pyrrblup-1.0.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file pyrrblup-1.0.0.tar.gz.

File metadata

  • Download URL: pyrrblup-1.0.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for pyrrblup-1.0.0.tar.gz
Algorithm Hash digest
SHA256 05dbaf8f9df7e6db6374c71f66f209773825f115e8316b1cd23b21b0b768f508
MD5 627cb013bc2b5603ef0cbc71ef7f00a1
BLAKE2b-256 5db107e1817edf8166c32eb2d9e0f754bc1ae56675cd59169df0a046b5304a52

See more details on using hashes here.

File details

Details for the file pyrrblup-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyrrblup-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for pyrrblup-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1059fb4ac7cb5e7ff51ee257a9cd4d73d27f8c821a8e7efec778fc1f6218f7c4
MD5 00098ac930d75e9f0a4c3ab31ebd7846
BLAKE2b-256 ceab607195805055a2fb9bcb948adb9cbf87bac18645263cd79baa15ef65cb6b

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