FACSPy.tl.tsne_samplewise

FACSPy.tl.tsne_samplewise#

FACSPy.tl.tsne_samplewise(adata, layer, n_components=3, use_only_fluo=True, exclude=None, scaling='MinMaxScaler', data_group='sample_ID', data_metric='mfi', copy=False, *args, **kwargs)#

Computes samplewise TSNE based on either the median fluorescence values (MFI) or frequency of parent values (FOP). TSNE will be calculated for all gates at once. The values are added to the corresponding .uns slot where MFI/FOP values are stored.

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

  • 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.

  • n_components (int) – The number of components to be calculated. Defaults to 3.

  • use_only_fluo (bool) – Parameter to specify if the TSNE should only be calculated for the fluorescence channels.

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

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

  • data_metric (Literal['mfi', 'fop']) – One of mfi or fop. Using a different metric will calculate the asinh fold change on mfi and fop values, respectively

  • data_group (str) – When MFIs/FOPs are calculated, and the groupby parameter is used, use data_group to specify the right dataframe

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

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

Returns:

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

.uns[f’{data_metric}_{data_group}_{layer}’]

TSNE coordinates are added to the respective frame

.uns[‘settings’][f”_tsne_samplewise_{data_metric}_{layer}”]

Settings that were used for samplewise TSNE 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.mfi(dataset)
>>> fp.tl.tsne_samplewise(dataset)