---
title: "RTNsurvival: multivariate survival analysis using transcriptional networks and regulons."
author: "Clarice S Groeneveld, Vinícius S Chagas, Gordon Robertson, Kerstin B Meyer, Mauro AA Castro."
date: "`r doc_date()`"
package: "`r pkg_ver('RTNsurvival')`"
bibliography: bibliography.bib
abstract: <p>This package provides classes and methods to perform survival analysis using transcriptional networks inferred by the [RTN](http://bioconductor.org/packages/RTN/) package, including Kaplan-Meier and multivariate survival analysis using Cox's regression model.</p>
output: 
  BiocStyle::html_document:
    css: custom.css
vignette: >
  %\VignetteIndexEntry{"RTNsurvival: multivariate survival analysis using transcriptional networks and regulons."}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

# Overview

Transcriptional networks are important tools to visualize complex biological systems that involve large groups of genes and multiple regulators. In a previous study, we have implemented the **RTN** R/Bioconductor package to reconstruct transcriptional regulatory networks [@Fletcher2013]. This package reconstructs regulons, consisting of a regulator and its target genes. A regulon can be further used to investigate, for example, the association of its expression on survival probabilities.

**RTNsurvival** is a tool for integrating regulons generated by the **RTN** package with survival information for the same set of samples used in the reconstruction of the transcriptional regulatory network. There are two main survival analysis pipelines: a Cox Proportional Hazards approach used to model regulons as predictors of survival time (**Figure 1**), and a Kaplan-Meier analysis showing the stratification of a cohort based on the regulon activity (**Figure 2**). For a given regulon, the 2-tailed GSEA approach is used to estimate regulon activity (differential Enrichment Score - dES) for each individual sample [@Castro2016], and the dES distribution of all samples is then used to assess the survival statistics for the cohort. The plots can be fine-tuned to the user's specifications.

# Quick Start

## Load regulons and survival data

This Vignette uses precomputed regulons available in the RTN package:

```{r, eval=TRUE}
library(RTN)
data(stni, package="RTN")
```

The `stni` is a `TNI-class` object created from a subset of the expression data available in the `Fletcher2013b` package. The `stni` object contains a minimal toy reconstruction of 5 regulons (PGR, MYB, E2F2, FOXM1 and PTTG1).

More information about the parameters used to build the toy regulons can be viewed by calling the summary of the `stni` object.

```{r, eval=TRUE}
summary <- tni.get(stni, what = "summary")
```

The **RTNsurvival** package provides a survival table for the samples in the `stni` object, including clinical data from the METABRIC study [@Curtis2012] where the expression data was originally obtained.

```{r, eval=TRUE}
library(RTNsurvival)
data(survival.data)
```

## Preprocess input data

In order to run the analysis pipelines, the input data must be evaluated by the `tnsPreprocess` method in order to build a `TNS-class` object. Note that the survival table must be provided with time and event columns, and key covariates can also be specified for subsequent use in the Cox analysis.

```{r, eval=TRUE}
rtns <- tnsPreprocess(stni, survival.data, keycovar = c("Grade","Age"), time = 1, event = 2)
```

## Compute regulon activity

The survival analysis pipeline depends on the 2-tailed GSEA approach, which estimates regulon activity (dES) for all samples in the cohort. The `tnsGSEA2` function calls the `tni.gsea2` method available in the RTN package.

```{r, eval=TRUE}
rtns <- tnsGSEA2(rtns, verbose = FALSE)
```

## Run the Cox analysis pipeline

Once the dES metric has been computed by `tnsGSEA2` function, then it is possible to run the Cox analysis. 

The `tnsCox` method runs a Cox multivariate regression analysis and shows the proportional hazards of each of the specified regulons and the provided key covariates, indicating the contribution of each variable to survival (**Figure 1**). The method uses the Bioconductor survival package to fit the Cox model.

```{r, eval=TRUE}
tnsCox(rtns, sortregs = TRUE)
```

![title](figures/fig1.png)
<b>Figure 1</b> - The plot shows the Hazard Ratio for all key covariates and regulons. Lines that are completely to the right of the grey line, shown in red, are positively associated with hazard. This means that samples with high expression of this regulon have poor prognosis. The further to the right or left of the grey line, the more significant is the association.

## Run the Kaplan-Meier analysis pipeline

The `tnsKM` method generates a Kaplan-Meier plot, which consists of three panels put together: a ranked dES plot for the cohort, a status of key attributes plot (optional) and a Kaplan-Meier plot, showing survival curves for lower and higher dES samples (**Figure 2**).

```{r, eval=TRUE}
tnsKM(rtns, regs="FOXM1", attribs = list(c("ER+","ER-"),c("PR+","PR-"),c("G1","G2","G3"),"HT"), 
endpoint=180)
```

![title](figures/fig2.png)
<b>Figure 2</b> - The Kaplan-Meier plot for FOXM1 shows that samples with high regulon activity (red and pink) have poorer prognosis, as their survival probability is lower than the samples that have low regulon activity (light and dark blue).

# Plot 2-tailed GSEA for individual samples

Individual sample differential enrichment analysis can be investigated using the `tnsPlotGSEA2` function. This will generate a 2-tailed GSEA plot for the differential expression of both positive and negative targets of a regulon (**Figure 3**). This step takes a little longer because the GSEA is recomputed for a selected regulon, and because `tnsPlotGSEA2` is a wrapper for the **RTN** function `tna.plot.gsea2`, which generates the GSEA plot.

```{r, eval=TRUE}
tnsPlotGSEA2(rtns, "MB-5115", regs = "FOXM1", verbose = FALSE)
```

![title](figures/fig3.png)
<b>Figure 3</b> - The 2-tailed GSEA plot for the MB-5116 sample. It shows that the positive targets of the FOXM1 regulator are positively enriched, while the negative targets are negatively enriched. 

# Plot regulon activity for all samples

An overview of regulon activity can be obtained by plotting a heatmap with all evaluated samples and regulons. First, we need to obtain the matrix of dES values from the TNS object. Then, we can plot the heatmap using the `pheatmap` function from the **pheatmap** package. In this example, we also illustrate how to incorporate sample features from the survival data.

```{r, eval = FALSE}
library(pheatmap)
enrichmentScores <- tnsGet(rtns, "EScores")
survival.data <- tnsGet(rtns, "survivalData")
annotationBars <- survival.data[,c("ER+", "ER-")]
pheatmap(t(enrichmentScores$dif),
        annotation_col = annotationBars,
        main = "Differential Enrichment Scores (dES) for tumour samples",
        show_colnames = FALSE,
        annotation_legend = FALSE)
```

![title](figures/fig4.png)
<b>Figure 4</b> - Regulon activity of individual tumour samples. This heatmap shows two main regulon clusters. The PGR and MYB regulons are repressed in the ER- samples and activated in ER+ samples. The PTTG1, E2F2 and FOXM1 regulons, on the other hand, are activated in ER- samples and repressed in ER+ samples. 

# Evaluating survival in dual regulons

Integrating data from different regulons may be of interest, especially if they come from different regulatory networks made for the same expression matrix. Concepts from the **RTNduals** package can be used to compute dual regulons, which are regulon pairs whose common targets are likely to be affected by both regulators.

The workflow of the **RTNduals** can be used to infer dual TF-TF regulons, using the  precomputed regulons from this Vignette, for demonstration purposes only.

```{r}
library(RTNduals)
smbr <- tni2mbrPreprocess(stni, stni, verbose = FALSE)
smbr <- mbrAssociation(smbr, prob = 0.75, verbose = FALSE)
smbr <- mbrDuals(smbr, verbose = FALSE)
mbrGet(smbr, "dualsInformation")
```

The `smbr` is an object of `MBR-class`, containing the motifs between the regulons represented in the `stni` object. As `prob` was set to 75%, only the 25% most significant inferred duals are shown in the results.

Now, since the `rtns` object and `smbr` object were computed from the same expression matrix, we can use the survival information for that cohort in conjunction with the duals information.

```{r, eval = FALSE}
duals <- mbrGet(smbr, what="dualRegulons")
dualSurvivalPanel(smbr, rtns, dual = duals[1], attribs = c("ER+", "ER-", "PR+", "PR-"))
```

The `dualsSurvivalPanel` method generated a directory containing six plots:
<ul>
<li> a sample stratification for regulon 1 of the dual, with sample attributes;</li>
<li> a sample stratification for regulon 2 of the dual, with the same attributes;</li>
<li> an interaction scatter plot of the samples, where x and y represent that sample's position in the stratifications;</li>
<li> Kaplan-Meier curves for both regulons, using their stratifications, and for the interaction between them, with the selected samples;</li>
<li> a Cox regression plot, showing the association of both regulon activities with risk, as well as the association of the interaction; and</li>
<li> a panel plot which contains all of these plots in a suggested panel, which is shown in **Figure 5**.</li>
</ul>

![title](figures/fig5.png)
<b>Figure 5</b> - Dual Survival Plot for MYB~PGR dual regulon. It shows the regulon activity is positively correlated, but there is no additional hazard ratio information given by the Cox regression of the interaction. **a)** Sample ranking using differential Enrichment Score (dES) of regulon MYB **b)** dES sample ranking for regulon PGR and a sample scatter plot, showing the ranking of each sample in both regulons. In this case, MYB and PGR agree in sample stratification. **c)** Kaplan-Meier curves. The Interaction curve follows the individual regulons very closely. **d)** Cox regression plot. It doesn't show any association between the activity of these regulons or interaction and hazard ratio.


# Session information
```{r label='Session information', eval=TRUE, echo=FALSE}
sessionInfo()
```

# References

