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, percategorylevel.For a grid of
n_bins+ 1 centers on[0, 1], all cells withinwindow_radiusof a center are averaged, separately for every level ofcategory. The grid does not depend on the gene, so allgenesare binned at once.- Parameters:
- adata
Annotated data matrix.
- genes
Gene name(s) to bin.
- anchor
Column in
design_matrixholding the ordering coordinate, in[0, 1].- category
Column in
design_matrixto stratify by (e.g. the condition), also the column name in the output.Nonebins alonganchoronly, as a single group.- design_matrix default:
'design_matrix' adata.obsmkey of a data frame holdinganchorandcategory.- n_bins default:
50 Number of bins spanning
[0, 1]; the grid hasn_bins+ 1 centers.- window_radius default:
None Half-width of the averaging window. Windows wider than
0.5 / n_binsoverlap.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 ofadata.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 fromavg_var) whenwindow_radius=None.