Mutational signature estimation with Hierarchical Dirichlet Process
The Hierarchical Dirichlet Process (HDP) is used in several fields, including cancer genomics. While researching methods for mutational signature estimation, I found several studies that applied HDPs but gave little detail on how the model maps to this problem.
Nicola Roberts’ dissertation describes parts of the mathematical model in its appendix. This post fills in the derivation, starting with a finite mixture model for mutational signatures, then moving to the Dirichlet Process and the Hierarchical Dirichlet Process.
Introduction
Cancer cells have elevated rates of somatic mutation. The resulting mutation patterns help identify mechanisms that drive the disease (Fischer et al., 2013), which can inform treatment and prevention.
One type of somatic mutation is the single nucleotide variant (SNV), also referred to as a single base substitution. This involves the replacement of one base pair in the genome with another. There are six possible base pair mutations: C:G>A:T, C:G>G:C, C:G>T:A, T:A>A:T, T:A>C:G, and T:A>G:C. When considering the context of the immediate 5’ and 3’ neighboring bases, the total number of mutations increases to 96, calculated as . These are known as trinucleotide mutation channels. Examples of such mutations include ACA:TGT>AAA:TTT and ACT:TGA>AGT:TCA. For simplicity, we will abbreviate these mutations as ACA>AAA and ACT>AGT respectively.
Mutational signatures
A mutational signature with respect to trinucleotide mutation channels is a discrete probability distribution over the 96 mutational channels i.e. where
A mutational signature can be visualised as in the following.

The framework for studying somatic mutations through mutational signatures was introduced in a landmark study by Alexandrov et al. (2013), where over 7,000 bulk-sequenced cancer samples were analyzed. Conceptually, a mutational signature represents a biological process acting on the genome, leaving a distinct imprint captured in a probability vector, . The COSMIC project maintains a list of mutational signatures and their proposed underlying biological processes. Some of the signatures and their probability vectors are consistently identifiable across most examined cohorts and signature identification algorithms (cite).
To estimate mutational signatures and their activities, Alexandrov et al. employed Non-Negative Matrix Factorization (NMF). NMF and its variations remain the most widely used methods for estimating mutational signatures and mutational signature activities.
Dirichlet Process
The Dirichlet Process (DP), denoted , is a distribution over probability measures. Sampling gives a probability measure . Its two parameters are the concentration and the base measure ; the support of is a subset of the support of .
To sample from the Dirichlet process, we begin by drawing an infinite sequence of i.i.d. samples . Then, we draw a vector , where refers to the stick-breaking process. Intuitively, the stick-breaking process works by repeatedly breaking off and discarding a random fraction of a “stick” that is initially of length . Each broken off part of the stick has a length . The stick-breaking process generates a sequence , where the total length of all the broken pieces is 1.
Finally, we construct the random measure as:
where is a Dirac delta function centered at . The resulting measure is discrete, with countable support given by .
Mathematical properties
The base measure is the mean of the random measure . Specifically, for any measurable set , the expectation of under the Dirichlet process is given by [@millerDirichletProcessModels]:
As , the distribution of converges to in the weak topology, meaning that larger values of make more closely resemble the base measure .
is centered around the prior distribution , with the concentration parameter controlling how tightly clusters around . A higher reduces variability, causing to approximate more closely.
Dirichlet Process resources
Recommended material for Dirichlet Process
Notebook implementations of the Dirichlet Process
Modelling mutational signatures with a Dirichlet Process
Previous studies have used Dirichlet processes to model trinucleotide mutations associated with mutational signatures (cite) and (cite). Appendix B (p. 234) and Chapter 4 (p. 132) in (cite) provide an overview but omit parts of the derivation. This section works through the model, beginning with a finite mixture. Consider the trinucleotide mutations within a single sample, encoded as for the 96 possible mutation types.
Step 1: Known number of mutational signatures
First assume we know the number of active mutational signatures, denoted by . Each signature is a discrete probability distribution , where . With no prior knowledge of the specific signatures, we model these distributions as:
where denotes the Dirichlet distribution, serving as a symmetric prior. Similarly, we assume no prior information about the activity of these mutational signatures. We model the activity of the mutational signatures in a sample as:
where is a hyperparameter controlling the concentration of the distribution. Next, let represent the event that the -th mutation was generated by the -th mutational signature. If we observe a total of trinucleotide mutations in our sample, we draw each according to the mutational signature activity , as follows:
indicating that the probability , where is the activity level of signature . Finally, the observed trinucleotide mutation is drawn from a categorical distribution based on the corresponding mutational signature and its distribution :
This model describes how the mutational signatures generate the observed trinucleotide mutations .
Graphical model for known number of components
We can visualize the process that generates trinucleotide mutations in a sample using a graphical model:

