# Inferring Somatic Signatures from Single Nucleotide Variant Calls

## Table of Contents

- 1. Motivation: The Concept Behind Mutational Signatures
- 2. Methodology: From Mutations to Somatic Signatures
- 3. Workflow: Analysis with the SomaticSignatures Package
- 4. Use case: Estimating Somatic Signatures from TCGA WES Studies
  - 4.1. Data: Preproccessing of the TCGA WES Studies
  - 4.2. Motifs: Extracting the Sequence Context of Somatic Variants
  - 4.3. Decomposition: Inferring Somatic Signatures
  - 4.4. Assessment: Number of Signatures
  - 4.5. Visualization: Exploration of Signatures and Samples
    - 4.5.1. Customization: Changing Plot Properties
  - 4.6. Clustering: Grouping by Motifs or Samples
  - 4.7. Extension: Correction for Batch Effects and Confounding Variables
  - 4.8. Extension: Normalization of Sequence Motif Frequencies
  - 4.9. Extension: Motifs from Non-Reference Genomes
- 5. Alternatives: Inferring Somatic Signatures with Different Approaches
- 6. Frequently Asked Questions
  - 6.1. Citing SomaticSignatures
  - 6.2. Getting Help
  - 6.3. Installing and Upgrading
  - 6.4. Working with VRanges
- 7. References
- 8. Session Information

Julian Gehring, EMBL Heidelberg

## 1 Motivation: The Concept Behind Mutational Signatures

Recent publications introduced the concept of identifying mutational signatures from cancer sequencing studies and linked them to potential mutation generation processes [11,2,3]. Conceptually, this relates somatically occurring single nucleotide variants (SNVs) to the surrounding sequence which will be referred to as mutational or somatic motifs in the following. Based on the frequency of the motifs occurring in multiple samples, these can be decomposed mathematically into so called mutational signatures. In case of the investigation of tumors, the term somatic signatures will be used here to distinguish them from germline mutations and their generating processes.

The `SomaticSignatures` package provides an efficient and user-friendly implementation for the extraction of somatic motifs based on a list of somatically mutated genomic sites and the estimation of somatic signatures with different matrix decomposition algorithms. Methodologically, this is based on the work of Nik-Zainal and colleagues [11]. If you use `SomaticSignatures` in your research, please cite it as:

> Gehring, Julian S., Bernd Fischer, Michael Lawrence, and Wolfgang Huber.
> SomaticSignatures: Inferring Mutational Signatures from Single Nucleotide Variants.
> Bioinformatics, 2015, btv408. http://dx.doi.org/10.1093/bioinformatics/btv408

## 2 Methodology: From Mutations to Somatic Signatures

The basic idea of somatic signatures is composed of two parts:

Firstly, each somatic mutation is described in relation of the sequence context in which it occurs. As an example, consider a SNV, resulting in the alteration from `A` in the normal to `G` in the tumor sample, that is embedded in the sequence context `TAC`. Thus, the somatic motif can be written as `TAC>TGC` or `T.C A>G`. The frequency of these motifs across multiple samples is then represented as a matrix \(M_{ij}\), where \(i\) counts over the motifs and \(j\) over the samples.

In a second step, the matrix \(M\) is numerically decomposed into two matrices \(W\) and \(H\)

\(M_{ij} \approx \sum_{k=1}^{r} W_{ik} H_{kj}\)

for a fixed number \(r\) of signatures. While \(W\) describes the composition of each signature in term of somatic motifs, \(H\) shows the contribution of the signature to the alterations present in each sample.

## 3 Workflow: Analysis with the SomaticSignatures Package

The `SomaticSignatures` package offers a framework for inferring signatures of SNVs in a user-friendly and efficient manner for large-scale data sets. A tight integration with standard data representations of the `Bioconductor` project [8] was a major design goal. Further, it extends the selection of multivariate statistical methods for the matrix decomposition and allows a simple visualization of the results.

For a typical workflow, a set of variant calls and the reference sequence are needed. Ideally, the SNVs are represented as a `VRanges` object with the genomic location as well as reference and alternative allele defined. The reference sequence can be, for example, a `FaFile` object, representing an indexed FASTA file, a `BSgenome` object, or a `GmapGenome` object. Alternatively, we provide functions to extract the relevant information from other sources of inputs. At the moment, this covers the MuTect [4] variant caller.

Generally, the individual steps of the analysis can be summarized as:

