Tutorials › High-Dimensional Genomic Data Analysis › Building Ranked Gene Lists for Enrichment Analysis

Gene Set and Pathway Enrichment · Tutorial 461 of 795

Building Ranked Gene Lists for Enrichment Analysis

Build and audit a ranked gene list that preserves the direction of a defined expression contrast without confusing statistical evidence with effect size.

Intermediate 10 min read

What You'll Learn

  • Define the contrast and sign convention before ordering genes.
  • Compare rankings based on signed test statistics, effect estimates, and signed p-values.
  • Calculate signed statistics and transformed p-values from hypothetical expression results.
  • Handle ties without inventing evidence and document missing or ambiguous gene identifiers.
  • Recognize how model assumptions and filtering choices affect the ranked list.
  • Distinguish a complete ranked list from a significance-thresholded gene list.

Why the Ranking Rule Matters

A ranked gene list gives each eligible gene a position according to a chosen gene-level result. In enrichment analysis, this ordering can retain information that is lost when genes are divided into “significant” and “not significant” groups. But there is no ranking independent of a scientific question: the direction of the contrast, the gene-level quantity being ranked, and the rules for identifiers and ties all affect the result.

Start with the contrast. For example, if the contrast is treatment minus control, a positive effect estimate means higher expression under treatment, and a negative estimate means lower expression under treatment. Reversing the contrast reverses the signs. State this convention before constructing the list, and use the same contrast for every gene.

Definition: A ranked gene list is an ordered set of genes, each represented once, paired with a specified numerical ranking score. The score’s sign and ordering must be defined in relation to a particular contrast. The list’s eligible genes and identifier-handling rules should also be recorded.

The list is based on results from a gene-level analysis, not on an enrichment result. For a model-based differential-expression analysis, the estimated effects, standard errors, test statistics, and p-values inherit the model’s assumptions and data-processing decisions. A ranking does not repair a poorly specified model, and a large score is not by itself proof of a biological effect.

Choose a Score That Matches the Aim

Three common choices are a signed test statistic, a signed effect estimate, and a signed transformation of a p-value. They answer related but different questions. A signed effect estimate ranks by estimated magnitude in the units of the effect; a signed test statistic combines magnitude with uncertainty; a signed p-value transformation ranks by evidence against a null hypothesis while retaining direction.

For a Wald-type test of a gene’s contrast effect, let \(\hat{\beta}_g\) denote its estimated effect and \(SE(\hat{\beta}_g)\) its standard error. The signed Wald statistic is the estimate divided by its standard error:

$$ z_g=\frac{\hat{\beta}_g}{SE(\hat{\beta}_g)}. $$

This statistic is positive or negative according to the estimate, and its magnitude reflects how many standard errors the estimate is from zero. When the test uses a \(t\) reference distribution, its signed \(t\) statistic can serve the same directional purpose. Use the statistic actually reported by the analysis rather than relabelling it as a \(z\) statistic.

For a two-sided p-value \(p_g\) and a nonzero estimated effect, another possible score is \(\operatorname{sign}(\hat{\beta}_g)[-\log_{10}(p_g)]\). It puts positive scores on the positive-effect side and negative scores on the negative-effect side. This is a score convention, not a new test: it preserves direction while transforming the p-value scale.

Key distinction: A signed effect estimate ranks estimated change; a signed test statistic ranks change relative to its uncertainty; a signed p-value transformation ranks evidence relative to a specified null and test. Do not describe these scores as interchangeable measures of effect size.

Worked Example: Ranking by a Signed Test Statistic

Suppose a hypothetical RNA-seq analysis compares treatment with control and reports log2 fold-change estimates and standard errors for four genes. The sign convention is treatment minus control, so positive values indicate higher estimated expression under treatment. Assume the gene-level Wald tests and their standard errors are appropriate for this contrast.

GeneEstimate \(\hat{\beta}_g\) (log2 fold change)\(SE(\hat{\beta}_g)\)
A0.800.20
B-1.200.40
C0.500.25
D-0.300.30

