FACSPy.dt.calculate_cofactors#
- FACSPy.dt.calculate_cofactors(adata, add_to_adata=True, return_dataframe=False, copy=False)#
Calculates the cofactors based on the channel histograms.
- Parameters:
adata (
AnnData) – The anndata object of shape n_obs x n_vars where Rows correspond to cells and columns to the channelsadd_to_adata (
bool) – Whether to add the calculated cofactors to the adata object. Defaults to True.return_dataframe (
bool) – Whether to return the calculated cofactors as a pd.DataFrame. Defaults to Falsecopy (
bool) – Whether to copy the dataset and return the copy.
- Return type:
Optional[AnnData,tuple[CofactorTable,DataFrame]]]- Returns:
If copy is True – The AnnData object. If add_to_adata is True, the .uns[‘cofactors’] and .uns[‘raw_cofactors’] slots are filled with the corresponding tables.
If return_dataframe – a tuple of the cofactor table and the raw cofactors per sample
Examples
>>> import FACSPy as fp >>> dataset = fp.create_dataset(...) >>> dataset AnnData object with n_obs × n_vars = 615936 × 22 obs: 'sample_ID', 'file_name', 'condition' var: 'pns', 'png', 'pne', 'pnr', 'type', 'pnn' uns: 'metadata', 'panel', 'workspace', 'gating_cols', 'dataset_status_hash' obsm: 'gating' layers: 'compensated' >>> fp.calculate_cofactors(dataset) >>> dataset AnnData object with n_obs × n_vars = 615936 × 22 obs: 'sample_ID', 'file_name', 'condition' var: 'pns', 'png', 'pne', 'pnr', 'type', 'pnn' uns: 'metadata', 'panel', 'workspace', 'gating_cols', 'dataset_status_hash', 'raw_cofactors', 'cofactors' obsm: 'gating' layers: 'compensated' >>> fp.transform( ... dataset, ... transform = "asinh", ... cofactor_table = dataset.uns["cofactors"], ... key_added = "transformed" ... ) >>> dataset AnnData object with n_obs × n_vars = 615936 × 22 obs: 'sample_ID', 'file_name', 'condition' var: 'pns', 'png', 'pne', 'pnr', 'type', 'pnn' uns: 'metadata', 'panel', 'workspace', 'gating_cols', 'dataset_status_hash', 'raw_cofactors', 'cofactors' obsm: 'gating' layers: 'compensated', 'transformed'