spi_gsea

spi_gsea(
    res,
    genesets,
    test=None,
    type='competitive',
    min_size=5,
    max_size=500,
    n_jobs=1,
)

Gene-set tests on spiDE’s niche results (R spiGSEA).

Asks, for every gene set and every (index cell type, niche cell type) column, whether the set’s genes as a group change with the niche (the pooled test) or change with it differently between the two conditions (the condition-specific test).

Every patient gets a slope for the set: the average of its genes’ niche slopes in that patient, each gene’s slope first divided by the gene’s typical spread of slopes between patients. By default the set’s slope is competitive: the same average over the column’s other tested genes is subtracted, so the test asks whether the set moves more than the typical gene. With type="self-contained" nothing is subtracted. The patients’ set slopes then go through the same pooled and condition tests as the genes’ slopes (test_spide); the patient is the unit of replication, so the correlation between a set’s genes is accounted for without being estimated.

Needs the slopes engine, whose fit holds each patient’s slopes.

Parameters

Name Type Description Default
res SpiDEResults Results of the slopes engine. required
genesets dict of str to list of str Gene sets by name. required
test ('pooled', 'condition') The tests to run; default every test res holds. "pooled"
type ('competitive', 'self-contained') Whether the set’s slope is compared with the other genes’ (competitive) or taken alone (self-contained). "competitive"
min_size int Smallest set size, after intersecting with the genes tested in each index type. 5
max_size int Largest set size, after intersecting with the genes tested in each index type. 500
n_jobs int Workers for the condition test (results do not depend on it). 1

Returns

Name Type Description
pandas.DataFrame One row per (set, index, niche, test): set, index, niche, test, size, estimate, se, t, df, p, q (Benjamini-Hochberg within the (index, niche, test) column), q.global (over every row of that test), n_patients and direction. The estimate is in units of the genes’ between-patient spread. Empty when no set is usable.

See Also

test_spide : The gene-level tests. test_niche_abundance : The between-patient test, which also takes gene sets.

Examples

from spidepy import build_niches, fit_spide, spi_gsea, test_spide
from spidepy.datasets import toy_spide
fit = fit_spide(build_niches(toy_spide(), sigma=30), condition="condition", verbose=False)
res = test_spide(fit)
sets = {"first": ["G1", "G2", "G3", "G4", "G5"], "second": ["G6", "G7", "G8", "G9", "G10"]}
gs = spi_gsea(res, sets)
gs.shape
(24, 14)
gs.columns.tolist()[:5]
['set', 'index', 'niche', 'test', 'size']