---
title: "LncPipe Reports"
date: '`r date()`'
output:
  flexdashboard::flex_dashboard:
    vertical_layout: scroll
    mathjax: null
    self_contained: false
    lib_dir: ~/LncPipeReports/libs
    navbar:
      - { title: "About", href: "http://icannotendure.space/", align: right }
      - { icon: "ion-social-github", href: "https://github.com/bioinformatist/multiIP", align: right }
    theme: flatly
params:
  input: 
    label: 'Input directory (results of up-stream analysis)'
    value: !r system.file(file.path("extdata", "demo_results"), package = "LncPipeReporter")
  output:
    label: "Output file (In HTML format)"
    value: 'reporter.html'
  de.method:
    label: 'Method of differential expression analysis'
    value: edger
    input: select
    choices: !r c("edgeR" = 'edger', 'DESeq2' = 'deseq2', 'NOISeq' = 'noiseq')
  theme:
    label: "Journal palette applied to all plots generated by ggplotly"
    value: npg
    input: select
    choices: !r c('NPG (Nature Publishing Group)' = 'npg', 'AAAS (American Association for the Advancement of Science)' = 'scale_color_aaas', 'NEJM (The New England Journal of Medicine)' = 'nejm', 'Lancet (Lancet Oncology)' = 'lancet', 'JAMA (The Journal of the American Medical Association)' = 'jama', 'JCO (Journal of Clinical Oncology)' = 'jco', 'UCSCGB (UCSC Genome Browser)' = 'ucscgb', 'D3 (D3.js)' = 'd3', 'LocusZoom' = 'locuszoom', 'IGV (Integrative Genomics Viewer)' = 'igv', 'UChicago (The University of Chicago)' = 'uchicago', 'Star Trek' = 'startrek', 'Futurama' = 'futurama', 'Rick and Morty' = 'rickandmorty', 'The Simpsons' = 'simpsons')
  cdf.percent:
    label: "Percentage of values to display when calculate coding potential"
    value: 10
    input: slider
    min: 0
    max: 100
    post: '%'
  max.lncrna.len:
    label: "Maximum length of lncRNAs to display when calculate distribution"
    value: 10000
  min.expressed.sample:
    label: "Minimal percentage of expressed samples"
    value: 50
    input: slider
    min: 0
    max: 100
    post: '%'
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
	echo = FALSE,
	message = FALSE,
	warning = FALSE,
	cache = FALSE,
	fig.height = 6,
	fig.width = 8
)

local({
  hook_plot = knitr::knit_hooks$get('plot')
  knitr::knit_hooks$set(plot = function(x, options) {
    x = paste(x, collapse = '.')
    if (!grepl('\\.svg', x)) return(hook_plot(x, options))
    # read the content of the svg image and write it out without <?xml ... ?>
    paste(readLines(x)[-1], collapse = '\n')
  })
})

options(DT.options = list(autoFill = TRUE, 
                          searchHighlight = TRUE, 
                          search = list(regex = TRUE, caseInsensitive = FALSE),
                          dom = 'Bfrtip', 
                          buttons = c('copy', 'csv', 'excel', 'pdf', 'print')))
# rm(list = setdiff(ls(), "params"))
# gc()
# The latest plotly should be used, for a lot of bugs fixed
# if (!require("devtools")) install.packages("devtools")
# install.packages(c("curl", "httr"))
# devtools::install_github('ramnathv/htmlwidgets')
# devtools::install_github("ropensci/plotly")
# source("https://bioconductor.org/biocLite.R")
# biocLite("edgeR")
# library(devtools)
# install_github("vqv/ggbiplot")
# require(plotly)
# require(data.table)
# require(cowplot)
# require(stringr)
# require(knitr)
# require(edgeR)
# require(ggbiplot)
# require(pheatmap)
# require(heatmaply)
# require(ggsci)

