%\VignetteIndexEntry{RNAdynamics}
%\VignettePackage{INSPEcT}
%\VignetteDepends{INSPEcT}
%\VignetteEngine{knitr::knitr}
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}

<<style-knitr, eval=TRUE, echo=FALSE, results="asis">>=

BiocStyle::latex()
@

\newcommand{\Rmethod}[1]{{\Rfunction{#1}}}

\title{Visualization and interaction with the RNA dynamics of single genes}
\author{de Pretis S., Pelizzola M.}

\begin{document}

\maketitle

\tableofcontents

\newpage

\section{Introduction}

The life cycle of RNAs is composed of three main steps, i.e. transcription and processing of the premature RNA (\(P\)) and degradation of the mature (\(M\)). The kinetic rates governing these steps define the dynamics of each transcript (\(k_{1-3}\) for synthesis, processing and degradation, respectively), and their role in transcriptional regulation is often underestimated. A complete understanding of the effects of the rates of the RNA life-cycle on premature and mature RNA requires mathematical and/or computer skills to solve the corresponding system of differential equations:

\begin{equation}\label{eq:modelsystem}
  \left\{
    \begin{array}{l l}
  \dot{P}=k_1 - k_2 \, \cdot \, P \\
  \dot{M}=k_2 \, \cdot \, P - k_3 \, \cdot \, M
    \end{array}
  \right.
\end{equation}

This system of differential equations is used by INSPEcT to estimate the rates of the RNA-life cycle when transctiptomic data and (possibly) newly-synthesized RNA are available. INSPEcT aims at assessing the dynamics of each gene by modeling the temporal behavior of the RNA kinetic rates with either constant or variable functions. In order to visualize and interact with output of the classification procedure of INSPEcT, and to ease the understanding of the role of the RNA life-cycle kinetic rates in shaping the dynamics of premature and mature RNA, we developed a Graphical User Interface (GUI). Specifically, the GUI allows to: (i) interact with the results of INSPEcT analysis on single genes, refining a model, or testing modes of regulation that are alternative to the one identified by INSPEcT, and (ii) explore how a given combination of rates results in the dynamical behavior of premature and mature RNA species.

\section{Run the application from an R session}

The GUI is distributed within the INSPEcT package, and starts with the following command line operations:

<<INSPEcT_loading,eval=FALSE,echo=TRUE,message=FALSE,warnings=FALSE>>=
library(INSPEcT)
runRNAdynamics()
@

\newpage

\section{Presentation of the Graphical User Interface}

The GUI is divided into 4 sections (Fig. \ref{fig:fig1}), which account for specific functions: 

\begin{itemize}
\item Section 1: interaction with an object of class INSPEcT;
\item Section 2: visualization of the RNA dynamics for a single gene;
\item Section 3: model minimization;
\item Section 4: interaction with individual parameters of RNA rates.
\end{itemize}

\begin{figure}
  \centering
      \includegraphics[width=1\textwidth]{RNAdynamicsAPP.png}
      \caption{Representation of the GUI divided into its 4 main sections.}
  \label{fig:fig1}
\end{figure}

\newpage

\subsection{Interaction with an object of class INSPEcT}

At startup, the software loads a predefined INSPEcT object, which contains 10 genes and can be used to explore the software functionalities. This object can be replaced by any INSPEcT dataset generated by the user, and saved in the "rds" format ("Choose INSPEcT file", Fig. \ref{fig:fig2}). Genes that are part of the INSPEcT object are divided according to their regulation class. This is encoded by a three digit string, where each digit represent a step in the RNA life-cycle (in the order: synthesis, processing and degradation), and the character represents the regulation status of the rate ("K"=constant, "V"=variable). For example: "KVK" represent a gene regulated in its processing rate, while constant in its synthesis and degradation rates. Once a regulation class is selected via "Select class", a specific gene can be chosen from the list that appears in "Select gene" (Fig. \ref{fig:fig2}).

\begin{figure}
  \centering
      \includegraphics[width=0.6\textwidth]{select_INSPEcT_object_class_gene.png}
      \caption{Interaction with an object of class INSPEcT (section 1)}
  \label{fig:fig2}
\end{figure}

\newpage

\subsection{Visualization of the RNA dynamics for a single gene}

For the selected gene, the experimental quantifications of the premature and mature RNA levels (estimated from RNA-seq data) are plotted together with their standard deviations (Fig. \ref{fig:fig3}). In case the nascent RNA have been profiled, also the synthesis rate is considered part of the experimental data and plotted with its standard deviation. Otherwise, the rate of synthesis can be inferred from total RNA-seq data. In this case, nascent RNA data is not necessary but the rate of synthesis lacks the standard deviation. Most of the times, due to noise associated with this kind of data, smoothing the experimental profiles ("Smooth data" in "Select input", Fig. \ref{fig:fig2}) can lead to more precise identification of the regulation pattern. Alternatively, the user can use raw data by selecting "Experimental data" in "Select input" (Fig. \ref{fig:fig2}). In addition to experimental or smoothed data, the results of the INSPEcT modeling are plotted with continuous lines within the synthesis, pre-RNA, processing, mature RNA and degradation panels (Fig. \ref{fig:fig3}). The "User defined" mode in "Select input" will be covered in section \ref{denovo}.

\begin{figure}
    \includegraphics[width=0.9\textwidth, trim=2cm 0 0 0]{rates_and_concentrations_panel.png}
    \caption{Visualization of the RNA dynamics for a single gene (section 2)}
  \label{fig:fig3}
\end{figure}

\newpage

\subsection{Model minimization} \label{modelmin}

The minimization status corresponding to the modeling are reported in section 3 of the GUI (Fig. \ref{fig:fig4}). In particular, the p-value associated to the chi-squared statistic and the Akaike information criterion indicate the goodness of the fit. Both these metrics are penalized for the complexity of the model, meaning that they measure a trade-off between performance and simplicity and can be used to compare models with different complexity. The complexity of a model depends on the functional forms that describe the RNA life-cycle kinetic rates: a constant rate has a complexity of 1, a sigmoidal 4, and impulsive 6, i.e. the number of their parameters. In practice, when two models explains the data adequately well, the simpler one is selected due to its simplicity (lower p-value of the chi-squared statistic and lower AIC). Additionally, the chi-squared p-value can be used to assess whether the model under consideration adequately explains the experimental (or smooth) data (when p<0.05). Finally, the number of iterations spent trying to reach the minimum is reported, as well as whether the minimization converged or not to a local minimum. In case the minimization status is not satisfactory, supplementary iterations can be provided to search for a better minimum, either using the Nelder Mead simplexes method (NM, used from INSPEcT) or the quasi-Newton BFGS method, by pushing the button "Optimize - Run".

\begin{figure}
  \centering
      \includegraphics[width=0.6\textwidth]{minimization_status.png}
      \caption{Model minimization (section 3)}
  \label{fig:fig4}
\end{figure}

\newpage

\subsection{Interaction with individual parameters of RNA rates}

Parameters of the modeling can be directly modified "by hand". In fact, for each kinetic rate of the RNA life-cycle, the parameters describing the selected functional form are provided in the bottom part of the GUI (Fig. \ref{fig:fig5}). Constant rates are described by a single parameter, which correspond to the value of the rates throughout the time-course, alternatively, variable rates can be described either by sigmoidal or impulsive functions. Sigmoidals are S-shaped functions described by four parameters: starting levels, final levels, time of transition between starting and final levels, and slope of the response. Impulsive functions allow more complex behaviors with two additional parameters that describe time and levels of a second transition, possibly encoding for bell-shaped responses. Minimum and maximum levels can be set individually per each rate, allowing the user maximum flexibility in the definition of rate levels. At startup, these ranges are set to include all the parameters of the sample dataset. Each time a new dataset is loaded, ranges are updated accordingly.

\begin{figure}
  \centering
      \includegraphics[width=1.1\textwidth, trim=5cm 0 0 0]{rates_functional_forms.png}
      \caption{Direct interaction with RNA life-cycle kinetic rates (section 4)}
  \label{fig:fig5}
\end{figure}

The user can test different regulative scenarios from the one selected by INSPEcT, by tuning each function parameter or switching the functional form assigned to one or more rates. In the latter case, the new parameter set can be searched via the minimization of the error over the data (\ref{modelmin}) and/or "by hand" the best combination of parameters. Each time the model is modified, its plot and minimization status are updated.

\section{De novo hypothesis generation - Case studies} \label{denovo}

The procedure explained in the previous sections mostly refers to the interaction with experimental data. Nonetheless, the software is designed also to test hypothesis independently from experiments. This can be easily achieved by choosing "User defined (No input)" in "Select input" (Fig. \ref{fig:fig2}). In this mode, experimental or smooth data are not represented, as well as the minimization status. The user is therefore free to change both the functional forms and the parameters associated to the RNA life-cycle kinetic rates, directly assessing the effects on premature and mature RNA dynamics. In the following subsections, we report some case studies to exemplify the role of the RNA life-cycle in the definition of premature and mature RNA dynamics.

\newpage

\subsection{Constant kinetic rates}

The combination of the RNA kinetic rates establishes the levels of mature and premature RNA: the ratio between the rates of synthesis and processing sets premature RNA levels, and the ratio between synthesis and degradation sets the mature ones. When no perturbations occur, this long standing condition is called steady state. (Set rates to: synthesis = constant\{10\}; processing = constant\{20\}; degradation = constant\{2\})

\begin{figure}
  \centering
      \includegraphics[width=1\textwidth, trim=3.5cm 0 0 0]{case_study_1.png}
      \caption{Case study 1: constant kinetic rates}
  \label{fig:fig6}
\end{figure}

As a consequence of this, steady state premature RNA levels are independent from degradation rates, and (more importantly and less intuitively) steady state mature RNA levels are independent from processing rates.

\newpage

\subsection{Modulation of processing rate}

As mentioned above, steady state mature RNA levels are independent from processing rates. Nonetheless, a perturbation in the processing dynamics leads to a variation in mature RNA levels, which is just temporary. Conversely, it produces a lasting effect on premature RNA levels. (Set rates to: synthesis = constant\{10\}; processing = sigmoidal\{5,20,8,5\}; degradation = constant\{2\})

\begin{figure}
  \centering
      \includegraphics[width=1\textwidth, trim=3.5cm 0 0 0]{case_study_2.png}
      \caption{Case study 2: modulation of processing rate}
  \label{fig:fig7}
\end{figure}

Note that the decrease of the degradation rate makes the perturbation of the mature RNA less visible. (Set degradation = constant\{0.5\})

\newpage

\subsection{Modulation of the synthesis rate}

A modulation in the synthesis rate determines a similar modulation for premature and mature RNAs (in terms of fold change compared to the untreated condition). (Set rates to: synthesis = sigmoidal\{10,20,8,5\}; processing = constant\{20\}; degradation = constant\{2\})

\begin{figure}
  \centering
      \includegraphics[width=1\textwidth, trim=3.5cm 0 0 0]{case_study_3.png}
      \caption{Case study 3: modulation of syntheis rate}
  \label{fig:fig8}
\end{figure}

Note that the time lag between the synthesis and premature RNA response is inversely proportional to the processing rate (Set processing = constant\{10\}). Following the same logic, the time lag between the premature and the mature RNA response is inversely proportional to the degradation rate (Set degradation = constant\{0.5\}).

\newpage

\subsection{Concomitant modulation of synthesis and degradation rates}

When synthesis and degradation rates are modulated in the same direction they apply an opposite effect on mature RNA levels, leaving trace of the transcriptional regulation only on premature RNA levels (a similar response have been observed in yeasts, during heat shock). (Set rates to: synthesis = sigmoidal\{10,20,8,5\}; processing = constant\{20\}; degradation = sigmoidal\{0.25,0.5,8,5\}). Rather, their opposite modulation reinforces the transcriptional response of mature RNA. (Set degradation = sigmoidal\{0.5,0.25,8,5\})

\begin{figure}
  \centering
      \includegraphics[width=1\textwidth, trim=3.5cm 0 0 0]{case_study_4.png}
      \caption{Case study 4: concomitant modulation of synthesis and degradation rates}
  \label{fig:fig9}
\end{figure}

\newpage

\section{About this document}

<<r>>=
sessionInfo()
@

\end{document}