Skip to main content

Module state_aware_batch_fold

Module state_aware_batch_fold 

Source
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:

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§

CollapsePseudobulks
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).
StateAwareBatchFoldParams

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).