1. The somatic motifs for each variant are retrieved from the reference sequence with the `mutationContext` function and converted to a matrix representation with the `motifMatrix` function.
2. Somatic signatures are estimated with a method of choice (the package provides with `nmfDecomposition` and `pcaDecomposition` two approaches for the NMF and PCA).
3. The somatic signatures and their representation in the samples are assessed with a set of accessor and plotting functions.

To decompose \(M\), the `SomaticSignatures` package implements two methods:

Non-negative matrix factorization (NMF)
  The NMF decomposes \(M\) with the constraint of positive components in \(W\) and \(H\) [7]. The method was used [11] for the identification of mutational signatures, and can be computationally expensive for large data sets.
Principal component analysis (PCA)
  The PCA employs the eigenvalue decomposition and is therefore suitable for large data sets [13]. While this is related to the NMF, no constraint on the sign of the elements of \(W\) and \(H\) exists.

Other methods can be supplied through the `decomposition` argument of the `identifySignatures` function.

## 4 Use case: Estimating Somatic Signatures from TCGA WES Studies

In the following, the concept of somatic signatures and the steps for inferring these from an actual biological data set are shown. For the example, somatic variant calls from whole exome sequencing (WES) studies from The Cancer Genome Atlas (TCGA) project will be used, which are part of the `SomaticCancerAlterations` package.

### 4.1 Data: Preproccessing of the TCGA WES Studies

The `SomaticCancerAlterations` package provides the somatic SNV calls for eight WES studies, each investigating a different cancer type. The metadata summarizes the biological and experimental settings of each study.

The starting point of the analysis is a `VRanges` object which describes the somatic variants in terms of their genomic locations as well as reference and alternative alleles. For more details about this class and how to construct it, please see the documentation of the `VariantAnnotation` package [12]. In this example, all mutational calls of a study will be pooled together, in order to find signatures related to a specific cancer type.

To get a first impression of the data, we count the number of somatic variants per study.

### 4.2 Motifs: Extracting the Sequence Context of Somatic Variants

In a first step, the sequence motif for each variant is extracted based on the genomic sequence. Here, the `BSgenomes` object of the human hg19 reference is used for all samples. However, personalized genomes or other sources for sequences, for example an indexed FASTA file, can be used naturally. Additionally, we transform all motifs to have a pyrimidine base (`C` or `T`) as a reference base [2]. The resulting `VRanges` object then contains the new columns `context` and `alteration` which specify the sequence content and the base substitution.

To continue with the estimation of the somatic signatures, the matrix \(M\) of the form {motifs × studies} is constructed. The `normalize` argument specifies that frequencies rather than the actual counts are returned.

The observed occurrence of the motifs, also termed somatic spectrum, can be visualized across studies, which gives a first impression of the data. The distribution of the motifs clearly varies between the studies.

### 4.3 Decomposition: Inferring Somatic Signatures

The somatic signatures can be estimated with each of the statistical methods implemented in the package. Here, we will use the `NMF` and `PCA`, and compare the results. Prior to the estimation, the number \(r\) of signatures to obtain has to be fixed; in this example, the data will be decomposed into 5 signatures.

The individual matrices can be further inspected through the accessors `signatures`, `samples`, `observed` and `fitted`.

### 4.4 Assessment: Number of Signatures

Up to now, we have performed the decomposition based on a known number \(r\) of signatures. In many settings, prior biological knowledge or complementing experiments may allow to determine \(r\) independently. If this is not the case, we can try to infer suitable values for \(r\) from the data.

Using the `assessNumberSignatures` function, we can compute the residuals sum of squares (RSS) and the explained variance between the observed \(M\) and fitted \(WH\) mutational spectrum for different numbers of signatures. These measures are generally applicable to all kinds of decomposition methods, and can aid in choosing a likely number of signatures. The usage and arguments are analogous to the `identifySignatures` function.

The obtained statistics can further be visualized with the `plotNumberSignatures`. For each tested number of signatures, black crosses indicate the results of individual runs, while the red dot represents the average over all respective runs. Please note that having multiple runs is only relevant for randomly seeded decomposition methods, as the NMF in our example.

\(r\) can then be chosen such that increasing the number of signatures does not yield a significantly better approximation of the data, i.e. that the RSS and the explained variance do not change sufficiently for more complex models. The first inflection point of the RSS curve has also been proposed as a measure for the number of features in this context [9]. Judging from both statistics for our dataset, a total of 5 signatures seems to explain the characteristics of the observed mutational spectrum well. In practice, a combination of a statistical assessment paired with biological knowledge about the nature of the data will allow for the most reliable interpretation of the results.

