scanpy.external.pp.scanorama_integrate
- scanpy.external.pp.scanorama_integrate(adata, key, basis='X_pca', adjusted_basis='X_scanorama', knn=20, sigma=15, approx=True, alpha=0.1, batch_size=5000, **kwargs)
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 PCA but before computing the neighbor graph, as illustrated in the example below.
This uses the implementation of scanorama [Hie19].
- Parameters
- adata :
AnnData
AnnData
The annotated data matrix.
- key :
str
str
The name of the column in
adata.obs
that differentiates among experiments/batches. Cells from the same batch must be contiguously stored inadata
.- basis :
str
str
(default:'X_pca'
) The name of the field in
adata.obsm
where the PCA table is stored. Defaults to'X_pca'
, which is the default forsc.tl.pca()
.- adjusted_basis :
str
str
(default:'X_scanorama'
) The name of the field in
adata.obsm
where the integrated embeddings will be stored after running this function. Defaults toX_scanorama
.- knn :
int
int
(default:20
) Number of nearest neighbors to use for matching.
- sigma :
float
float
(default:15
) Correction smoothing parameter on Gaussian kernel.
- approx :
bool
bool
(default:True
) Use approximate nearest neighbors with Python
annoy
; greatly speeds up matching runtime.- alpha :
float
float
(default:0.1
) Alignment score minimum cutoff.
- batch_size :
int
int
(default:5000
) The batch size used in the alignment vector computation. Useful when integrating very large (>100k samples) datasets. Set to large value that runs within available memory.
- kwargs
Any additional arguments will be passed to
scanorama.integrate()
.
- adata :
- Returns
Updates adata with the field
adata.obsm[adjusted_basis]
, containing Scanorama embeddings such that different experiments are integrated.
Example
First, load libraries and example dataset, and preprocess.
>>> import scanpy as sc >>> import scanpy.external as sce >>> adata = sc.datasets.pbmc3k() >>> sc.pp.recipe_zheng17(adata) >>> sc.tl.pca(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'] = 1350*['a'] + 1350*['b']
Finally, run Scanorama. Afterwards, there will be a new table in
adata.obsm
containing the Scanorama embeddings.>>> sce.pp.scanorama_integrate(adata, 'batch') >>> 'X_scanorama' in adata.obsm True