type.list <- search_then_determine(path = input)
theme_set(cowplot::theme_cowplot())
```

Home
===================================== 

Column
-------------------------------------

### Overview {.no-padding}

```{r echo = FALSE}
knitr::include_graphics('Figure_1_A.svg')
```

Column
-------------------------------------

### Introduction

Thanks for using [LncPipe](https://git.oschina.net/likelet/workflow)! LncPipe is a nextflow-based pipeline which collected several popular tools and in-house scripts so as to identifiy and analyze novel lncRNAs from raw RNA sequencing data.  As we known, identification and profiling of lncRNAs is a fundamental step to advance our knowledge on their function and regulatory mechanisms. We thus present LncPipe to facilitate related researches on LncRNA discovery and annotation.
This report summarized all output files produced by [LncPipe](https://git.oschina.net/likelet/workflow) and shown them via fancy interactive plots. Briefly, LncPipeReporter's output contains sections as follows:

1. Reads alignment summary. Since the intial mapping step was carried out by STAR,HISAT or Tophat, we summarized the basic information that can help assess the library quanlity of each samples.
2. Novel lncRNAs basic charateristics such as length distribution, exon number, coding potiential and classifications.
3. Differential expression analysis if design file was feed. Abandunce of each transcript was assessed and compared between conditions. We also provide exploration analysis like PCA and clustering to help check the experimental design.
4. Comparison analysis was also performed between coding gene, known lncRNA and novel lncRNAs 

### Quick start

To run in R session:

```{r, eval = FALSE, echo = TRUE}
library(LncPipeReporter)
run_reporter(input = system.file(file.path("extdata", "demo_results"),package = "LncPipeReporter"),
             output = 'reporter.html',
             theme = 'npg',
             cdf.percent = 10,
             max.lncrna.len = 10000,
             min.expressed.sample = 50,
             ask = FALSE)
```

To call in command line:

```{bash, eval = FALSE, echo = TRUE}
# Replace ... with arguments
$ Rscript -e "library(LncPipeReporter); run_reporter(input = '.', ...)"
```

> `...` stands for other arguments. You should use **single-quotes** here.

Column
-------------------------------------

### Authors 

[Qi Zhao](https://github.com/likelet) from Sun Yat-sen University Cancer Center, Guangdong, China.

[Yu Sun](http://icannotendure.space/) ([GitHub](https://github.com/bioinformatist)) from Nankai University. Tianjin, China.

### Release notes

This is the first version of LncPipeReporter.

### Citations

Coming soon!

### Lisence

[GPL v3 License](../LICENSE)

<!-- Quality control -->
<!-- ===================================== -->
<!-- Column -->
<!-- ------------------------------------- -->

<!-- ### Quality control -->
<!-- This sections presents the fastQC output. Samples were listed in the following table.  -->

<!-- ```{r results='asis'} -->
<!-- fastqc.dirs <- list.files(path = params$input, pattern = '_fastqc$') -->
<!-- fastqc.table <- data.table::data.table( -->
<!-- Sample = substr(fastqc.dirs, 7, nchar(fastqc.dirs) - 7), -->
<!-- HTML = paste0( -->
<!-- '[**Click** for HTML](', -->
<!-- paste0(params$input, .Platform$file.sep, fastqc.dirs, .Platform$file.sep, "fastqc_report.html"), -->
<!-- ')' -->
<!-- ), -->
<!-- Summary = paste0( -->
<!-- '[**Click** for summmary](', -->
<!-- paste0(params$input, .Platform$file.sep, fastqc.dirs, .Platform$file.sep, "summary.txt"), -->
<!-- ')' -->
<!-- ), -->
<!-- Details = paste0( -->
<!-- '[**Click** for details](', -->
<!-- paste0(params$input, .Platform$file.sep, fastqc.dirs, .Platform$file.sep, "fastqc_data.txt"), -->
<!-- ')' -->
<!-- ) -->
<!-- ) -->
<!-- knitr::kable(fastqc.table, caption = "FastQC results") -->
<!-- rm(fastqc.dirs, fastqc.table) -->
<!-- invisible(gc()) -->
<!-- ``` -->


<!-- ```{r star-child, child='STAR.Rmd', eval=!is.null(type.list[['STAR']])} -->
<!-- ``` -->

<!-- ```{r hisat2-child, child='Hisat2.Rmd', eval=!is.null(type.list[['Hisat2']])} -->
<!-- ``` -->

<!-- ```{r tophat2-child, child='Tophat2.Rmd', eval=!is.null(type.list[['Tophat2']])} -->
<!-- ``` -->

```{r lncRNA-child, child='lncRNA.Rmd', eval=!is.null(type.list[['lncRNA']])}
```

```{r DE-child, child=switch(de.method, edger = 'edger.Rmd', deseq2 = 'deseq2.Rmd', noiseq = 'noiseq.Rmd'), eval=!is.null(type.list[['Design']])}
```
