diffsvg.tl.gene_set_test#

diffsvg.tl.gene_set_test(model_setup, gene_sets, *, summary=('level', 'slope'), method='rotation', n_rotations=9999, min_size=3, random_state=0)#

Test whether the genes of a set change together between the conditions, with slides as replicates.

Every slide contributes one level and one slope per gene (replicate_summaries), so the slide, not the cell, is the unit of replication. method="rotation" (default) is a self-contained rotation test (Wu et al. 2010, as limma’s roast): per gene a two-sample t, per set their (weighted) mean, compared with random rotations of the slides’ residuals. Rotating all genes together keeps their correlation, so sets of co-regulated genes are not overconfident. method="ulm" runs decoupler’s univariate linear model on the per-gene t values instead (a competitive test; needs pip install decoupler).

On random splits of the slides of three datasets the rotation test called 1 to 4% of sets at p < 0.05; sets of 10 genes with a 2% level shift were detected in 80% of cases, where single genes were not.

Parameters:
model_setup

setup_model’s output for data binned with sample.

gene_sets

{name: [genes]}, or a decoupler network (source, target and optionally weight columns, e.g. decoupler.op.hallmark()). Signed weights (e.g. PROGENy) make the set statistic a weighted mean, so genes expected to go down count with a negative sign.

summary default: ('level', 'slope')

Which per-slide summaries to test: "level", "slope" or both.

method default: 'rotation'

"rotation" or "ulm".

n_rotations default: 9999

Rotations for the rotation test; the smallest p-value is 1 / (n_rotations + 1).

min_size default: 3

Sets with fewer genes in the data are skipped.

random_state default: 0

Seed for the rotations.

Returns:

pandas.DataFrame One row per set and summary: size, mean_t (positive: higher, or steeper, in condition 1), and for the rotation test pval_up, pval_down, pval_mixed (genes changing in either direction), pval (two-sided) and pval_adj (Benjamini-Hochberg over the sets of each summary). For method="ulm", mean_t is decoupler’s score and pval its p-value as decoupler returns it (already adjusted across the sets).