FACSPy.tl.mfi#
- FACSPy.tl.mfi(adata, layer, method='median', groupby='sample_ID', use_only_fluo=False, aggregate=False, copy=False)#
Calculates the median/mean fluorescence intensities (MFI). MFIs are calculated for all gates at once.
- Parameters:
adata (
AnnData) – The anndata object of shape n_obs x n_vars where rows correspond to cells and columns to the channelslayer (
Union[list[str],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. Multiple layers can be passed as a list.method (
Literal['mean','median']) – Whether to use mean or median for the calculation. Defaults to median.groupby (
Union[Literal['sample_ID'],str]) – Argument to specify the grouping. Defaults to sample_ID, which will calculate the FOP per sample. Can be any column from the .obs slot of adata.use_only_fluo (
bool) – Parameter to specify if the MFI should only be calculated for the fluorescence channels.aggregate (
bool) – If False, calculates the MFI as if groupby==[‘sample_ID’, groupby]. If set to True, the FOP is calculated per entry in .obs[groupby]. Defaults to False.copy (
bool) – Whether to copy the dataset.
- Returns:
Returns adata if copy = True, otherwise adds fields to the anndata object:
- .uns[f’mfi_{groupby}_{layer}’]
calculated MFI values per channel
- .uns[‘settings’][f’_mfi_{groupby}_{layer}’]
Settings that were used for calculation
- Return type:
AnnDataor 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.tl.mfi(dataset)
>>> 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.leiden(dataset) >>> fp.tl.mfi(dataset, ... groupby = "T_cells_transformed_leiden", ... aggregate = True) # will calculate MFI per leiden cluster >>> fp.tl.mfi(dataset, ... groupby = "T_cells_transformed_leiden", ... aggregate = False) # will calculate MFI per leiden cluster and sample_ID