SpatialQuery.spatial_query_multi.de_genes
- spatial_query_multi.de_genes(ind_group1, ind_group2, genes=None, min_fraction=0.05, method='fisher', alpha=None)[source]
Perform differential expression analysis on the given indices. The ind_group1 and ind_group2 should be a defaultdict with keys as modified dataset names and values as lists of indices in corresponding group. It provides a flexible way to perform DE analysis on different datasets, e.g., across different FOVs of the same condition, or across FOVs from different conditions.
- Parameters:
ind_group1 (defaultdict[str, List[int]]) – A defaultdict with keys as modified dataset names and values as lists of indices in corresponding group.
ind_group2 (defaultdict[str, List[int]]) – A defaultdict with keys as modified dataset names and values as lists of indices in corresponding group.
genes (str or List[str], optional) – Genes to be searched in the gene index.
min_fraction (float, default=0.05) – The minimum fraction of cells that express a gene for it to be considered differentially expressed.
method ({'fisher', 't-test', 'wilcoxon'}, default='fisher') – The method to use for DE analysis. If build_gene_index=True, only Fisher’s exact test is supported.
alpha (float, optional) – Significance threshold for adjusted p-values. If None, defaults to 0.1 when using Fisher’s exact test and 0.05 otherwise.
- Returns:
- DataFrame with differential expression results. Columns include:
gene: gene name
proportion_1: proportion of cells expressing the gene in group 1
proportion_2: proportion of cells expressing the gene in group 2
p_value: p-value from statistical test
adj-pval: FDR-corrected p-value
de_in: which group the gene is differentially expressed in (‘group1’ or ‘group2’)
- Return type:
pd.DataFrame