### 4.5 Visualization: Exploration of Signatures and Samples

To explore the results for the TCGA data set, we will use the plotting functions. All figures are generated with the `ggplot2` package, and thus, their properties and appearances can directly be modified, even at a later stage.

Focusing on the results of the NMF first, the five somatic signatures (named S1 to S5) can be visualized either as a heatmap or as a barchart.

Each signature represents different properties of the somatic spectrum observed in the data. While signature S1 is mainly characterized by selective `C>T` alterations, others as S4 and S5 show a broad distribution across the motifs.

In addition, the contribution of the signatures in each study can be represented with the same sets of plots. Signature S1 and S3 are strongly represented in the GBM and SKCM study, respectively. Other signatures show a weaker association with a single cancer type.

In the same way as before, the results of the PCA can be visualized. In contrast to the NMF, the signatures also contain negative values, indicating the depletion of a somatic motif.

Comparing the results of the two methods, we can see similar characteristics between the sets of signatures, for example S1 of the NMF and S2 of the PCA.

Since the observed mutational spectrum is defined by the data alone, it is identical for both all decomposition methods.

#### 4.5.1 Customization: Changing Plot Properties

As elaborated before, since all plots are generated with the `ggplot2` framework [15], we can change all their properties. To continue the example from before, we will visualize the relative contribution of the mutational signatures in the studies, and change the plot to fit our needs better.

If you want to visualize a large number of samples or signatures, the default color palette may not provide a sufficient number of distinct colors. You can add a well-suited palette to your plot, as we have shown before with the `scale_fill` functions. For example, `scale_fill_discrete` will get you the default `ggplot2` color scheme; while this supports many more colors, the individual levels may be hard to distinguish.

### 4.6 Clustering: Grouping by Motifs or Samples

An alternative approach to interpreting the mutational spectrum by decomposition is clustering. With the `clusterSpectrum` function, the clustering is computed, by grouping either by the `sample` or `motif` dimension of the spectrum. By default, the Euclidean distance is used; other distance measures, as for example cosine similarity, are implemented is the `proxy` package and can be passed as an optional argument.

### 4.7 Extension: Correction for Batch Effects and Confounding Variables

When investigating somatic signatures between samples from different studies, corrections for technical confounding factors should be considered. In our use case of the TCGA WES studies, this is of minor influence due to similar sequencing technology and variant calling methods across the studies. Approaches for the identification of so termed batch effects have been proposed [10,14] and existing implementations can be used in identifying confounding variables as well as correcting for them. The best strategy in addressing technical effects depends strongly on the experimental design; we recommend reading the respective literature and software documentation for finding an optimal solution in complex settings.

From the metadata of the TCGA studies, we have noticed that two different sequencing approaches have been employed, constituting a potential technical batch effect. The `ComBat` function of the `sva` package allows us to adjust for this covariate, which yields a mutational spectrum corrected for contributions related to sequencing technology. We can then continue with the identification of somatic signatures as we have seen before.

### 4.8 Extension: Normalization of Sequence Motif Frequencies

If comparisons are performed across samples or studies with different capture targets, for example by comparing whole exome with whole genome sequencing, further corrections for the frequency of sequence motifs can be taken into account [11]. The `kmerFrequency` function provides the basis for calculating the occurrence of k-mers over a set of ranges of a reference sequence.

As an example, we compute the frequency of 3-mers for the human toplevel chromosomes, based on a sample of 10'000 locations.

Analogously, the k-mer occurrence across a set of enriched regions, such as in exome or targeted sequencing, can be obtained easily. The following outlines how to apply the approach to the human exome.

With the `normalizeMotifs` function, the frequency of motifs can be adjusted. Here, we will transform our results of the TCGA WES studies to have the same motif distribution as of a whole-genome analysis. The `kmers` dataset contains the estimated frequency of 3-mers across the human genome and exome.

### 4.9 Extension: Motifs from Non-Reference Genomes

When we determine the sequence context for each alteration, we typically use one of the reference BSgenome packages in Bioconductor. But we are not restricted to those, and derive the somatic motifs from different types of sequence sources, for example 2bit and FASTA files. More precisely, the `mutationContext` function will work on any object for which a `getSeq` method is defined. You can get the full list available on your system, the results may vary depending on which packages you have loaded.

This allows us to perform our analysis also on non-standard organisms and genomes, for which a BSgenome package is not available, for example the 1000genomes human reference sequence. Or we can generate genomic references for specific populations, by updating the standard genomes with a set of known variants; see the documentation of the `BSgenome` package and the `injectSNPs` function in particular for this.

