Expand description
State-aware batch fold: one fold per (gene × node × batch), on top of δ.
δ (gene × batch) cannot hold the part of a batch effect that depends on the cell state (donor × state), and that part alone keeps batches apart in every local neighbourhood. This module estimates it on coarse nodes that are state-pure and span batches, at pseudobulk sample sizes.
Two kinds of unit, by meaning; keep them apart:
- samples (
sample_units): columns as they are, cells or carried pseudobulks, with the existing sample collapse’s groups. For senna, bge and pinto’s baselines. Entry:estimate_state_aware_batch_fold_over_samples. - cell pairs (
cell_pair_units): pair units built once (build_cell_pair_units: every cell’s reads split once over its pairs and a self-loop), collapsed on their own for the pair δ. A pair’s state (PairStates) is its link state by default (learned from the pair after its cells’ fold is divided out,link_state_pair_fold), or its endpoint states (placed on the samples kind’s tree by its endpoints). For link-based methods, where the pair is the unit. Entry:collapse_cell_pairs_and_estimate_state_aware_batch_fold; it needs the samples kind’s result first.
Both read the data once, into per-pseudobulk sums
([pseudobulk_sums]); everything after runs on those sums: the tree over
the coarsest sample groups and its batch-spanning cut
(coarse_group_ward_tree, coarsening, bottom up), local swaps of whole
pseudobulks between nodes ([local_swap_refinement], uncoarsening, top
down), and the fold matched pseudobulk to pseudobulk across batches within
each node (cross_batch_matched_fold). The samples kind estimates the
fold top down along the tree, each node a residual over its parent’s
([top_down_fold]); the cell-pair kind matches once per pair node (top
down over pair keys did worse on the sims, 2026-11-21).
If not even the root spans enough batches, every unit keeps δ, with a warning; the estimate never fails for that reason.
Re-exports§
pub use cell_pair_units::build_cell_pair_units;pub use cell_pair_units::collapse_cell_pairs_and_estimate_state_aware_batch_fold;pub use cell_pair_units::split_cell_reads_over_pair_units_without_double_counting;pub use cell_pair_units::CellPairBatchFold;pub use cell_pair_units::CellPairFoldParams;pub use cell_pair_units::CellPairUnits;pub use cell_pair_units::PairNodeOfEndpointNodes;pub use cell_pair_units::PairStateModel;pub use cell_pair_units::PairStates;pub use coarse_group_ward_tree::CoarseGroupWardTree;pub use coarse_group_ward_tree::EXACT_WARD_MAX_GROUPS;pub use cross_batch_matched_fold::MatchingCoordinates;pub use cross_batch_matched_fold::StateAwareBatchFold;pub use link_state_pair_fold::cell_predicted_pair_log_fold;pub use link_state_pair_fold::LinkStateDecomposition;pub use node_compositions::place_by_composition;pub use node_compositions::CompositionPlacer;pub use sample_units::estimate_state_aware_batch_fold_over_samples;pub use sample_units::SampleBatchFold;pub use sample_units::UnseenPlacement;
Modules§
- cell_
pair_ units - Cell-pair kind: the state-aware batch fold over cell pairs, for the link-based methods (pinto’s lc, dsvd, cage), where the pair is the unit.
- coarse_
group_ ward_ tree - The tree the state-aware batch fold cuts its nodes from: Ward linkage over the sample collapse’s coarsest groups (their δ-adjusted pooled profiles), and the cut that splits a node only where both children span batches.
- cross_
batch_ matched_ fold - The fold itself, for either kind of unit, on the pseudobulk sums: within each node, every pseudobulk (pb sample, or pb pair) is matched to its nearest pseudobulks of every other batch (in a batch-corrected projection), and the node’s fold for a batch is its base-adjusted sum over the matched counterfactual sum, centred over the node’s batches, on top of the node’s base (δ, or its parent’s fold).
- link_
state_ pair_ fold - Cell-pair kind, link states (
super::cell_pair_units::PairStates::LinkStates): a pair’s state learned from the pair itself, not from its endpoints. - node_
compositions - Node compositions, and scoring counts against them: what the local swaps move pseudobulks by, and what places a unit the fit never saw (predict, impute) on a node or a link state.
- sample_
units - Samples kind: the state-aware batch fold over columns as they are (cells,
or carried pseudobulks), from the sample collapse’s groups and δ. senna,
bge and pinto’s baselines read this kind; the cell-pair kind
(
super::cell_pair_units) builds its pair nodes on this kind’s tree.
Structs§
- Collapse
Pseudobulks - A collapse’s groups, per unit: the finest (each in one batch, the pseudobulks the fold matches) and the coarsest (each in one batch, the pseudobulks a node’s size is counted in; the tree’s leaves for samples).
- State
Aware Batch Fold Params
Constants§
- DEFAULT_
FOLD_ KNN - Nearest pseudobulks drawn from each other batch for a counterfactual.
- DEFAULT_
FOLD_ PSEUDO_ COUNT - Pseudo-count on both sides of a node’s fold ratio (shrinks thin genes to 1).