Skip to main content

crispyx

License: Modified MIT Python 3.10+ PyPI PyPI Downloads Tests Documentation

Motivation

Genome-wide CRISPR screens routinely produce datasets with hundreds of thousands of cells and tens of thousands of genes. Standard single-cell analysis toolkits (Scanpy, Pertpy) load the entire count matrix into memory, requiring large RAM allocations and often making routine workflows impractical on laptops or shared compute nodes.

crispyx runs quality control, normalisation, pseudo-bulk aggregation, differential expression (t-test, Wilcoxon, NB-GLM with covariates, covariate-adjusted residual effects), control checks and PCA/KNN on screens stored as .h5ad files, streaming from disk with a peak memory you can predict from the file's shape, so that million-cell screens run on a laptop or a cluster node. Each function's peak, and what in it still grows with the screen, is in the memory model. The API mirrors Scanpy. It starts from an .h5ad file; it does not read raw sequencing outputs, and it is not a general single-cell toolkit.

Documentation: crispyx.readthedocs.io — installation, quick start, tutorials and API reference.

Installation

pip install crispyx

For development (editable install with all extras):

git clone https://github.com/jinhongdu-lab/crispyx.git
cd crispyx
pip install -e ".[test,benchmark,docs]"

crispyx supports Python 3.10–3.12 and is compatible with recent releases of the scientific stack, including anndata >= 0.13 and pandas >= 3.0 (where string metadata is stored on disk using the nullable-string encoding).

Quick start

import crispyx as cx

# Open dataset without loading into memory
adata = cx.read_h5ad_ondisk("data/demo_benchmark.h5ad")

# Quality control with adaptive thresholds
adata = cx.pp.qc_summary(
    adata,
    perturbation_column="perturbation",
    min_genes=5,
    min_cells_per_perturbation=5,
)

# Differential expression
adata = cx.tl.rank_genes_groups(
    adata,
    perturbation_column="perturbation",
    method="wilcoxon",  # or "t-test", "nb_glm"
)

# Access results
print(adata.uns["rank_genes_groups"])
de_results = adata.uns["rank_genes_groups"].load()

For the full workflow (normalisation, PCA, pseudo-bulk, NB-GLM, LFC shrinkage, plotting, data preparation utilities), see the Quick start, which links each step's guide page, and the tutorial. Covariate adjustment compares the ways to adjust for batches, donors and lines.

Features

  • Streaming QC & preprocessing – Filter cells, perturbations, and genes; normalise and log-transform; select highly variable genes (seurat_v3/mean_dispersion, control-cells-only by default); CSC-aware streaming with format_mismatch_policy; streamed from disk, except that qc_summary reads a file into memory when it fits well within the memory budget
  • Subsampling & downsampling – Stratified or cluster-sampled cell subsampling (cx.pp.subsample, exact count or proportion per stratum, drop or keep small groups) and dependency-free per-cell count thinning (cx.pp.downsample_counts, the streaming equivalent of scanpy.pp.downsample_counts) for aligning dataset scale and sequencing depth before comparing screens
  • Pseudo-bulk aggregation – Absolute profiles over multiple grouping columns (for example, perturbation × batch), strict count sums or mean log1p expression, optional deterministic bootstrap sampling, and explicit within-batch effect calculation
  • Differential expression – t-test, Wilcoxon rank-sum (including batch-stratified / van Elteren test via batch_column), negative binomial GLM with covariates and apeGLM LFC shrinkage, and a fixed-offset NB test for many small perturbations against a large, stratified control set (cx.tl.nb_offset_test); multi-core support and adaptive memory management; per-condition low-expression filtering to exclude genes that are near-zero in both groups
  • Covariate-adjusted effects – cx.tl.residual_effects (Feng et al., 2026) fits each gene to covariates such as donor, lane or batch on the control cells only, and takes a perturbation's effect as the mean residual of its cells. Unlike the NB GLM, which fits the covariates on counts jointly with each perturbation, the control fit is shared by every perturbation, so a perturbation's own cells cannot shift its covariate adjustment, and all perturbations come from one streaming pass. On a 1.16-million-cell screen it reproduces the published effects and significance calls in under a minute.
  • Storage-format aware – Gene-streaming functions (wilcoxon_test, batch_process) can convert a CSR source once to a temporary, memory-bounded CSC copy beside the output instead of re-reading the whole matrix once per gene chunk; format_mismatch_policy="auto" (the default) measures the source's read throughput and does so only when the re-reads would really cost more than the conversion, so a small local file is streamed as-is and a large one on a network filesystem is converted; convert_to_csc/convert_to_csr honour memory_limit_gb and preserve the value dtype
  • Dimension reduction – Streaming PCA (exact from one gene × gene matrix, or incremental) sized from memory_limit_gb, its scores written to the file a chunk at a time; KNN and UMAP on the embedding in memory
  • Scanpy-compatible API & plotting – Familiar cx.pp, cx.pb, cx.tl, and cx.pl namespaces; Scanpy-style rank genes plots, volcano, MA, PCA, UMAP, QC summaries, and overlap heatmaps
  • Data preparation utilities – Edit backed metadata without loading X; normalise perturbation labels and take target genes out of guide names (target_pattern); assign guides from guide-capture counts (cx.pp.assign_guides); recover integer counts from data published as log1p-normalised values (cx.pp.recover_counts); sum the rows of a gene split over several (cx.pp.collapse_genes); concatenate multi-file screens; check a file for the mistakes that mislead an analysis (cx.pp.check_data); auto-detect metadata columns
  • HPC-ready – Resume/checkpoint for long-running jobs; configurable memory_limit_gb
  • Disk-aware – Estimates and warns about scratch-disk usage before large writes or CSC/CSR conversions, and cx.estimate_disk_usage(...) answers "how much disk will this need?" up front; the memory savings above assume the machine has enough free disk for streaming intermediates and output files

