snapatac2.pp.scanorama_integrate#

snapatac2.pp.scanorama_integrate(adata, *, batch, n_neighbors=20, use_rep='X_spectral', use_dims=None, groupby=None, key_added=None, sigma=15, approx=True, alpha=0.1, batch_size=5000, inplace=True, **kwargs)[source]#

Use Scanorama [Hie19] to integrate different experiments.

Scanorama [Hie19] is an algorithm for integrating single-cell data from multiple experiments stored in an AnnData object. This function should be run after performing tl.spectral but before computing the neighbor graph, as illustrated in the example below.

This uses the implementation of scanorama [Hie19].

Parameters:
  • data – Matrice or AnnData object. Matrices should be shaped like n_obs x n_vars.

  • batch – Batch labels for cells. If a string, labels will be obtained from obs.

  • n_neighbors – Number of mutual nearest neighbors.

  • use_rep – Use the indicated representation in .obsm.

  • use_dims – Use these dimensions in use_rep.

  • groupby – If specified, split the data into groups and perform batch correction on each group separately.

  • key_added – If specified, add the result to adata.obsm with this key. Otherwise, it will be stored in adata.obsm[use_rep + "_scanorama"].

  • inplace – Whether to store the result in the anndata object.

Returns:

if inplace=True it updates adata with the field adata.obsm[`use_rep`_scanorama], containing adjusted principal components. Otherwise, it returns the result as a numpy array.

Return type:

np.ndarray | None

See also

spectral

compute spectral embedding of the data matrix.

Example

First, load libraries and example dataset, and preprocess.

>>> import snapatac2 as snap
>>> adata = snap.read(snap.datasets.pbmc5k(type='h5ad'), backed=None)
>>> snap.pp.select_features(adata)
>>> snap.tl.spectral(adata)

We now arbitrarily assign a batch metadata variable to each cell for the sake of example, but during real usage there would already be a column in adata.obs giving the experiment each cell came from.

>>> adata.obs['batch'] = 2218*['a'] + 2218*['b']

Finally, run Scanorama. Afterwards, there will be a new table in adata.obsm containing the Scanorama embeddings.

>>> snap.pp.scanorama_integrate(adata, batch='batch')
>>> 'X_spectral_scanorama' in adata.obsm
True