---
title: "CyTOF Raw Event Type Summary Report"
author: "Generated by cytofQC"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
params:
    runUMAP: TRUE
---

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

```{r load_data}
res <- readRDS('cytofQCdata_temp.rds')
tech <- res$tech
labels <- factor(res$label)
rm(res)
stopifnot(nrow(tech) == length(labels))
message('Found ', nrow(tech), ' events.', '\n')
message('Found the following technical variables:','\n',
        paste(colnames(tech), collapse = ', '), '\n')
```


## Event type summary

```{r table1}
cbind(count = table(labels), 
      percent = round(100 * table(labels) / length(labels), digits = 2))
```


```{r umap}
if(params$runUMAP){
    s.tech <- scale(tech[, -1])
    umap <- uwot::umap(s.tech)
    
    require(RColorBrewer)
    cols <- brewer.pal(5, "Set2")
    layout(matrix(c(1,1,2), nrow=1))
    plot(umap, asp=1, col = cols[labels], cex = .25, pch=16,
         main = "UMAP on Technical Variables")
    plot.new()
    legend("left", pch=19, col = cols, legend = levels(labels), bty='n')
}
```

