snapatac2.tl.multi_spectral#

snapatac2.tl.multi_spectral(adatas, n_comps=30, features='selected', weights=None, random_state=0, weighted_by_sd=True)[source]#

Compute one spectral embedding from multiple modalities.

Use this function to integrate multiple AnnData or AnnDataSet objects that describe the same cells with different feature spaces. The returned embedding combines modality-specific graph structure before downstream clustering.

Anti-Patterns#

  • Do NOT pass modalities with different cell order; rows are assumed to refer to the same cells in the same order.

  • Do NOT pass features="selected" unless each modality has adata.var["selected"].

param adatas:

Modalities to embed. Each object must have the same observations in the same order.

type adatas:

list[AnnData] | list[AnnDataSet]

param n_comps:

Maximum number of spectral dimensions to compute.

type n_comps:

int

param features:

Feature selectors for each modality. A single string or None is reused for every modality.

type features:

str | list[str] | list[ndarray] | None

param weights:

Modality weights. If None, weight all modalities equally.

type weights:

list[float] | None

param random_state:

Seed for random initialization.

type random_state:

int

param weighted_by_sd:

If True, multiply eigenvectors by the square root of their eigenvalues.

type weighted_by_sd:

bool

returns:

Eigenvalues and integrated eigenvectors.

rtype:

tuple[ndarray, ndarray]

See also

spectral

Examples

>>> import snapatac2 as snap
>>> atac = snap.datasets.pbmc5k(type="annotated_h5ad")
>>> gene = snap.pp.make_gene_matrix(atac, snap.genome.hg38)
>>> evals, evecs = snap.tl.multi_spectral([atac, gene], features=None)
>>> evecs.shape[0] == atac.n_obs
True