Tutorials › Statistical Genetics › Gene Sets, Ontologies, and Membership Matrices

Gene Prioritization and Pathway Tests · Tutorial 682 of 989

Gene Sets, Ontologies, and Membership Matrices

Represent pathway and ontology annotations consistently, and assess how identifier and set-definition choices change the gene-membership structure used in downstream analyses.

Advanced 10 min read

What You'll Learn

  • Define a gene set relative to an explicit collection of eligible genes
  • Construct and interpret a binary gene-membership matrix
  • Distinguish curated pathways from ontology terms and their hierarchies
  • Trace how identifier mapping decisions change set membership
  • Compare membership counts and overlaps across set definitions
  • Separate descriptive membership summaries from enrichment tests

Why Membership Representation Matters

Pathway analyses begin with a representation problem: which genes belong to which biological categories? A pathway database may describe genes participating in a process or molecular system, while an ontology database assigns terms from a controlled vocabulary. In either case, the data used for analysis are usually a collection of gene-to-category memberships. Those memberships are not self-defining: they depend on gene identifiers, database releases, evidence rules, and the set of genes considered eligible.

Making these choices explicit is essential before using gene-level association scores. A membership matrix provides a compact way to record the choices and inspect their consequences. It does not, by itself, say whether a gene set is enriched or whether a pathway is associated with a trait. Those are inferential questions; here the goal is to define the sets accurately and represent them transparently.

Definition: Let \(U=\{g_1,\ldots,g_n\}\) be a specified universe of genes and let \(S_1,\ldots,S_K\) be gene sets. The binary membership matrix \(M\) has \(n\) rows and \(K\) columns, with $$ M_{ik} = \begin{cases} 1, & g_i \in S_k,\\ 0, & g_i \notin S_k. \end{cases} $$ A row corresponds to a gene, a column to a set, and an entry records membership under the chosen identifier and annotation rules.

The universe \(U\) is part of the representation, not merely a convenience for displaying a table. A set is represented relative to \(U\) as \(S_k \cap U\). Genes outside \(U\) have no rows, even if a database lists them as members. For example, a study might use only genes with an association score, whereas a separate annotation resource might contain many genes without such a score. Keeping those distinctions visible prevents a database's full membership list from being mistaken for the actual set used in an analysis.

Pathways and Ontology Terms

A curated pathway is generally assembled to represent a biological pathway, process, or molecular system, often using literature and expert curation. Depending on the resource, a pathway may describe a sequence of reactions, a signaling system, or a collection of genes involved in a biological function. Pathway membership is therefore tied to a particular resource's definitions and curation practices; different resources may define similar-sounding pathways differently.

An ontology term is a term in a controlled vocabulary with a defined meaning and relationships to other terms. Biological ontologies often organize terms into a hierarchy or directed graph. A gene can be annotated to a more specific term, and an analysis resource may also propagate that annotation to broader parent terms. Consequently, memberships in ontology terms may be related by the ontology's structure. A term's gene set depends on whether annotations are direct only or include inherited annotations, as well as on which evidence types and releases are accepted.

These labels describe common resource designs rather than an absolute divide. A pathway database may include hierarchical groupings, and a pathway may overlap substantially with an ontology term. The key is to retain the source and definition of each set rather than treating every category called a “pathway” or “process” as interchangeable.

FeatureCurated pathwayOntology term
MeaningA resource-defined pathway, process, or biological systemA controlled-vocabulary concept with a defined term
OrganizationMay have pathway groupings or related pathwaysTypically linked to other terms in a hierarchy or graph
Membership definitionDepends on the pathway resource and curationDepends on annotations, evidence rules, propagation, and ontology version
Practical implicationRecord pathway identifier and resource releaseRecord term identifier, ontology release, and annotation policy

A useful record for each set includes its stable set identifier, display name, source, release or retrieval date, and membership policy. For ontology annotations, it should also specify whether parent-term propagation was applied and which evidence classes were included. Names alone are insufficient: two sets with similar labels need not have identical members, while a set's label may remain unchanged even as its membership changes between releases.

Building a Membership Matrix

To construct \(M\), first define the gene universe and the set definitions. Then standardize gene identifiers, map annotation records to those identifiers, and mark the resulting memberships. The matrix is usually sparse: a gene belongs to only a fraction of the many available sets, so most entries are zero. A sparse representation can store only the nonzero entries, but its interpretation is the same as the full binary matrix.

