decoupler.pp.swap_layer

Contents

decoupler.pp.swap_layer#

decoupler.pp.swap_layer(adata, key, X_key='X', inplace=False)#

Swaps an AnnData.X for a given layer key. Generates a new object by default.

Parameters:
  • adata (AnnData) – Annotated data matrix with observations (rows) and features (columns).

  • key (str) – adata.AnnData.layers key to place in adata.AnnData.X.

  • X_key (str | None (default: 'X')) – adata.AnnData.layers key where to move and store the original adata.AnnData.X. If None, the original adata.AnnData.X is discarded.

  • inplace (bool (default: False)) – If False, return a copy. Otherwise, do operation inplace and return None.

Return type:

None | AnnData

Returns:

If inplace=False, new AnnData object.

Example

import decoupler as dc
import scanpy as sc

adata, net = dc.ds.toy()
adata.layers["lognorm"] = adata.X
sc.pp.scale(adata)
adata = dc.pp.swap_layer(adata, key="lognorm", X_key="scaled")
adata