Performance

Across 12 public CRISPR screens, crispyx completes every dataset where Scanpy, Pertpy/PyDESeq2 and edgeR run out of memory or time, with t-test and Wilcoxon results matching Scanpy to Pearson r > 0.999 and NB-GLM statistics agreeing with PyDESeq2 given the same size factors (z correlation 0.997–0.9999):

Benchmark results across 12 CRISPR screens: (a) dataset sizes, (b) completion status by method, (c) concordance with Scanpy, (d) runtime scaling, (e) peak memory scaling

Running on HPC

crispyx reads its data from disk instead of loading it into memory, so where the files live matters as much as cores or memory. Clusters usually offer several kinds of storage:

  • A parallel filesystem (Lustre, GPFS, BeeGFS): large and fast for big sequential reads, but slow for small random reads.
  • Node-local disk ($TMPDIR or /tmp on the compute node): fast for random access, but visible to one node only and usually wiped when the job ends.
  • Home and project directories: often small and not meant for heavy I/O.

Steps that stream a file chunk by chunk, such as QC, normalisation, residual_effects and pseudo-bulk, run well on a parallel filesystem. Steps that read or write cells and genes in scattered order do not: sorting cells (sort_by_perturbation), converting between CSR and CSC, nb_glm_test on a file that is not sorted by perturbation, and streaming a matrix along the axis it is not stored by. For those, copy the input to node-local disk, write outputs and temporary files there too (output_path, TMPDIR), and copy the results back before the job ends:

cp /parallel-fs/project/screen.h5ad "$TMPDIR"/
python analysis.py --input "$TMPDIR/screen.h5ad" --output "$TMPDIR/results"
cp -r "$TMPDIR/results" /parallel-fs/project/

Acknowledgements

crispyx builds on the foundational work of Scanpy (Wolf et al., 2018), Pertpy, PyDESeq2 (Muzellec et al., 2023), and AnnData (Virshup et al., 2024). We gratefully acknowledge these projects for establishing the single-cell analysis ecosystem in Python; crispyx extends their APIs and algorithmic designs to enable memory-efficient, streaming computation for large-scale CRISPR screen datasets. residual_effects implements the covariate-adjusted effect estimator of Feng et al. (2026, doi:10.1016/j.xgen.2025.101076).

Contributing

Suggestions, bug reports, and contributions are welcome! Please open an issue or submit a pull request.

License

crispyx is released under a Modified MIT License. If you use crispyx in research, please cite it — see CITATION.cff.

Metadata

Release files for crispyx 0.2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crispyx 0.2.9
File Size Uploaded Provenance Actions
crispyx-0.2.9.tar.gz 564.2 kB With provenance Details for crispyx-0.2.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for crispyx 0.2.9
File Interpreter ABI Platform Actions
crispyx-0.2.9-py3-none-any.whl Python 3 none any Details for crispyx-0.2.9-py3-none-any.whl

Total release size: 951.6 kB

Release files / crispyx-0.2.9.tar.gz

Download URL crispyx-0.2.9.tar.gz
Size 564.2 kB
Tags Source
SHA-256 checksum
How to use checksums
de9fcdac835c00afbe64f1f7607f05abd18f2b21ba78ed9f822ca32cc854d7c8
BLAKE2b-256 checksum
How to use checksums
096de2b8db93534ede7686749726b611814b7401988b8cb7ee227668230e05de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 23, 2026.

Transparency log

Release files / crispyx-0.2.9-py3-none-any.whl

Download URL crispyx-0.2.9-py3-none-any.whl
Size 387.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae8d0e0410a7c7288a27a58cbf95af0881764afb93ab7e3c45234635c14f7407
BLAKE2b-256 checksum
How to use checksums
274538b677ee4829bfdb2974982732e38fdf799b74bac8db96185211c1b622fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 23, 2026.

Transparency log

Security for crispyx 0.2.9

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for crispyx-0.2.9.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 Nov 23, 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.9 This release

2 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