scPyviewer.prepare.prepare_subsample#

scPyviewer.prepare.prepare_subsample(in_path, out_path, n_cells=50000, stratify_by='auto', group_key=None, seed=0, n_top_genes=2000)[source]#

Write a stratified cell subsample of a too-big .h5ad for fast, low-RAM viewing.

Designed for files larger than available RAM (e.g. a 1M+ cell atlas). Opens the input in backed mode and pulls only ~``n_cells`` rows into memory via bounded backed row-indexing, so peak RAM scales with ``n_cells``, not with the file size. The subsample is normalised, annotated (HVG + per-group DE), and written with X in CSC format so the viewer gets instant per-gene column access.

A stratified subsample of 50–100k cells reproduces group composition, embeddings, and per-group expression statistics of the full atlas while staying small enough to explore interactively on a laptop.

Parameters:
  • n_cells (int) – Target number of cells to keep.

  • stratify_by (str or None) – obs column to stratify the subsample by (keeps each group’s share). "auto" picks a cell-type/cluster column; None samples uniformly.

  • group_key (str, optional) – Grouping column for DE / the viewer’s default (auto-detected if omitted).

  • seed (int) – RNG seed for reproducible subsampling.

  • in_path (str)

  • out_path (str)

  • n_top_genes (int)

Return type:

dict[str, Any]