Taking further, we can base our analysis on the personalized genomic sequence for each individual, in case it is available. If we imagined that we had a set of somatic variant calls as `VCF` files and the personalized genomic sequence as `FASTA` files for two individuals `A` and `B` at hand, here a simple outline on how our analysis could work.

## 5 Alternatives: Inferring Somatic Signatures with Different Approaches

For the identification of somatic signatures, other methods and implementations exist. The original framework [11,3] proposed for this is based on the NMF and available for the Matlab programming language [1]. In extension, a probabilistic approach based on Poisson processes has been proposed [6] and implemented [5].

## 6 Frequently Asked Questions

### 6.1 Citing SomaticSignatures

If you use the `SomaticSignatures` package in your work, please cite it:

### 6.2 Getting Help

We welcome questions or suggestions about our software, and want to ensure that we eliminate issues if and when they appear. We have a few requests to optimize the process:

- All questions and follow-ups should take place over the Bioconductor support site, which serves as a repository of information. First search the site for past threads which might have answered your question.
- The subject line should contain SomaticSignatures and a few words describing the problem.
- If you have a question about the behavior of a function, read the sections of the manual page for this function by typing a question mark and the function name, e.g. `?mutationContext`. Additionally, read through the vignette to understand the interplay between different functions of the package. We spend a lot of time documenting individual functions and the exact steps that the software is performing.
- Include all of your R code and its output related to the question you are asking.
- Include complete warning or error messages, and conclude your message with the full output of `sessionInfo()`.

### 6.3 Installing and Upgrading

Before you want to install the `SomaticSignatures` package, please ensure that you have the latest version of `R` and `Bioconductor` installed. For details on this, please have a look at the help packages for R and Bioconductor. Then you can open `R` and run the following commands which will install the latest release version of `SomaticSignatures`:

Over time, the packages may also receive updates with bug fixes. These installed packages can be updated with:

### 6.4 Working with VRanges

A central object in the workflow of `SomaticSignatures` is the `VRanges` class which is part of the `VariantAnnotation` package. It builds upon the commonly used `GRanges` class of the `GenomicRanges` package. Essentially, each row represents a variant in terms of its genomic location as well as its reference and alternative allele.

There are multiple ways of converting its own variant calls into a `VRanges` object. One can for example import them from a `VCF` file with the `readVcf` function or employ the `readMutect` function for importing variant calls from the `MuTect` caller directly. Further, one can also construct it from any other format in the form of:

## 7 References

## References

[1] | L. Alexandrov. WTSI Mutational Signature Framework, Oct. 2012. [ http ]

[2]

L. B. Alexandrov, S. Nik-Zainal, D. C. Wedge, S. A. J. R. Aparicio, S. Behjati, A. V. Biankin, G. R. Bignell, N. Bolli, A. Borg, A.-L. Børresen-Dale, S. Boyault, B. Burkhardt, A. P. Butler, C. Caldas, H. R. Davies, C. Desmedt, R. Eils, J. E. Eyfjörd, J. A. Foekens, M. Greaves, F. Hosoda, B. Hutter, T. Ilicic, S. Imbeaud, M. Imielinsk, N. Jäger, D. T. W. Jones, D. Jones, S. Knappskog, M. Kool, S. R. Lakhani, C. López-Otín, S. Martin, N. C. Munshi, H. Nakamura, P. A. Northcott, M. Pajic, E. Papaemmanuil, A. Paradiso, J. V. Pearson, X. S. Puente, K. Raine, M. Ramakrishna, A. L. Richardson, J. Richter, P. Rosenstiel, M. Schlesner, T. N. Schumacher, P. N. Span, J. W. Teague, Y. Totoki, A. N. J. Tutt, R. Valdés-Mas, M. M. van Buuren, L. v. . Veer, A. Vincent-Salomon, N. Waddell, L. R. Yates, Australian Pancreatic Cancer Genome Initiative, ICGC Breast Cancer Consortium, ICGC MMML-Seq Consortium, Icgc PedBrain, J. Zucman-Rossi, P. Andrew Futreal, U. McDermott, P. Lichter, M. Meyerson, S. M. Grimmond, R. Siebert, E. Campo, T. Shibata, S. M. Pfister, P. J. Campbell, and M. R. Stratton. Signatures of mutational processes in human cancer. Nature, 500(7463):415-421, Aug. 2013. [ DOI | .html ]