For gene A, \(z_A=0.80/0.20=4.00\). For B, \(z_B=-1.20/0.40=-3.00\). For C, \(z_C=0.50/0.25=2.00\), and for D, \(z_D=-0.30/0.30=-1.00\). Ordering from largest to smallest signed statistic gives A, C, D, B. The positive end represents genes with evidence in the treatment-higher direction, and the negative end represents genes with evidence in the treatment-lower direction.

This order is not the order by absolute estimated effect: B has the largest absolute estimate, but its statistic has smaller absolute value than A’s because B also has greater uncertainty. The model’s validity and the standard errors’ calibration are assumptions inherited from the differential-expression analysis; the ranking calculation does not check them.

Transforming P-Values Without Losing Direction

If the analysis supplies a two-sided p-value but the chosen ranking score requires direction, use the sign of the estimated contrast effect. With positive estimates defined as treatment higher than control, the score is positive for a positive estimate and negative for a negative estimate. A p-value alone has no direction, so assigning signs from p-values without consulting the contrast estimate is not justified.

Worked Example: A Signed Log-P-Value Score

Consider three hypothetical genes from the same treatment-minus-control comparison. Their reported p-values are two-sided, and their estimated effects have the signs shown. Assume the p-values were computed for the stated contrast using a valid model-based test.

GeneEffect signTwo-sided p-valueSigned score
EPositive0.002?
FNegative0.020?
GPositive0.010?

For E, \(-\log_{10}(0.002)=2.699\), so its signed score is \(+2.699\). For F, \(-\log_{10}(0.020)=1.699\), so its score is \(-1.699\). For G, \(-\log_{10}(0.010)=2.000\), so its score is \(+2.000\). From largest to smallest, the order is E, G, F. The negative score for F places it on the treatment-lower side; it does not mean that its p-value is negative.

This ranking compares evidence on the transformed p-value scale, not estimated log2 fold change. If a reported p-value is displayed as zero because of rounding, do not calculate \(-\log_{10}(0)\). Obtain a more precise value or use the signed test statistic; rounding a tiny p-value to zero does not make its score infinite.

A Short Justification for the Signed P-Value Ordering

For a two-sided standard normal test, the p-value corresponding to a signed statistic \(z_g\) is \(p_g=2[1-\Phi(|z_g|)]\), where \(\Phi\) is the standard normal cumulative distribution function. This expression depends on the absolute statistic, so the p-value alone discards its sign. The transformation \(-\log_{10}(p_g)\) increases as \(p_g\) decreases. Restoring the sign from \(\hat{\beta}_g\) therefore creates a directional score whose magnitude is ordered by the extremeness of the two-sided test statistic, provided the same test and reference distribution are used.

This does not make the signed log-p-value equivalent to an effect estimate: the transformation is nonlinear and depends on the test’s uncertainty as well as the effect. Nor does this justification apply unchanged when the p-values come from different tests, different hypotheses, or different reference procedures.

Genes, Ties, and Identifier Problems

Define the eligible genes before sorting. A useful default is the set of genes that were actually tested and have a usable ranking score for the stated contrast. This aligns the list with the analysis’s tested-gene universe. Genes excluded by independent filtering, absent from the assay, or lacking a valid score should not silently be assigned a score of zero: “not ranked” is not the same as “estimated no effect.”

Map identifiers consistently to the gene-set annotation system. Remove version suffixes only when the mapping convention supports doing so, and retain a record of the mapping. A one-to-many or many-to-one mapping can change which genes appear in the list. If multiple rows map to one gene, do not arbitrarily keep the row with the smallest p-value or largest absolute statistic. Resolve the duplication from the data and analysis definition where possible; if it cannot be resolved, exclude the ambiguous gene and report that decision.

