diffsvg.pp.bin_counts#

diffsvg.pp.bin_counts(adata, genes, anchor, category, design_matrix='design_matrix', n_bins=50, window_radius=None, layer=None, drop_empty_bins=True)#

Average expression of one or more genes in windows along anchor, per category level.

For a grid of n_bins + 1 centers on [0, 1], all cells within window_radius of a center are averaged, separately for every level of category. The grid does not depend on the gene, so all genes are binned at once.

Parameters:
adata

Annotated data matrix.

genes

Gene name(s) to bin.

anchor

Column in design_matrix holding the ordering coordinate, in [0, 1].

category

Column in design_matrix to stratify by (e.g. the condition), also the column name in the output. None bins along anchor only, as a single group.

design_matrix default: 'design_matrix'

adata.obsm key of a data frame holding anchor and category.

n_bins default: 50

Number of bins spanning [0, 1]; the grid has n_bins + 1 centers.

window_radius default: None

Half-width of the averaging window. Windows wider than 0.5 / n_bins overlap. None (default) makes them contiguous: each cell counts once, in the bin of its nearest center.

layer default: None

If given, bin adata.layers[layer] instead of adata.X.

drop_empty_bins default: True

Drop (category, bin) rows without cells (the same rows for every gene).

Returns:

dict[str, pandas.DataFrame] One data frame per gene with columns [category, anchor, "window_start", "window_end", "n_obs", "avg_var"], plus "ss_var" (the within-bin sum of squared deviations from avg_var) when window_radius=None.