This page holds the details that are useful when building on top of embpy, but too heavy for the GitHub README.
For per-function documentation, see the API reference.
This repository contains the public embpy Python package:
| Package | Purpose | Source |
|---|---|---|
embpy |
Embeddings, resolvers, annotations, preprocessing, plotting, and analysis utilities. | src/embpy/ |
BioEmbedder.embed(...) is the preferred user-facing embedding entry point.
It accepts direct identifiers, pandas objects, AnnData objects, and supported
input files such as CSV, TSV, and Parquet.
The output can be:
output="anndata"for scverse workflowsoutput="table"for embedding tablesoutput="payload"for canonical IDs, matrix, aliases, and provenance
Generated embeddings are never placed in .X.
| Entity type | Default AnnData location | Notes |
|---|---|---|
| genes | .varm |
Feature-aligned by default, canonicalized to gene IDs when possible. |
| gene perturbation labels | .obsm |
Set is_perturbation=True when genes are row-level action labels. |
| proteins | .varm |
Feature-aligned, usually keyed by UniProt/canonical protein IDs. |
| molecules | .obsm |
Observation-aligned, canonical SMILES used when possible. |
| text and sequences | .obsm |
Observation-aligned raw inputs. |
| cells | .obsm |
One vector per cell. |
| perturbation morphology/actions | .uns |
Entity-aligned payload; materialize to .obsm only when a downstream model needs one vector per observation. |
For gene perturbation/action embeddings, attach directly to rows:
adata = embedder.embed(
adata,
entity_type="gene",
obs_column="perturbation",
id_type="symbol",
model="esm2_650M",
output="anndata",
is_perturbation=True,
key="X_pert_esm2_650M",
)For entity-aligned perturbation payloads, such as morphology embeddings,
keep the source-of-truth table in .uns and materialize a row-aligned
matrix when needed:
from embpy.io import materialize_perturbation_obsm
adata = materialize_perturbation_obsm(
adata,
embedding_key="X_pert_esm2_650M",
perturbation_key="perturbation",
obsm_key="X_pert_esm2_650M",
)BioEmbedder.embed(...) normalizes inputs before model inference:
- Python lists, tuples, NumPy arrays, and pandas Series are treated as identifier collections.
- Multi-column pandas DataFrames require
identifier_column=.... - AnnData identifiers can come from
.obs_names,.var_names,obs_column=..., orvar_column=.... - File inputs can be CSV, TSV, or Parquet.
Canonical biological IDs are used as primary keys where possible. Original symbols, names, SMILES, and user inputs are preserved as aliases and metadata.
Cell embeddings go through the single-cell preprocessing policy owned by
embpy.pp.
Use:
embedder.embed(
adata,
entity_type="cell",
model="pca",
preprocessing="auto",
output="anndata",
)preprocessing="auto" resolves the appropriate preparation for the requested
model. The policy can preserve raw counts, create .layers["counts"], create
.layers["log_normalized"], select highly variable genes, and record the
resolved preprocessing choices in .uns["embpy_cell_embeddings"].
Users can still override the important knobs:
n_top_genesselect_hvgtarget_sumlog_transformscalemin_genesmin_cellsmax_pct_mitopca_use_hvg
Pixi is the recommended development path:
pixi install -e default
pixi run -e default verifyCommon environments:
pixi install -e default # CPU/dev
pixi install -e mps # Apple Silicon/PyTorch MPS
pixi install -e gpu # Linux CUDA GPU
pixi install -e boltz # Boltz-specific examplesPip users can start with:
pip install embpyOptional model families may require extra dependencies. Large GPU models should be installed in an environment with compatible PyTorch/CUDA wheels.
The active model registry depends on the installed optional dependencies.
Use:
from embpy import BioEmbedder
embedder = BioEmbedder(device="auto")
embedder.list_available_models()for the model keys available in the current environment.
The registry covers DNA, protein, molecule, single-cell, morphology, text, and structure-backed models.
High-level annotation helpers live in embpy.tl:
from embpy import tl
tl.annotate_gene_perturbations(adata, column="gene")
tl.annotate_proteins(adata, column="protein")
tl.annotate_molecules(adata, column="smiles")Resource-level annotators live in embpy.resources:
from embpy.resources import CellLineAnnotator
annotator = CellLineAnnotator()
annotator.annotate_adata(adata, column="cell_line")Analysis helpers live in embpy.tl; plotting helpers live in embpy.pl.
Common functions include:
tl.compute_similaritytl.compute_distance_matrixtl.compute_knn_overlaptl.rank_perturbationspl.plot_embedding_spacepl.knn_overlappl.cross_embedding_correlationpl.embedding_norms
See the API reference for the full list.
Keep user-facing examples in the README and notebooks centered on
BioEmbedder.embed(...). Lower-level helpers may remain public and documented,
but tutorials should introduce them only when they clarify a real workflow.