spateo.tools.cluster_degs ========================= .. py:module:: spateo.tools.cluster_degs Functions --------- .. autoapisummary:: spateo.tools.cluster_degs.find_spatial_cluster_degs spateo.tools.cluster_degs.find_cluster_degs spateo.tools.cluster_degs.find_all_cluster_degs spateo.tools.cluster_degs.top_n_degs Module Contents --------------- .. py:function:: find_spatial_cluster_degs(adata: anndata.AnnData, test_group: str, x: Optional[List[int]] = None, y: Optional[List[int]] = None, group: Optional[str] = None, genes: Optional[List[str]] = None, k: int = 10, ratio_thresh: float = 0.5) -> pandas.DataFrame Function to search nearest neighbor groups in spatial space for the given test group. :param adata: an Annodata object. :param test_group: The group name from `group` for which neighbors has to be found. :param x: x-coordinates of all buckets. :param y: y-coordinates of all buckets. :param group: The column key/name that identifies the grouping information (for example, clusters that correspond to different cell types) of buckets. :param genes: The list of genes that will be used to subset the data for identifying DEGs. If `None`, all genes will be used. :param k: Number of neighbors to use for kneighbors queries. :param ratio_thresh: For each non-test group, if more than 50% (default) of its buckets are in the neighboring set, this group is then selected as a neighboring group. :returns: A pandas DataFrame of the differential expression analysis result between the test group and neighbor groups. .. py:function:: find_cluster_degs(adata: anndata.AnnData, test_group: str, control_groups: List[str], genes: Optional[List[str]] = None, layer: Optional[str] = None, X_data: Optional[numpy.ndarray] = None, group: Optional[str] = None, qval_thresh: float = 0.05, ratio_expr_thresh: float = 0.1, diff_ratio_expr_thresh: float = 0, log2fc_thresh: float = 0, method: Literal['multiple', 'pairwise'] = 'multiple') -> pandas.DataFrame Find marker genes between one group to other groups based on gene expression. Test each gene for differential expression between buckets in one group and the other groups via Mann-Whitney U test. We calculate the percentage of buckets expressing the gene in the test group (ratio_expr), the difference between the percentages of buckets expressing the gene in the test group and control groups (diff_ratio_expr), the expression fold change between the test and control groups (log2fc), qval is calculated using Benjamini-Hochberg. In addition, the `1 - Jessen-Shannon` distance between the distribution of percentage of cells with expression across all groups to the hypothetical perfect distribution in which only the test group of cells has expression (jsd_adj_score), and Pearson's correlation coefficient between gene vector which actually detected expression in all cells and an ideal marker gene which is only expressed in test_group cells (ppc_score), as well as cosine_score are also calculated. :param adata: an Annodata object :param test_group: The group name from `group` for which markers has to be found. :param control_groups: The list of group name(s) from `group` for which markers has to be tested against. :param genes: The list of genes that will be used to subset the data for identifying DEGs. If `None`, all genes will be used. :param layer: The layer that will be used to retrieve data for DEG analyses. If `None` and `X_data` is not given, .X is used. :param group: The column key/name that identifies the grouping information (for example, clusters that correspond to different cell types) of buckets. This will be used for calculating group-specific genes. :param X_data: The user supplied data that will be used for marker gene detection directly. :param qval_thresh: The maximal threshold of qval to be considered as significant genes. :param ratio_expr_thresh: The minimum percentage of buckets expressing the gene in the test group. :param diff_ratio_expr_thresh: The minimum of the difference between two groups. :param log2fc_thresh: The minimum expression log2 fold change. :param method: This method is to choose the difference expression genes between test group and other groups one by one or combine them together (default: 'multiple'). Valid values are "multiple" and "pairwise". :returns: A pandas DataFrame of the differential expression analysis result between the two groups. :raises ValueError: If the `method` is not one of "pairwise" or "multiple". .. py:function:: find_all_cluster_degs(adata: anndata.AnnData, group: str, genes: Optional[List[str]] = None, layer: Optional[str] = None, X_data: Optional[numpy.ndarray] = None, copy: bool = True, n_jobs: int = 1) -> anndata.AnnData Find marker genes for each group of buckets based on gene expression. :param adata: An Annadata object :param group: The column key/name that identifies the grouping information (for example, clusters that correspond to different cell types) of buckets. This will be used for calculating group-specific genes. :param genes: The list of genes that will be used to subset the data for identifying DEGs. If `None`, all genes will be used. :param layer: The layer that will be used to retrieve data for DEG analyses. If `None` and `X_data` is not given, .X is used. :param X_data: The user supplied data that will be used for marker gene detection directly. :param copy: If True (default) a new copy of the adata object will be returned, otherwise if False, the adata will be updated inplace. :param n_cores: `int` (default=1) The maximum number of concurrently running jobs. By default it is 1 and thus no parallel computing code is used at all. When -1 all CPUs are used. :returns: An `~anndata.AnnData` with a new property `cluster_markers` in the .uns attribute, which includes a concatenated pandas DataFrame of the differential expression analysis result for all groups and a dictionary where keys are cluster numbers and values are lists of marker genes for the corresponding clusters. Please note that the markers are not the top marker genes. To identify top `n` marker genes, Use `st.tl.cluster_degs.top_n_degs(adata, group='louvain')`. .. py:function:: top_n_degs(adata: anndata.AnnData, group: str, custom_score_func: Union[None, Callable] = None, sort_by: Union[str, List[str]] = 'log2fc', top_n_genes=10, only_deg_list: bool = True) Find top `n` marker genes for each group of buckets based on differential gene expression analysis results. :param adata: an Annodata object :param group: The column key/name that identifies the grouping information (for example, clusters that correspond to different cell types) of buckets. This will be used for calculating group-specific genes. :param custom_score_func: A custom function to calculate the score based on the DEG analyses result. Note the columns in adata.uns["cluster_markers"]["deg_tables"] includes: * "test_group", * "control_group", * "ratio_expr", * "diff_ratio_expr", * "person_score", * "cosine_score", * "jsd_adj_score", * "log2fc", * "combined_score", * "pval", * "qval". :param sort_by: `str` or `list` Column name or names to sort by. :param top_n_genes: `int` The number of top sorted markers. :param only_gene_list: `bool` Whether to only return the marker gene list for each cluster.