decoupler.mt.gsea

Contents

decoupler.mt.gsea#

decoupler.mt.gsea = <decoupler._Method.Method object>#

Gene Set Enrichment Analysis (GSEA) [STM+05].

Features are ranked based on a continuous statistic (e.g., expression, score, or correlation). The enrichment score (ES) for a feature set is computed by walking down the ranked list and increasing a running-sum statistic when a feature is in the set, and decreasing it when it is not.

δ(F,i)={rijFrjif feature iF1lif feature iF\delta(F, i) = \begin{cases} \frac{|r_i|}{\sum\limits_{j \in F} |r_j|} & \text{if feature } i \in F \\ -\frac{1}{l} & \text{if feature } i \notin F \end{cases}

Where:

  • FF is a feature set

  • rr is the ranking of the feature statistics in descending order

  • rir_i is the value for feature ii

  • rjr_j is the value for feature jj in FF

  • kk is the number of features in FF

  • NN is the total number of features in rr

  • l=Nkl=N-k is the number of features not in FF but present in rr

For each feature, the function δ(F,i)\delta(F,i) is applied and stored as a sequence LL.

L=δ(F,i) for i=1, 2, ... , NL = \delta(F, i)\text{ for i} = \text{1, 2, ... , N}

The enrichment score ESES corresponds to the maximum deviation from zero of this running sum.

ES=LargmaxLES = L_{arg max |L|}

When multiple random permutations are done (times > 1), statistical significance is assessed via empirical testing.

pvalue=ESrandESPp_{value}=\frac{ES_{rand} \geq ES}{P}

Where:

  • ESrandES_{rand} are the enrichment scores of the random permutations

  • PP is the total number of permutations

Additionaly, ESES is updated to a normalized enrichment score NESNES.

NES={ESμ+if ES>0ESμif ES<0NES = \begin{cases} \frac{ES}{\mu_{+}} & \text{if } ES > 0 \\ \frac{ES}{\mu_{-}} & \text{if } ES < 0 \end{cases}

Where:

  • μ+\mu{+} is the mean of positive values in ESrandES_{rand}

  • μ\mu{-} is the mean of negative values in ESrandES_{rand}

Finally, the obtained pvaluep_{value} are adjusted by Benjamini-Hochberg correction.

Parameters:
  • data

    anndata.AnnData instance, pandas.DataFrame, or a tuple of (matrix, samples, features). All methods assume that input values follow a normal distribution unless otherwise specified. Therefore, when working with observational count data, some form of normalization is required (e.g., scanpy’s library-size normalization followed by log1p). Using raw integer counts is not recommended, as they follow a Poisson distribution.

    Feature scaling on normalized counts is also acceptable, but note that it changes the results by assuming equal importance across features, and outcomes will vary depending on which observations are included.

    No normalization or transformation is required when using contrast-level feature statistics such as log fold changes or Wald test statistics.

  • net – Dataframe in long format. Must include source and target columns, and optionally a weight column.

  • tmin (default: 5) – Minimum number of targets per source. Sources with fewer targets will be removed.

  • layer – Layer key name of an anndata.AnnData instance.

  • raw (default: False) – Whether to use the .raw attribute of anndata.AnnData.

  • empty (default: True) – Whether to remove empty observations (rows) or features (columns).

  • bsize (default: 250000) – For large datasets in sparse format, this parameter controls how many observations are processed at once. Increasing this value speeds up computation but uses more memory.

  • verbose (default: False) – Whether to display progress messages and additional execution details.

  • times – Number of random permutations to do.

  • seed – Random seed to use.

Returns:

Enrichment scores ESES and, if applicable, adjusted pvaluep_{value} by Benjamini-Hochberg.

Example

import decoupler as dc
adata, net = dc.ds.toy()
dc.mt.gsea(adata, net, tmin=3)