FACSPy.tl.diffmap

Contents

FACSPy.tl.diffmap#

FACSPy.tl.diffmap(adata, gate, layer, recalculate_pca=False, use_only_fluo=True, exclude=None, scaling=None, copy=False, **kwargs)#

Diffusion Map Embedding calculation

If PCA and neighbors have not been calculated for this gate and layer, the function will compute it automatically.

From the scanpy docs: Diffusion maps [CLL+05] has been proposed for visualizing single-cell data by [HBT15]. The tool uses the adapted Gaussian kernel suggested by [HButtnerW+16] in the implementation of [WAT18].

The width (“sigma”) of the connectivity kernel is implicitly determined by the number of neighbors used to compute the single-cell graph in neighbors(). To reproduce the original implementation using a Gaussian kernel, use method==’gauss’ in neighbors(). To use an exponential kernel, use the default method==’umap’. Differences between these options shouldn’t usually be dramatic.

Parameters:
  • adata (AnnData) – The anndata object of shape n_obs x n_vars where rows correspond to cells and columns to the channels

  • gate (str) – The gate to be analyzed, called by the population name. This parameter has a default stored in fp.settings, but can be superseded by the user.

  • layer (str) – The layer corresponding to the data matrix. Similar to the gate parameter, it has a default stored in fp.settings which can be overwritten by user input.

  • recalculate_pca (bool) – Parameter to specify whether to re-calculate the PCA. Defaults to False.

  • use_only_fluo (bool) – Parameter to specify if the UMAP should only be calculated for the fluorescence channels. Specify recalculate_pca to repeat PCA calculation.

  • exclude (Optional[Union`[:py:class:`list[str], str]]) – Can be used to exclude channels from calculating the embedding. Specify recalculate_pca to repeat PCA calculation.

  • scaling (Optional[Literal['MinMaxScaler', 'RobustScaler', 'StandardScaler']]) – Whether to apply scaling to the data for display. One of MinMaxScaler, RobustScaler or StandardScaler (Z-score). Defaults to None.

  • copy (bool) – Return a copy of adata instead of modifying inplace

  • **kwargs (dict, optional) – keyword arguments that are passed directly to the _compute_diffmap function. Please refer to its documentation.

Returns:

Returns adata if copy = True, otherwise adds fields to the anndata object:

.obsm[f’X_diffmap_{gate}_{layer}]

DiffusionMap embedding of the data

.uns[f’diffmap_evals’_{gate}_{layer}]

Array of size (number of eigen vectors). Eigenvalues of transition matrix

.uns[‘settings’][f’_diffmap_{gate}_{layer}]

Settings that were used for PCA calculation

Return type:

AnnData or None

Examples

>>> import FACSPy as fp
>>> dataset
AnnData object with n_obs × n_vars = 615936 × 22
obs: 'sample_ID', 'file_name', 'condition', 'sex'
var: 'pns', 'png', 'pne', 'pnr', 'type', 'pnn', 'cofactors'
uns: 'metadata', 'panel', 'workspace', 'gating_cols', 'dataset_status_hash'
obsm: 'gating'
layers: 'compensated', 'transformed'
>>> fp.settings.default_gate = "T_cells"
>>> fp.settings.default_layer = "transformed"
>>> fp.tl.pca(dataset)
>>> fp.tl.neighbors(dataset)
>>> fp.tl.diffmap(dataset)