Genotype-phenotype map container and simulators, Rust-accelerated.
Project description
gpmap-v2
Live interactive tour: gpmap-v2.streamlit.app (source under examples/streamlit/).
A typed, Rust-accelerated container and simulator toolkit for genotype-phenotype maps.
gpmap-v2 is a clean-break rewrite of harmslab/gpmap. It exposes the same conceptual model (a GenotypePhenotypeMap backed by a pandas DataFrame) with a locked schema, vectorized hot paths, and a PyO3 Rust core for the operations that used to be inner Python loops.
Why
- Fast. String-encoded genotypes are replaced with packed
uint8matrices. The encoding step (genotypes_to_binary) runs rayon-parallel in Rust, delivering two orders of magnitude over the pure-Python v1 at L >= 16. - Typed. Full type hints, mypy-checked, strict mode.
- Safe. Cartesian-product enumeration is size-guarded out of the box (
SpaceTooLargeError). No more silent 10^26 allocations. - Stable surface. The container and
encoding_tableschema are locked inSCHEMA.mdfor downstream consumers. - Modern tooling.
uv+maturin+pyproject.toml. Automated releases viapython-semantic-release. OIDC-based PyPI publishing.
Install
pip install gpmap-v2
Or with uv:
uv add gpmap-v2
Python 3.10+. Prebuilt wheels ship for Linux (x86_64, aarch64), macOS (x86_64, aarch64), and Windows (x64).
Quick start
from gpmap import GenotypePhenotypeMap
gpm = GenotypePhenotypeMap(
wildtype="AAA",
genotypes=["AAA", "AAT", "ATA", "TAA", "ATT", "TAT", "TTA", "TTT"],
phenotypes=[0.1, 0.2, 0.2, 0.6, 0.4, 0.6, 1.0, 1.1],
stdeviations=[0.05] * 8,
)
gpm.genotypes # np.ndarray of strings, shape (8,)
gpm.phenotypes # np.ndarray[float64], shape (8,)
gpm.binary_packed # np.ndarray[uint8], shape (8, 3) - the fast path
gpm.binary # np.ndarray of '0'/'1' strings - back-compat accessor
gpm.n_mutations # per-genotype Hamming weight
gpm.encoding_table # pandas DataFrame per SCHEMA.md
gpm.data # pandas DataFrame view for Jupyter
Simulating landscapes
from gpmap.simulate import NKSimulation, MountFujiSimulation
import numpy as np
sim = NKSimulation(
wildtype="AAAA",
mutations={i: ["A", "T"] for i in range(4)},
K=2,
rng=np.random.default_rng(0),
)
sim.phenotypes.shape # (16,)
I/O round-trips
from gpmap import to_json, read_json, to_csv, read_csv
to_json(gpm, "map.json")
gpm2 = read_json("map.json")
to_csv(gpm, "map.csv") # writes map.csv + map.csv.meta.json
gpm3 = read_csv("map.csv")
Public API surface
The full list of stable exports lives in gpmap.__all__. The ones downstream consumers depend on (notably epistasis-v2) are:
GenotypePhenotypeMap,GenotypePhenotypeMap.from_dataframeget_encoding_table,genotypes_to_binary,genotypes_to_binary_packedupper_transform,lower_transformStandardDeviationMap,StandardErrorMapSpaceTooLargeError,SchemaError,UnknownLetterErrorread_csv,read_json,read_pickle,read_excel(andto_*counterparts)- All simulators under
gpmap.simulate
The load-bearing schema contract (column names, dtypes, invariants) is in SCHEMA.md. Breaking changes to that document bump the major version.
Development
git clone https://github.com/lperezmo/gpmap-v2
cd gpmap-v2
uv sync
uv run maturin develop --release
uv run pytest
uv run ruff check python/gpmap tests
A typical dev inner loop after editing Rust:
uv run maturin develop --release && uv run pytest
Consuming from another local project
gpmap-v2 is designed to be consumed as an editable dependency during co-development with sister packages (e.g. epistasis-v2). In the consumer's pyproject.toml:
[tool.uv.sources]
gpmap-v2 = { path = "/absolute/path/to/gpmap-v2", editable = true }
[project]
dependencies = ["gpmap-v2"]
Then uv sync or uv add gpmap-v2 in the consumer. Imports remain import gpmap.
Migration from v1 (harmslab/gpmap)
gpmap-v2 is not wire-compatible with v1. Key differences:
- Distribution name is
gpmap-v2on PyPI; import path is stillgpmap. - The
encoding_tablecolumngenotype_indexhas been renamed tosite_indexto match its actual meaning. The old name is still readable via a deprecated alias. read_dataframeis nowfrom_dataframe.binary_packed(uint8 2D) is exposed alongside the string-formbinary. Prefer the packed form for any hot-path consumer.- JSON files must carry
"schema_version": "1". Legacy files are readable with a warning. upper_transformandlower_transformare now genuinely distinct (v1 had a copy-paste bug where they were identical).stats.unbiased_varhonors theaxiskwarg (v1 ignored it and hardcodedaxis=1).simulate.random_mutation_setno longer mutates the module-level amino-acid list.simulate.MultiPeakMountFujiSimulationpeak search has a retry cap; it raises instead of spinning forever on infeasible constraints.
See CHANGELOG.md for the full list.
Releases
Releases are driven by python-semantic-release on merge to main. Commit messages follow Conventional Commits:
fix: ...-> patchfeat: ...-> minorfeat!: ...orBREAKING CHANGE:footer -> major
CHANGELOG.md, version bumps, Git tags, GitHub Releases, wheel builds, and PyPI uploads all happen automatically.
License
MIT. See LICENSE.
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 Distributions
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 gpmap_v2-1.0.1.tar.gz.
File metadata
- Download URL: gpmap_v2-1.0.1.tar.gz
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73fb66da953561ebc40ab5384c833bb4b58280b9af10c5e03ff79c3a0f2ca22a
|
|
| MD5 |
e0c3dbc8cdf1fa139b8a0e01938ec462
|
|
| BLAKE2b-256 |
f7b90fa14c73422041ed259881dfc00a09393f33b6183072f94e7283462bbd6b
|
File details
Details for the file gpmap_v2-1.0.1-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: gpmap_v2-1.0.1-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 226.1 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f030a65bda2a8fce983a0dcea11eaf0be779ae30ac717243aee65c717340cd70
|
|
| MD5 |
f549528bbee5784d91d3413df1ac694f
|
|
| BLAKE2b-256 |
22b4dfb8c450dae2d8f348756e729854a5e13bbe19eb0f878963792405c7cc9d
|
File details
Details for the file gpmap_v2-1.0.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gpmap_v2-1.0.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 396.0 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8eeee50dc2256108ce9b25c2f5467f93723c86a7fa181763d569f0cdca188b3
|
|
| MD5 |
e760b0db5ec39106299ab8aa60c661e8
|
|
| BLAKE2b-256 |
16243a662bed0f84e8bce5117bf58f9ffa0abcc9ee9c0826501669dce269baac
|
File details
Details for the file gpmap_v2-1.0.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: gpmap_v2-1.0.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 390.1 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54af8bf2f4862171e39c649a1396c03735b40f83fc5fbfbfbcd4c70f95707019
|
|
| MD5 |
10f48fbd975d2b89fdfd06e051383539
|
|
| BLAKE2b-256 |
f9a20f3431dc6c568a5bca1f32aac38540c536762d5e1b6cc97d0d6af81db59b
|
File details
Details for the file gpmap_v2-1.0.1-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: gpmap_v2-1.0.1-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 343.5 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0154ab0585ad388a9b02ad396daa730c61189562405bd7b331b833f4fb234176
|
|
| MD5 |
49551f0c2398be2d74588e01e25a4d09
|
|
| BLAKE2b-256 |
c02357cd2df75298ee4306a8f0e363cbc71a6014f0bf51daf5bdea95dd13d032
|
File details
Details for the file gpmap_v2-1.0.1-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: gpmap_v2-1.0.1-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 348.1 kB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da4b7d400f61f2b9b9f1f71e85874c72343f5a7f521943b471d6814daf0377a9
|
|
| MD5 |
9e95e9f087c3e92ffb0f4e5acc33cf0d
|
|
| BLAKE2b-256 |
7824cbb1320a84d0c4b770d9066dabbd36634aeee48bf22e23d91c2d143b76b9
|