spateo.tools.cci_two_cluster ============================ .. py:module:: spateo.tools.cci_two_cluster .. autoapi-nested-parse:: @File : cci_two_cluster.py @Time : 2022/07/03 11:50:40 @Author : LuluZuo @Version : 1.0 @Desc : spatial cell cell communication Functions --------- .. autoapisummary:: spateo.tools.cci_two_cluster.find_cci_two_group spateo.tools.cci_two_cluster.calculate_group_pair_lr_pair spateo.tools.cci_two_cluster.prepare_cci_df spateo.tools.cci_two_cluster.prepare_cci_cellpair_adata Module Contents --------------- .. py:function:: 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 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'. :param adata: An Annodata object. :param path: Path to ligand_receptor network of NicheNet (prior lr_network). :param species: Which species is your adata generated from. Will be used to determine the proper ligand-receptor database. :param layer: the key to the layer. If it is None, adata.X will be used by default. :param group: The group name in adata.obs :param lr_pair: given a lr_pair list. :param sender_group: the cell group name of send ligands. :param receiver_group: the cell group name of receive receptors. :param spatial_neighbors: spatial neighbor key {spatial_neighbors} in adata.uns.keys(), :param spatial_distances: spatial neighbor distance key {spatial_distances} in adata.obsp.keys(). :param 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. :param min_pairs: minimum number of cell pairs between cells from two groups. :param min_pairs_ratio: minimum ratio of cell pairs to theoretical cell pairs (n x M / 2) between cells from two groups. :param num: number of permutations. It is recommended that this number be at least 1000. :param pvalue: the p-value threshold that will be used to filter for significant ligand-receptor pairs. :param 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. :param 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'. :rtype: result_dict .. py:function:: calculate_group_pair_lr_pair(adata, group, group_pairs, cols, lr_network) .. py:function:: prepare_cci_df(cci_df: pandas.DataFrame, means_col: str, pval_col: str, lr_pair_col: str, sr_pair_col: str) 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. :param cci_df: CCI dataframe with columns for: ligand name, receptor name, L:R product, p value, and sender-receiver cell types :param means_col: Label for the column corresponding to the mean product of L:R expression between two cell types :param pval_col: Label for the column corresponding to the p-value of the interaction :param lr_pair_col: Label for the column corresponding to the ligand-receptor pair in format "{ligand}-{receptor}" :param sr_pair_col: Label for the column corresponding to the sending-receiving cell type pair in format "{ :param sender}-{receiver}": :returns: If 'adata' is None. Keys: 'means', 'pvalues', values: mean cell type-cell type L:R product, probability values, respectively :rtype: dict .. rubric:: 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"]) .. py:function:: 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 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.