---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
```

TopHat2 {data-navmenu="Aligning"}
=====================================

```{r tophat parsing}
tophat <- fread(paste0("grep -H '' ", paste(type.list$Tophat2, collapse=" "), " | perl -F':|\\(' -lanE'say qq{$F[0]\tLeft\tInput reads\t$F[2]} if $. % 14 == 2; say qq{$F[0]\tLeft\tMapped reads\t$F[2]} if $. % 14 == 3; say qq{$F[0]\tLeft\tMultiple alignments\t$F[2]} if $. % 14 == 4; say qq{$F[0]\tRight\tInput reads\t$F[2]} if $. % 14 == 6; say qq{$F[0]\tRight\tMapped reads\t$F[2]} if $. % 14 == 7; say qq{$F[0]\tRight\tMultiple alignments\t$F[2]} if $. % 14 == 8'"), header = FALSE, sep = "\t", fill = TRUE)
tophat[, V1 := tstrsplit(V1, .Platform$file.sep)[[length(tstrsplit(V1, .Platform$file.sep))]]][, V1 := tstrsplit(V1, '[._]')[[1]]]
setnames(tophat, c("Sample", "Direction", "Type", "Number"))
fig.height <- length(unique(as.vector(t(tophat[,1])))) * 0.7
```

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

### *TopHat2* aligning report plot

```{r tophat plot, fig.height = fig.height}
p <- ggplot() +
  geom_bar(data = tophat, aes(x = Direction, y = Number, fill = Type), stat = 'identity') +
  coord_flip() + facet_grid(Sample ~ .) + get(paste0('scale_fill_',params$theme))()
save_plot('TopHat2.tiff', p, base_height = fig.height, base_width = 11, dpi = 300, compression = 'lzw')
save_plot('TopHat2.pdf', p, base_height = fig.height, base_width = 11, dpi = 300)
ggplotly(p) %>% layout(margin = list(b = 60))
```

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

### Description

This section summarized the Tophat mapping stats of reads from multiple samples. `aligner` paramerter set in LncPipe result in different kind of summary report, and LncPipeReporter can also automatically determine the aligner from file content, which means that lncPipeReportered can be run seperatedly based a set of aligner ouputs files. 
Mapping status usually contains reads count that mapped or unmapped, where mapped reads can also divided into discordinate mapped, unique mapped, multiple mapped or mapped with low quality. This kind of information are necessary for evaluated the sequencing and library quality. When multiple samples are involved in analysis, this overview analysis can quickly detect batch effect or outlier samples.

An typical output of Tophat2 log file can be found from this link
[Tophat Log file](https://github.com/bioinformatist/LncPipeReporter/blob/master/inst/extdata/demo_results/N1037.log)

### *TopHat2* aligning report table

```{r tophat table}
fwrite(tophat, 'TopHat2.csv')
DT::datatable(head(tophat, n = 80L))
```
