pl.plot_patient_effects

pl.plot_patient_effects(
    x,
    index,
    niche=None,
    covariates=None,
    type='association',
    colour_by=None,
    n_pcs=5,
    ntop=500,
)

What the patient intercepts, or slopes, capture (R plotPatientEffects).

Every index type’s shared fit gives each patient an intercept per gene (patient_intercepts): they absorb every difference between patients (the condition’s main effect, composition, batch), which is what makes the niche slopes within-patient slopes. This relates the principal components of the patients’ gene-centred intercepts to patient covariates: every patient-level obs column, plus the patients’ index cells (log10), mean log library size, and mean log1p density of each tested niche type. Each tile is the adjusted R^2 of a component on a covariate.

Structure in the intercepts is harmless to the tests: it is absorbed by design. With niche, the same analysis runs on the patients’ slopes on that niche (each gene’s slopes scaled by its between-patient spread, as in spi_gsea): a slide or batch that organises the slopes can reach the condition test, and belongs in strata.

Parameters

Name Type Description Default
x SpiDEResults or SpiDEFit The results (or the fit) whose patients are analysed. required
index str The index cell type. required
niche str None (the intercepts) or a niche type (its slopes; slopes engine). None
covariates sequence of str None (all) or the covariates to show, by the names in the plot. None
type ('association', 'pca') The R^2 tiles, or the first two components coloured by colour_by. "association"
colour_by str For type="pca": a covariate (default the condition, else the first). None
n_pcs int The number of components shown. 5
ntop int The number of genes, most expressed first, whose values enter the components (a gene with any non-finite value is left out). 500

Returns

Name Type Description
matplotlib.figure.Figure The R^2 tiles, or the PCA scatter for type="pca".

See Also

patient_intercepts : The intercepts analysed here. plot_patient_slopes : The patients’ slopes for one triplet.

Examples

import matplotlib.pyplot as plt
from spidepy import build_niches, fit_spide, test_spide
from spidepy.datasets import toy_spide
from spidepy.pl import plot_patient_effects
adata = build_niches(toy_spide(), sigma=30)
fit = fit_spide(adata, condition="condition", verbose=False)
res = test_spide(fit)
fig = plot_patient_effects(res, index="A")
fig