---
title: "`r if (exists('reportTitle')) reportTitle else 'SUSHI Report'`"
output: 
  html_document:
    mathjax: https://fgcz-gstore.uzh.ch/reference/mathjax.js
    self_contained: true
    includes:
      in_header: !expr system.file("templates/fgcz_header.html", package="ezRun")
    css: !expr system.file("templates/fgcz.css", package="ezRun")
editor_options: 
  chunk_output_type: inline
---


```{r cluster plot, echo=FALSE, fig.width=max(8,4+0.15*ncol(ncol(rawData))), fig.height=10, fig.retina=2, warning=FALSE}
## Cluster plot again
plot(clusterResult$pheatmap$gtable)
```

```{r cluster table, echo=FALSE}
## The detailed table
ktables <- goTables$ktables
ngroups <- sapply(ktables, nrow)
ktables <- do.call(rbind, ktables)
stopifnot(identical(names(clusterResult$GO), c("BP", "MF", "CC"))) ## The order matters
p <- kable(ktables, escape=FALSE, row.names=FALSE, format = "html", digits=4,
          caption="GO categories of feature clusters") %>%
  kable_styling(bootstrap_options = "striped",
                full_width = F, position = "float_right") %>%
  footnote(general="Cluster font color corresponds to the row colors in the heatmap plot.") %>%
  add_header_above(c("Biological Proc. (BP)" = 4, "Molecular Func. (MF)" = 4, "Cellular Comp. (CC)" = 4))
stopifnot(length(bgColors) == length(ngroups)) ## The colour and clusters should match.
indices <- c(0,cumsum(ngroups))
for(i in 1:length(ngroups)){
  p <- p %>% 
    kableExtra::group_rows(paste("Cluster", i), indices[i]+1, indices[i+1],
                label_row_css = paste("background-color:", bgColors[i], 
                                     "; color: #fff;"))
}
p
```