1
Specify the rows.
Choose the gene universe and a single row-level identifier system. State why genes are included in the universe.
2
Specify the columns.
Choose pathway or ontology sets, with source, release, stable identifiers, and any annotation filters.
3
Resolve annotation identifiers.
Map source gene identifiers to the row identifiers using documented rules; record unmapped and ambiguous records rather than silently guessing.
4
Encode and audit memberships.
Set an entry to one when the resolved gene belongs to that defined set, and zero otherwise. Check set sizes, duplicate records, and overlaps.

Worked Example: Encoding Two Sets in a Small Universe

Suppose a hypothetical analysis uses six eligible genes, \(U=\{g_1,g_2,g_3,g_4,g_5,g_6\}\). A curated pathway has members \(\{g_1,g_3,g_5\}\), and an ontology term has members \(\{g_2,g_3,g_5,g_6\}\). All identifiers have already been resolved to the same gene identifiers, and the definitions use the same release and annotation policy.

The rows are ordered as \(g_1,\ldots,g_6\), and the columns are the pathway and the ontology term. The resulting matrix is

$$ M = \begin{pmatrix} 1 & 0\\ 0 & 1\\ 1 & 1\\ 0 & 0\\ 1 & 1\\ 0 & 1 \end{pmatrix}. $$

For example, row three is \((1,1)\) because \(g_3\) belongs to both sets; row four is \((0,0)\) because \(g_4\) belongs to neither. Summing the first column gives pathway size \(1+0+1+0+1+0=3\). Summing the second gives ontology-term size \(0+1+1+0+1+1=4\). The two sets overlap at \(g_3\) and \(g_5\), so their intersection has two genes.

These counts describe this matrix for this universe and these definitions. They do not show that either set is unusually associated with a phenotype.

Identifier Choices Change Membership

Gene identifiers are not interchangeable labels. A resource may use a stable database identifier, a gene symbol, a transcript identifier, or an older identifier that has since been retired. Symbols can be aliased, reused, or changed; some identifiers refer to genes that are split, merged, or otherwise reannotated over time. A mapping step can therefore change which rows receive a one in a membership column.

A robust workflow chooses one gene-level identifier system for the matrix and documents the mapping from each source. It should distinguish an unambiguous mapping from a one-to-many or many-to-one mapping. For example, if one source identifier maps to two current genes, assigning its annotation to both may inflate memberships; choosing one without justification may discard a valid assignment. There is no universally correct resolution rule for every ambiguity. The rule should fit the biological and data context, be applied consistently, and be reported. Unresolved records can be retained in a mapping log and excluded from the matrix rather than being silently assigned.

Worked Example: An Ambiguous Symbol Alters a Set

Consider the hypothetical universe \(U=\{\text{ENSG-A},\text{ENSG-B},\text{ENSG-C},\text{ENSG-D}\}\). A source provides a pathway membership list using symbols: “ALFA,” “BETA,” and “GAMMA.” In a hypothetical identifier map, ALFA maps only to ENSG-A, BETA maps only to ENSG-C, and GAMMA maps ambiguously to ENSG-B or ENSG-D. Assume the set has no other members in this universe.

If the analyst's prespecified rule is to retain only unambiguous mappings, then the pathway in the analysis universe is \(\{\text{ENSG-A},\text{ENSG-C}\}\). In row order A, B, C, D, its membership column is \((1,0,1,0)^\mathsf{T}\), with size \(1+0+1+0=2\). The GAMMA record is logged as unresolved rather than assigned.

If a different, explicitly justified rule assigned GAMMA to both possible genes, the set would instead be \(\{\text{ENSG-A},\text{ENSG-B},\text{ENSG-C},\text{ENSG-D}\}\), giving column \((1,1,1,1)^\mathsf{T}\) and size four. This is not a minor formatting difference: the number and identity of member genes change. The two columns should not be treated as equivalent definitions of the same observed set. A sensitivity analysis can compare the resulting membership structures, but it must label each mapping rule.

Identifier harmonization also affects duplicates. If two source records resolve to the same gene and set, the binary matrix still records one membership, not two. The matrix represents whether a gene is a member, rather than how many annotation records happened to support that membership. If record counts or evidence strength matter, they require a separate representation and an explicit interpretation; they should not be smuggled into a binary membership value.

Set Size, Overlap, and Matrix Checks

The matrix makes several basic checks and summaries straightforward. The sum of column \(k\) is the number of genes in set \(S_k\cap U\). The sum of row \(i\) is the number of included sets to which gene \(g_i\) belongs. A gene with a large row sum is annotated to many of the included categories; this is a property of the chosen collection of sets, not automatically evidence that the gene is more important.

