cellflow.preprocessing.centered_pca

cellflow.preprocessing.centered_pca(adata, n_comps=50, layer=None, method='scanpy', keep_centered_data=True, copy=False, **kwargs)[source]

Performs PCA on the centered data matrix and stores the results in obsm.

Parameters:
  • adata (AnnData) – An AnnData object.

  • n_comps (int) – Number of principal components to compute.

  • layer (str | None) – Layer in layers to use for PCA. If None, uses adata.X.

  • method (str) – Method to use for PCA. If "rapids", uses rapids_singlecell.pp.pca() with GPU acceleration. Otherwise, uses scanpy.pp.pca().

  • keep_centered_data (bool) – Whether to keep the centered data. Set to False to save memory.

  • copy (bool) – Return a copy of adata instead of updating it in place.

  • kwargs – Additional arguments to pass to scanpy.pp.pca() or rapids_singlecell.pp.pca()

Return type:

AnnData | None

Returns:

: If copy is True, returns a new AnnData object with the PCA results stored in obsm. Otherwise, updates adata in place.

Sets the following fields:

  • .obsm["X_pca"]: PCA coordinates.

  • .varm["PCs"]: Principal components.

  • .varm["X_mean"]: Mean of the data matrix.

  • .layers["X_centered"]: Centered data matrix. # TODO adapt

  • .uns['pca']['variance_ratio']: Variance ratio of each principal component.

  • .uns['pca']['variance']: Variance of each principal component.