---
title: "WOTPLY"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{WOTPLY}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---


```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width=7, 
  fig.height=5
)
```


```{r setup}
library(WOTPLY)
```


In this vignette it is shown the analysis performed on a single cell RNA seq dataset from a time-course of iPS reprogramming. The data are from day 10, day 12, day 14, day 16 and day 18 from [Schiebinger et al. 2019](https://www.cell.com/cell/fulltext/S0092-8674(19)30039-X).
Below the transition matrices between time points t and t+1 are loaded. Each matrix is the output of \emph{get_transition_matrix} and was built starting from \emph{compute_all_transport_maps} function from pyhton package \emph{WOT}. See ?\emph{get_transition_matrix} for more info.

```{r}

load(system.file("extdata", "cluster_label_example.Rda", package = "WOTPLY"))
#load(system.file("extdata", "time_label_example.Rda", package = "WOTPLY"))

load(system.file("extdata", "example_day_10_12.Rda", package = "WOTPLY"))
load(system.file("extdata", "example_day_12_14.Rda", package = "WOTPLY"))
load(system.file("extdata", "example_day_14_16.Rda", package = "WOTPLY"))
load(system.file("extdata", "example_day_16_18.Rda", package = "WOTPLY"))



```





```{r}
list_transition_matrices_example <- list(example_day_10_12,example_day_12_14,example_day_14_16,example_day_16_18)
selected_stages <- c("IPS","Trophoblast","Epithelial","STROMAL","NEURAL")
legend_time_example <- c("day_10","day_12","day_14","day_16","day_18")


customize_color <- WOTPLY:::gg_color_hue(length(levels(factor(cluster_label_example))))


```


The output of WOTPLY function shows the connections between \emph{selected_stages} from the latest time point and the clusters from previous time points. The number of columns is equal to the numbers of time points. In each column, the cluster of the
corresponding time point is shown as network node. The weight of the links between clusters at time points t and t+1 reflect the weight of the
transition probabilities from \emph{list_transition_matrices}.
It is possible to change the maximum number of links to select between clusters at time t and clusters at time t+1. Links are sorted according to the weight and then only the \emph{top_link} are kept. If \emph{NULL} (default), all the links are kept.

```{r}


#png("/Users/gabriele.lubatti/Desktop/Phd/Embryo_Organoids/wot_publsihed_data/input_wot/WOTPLY_1.png")
WOTPLY(list_transition_matrices_example, selected_stages, cluster_label_example, legend_time_example, customize_color, top_link = NULL)
#dev.off()

```


```{r}

#png("/Users/gabriele.lubatti/Desktop/Phd/Embryo_Organoids/wot_publsihed_data/input_wot/WOTPLY_2.png")
WOTPLY(list_transition_matrices_example, selected_stages, cluster_label_example, legend_time_example,customize_color, top_link = 3)
#dev.off()
```



```{r}
utils::sessionInfo()
```