[3] | L. B. Alexandrov, S. Nik-Zainal, D. C. Wedge, P. J. Campbell, and M. R. Stratton. Deciphering Signatures of Mutational Processes Operative in Human Cancer. Cell Reports, 3(1):246-259, Jan. 2013. [ DOI | http ]
[4] | K. Cibulskis, M. S. Lawrence, S. L. Carter, A. Sivachenko, D. Jaffe, C. Sougnez, S. Gabriel, M. Meyerson, E. S. Lander, and G. Getz. Sensitive detection of somatic point mutations in impure and heterogeneous cancer samples. Nature Biotechnology, advance online publication, Feb. 2013. [ DOI | .html ]
[5] | A. Fischer, C. J. Illingworth, P. J. Campbell, and V. Mustonen. EMu: probabilistic inference of mutational processes and their localization in the cancer genome. Genome biology, 14(4):R39, Apr. 2013. [ DOI ]
[6] | A. Fischer. EMu: Expectation-Maximisation inference of mutational signatures, 2013. [ http ]
[7] | R. Gaujoux and C. Seoighe. A flexible R package for nonnegative matrix factorization. BMC Bioinformatics, 11(1):367, July 2010. [ DOI | http ]

[8]

R. C. Gentleman, V. J. Carey, D. M. Bates, B. Bolstad, M. Dettling, S. Dudoit, B. Ellis, L. Gautier, Y. Ge, J. Gentry, K. Hornik, T. Hothorn, W. Huber, S. Iacus, R. Irizarry, F. Leisch, C. Li, M. Maechler, A. J. Rossini, G. Sawitzki, C. Smith, G. Smyth, L. Tierney, J. Y. Yang, and J. Zhang. Bioconductor: open software development for computational biology and bioinformatics. Genome Biology, 5(10):R80, Sept. 2004. [ DOI | http ]

[9] | L. N. Hutchins, S. M. Murphy, P. Singh, and J. H. Graber. Position-dependent motif characterization using non-negative matrix factorization. Bioinformatics, 24(23):2684-2690, Dec. 2008. [ DOI | http ]
[10] | J. T. Leek and J. D. Storey. Capturing Heterogeneity in Gene Expression Studies by Surrogate Variable Analysis. PLoS Genet, 3(9):e161, Sept. 2007. [ DOI | http ]

[11]

S. Nik-Zainal, L. B. Alexandrov, D. C. Wedge, P. Van Loo, C. D. Greenman, K. Raine, D. Jones, J. Hinton, J. Marshall, L. A. Stebbings, A. Menzies, S. Martin, K. Leung, L. Chen, C. Leroy, M. Ramakrishna, R. Rance, K. W. Lau, L. J. Mudie, I. Varela, D. J. McBride, G. R. Bignell, S. L. Cooke, A. Shlien, J. Gamble, I. Whitmore, M. Maddison, P. S. Tarpey, H. R. Davies, E. Papaemmanuil, P. J. Stephens, S. McLaren, A. P. Butler, J. W. Teague, G. Jönsson, J. E. Garber, D. Silver, P. Miron, A. Fatima, S. Boyault, A. Langerød, A. Tutt, J. W. Martens, S. A. Aparicio, A. Borg, A. V. Salomon, G. Thomas, A.-L. Børresen-Dale, A. L. Richardson, M. S. Neuberger, P. A. Futreal, P. J. Campbell, and M. R. Stratton. Mutational Processes Molding the Genomes of 21 Breast Cancers. Cell, 149(5):979-993, May 2012. [ DOI | http ]

[12] | V. Obenchain, M. Morgan, and M. Lawrence. VariantAnnotation: Annotation of Genetic Variants, 2011. [ .html ]
[13] | W. Stacklies, H. Redestig, M. Scholz, D. Walther, and J. Selbig. pcaMethodsa bioconductor package providing PCA methods for incomplete data. Bioinformatics, 23(9):1164-1167, May 2007. [ DOI | http ]
[14] | Y. Sun, N. R. Zhang, and A. B. Owen. Multiple hypothesis testing adjusted for latent variables, with an application to the AGEMAP gene expression data. The Annals of Applied Statistics, 6(4):1664-1688, Dec. 2012. Zentralblatt MATH identifier: 06141543; Mathematical Reviews number (MathSciNet): MR3058679. [ DOI | http ]
[15] | H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer, New York, 1st ed. 2009. corr. 3rd printing 2010 edition edition, Feb. 2010. [ http ]

## 8 Session Information