Here the grey background color indicates that is an observed random variable.
Step 2: Equivalent model as mixture
Next, we integrate out the indicator variable to obtain an equivalent mixture representation. As before, we draw the mutational signature activities as follows:
Let . Similar to the last step, we generate the mutational signatures as
Now, instead of assuming that each observation is first assigned a mutational signature and then drawn from the corresponding signature we directly draw from , with probabilities for each observation:
Here, represents a finite mixture distribution with support on the acting mutational signatures. Finally, we draw the trinucleotide mutation as follows:
Step 3: Unknown, unbounded number of components
Let
We now extend the model from the previous step to allow for an unknown number of components , with any being possible. As in the previous step, we generate the underlying mutational signatures from as follows:
Previously, we sampled a finite set of mutational signatures , but now we generate an infinite sequence of signatures. Accordingly, the mutational signature activities now lie in . To model these activities, we use the Stick-breaking process, which defines a distribution over . Thus, we sample the mutational signature activities as:
Intuitively, the stick-breaking process works by repeatedly breaking off and discarding a random fraction of a “stick” that is initially of length . Each broken off part of the stick has a length . The stick-breaking process generates a sequence , where the total length of all the broken pieces is . Consequently, the mixture distribution , which previously had finite support, now has countably infinite support and takes the form:
where denotes the space of probability distributions on . We draw from the support of , which is , as follows:
Finally, we observe the mutations as
Step 4: Shorthand notation
The Dirichlet Process notation summarizes the construction of from and :
This completes the derivation of a Dirichlet Process model for trinucleotide mutations, as used in (cite). It provides an alternative to the classical Non-negative Matrix Factorisation approach used in (cite) for estimating mutational signatures and their activities.
Graphical model of a Dirichlet Process
We can visualise the Dirichlet process as a graphical model:

Hierarchical Dirichlet Process
A Hierarchical Dirichlet Process (HDP) composes multiple Dirichlet Processes (cite). For trinucleotide mutations, it gives each sample a separate mixture while sharing signatures across samples. We start with the prior distribution and draw a common base distribution :
Assume we have samples. For each sample, we draw a separate Dirichlet Process from the common base distribution as
The Dirichlet Process sits at the top, with the processes below it. Each varies around , allowing samples to share information through the common base distribution. If we observe mutations in sample , we draw them as before:
The corresponding graphical model is:

Estimating signatures and their activities
Assume the mutational signatures act on the genome. Borrowing notation from the finite model, let denote the signature that generated mutation . Fitting an HDP gives an estimate of . The estimate for the probability vector of signature is
where has mass at position . Further, we estimate the mutational signature activity of mutational signature in sample by
Comparison with NMF
Compared with classical Non-negative Matrix Factorization (NMF), the HDP can incorporate prior knowledge and group structure (cite). It estimates signature activity while discovering signatures de novo, and can match observations to an existing signature library while identifying new signatures by pseudo-counting that library as observational data. It also learns the number of signatures from the data. Some NMF variants can quantify uncertainty, but the HDP provides this more directly.
References
Python implementations 1
- https://radimrehurek.com/gensim/models/hdpmodel.html
- Gensim is a Python library for topic modelling, document indexing and similarity retrieval with large corpora. Target audience is the natural language processing (NLP) and information retrieval (IR) community.
- https://github.com/piskvorky/gensim/blob/develop/gensim/models/hdpmodel.py
- based on https://github.com/blei-lab/online-hdp
- https://towardsdatascience.com/dont-be-afraid-of-nonparametric-topic-models-d259c237a840
- https://towardsdatascience.com/dont-be-afraid-of-nonparametric-topic-models-part-2-python-e5666db347a
- https://github.com/ecoronado92/hdp
- https://github.com/morrisgreenberg/hdp-py
Python implementations 2
- https://radimrehurek.com/gensim/models/hdpmodel.html
- Gensim is a Python library for topic modelling, document indexing and similarity retrieval with large corpora. Target audience is the natural language processing (NLP) and information retrieval (IR) community.
- https://github.com/piskvorky/gensim/blob/develop/gensim/models/hdpmodel.py
- based on https://github.com/blei-lab/online-hdp
- https://towardsdatascience.com/dont-be-afraid-of-nonparametric-topic-models-d259c237a840
- https://towardsdatascience.com/dont-be-afraid-of-nonparametric-topic-models-part-2-python-e5666db347a
- https://github.com/ecoronado92/hdp
- https://github.com/morrisgreenberg/hdp-py
- Simple Jupyter notebook: https://github.com/tdhopper/notes-on-dirichlet-processes/blob/master/pages/2015-07-30-sampling-from-a-hierarchical-dirichlet-process.ipynb (just for sampling?)