Session #3: Model-based gene-set analysis: MGSA
Free University Berlin
2026-04-26
\[ \newcommand{\argmax}{\mathop{\mathrm{arg\,max}\;}\limits} \]
We have seen in the previous chapter that a major difficulty of the standard approach to GO overrepresentation analysis is that each term is analyzed in isolation.
MGSA is a completely different approach to GO analysis that seeks to find the best combination of terms that correspond to an experimental result.
A Markov chain has a
We can represent the transition probabilities in matrix form
\[ \mathbf{P}= \begin{array}{c|cc} w_{t-1}\backslash w_t & s & c \\ \hline s & 0.3 & 0.7 \\ c & 0.5 & 0.5 \\ \end{array} \]
Key question:
\[ \begin{array}{c|cccc} & w_0 & w_1 & w_2& \ldots & \\ \hline p(\mathrm{sunny})& 1 & 0.3 & 0.44 & \ldots & \pi_1 \\ p(\mathrm{cloudy})& 0 & 0.7 & 0.56 & \ldots & \pi_2 \\ \end{array} \]
\[ \begin{align} \mathbf{\pi}\begin{bmatrix}0.3 & 0.7\\0.5 & 0.5\end{bmatrix} &= \mathbf{\pi} \\ \begin{bmatrix}\pi_1 & \pi_2\end{bmatrix}\begin{bmatrix}0.3 & 0.7\\0.5 & 0.5\end{bmatrix} &= \begin{bmatrix}\pi_1 & \pi_2\end{bmatrix} \\ \begin{bmatrix}(0.3\pi_1 + 0.5\pi_2) & (0.7\pi_1 + 0.5\pi_2)\end{bmatrix} &= \begin{bmatrix}\pi_1 & \pi_2\end{bmatrix} \\ \end{align} \]
\[ \begin{equation} p(\theta \mid \text{data}) = \frac{\overbrace{p(\text{data}\mid\theta)}^{\text{likelihood}} \cdot \overbrace{p(\theta)}^{\text{prior}}} {\underbrace{p(\text{data})}_{\text{evidence } = NC}} \end{equation} \]
If \(P(x)\) can be evaluated, at least to within a multiplicative constant; that is, we can evaluate a function \(g(x)\) such that
\[ P(x) = \frac{g(x)}{NC} \]
David J. C. MacKay (2003) Information Theory, Inference and Learning Algorithms. Cambridge University Press
\[ \hat{\mu} = \frac{1}{N}\sum_{1}^{N}x \qquad x_i \sim p(x) \text{ (approximately, post burn-in)} \]
Design the transition probabilities \(T(y\mid x)\) to satisfy the detailed balance condition: \[ p(x)\,T(y\mid x) = p(y)\,T(x\mid y) \]
Sum both sides over all values of \(x\): \[ \begin{align} \sum_x p(x)\,T(y\mid x) &= \sum_x p(y)\,T(x\mid y) \\ &= p(y) \underbrace{\sum_x T(x\mid y)}_{=1 \text{, since } T(\cdot\mid y) \text{ is a valid distribution}} \\ &= p(y) \end{align} \]
Here, \(x\) and \(y\) are the discrete states (e.g., sunny and rainy)
Let us first examine the case where the proposal distribution is symmetric, i.e., \(q(y\mid x)=q(x\mid y)\).
This class of algorithms are known as Metropolis algorithms and are a special case of MH algorithms
Let \(x, y\) be two states with \(p(y) < p(x)\). Then we get \[ \begin{align} a(x,y) &= \min\!\left(1,\ \frac{p(y)\,q(x\mid y)}{p(x)\,q(y\mid x)}\right) \\ &= \min\!\left(1,\ \frac{p(y)}{p(x)}\right) \\ &= \frac{p(y)}{p(x)} \quad \bullet \text{ because } p(y) < p(x)\\ \end{align} \]
The Metroplis algorithm (and the MH algorithm) draw a uniformly distributed random number \(r\in [0,1]\) and choose to transition to state \(y\) if \(r<a(x,y)\)
Thus in this case, it will not always choose to do so because \(\tfrac{p(y)}{p(x)} < 1\),
| Discrete | Continuous | |
|---|---|---|
| state space | finte or countable set | Interval of \(\mathbb{R}\) or \(\mathbb{R}^{n}\) |
| \(p(x)\) | a probability mass function | a density |
| normalization | \(\sum_x p(x) = 1\) | \(\int p(x) dx = 1\) |
| Detailed balance | \(\sum_x p(x) T(y\mid x) = p(y)\) | \(\int p(x) T(y\mid x) dx = p(y)\) |
Example
i.e., we want to generate samples \(x_1, x_2, \ldots, x_n\) with \[ x_t \sim \mathcal{N}(\mu=0, \sigma^2=1) \]
Start the MCMC at \(x_0=0\)
Propose moves from current value \(x_t \rightarrow x_{t+1}\) with a uniform transition kernel: \[ q(x_t, x_{t+1})\sim \mathcal{U}\left(x_t - \frac{1}{2}, x_t + \frac{1}{2}\right) \]
That is, given the chain’s current position \(x_t\), the proposed next value \(x_{t+1}\) is drawn uniformly at random from the interval centered on \(x_t\), with width 1. Every point in that interval is equally likely.
\[ q(x_t, x_{t+1}) = \begin{cases} 1 & x_{t+1} \in (x_t - \frac{1}{2},x_t + \frac{1}{2}) \\ 0 & \text{otherwise} \end{cases} \]
\[ \begin{align} \log h &= \log \frac{p(a)}{p(b)}\\ &= \log \frac{\frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(x-\mu)^2}{2\sigma^2}}}{\frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(y-\mu)^2}{2\sigma^2}}}\\ &= \log \frac{e^{-\frac{(x-\mu)^2}{2\sigma^2}}}{e^{-\frac{(y-\mu)^2}{2\sigma^2}}}\\ &= \frac{1}{2\sigma^2}\left[ (x-\mu)^2 - (y-\mu)^2\right] \end{align} \]
Acceptance rate: 31.96%
Acceptance rate: 99.12%
Acceptance rate: 3.22%
Acceptance rate: 35.52%
state (such as differential expression), which can be ON or OFF. The true state of any gene is hidden.ON state would correspond to differential expression, and the OFF state would correspond to a lack of differential expression of a gene. Our model hence assumes that differential expression is the consequence of the annotation to some terms that are active.An additional parameter \(p\) represents the prior probability of a term being in the active state. The probability \(p\) is typically low (less than 0.5), which has the effect of introducing a penalization for increasing the number of active terms. This favors results that identify a relatively low number of active terms.
Gene categories, or terms (\(T_i\)) that constitute the first layer can be either active or inactive.
active activate the hidden state (\(H_j\)) of all genes annotated to them, with the other genes remaining OFF.active, \(p\), the false positive rate, \(\alpha\), and the false negative rate, \(\beta\).More formally, the model can be described using a Bayesian network with three layers that is augmented with a set of parameters.
active (1) or inactive (0).More formally, the model can be described using a Bayesian network with three layers that is augmented with a set of parameters.
ON (1), or OFF (0).For didactic purposes, we will initially explain a simplified version of MGSA in which the parameters \(\alpha\), \(\beta\) and \(p\) are considered to have known, fixed values.
The state propagation of the nodes can be modeled using various local probability distributions (LPDs), denoted by \(P\). The joint probability distribution for this Bayesian network can be written as
\[ P(T,H,O) \; = \; P(T)P(H|T)P(O|H)\; = P(T)\prod_{i=1}^n P(H_i|T) P(O_i|H_i). \tag{1}\]
then
\[ P(T) = p^{m_{1|T}}(1-p)^{m_{0|T}}. \tag{2}\]
on.In the following, \(T(H_i) \subseteq T\) is used to denote the set of terms to which gene \(H_i\) is annotated, i.e., the parents of \(H_i\) in the Bayesian network. For the \(T \rightarrow H\) links, any node \(H_i \in H\) is ON (\(H_i=1\)) if at least one of its parents is active. Otherwise it is OFF:
\[ P(H_i=1|T) = \begin{cases}1, & \text{if } \exists \; T_j \in T(H_i): T_j=1 \\ 0, & \text{otherwise.} \end{cases} %P(H_i|\emph{Pa}(H_i)) = \bigvee_{T\in\emph{Pa}(H_i)}T \label{eqn:lpd.hidden.given.t} \tag{3}\]
Note that this transition is deterministic.
ON, then in the MGSA model any annotated gene is (truly) ON.For the \(H \rightarrow O\) connection, the following two Bernoulli distributions are used:
\[ P(O_i=1|H_i=0) = \alpha \label{eq:mgsa-bernoulli-alpha} \]
and
\[ P(O_i=0|H_i=1) = \beta. \label{eq:mgsa-bernoulli-beta} \]
OFF, although the hidden node is ON (false negative) etc.ON.\[ P(O|T) = \alpha^{n_{10|T}} (1 - \alpha)^{n_{00|T}} (1-\beta)^{n_{11|T}} \beta^{n_{01|T}}. \]
\[ P(O|T) = \alpha^{n_{10|T}} (1 - \alpha)^{n_{00|T}} (1-\beta)^{n_{11|T}} \beta^{n_{01|T}}. \tag{4}\]
active terms, because otherwise their probability is zero according to Equation 3.In Bayesian statistics, maximum a posteriori (MAP) estimation is often used to generate an estimate of the maximum value of a probability distribution.
That is, if \(x\) is used to refer to the data (\(x\) can be an arbitrary expression), and \(\theta\) is used to refer to the parameters of a model, then Bayes’ law states that:
\[ P(\theta | x) = \dfrac{P(x|\theta )P(\theta )}{P(x)} \label{eq:bayes-law-for-map} \]
\[ \argmax_{\theta} P(\theta | x) = \argmax_{\theta} P(x|\theta )(P(\theta ) \label{eq:map} \]
active terms as well as values for \(\alpha,\beta\), and \(p\).These considerations motivate the use of the MCMC algorithm to sample from the posterior distribution.
ON state (e.g., differentially expressed).active term, then the observation could be explained by risking an error of one false-negative. The same can be noticed if \(T_2\) is the only active term.active state.\[ P(X=x')=\sum_{i} P(X=x',Y=y_i) \]
or
\[ P(X=x')=\int_Y P(X=x',Y) \mathrm{d}Y \]
MCMC
One of the best known and most effective algorithms for this purpose is the Metropolis-Hasting algorithm, which is a Markov chain Monte Carlo (MCMC) method. The MCMC algorithm performs a random walk over the term and parameter configurations, which asymptotically provides a random sampler according to the target distribution \(P(T|O)\).
Given the current configuration of the terms denoted by \(T^t\), the algorithm proposes a neighbor state \(T^p\) in accordance to a proposal density function \(Q_T(\cdot|T^t)\). A value \(r\) is sampled uniformly from the range (0,1). Then, if
\[ r < P_{\text{accept}}(T^t,T^p) = \frac{P(T^{p}|O)Q_T(T^{t}|T^{p})}{P(T^{t}|O)Q_T(T^{p}|T^t)} \label{eqn:acceptance} \]
the proposal is accepted, i.e., \(T^{t+1} = T^p\), otherwise it is rejected, i.e., \(T^{t+1} = T^t\).
Using Bayes’ law, we have
\[ P(T^{p}|O) = \dfrac{P(O|T^{p})P(T^{p})}{P(O)} \label{eqn:cond.prob} \]
and similarly for \(T^{t}\). Substituting these expressions for \(P(T^{p}|O)\) and \(P(T^{t}|O)\) cancels out the normalization constant \(P(O)\). The acceptance probability is then:
\[ P_{\text{accept}}(T^t,T^p) = \frac{P(O|T^{p})P(T^{p})Q_T(T^{t}|T^{p})}{P(O|T^{t})P(T^{t})Q_T(T^{p}|T^t)}. \label{eqn:accept.prop.2} \tag{5}\]
Equation 5 is used iteratively to define a random walk through the space of configurations. A burn-in period consisting of a certain number of iterations is used to initialize the MCMC chain (in our implementation of the MGSA algorithm in the Ontologizer, the default is 20,000 iterations).
active. Then\[ P(T_i|O)\approx \frac{C(T_i)}{l}. \label{eqn:mgsa-marginal} \]
In order to finish the description of the algorithm, one needs to define classes of operations of which a proposal is chosen, that is, we need to specify \(Q_T(T^p|T^t)\).
Denote by \(T^p \leftrightarrow_T T^t\) the binary relation that states that \(T^p\) be constructed from \(T^t\) by either
active/inactive state of a single term, or byactive term and a single inactive term.Denote by \(N(T)\) the neighborhood of a given configuration for \(T\), that is, the number of different operations that can be applied once to \(T\) in order to get a new configuration. At first, there are \(m\) terms in total, each of which can be toggled. In addition, there are \(m_{0|T}m_{1|T}\) possibilities to combine terms that are active with terms that are inactive. Thus, there are a total of \(N(T)=m+m_{0|T}m_{1|T}\) valid state transitions. We would like to sample the valid proposals with equal probability; therefore, the proposal distribution \(Q_T\) is determined by
\[ Q_T(T^p|T^t)=\begin{cases} \frac{1}{N(T^t)}, & \text{if } T^p \leftrightarrow_T T^t\\ 0, & \text{otherwise.} \end{cases}, \]
which we can use to rewrite Equation 5 to:
\[ P_{\text{accept}}(T^t,T^p) = \frac{P(O|T^{p})P(T^{p})N(T^t)}{P(O|T^{t})P(T^{t})N(T^p)}. \label{eqn:accept.prop.3} \]
Require: \(O\), \(l\) (number of steps)
MGSA results