spateo.tools.cci_two_cluster

@File : cci_two_cluster.py @Time : 2022/07/03 11:50:40 @Author : LuluZuo @Version : 1.0 @Desc : spatial cell cell communication

Functions

find_cci_two_group(→ dict)

Performing cell-cell transformation on an anndata object, while also

calculate_group_pair_lr_pair(adata, group, ...)

prepare_cci_df(cci_df, means_col, pval_col, ...)

Given a dataframe generated from the output of :func cci_two_cluster, prepare for visualization by heatmap by

prepare_cci_cellpair_adata(→ anndata.AnnData)

prepare for visualization cellpairs by func st.tl.space, plot all_cell_pair,

Module Contents

spateo.tools.cci_two_cluster.find_cci_two_group(adata: anndata.AnnData, path: str, species: Literal['human', 'mouse', 'drosophila', 'zebrafish', 'axolotl'] = 'human', layer: Tuple[None, str] = None, group: str = None, lr_pair: list = None, sender_group: str = None, receiver_group: str = None, mode: Literal['mode1', 'mode2'] = 'mode2', filter_lr: Literal['outer', 'inner'] = 'outer', top: int = 20, spatial_neighbors: str = 'spatial_neighbors', spatial_distances: str = 'spatial_distances', min_cells_by_counts: int = 0, min_pairs: int = 5, min_pairs_ratio: float = 0.01, num: int = 1000, pvalue: float = 0.05, fdr: bool = False) dict[source]
Performing cell-cell transformation on an anndata object, while also

limiting the nearest neighbor per cell to n_neighbors. This function returns a dictionary, where the key is ‘cell_pair’ and ‘lr_pair’.

Parameters:
adata

An Annodata object.

path

Path to ligand_receptor network of NicheNet (prior lr_network).

species

Which species is your adata generated from. Will be used to determine the proper ligand-receptor database.

layer

the key to the layer. If it is None, adata.X will be used by default.

group

The group name in adata.obs

lr_pair

given a lr_pair list.

sender_group

the cell group name of send ligands.

receiver_group

the cell group name of receive receptors.

spatial_neighbors

spatial neighbor key {spatial_neighbors} in adata.uns.keys(),

spatial_distances

spatial neighbor distance key {spatial_distances} in adata.obsp.keys().

min_cells_by_counts

threshold for minimum number of cells expressing ligand/receptor to avoid being filtered out. Only used if ‘lr_pair’ is None.

min_pairs

minimum number of cell pairs between cells from two groups.

min_pairs_ratio

minimum ratio of cell pairs to theoretical cell pairs (n x M / 2) between cells from two groups.

num

number of permutations. It is recommended that this number be at least 1000.

pvalue

the p-value threshold that will be used to filter for significant ligand-receptor pairs.

filter_lr

filter ligand and receptor based on specific expressed in sender groups and receiver groups. ‘inner’: specific both in sender groups and receiver groups; ‘outer’: specific in sender groups or receiver groups.

top

the number of top expressed fraction in given sender groups(receiver groups) for each gene(ligand or receptor).

Returns:

a dictionary where the key is ‘cell_pair’ and ‘lr_pair’.

Return type:

result_dict

spateo.tools.cci_two_cluster.calculate_group_pair_lr_pair(adata, group, group_pairs, cols, lr_network)[source]
spateo.tools.cci_two_cluster.prepare_cci_df(cci_df: pandas.DataFrame, means_col: str, pval_col: str, lr_pair_col: str, sr_pair_col: str)[source]

Given a dataframe generated from the output of :func cci_two_cluster, prepare for visualization by heatmap by splitting into two dataframes, corresponding to the mean cell type-cell type L:R product and probability values from the permutation test.

Parameters:
cci_df

CCI dataframe with columns for: ligand name, receptor name, L:R product, p value, and sender-receiver cell types

means_col

Label for the column corresponding to the mean product of L:R expression between two cell types

pval_col

Label for the column corresponding to the p-value of the interaction

lr_pair_col

Label for the column corresponding to the ligand-receptor pair in format “{ligand}-{receptor}”

sr_pair_col

Label for the column corresponding to the sending-receiving cell type pair in format “{

sender}-{receiver}"

Returns:

If ‘adata’ is None. Keys: ‘means’, ‘pvalues’, values: mean cell type-cell type L:R product, probability

values, respectively

Return type:

dict

Example

res = find_cci_two_group(adata, …) # The df to save can be found under “lr_pair”: res[“lr_pair”].to_csv(…)

adata, dict = prepare_cci_df(res[“lr_pair”])

spateo.tools.cci_two_cluster.prepare_cci_cellpair_adata(adata: anndata.AnnData, sender_group: str = None, receiver_group: str = None, group: str = None, cci_dict: dict = None, all_cell_pair: bool = False) anndata.AnnData[source]

prepare for visualization cellpairs by func st.tl.space, plot all_cell_pair, or cell pairs which constrain by spatial distance(output of :func cci_two_cluster).

Args:

adata:An Annodata object. sender_group: the cell group name of send ligands. receiver_group: the cell group name of receive receptors. group:The group name in adata.obs, Unused unless ‘all_cell_pair’ is True. cci_dict: a dictionary result from :func cci_two_cluster, where the key is ‘cell_pair’ and ‘lr_pair’.

Unused unless ‘all_cell_pair’ is False.

all_cell_pair: show all cells of the sender and receiver cell group, spatial_key: Key in .obsm containing coordinates for each bucket. Defult False.

Returns:

adata: Updated AnnData object containing ‘spec’ in .obs.