#### Table of contents

- 1: Introduction
- 2: Installation
- 3: Preparing the input
  - 3.1: Input from VCF
  - 3.2: Input from tab-delimited file
- 4: Estimating the number of mutational processes and their signatures
- 5: Results and further analyses
  - 5.1: Plot the MCMC paths for the NMF parameters
  - 5.2: Plot the signatures
    - Signature barplot
    - Signature heatmap
  - 5.3: Plot the exposures
    - Exposure boxplot
    - Exposure barplot
    - Exposure heatmap
  - 5.4: Differential Exposure Analysis
  - 5.5: Sample Classification
- 6. Frequently Asked Questions
  - 6.1: Citing signeR
  - 6.2: Compilation errors on OS X
  - 6.3: Missing library headers
- 7. References

# signeR

#### Rodrigo Drummond, Renan Valieris, Rafael Rosales and Israel Tojal da Silva

## 1: Introduction

Motivation: Cancer is an evolutionary process driven by continuous acquisition of genetic variations in individual cells. The diversity and complexity of somatic mutational processes is a conspicuous feature orchestrated by DNA damage agents and repair processes, including exogenous or endogenous mutagen exposures, defects in DNA mismatch repair and enzymatic modification of DNA. The identification of the underlying mutational processes is central to understanding of cancer origin and evolution.

The signeR package focuses on the estimation and further analysis of mutational signatures. The functionalities of this package can be divided into three categories. First, it provides tools to process VCF files and generate matrices of SNV mutation counts and mutational opportunities, both defined according to a 3bp context (mutation site and its neighbouring 3' and 5' bases). Second, these count matrices are considered as input for the estimation of the underlying mutational signatures and the number of active mutational processes. Third, the package provides tools to correlate the activities of those signatures with other relevant information such as clinical data, in order to draw conclusions about the analysed genome samples, which can be useful for clinical applications. These include the Differential Exposure Score and the a posteriori sample classification.

Although signeR is intended for the estimation of mutational signatures, it actually provides a full Bayesian treatment to the non-negative matrix factorisation (NMF) model. Further details about the method can be found in Rosales & Drummond et al., 2016 (see section 6.1 below).

This vignette briefly explains the use of signeR through examples.

## 2: Installation

Before installing, please make sure you have the latest version of R and Bioconductor installed.

To install signeR, start R and enter:

For more information, see this page.

Once installed the library can be loaded as

OS X users might experience compilation errors due to missing gfortran libraries. Please read this section.

## 3: Preparing the input

signeR takes as input a count matrix of samples x features. Each feature is usually a SNV mutation within a 3bp context (96 features, 6 types of SNV mutations and 4 possibilities for the bases at each side of the SNV change). Optionally, an opportunity matrix can also be provided containing the count frequency of the features in the whole analyzed region for each sample. Although not required, this argument is highly recommended because it allows signeR to normalize the features frequency over the analyzed region.

Input matrices can be read both from a VCF or a tab-delimited files, as described next.

### 3.1: Input from VCF

The VCF file format is the most common format for storing genetic variations, the signeR package includes a utility function for generating a count matrix from the VCF:

This function will generate a matrix of mutation counts for each sample in the provided VCF. The opportunity matrix can also be generated from the reference genome (hg19 in the following case):

Where `target.bed` is a bed file containing the genomic regions analyzed by the variant caller.

If a BSgenome is not available for your genome, you can use a fasta file:

### 3.2: Input from tab-delimited file

By convention, the input file should be tab-delimited with sample names as row names and features as column names. Features should be refered in the format "base change:triplet", e.g. "C>A:TCG", as can be seen in the example below. Similarly, the opportunity matrix can be provided in a tab-delimited file with the same structure as the mutation counts file. An example of the required matrix format can be seen here.

This tutorial uses as input the 21 breast cancer dataset described in Nik-Zainal et al 2012. For the sake of convenience this dataset is included with the package and can be accessed by using the `system.file` function:

## 4: Estimating the number of mutational processes and their signatures

signeR takes a count matrix as its only required parameter, but the user can provide an opportunity matrix as well. The algorithm allows the assessment of the number of signatures by three options, as follows.

1. signeR detects the number of signatures at run time by considering the best NMF factorisation rank between 1 and min(G, K)-1, with G = number of genomes and K = number of features (i.e. 96):
2. The user can give a interval of the possible numbers of signatures as the parameter nlim. signeR will calculate the optimal number of signatures within this range, for example:
3. Finally, signeR can also be run by passing the number of signatures as the parameter nsig. In this setting, the algorithm is faster. For example, the following command will make signeR consider only the rank N=5 to estimate the signatures and their exposures:

