diffsvg.pp.BinnedData#

class diffsvg.pp.BinnedData(genes, Y, intercept_initvals, anchor, condition, condition_categories, n_bsplines, degree, n_bins, B, B_masked, condition_fit, bin_centers, bin_assignment, B_pred, B_pred_masked_0, B_pred_masked_1, condition_pred_0, condition_pred_1, design_matrix='design_matrix', layer=None, n_obs=None, n_obs_grid=None, ss_within=None, sample=None, sample_labels=None, sample_index=None)#

Output of bin_obs, consumed by diffsvg.tl.setup_model.

Everything a per-gene GAM needs that does not depend on the gene, plus the binned targets Y.

Variables:
genes list

Gene order matching Y/intercept_initvals.

Y dict

Per-gene binned expression.

intercept_initvals dict

Per-gene initial value of intercept (mean binned expression at anchor == 0).

condition anchor,

Columns of the design matrix the data was binned on. condition is None when binned without one; every condition-dependent field is then None too.

condition_categories dict | None

{"0": <label>, "1": <label>}, how condition was encoded (string keys for h5ad).

n_bins n_bsplines, degree,

Binning/basis hyperparameters.

condition_fit B, B_masked,

Spline design matrices and encoded condition of the fitted rows.

bin_centers ndarray

Grid (n_bins + 1 points on [0, 1]), also the prediction grid.

bin_assignment ndarray

Per cell, the index of its nearest bin center, -1 without an anchor value.

layer design_matrix,

Where the unbinned data lives, for use_binned=False.

condition_pred_1 B_pred, B_pred_masked_0, B_pred_masked_1, condition_pred_0,

Design matrices for the prediction grid.

sample_index sample, sample_labels,

Only when binned with sample: the column, the samples that have rows, and per row its sample’s index. Rows are then one per (sample, bin).

n_obs ndarray | None

Cells per row. The fitters weight rows by it.

ss_within n_obs_grid,

Only for contiguous bins (window_radius=None): cells per grid point (n_categories x (n_bins + 1)) and per gene the within-bin sum of squares, so a binned fit matches a fit on the cells.

Attributes table#

design_matrix

has_condition

Whether this was binned with a condition, i.e. whether the two-condition models can be fit.

layer

n_obs

n_obs_grid

n_samples

Number of samples that have rows, or None when binned without sample.

sample

sample_index

sample_labels

ss_within

weighted

Whether the bins are contiguous and record the within-bin spread.

genes

Y

intercept_initvals

anchor

condition

condition_categories

n_bsplines

degree

n_bins

B

B_masked

condition_fit

bin_centers

bin_assignment

B_pred

B_pred_masked_0

B_pred_masked_1

condition_pred_0

condition_pred_1

Attributes#

design_matrix: str = 'design_matrix'#
property has_condition#

Whether this was binned with a condition, i.e. whether the two-condition models can be fit.

layer: str | None = None#
n_obs: ndarray | None = None#
n_obs_grid: ndarray | None = None#
property n_samples#

Number of samples that have rows, or None when binned without sample.

sample: str | None = None#
sample_index: ndarray | None = None#
sample_labels: list | None = None#
ss_within: dict | None = None#
property weighted#

Whether the bins are contiguous and record the within-bin spread.

Then a binned fit carries the same information as a fit on the cells. (Overlapping bins record n_obs too, and fits weight rows by it, but their rows share cells.)

genes: list#
Y: dict#
intercept_initvals: dict#
anchor: str#
condition: str | None#
condition_categories: dict | None#
n_bsplines: int#
degree: int#
n_bins: int#
B: ndarray#
B_masked: ndarray | None#
condition_fit: ndarray | None#
bin_centers: ndarray#
bin_assignment: ndarray#
B_pred: ndarray#
B_pred_masked_0: ndarray | None#
B_pred_masked_1: ndarray | None#
condition_pred_0: ndarray | None#
condition_pred_1: ndarray | None#