enrichmap.tl.build_signed_weights

enrichmap.tl.build_signed_weights#

enrichmap.tl.build_signed_weights(adata: AnnData, up_genes: list[str], down_genes: list[str], score_key: str = 'enrichmap') dict[str, dict[str, float]]#

Build a signed gene weight dictionary from upregulated and downregulated gene lists.

CV-inferred weights capture spatial variability (magnitude). The sign is determined by differential correlation: for each gene, the Spearman correlation with the mean expression of upregulated genes minus the correlation with the mean expression of downregulated genes. This difference cancels shared technical inflation (e.g. library size) and produces genuinely signed weights. Each group is normalised by its own size so that upregulated and downregulated genes contribute equally regardless of gene count.

Parameters:
  • adata (AnnData) – Annotated data matrix.

  • up_genes (list of str) – Upregulated gene symbols.

  • down_genes (list of str) – Downregulated gene symbols.

  • score_key (str, default "enrichmap") – Name for the signature in the returned dictionary.

Returns:

Gene weights dictionary ready for enrichmap.tl.score(gene_weights=...).

Return type:

dict

Examples

>>> from enrichmap.tools import build_signed_weights
>>> gw = build_signed_weights(adata, up_genes=up, down_genes=down, score_key="G0")
>>> em.tl.score(adata, gene_weights=gw)