<%=title%>
==================

**Date**: `r format(as.POSIXlt(Sys.time()), usetz = TRUE)`, **cola version**: `r installed.packages()["cola", "Version"]`

----------------------------------------------------------------

<style type='text/css'>
<%
css = paste(readLines(paste0(TEMPLATE_DIR, "/custom.css")), collapse = "\n") -%>
<%= css %>
</style>

```{r, echo = FALSE, message = NA}
library(knitr)
library(markdown)
options(width = 100)
options(digits = 3)
opts_chunk$set(
    comment = "#>",
    fig.path = "figure_cola/",
    warning = FALSE,
    message = FALSE
)
suppressPackageStartupMessages(library(ComplexHeatmap))
suppressPackageStartupMessages(library(genefilter))
ht_opt$message = FALSE

n_cores = get_nc(cores)
```

<% res = object; n_cores = cores -%>

## Summary

<% same_var_name = var_name == "res" -%>

<% if(!same_var_name) { -%>

First the variable is renamed to `res`.

```{r, eval = FALSE, echo = TRUE}
res = <%=var_name%>
```
<% } -%>

```{r, echo = FALSE}
res = object
```

Dimension of the input matrix:

```{r}
mat = get_matrix(res)
dim(mat)
```

Top-value method used:

```{r}
res@top_value_method
```

Partitioning method used:

```{r}
res@partition_method
```

The density distribution for each sample is visualized as in one column in the
following heatmap. The clustering is based on the distance which is the
Kolmogorov-Smirnov statistic between two distributions.

```{r, echo = FALSE, message = NA}
t1 = Sys.time()
message(qq("* making density heatmap of global distribution for each sample (@{ncol(mat)} samples)"), appendLF = FALSE)
```

```{r density-heatmap}
library(ComplexHeatmap)
<% if(is.null(get_anno(res))) { -%>
densityHeatmap(mat, ylab = "value", cluster_columns = TRUE, show_column_names = FALSE,
    mc.cores = <%=n_cores%>)
<% } else { -%>
densityHeatmap(mat, top_annotation = HeatmapAnnotation(df = get_anno(res), 
    col = get_anno_col(res)), ylab = "value", cluster_columns = TRUE, show_column_names = FALSE,
    mc.cores = <%=n_cores%>)
<% } -%>
```

```{r, echo = FALSE, message = NA}
t2 = Sys.time(); message(paste0(", ", gsub("^ +", "", format(t2 - t1))))
```

<% has_known_anno = FALSE
if(!is.null(res@anno)) { 
has_known_anno = TRUE -%>
<%}-%> 

## Results

```{r, results = "asis", echo = FALSE}
fs = min(c(3*1, 14))/1

is_hc = FALSE
node = NULL
single_report = TRUE

all_k = res@k

i_section = 1
n_section = 1
top_value_method = res@top_value_method
partition_method = res@partition_method

tmpfile = tempfile(tmpdir = cola:::.ENV$TEMP_DIR)

brew(file.path(cola:::TEMPLATE_DIR, "section_template.Rmd-template"), tmpfile)
rmd = paste(readLines(tmpfile), collapse = "\n")
invisible(file.remove(tmpfile))

ComplexHeatmap:::dev.null()
txt = knit(text = rmd, quiet = TRUE)
devlt = dev.list()
if(names(devlt)[1] == "quartz_off_screen") {
	invisible(dev.off())
}
invisible(dev.off())
cat(txt, "\n")
```

## Session info

```{r}
sessionInfo()
```

```{r, echo = FALSE, message = NA}
message("-----------------------------------------------------------------")
```


<script type="text/javascript">
$(function() {
    $("#TOC > ul > li > a").remove();
}); 
</script>
