---
title: "pathfindR - All Enriched Pathways - `r params$gset`"
output: html_document
params:
  df: ""
  gset: ""
  vis_cond: TRUE
  out_dir: ""
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r pathview, echo=FALSE, comment=NA}
if (params$gset == "KEGG" & params$vis_cond)
  cat("KEGG pathway visualizations were performed via the R Biocondutor package __pathview__ [1].\n")
```


```{r table, echo = F, comment=NA}
result_df <- params$df
result_df$lowest_p <- format(result_df$lowest_p, digits = 2)
result_df$highest_p <- format(result_df$highest_p, digits = 2)

if (params$vis_cond) {
  
  ## If hsa KEGG visualizations
  if (params$gset == "KEGG") {
    for(i in 1:nrow(result_df))
      result_df[i, 2] <- paste0("[", result_df[i, 2], "]", "(./pathway_visualizations/", result_df[i, 1],".", result_df[i, 2],".png)")
  } else {
    ## If interactions of pw genes visualizations
    pw_dir <- paste0(params$out_dir, "/pathway_visualizations")
    pw_dir <- normalizePath(pw_dir)
    for(i in 1:nrow(result_df)) {
      file_path <- paste0(pw_dir, "/", result_df[i, 2],".png")
      if (file.exists(file_path))
        result_df[i, 2] <- paste0("[", result_df[i, 2], "]", "(./pathway_visualizations/", result_df[i, 2],".png)")
    }
  }
}


knitr::kable(result_df, align = "c",table.caption.prefix ="")
```


```{r pathview_ref, echo=FALSE, comment=NA}
if (params$gset == "KEGG" & params$vis_cond)
  cat("[1] Luo W, Brouwer C. Pathview: an R/Biocondutor package for pathway-based data integration and visualization. Bioinformatics, 2013, 29(14):1830-1831, doi: 10.1093/bioinformatics/btt285")
```