Pairwise set overlap can also be read from the matrix. For two columns \(j\) and \(k\), the sum \(\sum_{i=1}^n M_{ij}M_{ik}\) counts genes that have a one in both columns. This fact follows because each product is one exactly when both memberships are one, and is zero otherwise. In matrix notation, every entry of \(M^\mathsf{T}M\) is a pairwise overlap count; its diagonal entries are set sizes.

Justification: For any gene \(g_i\), \(M_{ij}M_{ik}=1\) if and only if \(g_i\in S_j\cap U\) and \(g_i\in S_k\cap U\). Otherwise, the product is zero. Therefore summing these products over all rows counts precisely the genes in \((S_j\cap U)\cap(S_k\cap U)\). When \(j=k\), \(M_{ij}^2=M_{ij}\), so the diagonal sum is the size of \(S_j\cap U\).

Worked Example: Reading Overlap Counts From a Matrix

Use the six-gene matrix from the first example. Let column one be the pathway and column two be the ontology term. The pathway size is the diagonal count \(1^2+0^2+1^2+0^2+1^2+0^2=3\), and the ontology-term size is \(0^2+1^2+1^2+0^2+1^2+1^2=4\).

The overlap is the off-diagonal sum \(1\cdot0+0\cdot1+1\cdot1+0\cdot0+1\cdot1+0\cdot1=2\). Thus the overlap consists of \(g_3\) and \(g_5\), consistent with the membership lists. The overlap matrix is

$$ M^\mathsf{T}M = \begin{pmatrix} 3 & 2\\ 2 & 4 \end{pmatrix}. $$

This calculation is descriptive. It tells us how the two sets intersect under the specified universe and annotation policy; it does not provide a p-value or a conclusion about association.

Definitions Are Part of the Result

A membership matrix is reproducible only when its construction choices are reproducible. At minimum, record the universe, the row identifier type and version, the source and release for each collection of sets, the mapping rules, and the policy for direct versus inherited ontology annotations. Also state whether sets with no members in \(U\) were retained, whether duplicate memberships were collapsed, and how ambiguous mappings were handled.

Changing any of these choices can change set size and overlap. Restricting the universe to genes with available association scores removes rows from every set. Updating an ontology annotation release may add or remove memberships. Propagating annotations to parent terms can make broader terms larger and increase overlap among related terms. These changes do not necessarily mean that the underlying biology changed; they may reflect a different representation or data-availability rule.

For a gene-level score vector \(x\), one can use the matrix to identify the scores belonging to a set: the \(i\)th score is included for set \(k\) when \(M_{ik}=1\). A sum such as \(\sum_i M_{ik}x_i\) is a descriptive aggregate under this membership definition. Its value depends on both the scores and the set construction. It is not an enrichment test, and interpreting it inferentially requires a separate model and null hypothesis.

Common Mistakes

  • Treating set names as definitions. Two categories with the same or similar names may have different members. Use stable set identifiers, source releases, and explicit membership rules.
  • Assuming a pathway and an ontology term are the same kind of object. Both can be encoded as gene sets, but their organization and annotation process differ. Preserve the source and term type.
  • Ignoring the universe. A database may list genes that are absent from the analysis matrix. Report memberships relative to the stated universe, \(S_k\cap U\).
  • Silently resolving ambiguous identifiers. Arbitrary mapping can add, remove, or duplicate gene memberships. Define a rule, document unresolved cases, and assess consequential alternatives.
  • Reading overlap as evidence of enrichment. Shared members are a property of set definitions. Statistical evidence requires a specified inferential procedure; a membership matrix alone supplies none.
Key takeaway: A gene set is not just a label: it is a defined membership relation between a specified gene universe and a specified category. A membership matrix makes that relation explicit, while identifier, release, and annotation policies determine what the matrix actually contains.

Check Your Understanding

Answer using the definitions and conventions in this tutorial.

  1. What do the rows and columns of a binary gene-membership matrix represent?
  2. Why can the size of a pathway in an analysis differ from the number of genes listed by its source database?
  3. Name two choices that can change memberships for an ontology term without changing the term's displayed name.
  4. In a binary membership matrix, what does the sum of a column represent, and what does an off-diagonal entry of \(M^\mathsf{T}M\) represent?
  5. Why should an ambiguous gene-identifier mapping rule be documented rather than applied silently?
Clinical Biostats