Exact ties can occur, particularly with rounded scores or discrete test results. Keep tied genes at the same score. If software requires a total order, use a stated deterministic secondary key, such as a stable identifier, only to order tied entries computationally. That secondary key does not add statistical evidence and must not be interpreted as a meaningful distinction between the genes.

Worked Example: Auditing Duplicate and Missing Identifiers

A hypothetical analysis reports the following rows for a treatment-minus-control contrast. Two distinct feature identifiers map to the same canonical gene, K. The mapping source cannot establish that these rows are duplicate copies of one identical tested feature. Gene M has no usable identifier in the annotation release, and genes L and N map uniquely.

Feature identifierMapped geneSigned statistic
f101K2.40
f102K1.70
f103L-2.10
f104M (unmapped)3.00
f105N0.60

Because K has conflicting statistics and there is no justified rule for combining these feature-level results into one gene-level result, retain neither K row in the gene-level list; do not choose 2.40 merely because it is larger. M cannot be matched to the required gene identifier system, so it is also omitted and recorded as unmapped. The resulting list contains L at \(-2.10\) and N at \(0.60\), ordered N then L. This exclusion is an explicit limitation of the available mapping, not evidence that K or M has no expression change. If the analysis can be reconstructed at the gene level with an appropriate feature definition, that is preferable to post hoc collapsing.

Practical Checks and Alternatives

Before using a list, check that the contrast and sign convention are documented, that every retained gene has one score, and that the list includes the intended tested genes rather than only those passing a significance threshold. Confirm that a positive and a negative score correspond to the intended biological directions. Inspect unusually large scores, p-values reported as zero, missing mappings, duplicate mappings, and the number of ties. These checks can reveal coding or annotation errors, but they do not replace diagnostics of the underlying expression model.

Ranking choiceUseful whenMain limitation
Signed test statisticDirection and evidence relative to uncertainty are both relevant.Depends on the test and its standard-error calibration; is not an effect size.
Signed effect estimateRanking by estimated change in a meaningful unit is the goal.May put imprecise estimates high in the list if magnitude alone is used.
Signed transformed p-valueA directional ordering based on test evidence is desired and p-values are available.Depends on the test, can be sensitive to rounding, and does not report change magnitude.

A significance-thresholded list is appropriate for methods that explicitly require a selected set, but it discards ordering information among selected genes and excludes genes just below the cutoff. For ranked enrichment, use the full eligible list rather than filtering it to significant genes unless the analysis specifically requires otherwise. The subsequent enrichment method determines how the ordering is used; constructing the list alone does not establish pathway significance.

Common pitfall: “The gene with the smallest p-value has the largest biological effect, so it should rank first.” This is incorrect because a p-value reflects evidence under a test and depends on uncertainty as well as effect. Choose a score that matches the intended question, retain its direction, and describe it accurately.

Check Your Understanding

Answer each question using the stated contrast and score definition.

  1. A contrast is treatment minus control. What does a negative estimated effect mean?
  2. A gene has \(\hat{\beta}=0.6\) and \(SE(\hat{\beta})=0.3\). Calculate its signed Wald statistic.
  3. A gene has a negative effect estimate and a two-sided p-value of 0.05. Calculate its signed \(-\log_{10}(p)\) score to three significant figures.
  4. Two feature rows map to one gene but have different test statistics. Why is keeping the larger absolute statistic not a neutral deduplication rule?
  5. Two genes have exactly equal ranking scores. What may be done if software requires a total order, and what should not be inferred from that order?

Solutions: (1) The estimated expression is lower under treatment than control for this contrast. (2) \(z=0.6/0.3=2.00\). (3) The score is \(-[-\log_{10}(0.05)]=-1.301\), approximately \(-1.30\). (4) Choosing the more extreme statistic systematically selects the row with stronger apparent evidence and can bias the list; resolving the feature-to-gene definition or documenting exclusion is preferable. (5) Apply a documented deterministic secondary key, such as a stable identifier, while treating the scores as tied; the secondary order has no statistical or biological meaning.

Clinical Biostats