The parameters `testing_burn` and `testing_eval` control the number of iterations used to estimate the number of signatures (default value is 1000 for both parameters). There are other arguments that may be passed on to signeR. Please have a look at signeR's manual, issued by typing `help(signeR)`.

Whenever signeR is left to decide which number of signatures is optimal, it will search for the rank Nsig that maximizes the median Bayesian Information Criterion (BIC). After the processing is done, this information can be plotted by the following command:

Boxplot of BIC values, showing that the optimal number of signatures for this dataset is 5.

## 5: Results and further analyses

### 5.1: Plot the MCMC paths for the NMF parameters (P and E matrices)

The following instruction plots the MCMC sampled paths for each entry of the signature matrix P and their exposures, i.e. the E matrix. Only post-burnin paths are available for plotting. Those plots are useful for checking if entries have leveled off, reflecting the sampler convergence.

Each plot shows the entries and exposures of one signature along sampler iterations.

### 5.2: Plot the signatures

Once the processing is done, the estimated signatures can be displayed in two charts, described below.

#### Signature barplot

Signatures can be visualized in a barplot by issuing the following command:

Signatures barplot with error bars reflecting the sample percentiles 0.05, 0.25, 0.75, and 0.95 for each entry.

#### Signature heatmap

Estimated signatures can also be visualized in a heatmap, generated by the following command:

Heatmap showing the entries of each signature.

### 5.3: Plot the exposures

The relative contribution of each signature to the inspected genomes can be displayed in several ways. signeR currently provides three alternatives.

#### Exposure boxplot

The levels of exposure to each signature in all genome samples can also be plotted:

#### Exposure barplot

The relative contribution of the signatures to the mutations found on each genome sample can also be visualized by the following command:

Barplot showing the contributions of the signatures to genome samples mutation counts.

#### Exposure heatmap

The levels of exposure to each signature can also be plotted in a heatmap:

Heatmap showing the exposures for each genome sample. Samples are grouped according to their levels of exposure to the signatures, as can be seen in the dendrogram on the left.

### 5.4: Differential Exposure Analysis

signeR can highlight signatures that are differentially active among previously defined groups of samples. To perform this task signeR needs a vector of group labels. In this example the samples were divided according to germline mutations at BRCA genes: groups `wt`, `BRCA1+` and `BRCA2+`, taken from the description of the 21 breast cancer data set.

Top chart: DES plot showing that the BRCA+ samples were significantly more exposed to signatures S3, S4 and S5. Bottom chart: plots showing the significant differences found when groups are compared against each other. These last plots are generated only when there are more than two groups in the analysis and any signature is found to be differentially active. Groups marked by the same letter are not significantly different for the corresponding signature.

The `Pvquant` vector holds the pvalues quantile of the test for each signature (by default, the 0.5 quantile, i.e. the median). The logarithms of those are considered the Differential Exposure Scores (DES). Signatures with `Pvquant` values below the cutoff, 0.05 by default, are considered as differentially exposed.

The `MostExposed` vector contains the name of the group where each differentially exposed signature showed the highest levels of activity.

### 5.5: Sample Classification

signeR can also classify unlabeled samples based on the given labels. In order to do this, those samples must correspond to `NA` values in the labels vector and the Classify function can be used to assign them to one of the defined groups. This example uses the sample labels defined in the DES analysis performed previously.

Barplot showing the relative frequencies of assignment of each unlabeled sample to the selected group.

## 6: Frequently Asked Questions

### 6.1: Citing signeR

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

### 6.2: Compilation errors on OS X

OS X users might get compilation errors similar to these:

    ld: warning: directory not found for option '-L/usr/local/lib/x86_64'
    ld: library not found for -lgfortran
    ld: library not found for -lquadmath

This problem arises when the machine is missing gfortran libraries necessary to compile RcppArmadillo and signeR. To install the missing libraries, execute these lines on a terminal:

    curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
    sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /

For more information see this post and the Rcpp FAQ, section 2.16.

### 6.3: Missing library headers

Some packages that signeR depends on requires that 3rd party library headers be installed. If you see errors like:

    Error: checking for curl-config... no
             Cannot find curl-config

It means you need to install these headers with your package manager. For example on ubuntu:

    $ sudo apt-get install libcurl4-openssl-dev

## 7: References

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 ]

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 ]

## Debug Info