Perturb-seq guide assignment — Python bindings to the kaichi-core Rust library
Project description
kaichi
CRISPR guide assignment for Perturb-seq.
A Perturb-seq experiment delivers a sparse cells × guides UMI count matrix
from Cell Ranger. Before any downstream analysis, you have to decide which
guide each cell actually received — separating real perturbations from
ambient/background guide reads. kaichi runs that decision step.
The Rust core ships ten assignment models (the count- and proportion-mixture methods used by crispat, plus simple UMI/ratio thresholds), fits guide-level EM in parallel, and returns zero-copy Arrow output. The same engine backs the CLI if you'd rather drive it from a shell pipeline.
Install
pip install kaichi
Wheels are available for Linux x86_64, macOS arm64, and macOS x86_64 (Python ≥ 3.11).
Quick start
import kaichi
# One-shot assign — returns an AnnData
adata = kaichi.assign("gRNA_counts.h5ad", model="poisson_gauss")
# Two-stage: fit once, threshold multiple times
scores = kaichi.score("gRNA_counts.h5ad", model="poisson_gauss")
strict = kaichi.decide(scores, min_confidence=0.9) # pyarrow.RecordBatch
lenient = kaichi.decide(scores, min_confidence=0.7) # reuses cached scores
adata is a standard anndata.AnnData you can drop into a scanpy workflow:
>>> adata
AnnData object with n_obs × n_vars = 21977 × 86
obs: 'guide_identity', 'assignment_confidence', 'n_guides_detected', 'is_unassigned', 'is_multi_infected'
uns: 'kaichi'
layers: 'assigned'
>>> adata.obs.head(3)
guide_identity assignment_confidence is_unassigned is_multi_infected
cell_barcode
AAACCCAAGAAA... gRNA_42 0.987 False False
AAACCCAAGAAC... NaN True False
AAACCCAAGAAG... gRNA_07 0.913 False False
API
kaichi.assign(path, model="poisson_gauss", *, min_confidence=None, quantile=None, n_jobs=None)
Fit and assign in one step. Returns an anndata.AnnData with:
.X— raw UMI counts (sparse CSR, uint32).layers["assigned"]— binary sparse CSR, 1 where assigned.obs— per-cell assignment columns (see table below).uns["kaichi"]— provenance (model,model_params,version)
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
str |
— | Path to an .h5ad guide-count file |
model |
str |
"poisson_gauss" |
Assignment model (see table below) |
min_confidence |
float | None |
None |
Override posterior threshold |
quantile |
float | None |
None |
Top-fraction threshold for the quantiles model |
n_jobs |
int | None |
None |
Worker threads; None = half of logical cores |
kaichi.score(path, model="poisson_gauss", *, n_jobs=None)
Run the EM fitting stage only; return a kaichi.ScoreResult. Raises ValueError for
single-stage models (umi, ratio, max) — use assign() for those.
kaichi.decide(scores, min_confidence=0.9)
Apply a confidence threshold to a cached ScoreResult. Returns a
pyarrow.RecordBatch with one row per cell. Call multiple times with different
thresholds without re-fitting.
.obs / output columns
| Column | Type | Notes |
|---|---|---|
cell_barcode |
string | |
guide_id |
string | null if unassigned |
umi_count |
uint32 | null if unassigned |
assignment_confidence |
float32 | posterior probability or proportion; null if unassigned |
is_unassigned |
bool | |
is_multi_infected |
bool | cell passes threshold for more than one guide |
n_guides_detected |
uint8 | guides above threshold, regardless of final assignment |
is_unassigned and is_multi_infected are mutually exclusive.
Models
If you're not sure which to use, poisson_gauss (the default) is a sensible
starting point for any UMI-based guide library. Switch to neg_binomial if
the library is noticeably overdispersed (high variance for cells at similar
sequencing depth), and to binomial if the experiment is dominated by total
guide UMIs rather than per-guide counts.
| Model | Type | When to use |
|---|---|---|
umi |
Threshold | Fast baseline; assign any guide ≥ N UMIs |
max |
Deterministic | Assign the single highest-count guide; ties → unassigned |
ratio |
Threshold | Assign if top guide UMIs / total UMIs > fraction |
poisson_gauss |
EM mixture | Good default; Poisson background, log-normal signal |
poisson |
EM mixture | Depth-normalised Poisson mixture |
neg_binomial |
EM mixture | Like poisson but handles overdispersed counts; recommended for noisy libraries |
binomial |
EM mixture | Models guide fraction (count / total guide UMIs) |
beta2 |
EM mixture | 2-component Beta mixture on per-cell max guide proportion |
beta3 |
EM mixture | 3-component Beta mixture; separates low / intermediate / high |
quantiles |
Rank-based | Assign top Q% of cells per guide by proportion |
Mixture models fit one model per guide in parallel and assign cells where the
posterior probability of the signal component exceeds min_confidence (default 0.8
for count-based models, 0.5 for Beta models).
Input format
An .h5ad file with:
obs_names— cell barcodesvar_names— guide IDsX— sparse count matrix (cells × guides)
This is the crispr_gene_expression feature-barcode matrix produced by Cell Ranger.
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 kaichi-0.2.0.tar.gz.
File metadata
- Download URL: kaichi-0.2.0.tar.gz
- Upload date:
- Size: 91.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
624c1389f7e5f9a4a493aa2aef0198b3270981c2748c9332c2b95095063ec7f8
|
|
| MD5 |
f4a277ac07aba783a22ccd9c58f7fcf4
|
|
| BLAKE2b-256 |
2f28fd6d7dd7a1a93498105ef508cc898fc3ac4a79f5fdc4ef9272f763e63600
|
Provenance
The following attestation bundles were made for kaichi-0.2.0.tar.gz:
Publisher:
release.yml on atchox/kaichi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kaichi-0.2.0.tar.gz -
Subject digest:
624c1389f7e5f9a4a493aa2aef0198b3270981c2748c9332c2b95095063ec7f8 - Sigstore transparency entry: 1619158190
- Sigstore integration time:
-
Permalink:
atchox/kaichi@bcdcc7840d91c683c615202daa9265eae74ead3f -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/atchox
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bcdcc7840d91c683c615202daa9265eae74ead3f -
Trigger Event:
push
-
Statement type:
File details
Details for the file kaichi-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: kaichi-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.11+, 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 |
29c2ca408aefd9226ede335ef786c3a08f3baa7cf57b09f8b01da990ddb0ed54
|
|
| MD5 |
7c44bf65e35d70b1507b6cdc12d5774a
|
|
| BLAKE2b-256 |
6896eb352deab41dc7b386b0e63061f54e3d3f3a8b5347338e90e18bd549165a
|
Provenance
The following attestation bundles were made for kaichi-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on atchox/kaichi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kaichi-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
29c2ca408aefd9226ede335ef786c3a08f3baa7cf57b09f8b01da990ddb0ed54 - Sigstore transparency entry: 1619158941
- Sigstore integration time:
-
Permalink:
atchox/kaichi@bcdcc7840d91c683c615202daa9265eae74ead3f -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/atchox
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bcdcc7840d91c683c615202daa9265eae74ead3f -
Trigger Event:
push
-
Statement type:
File details
Details for the file kaichi-0.2.0-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: kaichi-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.11+, 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 |
89a62ed60f0df80b02864047e0286fc85cc75773bd1b78695d0bd54c1fac91bd
|
|
| MD5 |
470d137fbf0b2d92b3df47cd138e8278
|
|
| BLAKE2b-256 |
53d6a762b5ed5bda60da31c8a9ab7867e196f7f96e7244dd86149ea986dd9e78
|
Provenance
The following attestation bundles were made for kaichi-0.2.0-cp311-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on atchox/kaichi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kaichi-0.2.0-cp311-abi3-macosx_11_0_arm64.whl -
Subject digest:
89a62ed60f0df80b02864047e0286fc85cc75773bd1b78695d0bd54c1fac91bd - Sigstore transparency entry: 1619159791
- Sigstore integration time:
-
Permalink:
atchox/kaichi@bcdcc7840d91c683c615202daa9265eae74ead3f -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/atchox
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bcdcc7840d91c683c615202daa9265eae74ead3f -
Trigger Event:
push
-
Statement type:
File details
Details for the file kaichi-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: kaichi-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.11+, 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 |
bbb657681ed3d96403b3ae3e8b7795d63a28cef6dbcee25bd620eaa7a947b8ab
|
|
| MD5 |
fcb07293f8fcd8c1b83f792147c1fa42
|
|
| BLAKE2b-256 |
4ac66233d4087026f9d8b12ba072d50b2f066019a7d75bfe1c242a934475c05b
|
Provenance
The following attestation bundles were made for kaichi-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on atchox/kaichi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kaichi-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl -
Subject digest:
bbb657681ed3d96403b3ae3e8b7795d63a28cef6dbcee25bd620eaa7a947b8ab - Sigstore transparency entry: 1619160309
- Sigstore integration time:
-
Permalink:
atchox/kaichi@bcdcc7840d91c683c615202daa9265eae74ead3f -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/atchox
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bcdcc7840d91c683c615202daa9265eae74ead3f -
Trigger Event:
push
-
Statement type: