Skip to main content

kaichi

PyPI Python License

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 barcodes
  • var_names — guide IDs
  • X — sparse count matrix (cells × guides)

This is the crispr_gene_expression feature-barcode matrix produced by Cell Ranger.

Metadata

Release files for kaichi 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 kaichi 0.2.0
File Size Uploaded Provenance Actions
kaichi-0.2.0.tar.gz 91.0 kB With provenance Details for kaichi-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for kaichi 0.2.0
File Interpreter ABI Platform Actions
kaichi-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for kaichi-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
kaichi-0.2.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for kaichi-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
kaichi-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for kaichi-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 9.2 MB

Release files / kaichi-0.2.0.tar.gz

Download URL kaichi-0.2.0.tar.gz
Size 91.0 kB
Tags Source
SHA-256 checksum
How to use checksums
624c1389f7e5f9a4a493aa2aef0198b3270981c2748c9332c2b95095063ec7f8
BLAKE2b-256 checksum
How to use checksums
2f28fd6d7dd7a1a93498105ef508cc898fc3ac4a79f5fdc4ef9272f763e63600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 24, 2026.

Transparency log

Release files / kaichi-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL kaichi-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.1 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
29c2ca408aefd9226ede335ef786c3a08f3baa7cf57b09f8b01da990ddb0ed54
BLAKE2b-256 checksum
How to use checksums
6896eb352deab41dc7b386b0e63061f54e3d3f3a8b5347338e90e18bd549165a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 24, 2026.

Transparency log

Release files / kaichi-0.2.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL kaichi-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Size 2.5 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
89a62ed60f0df80b02864047e0286fc85cc75773bd1b78695d0bd54c1fac91bd
BLAKE2b-256 checksum
How to use checksums
53d6a762b5ed5bda60da31c8a9ab7867e196f7f96e7244dd86149ea986dd9e78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 24, 2026.

Transparency log

Release files / kaichi-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL kaichi-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 2.6 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
bbb657681ed3d96403b3ae3e8b7795d63a28cef6dbcee25bd620eaa7a947b8ab
BLAKE2b-256 checksum
How to use checksums
4ac66233d4087026f9d8b12ba072d50b2f066019a7d75bfe1c242a934475c05b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 24, 2026.

Transparency log

Security for kaichi 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 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for kaichi-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 May 24, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

4 release files Full provenance

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