# Clustering - exercise

Imagine ETV6-RUNX1_4 failed leaving you with three ETV6-RUNX1 replicates,
... but the corrected values remain the same somehow.

Define Louvain and Leiden clusters and compare the outcome.
Maybe check clustering quality using per-cluster modularity, too. 

## load data

```{r}
splSetToGet <- "PBMMC,ETV6-RUNX1"
splSetVec <- unlist(strsplit(splSetToGet, ","))

nbPcToComp <- 50
figSize <- 7
```

```{r clusPostDsi_Caron.knitr_options, echo=FALSE, results="hide", message=FALSE}
# Set some variables:
require(knitr)
opts_chunk$set(error=FALSE, message=FALSE, warning=FALSE, cache=FALSE)
opts_chunk$set(echo = TRUE)
opts_chunk$set(eval = TRUE) 
opts_chunk$set(fig.width=7, fig.height=7)
options(stringsAsFactors = FALSE)
set.seed(123) # for reproducibility
```

```{r  clusPostDsi_Caron.library, warning=FALSE, message=FALSE}
library(tidyverse) # data wrangling and plotting (ggplot2)
library(scater) # scRnaSeq QC
library(scran) # scRnaSeq normalisation
library(bluster) # scRnaSeq clustering
library(dynamicTreeCut) # tree cutting in clustering
library(cluster) # for silhouette
library(igraph) # for graph-based clustering and plotting networks 
library(reticulate) # for graph-based clustering with leiden
library(leiden) # for community detection (clustering)
library(pheatmap) # for heatmap plotting
library(patchwork) # to combine plots
fontsize <- theme(axis.text=element_text(size=12), axis.title=element_text(size=16))
```


```{r}
sce <- readRDS("../Robjects/DataIntegration_mnn.out.Rds") # auto.merge

# remove ETV6-RUNX1_4
bcToKeep <- colData(sce) %>%
  data.frame() %>%
  rownames_to_column("Barcode2") %>%
  filter(!SampleName == "ETV6-RUNX1_4") %>%
  pull(Barcode2)
indToKeep <- which(colnames(sce) %in% bcToKeep)
sce <- sce[,indToKeep]

sce$SampleName <- factor(sce$SampleName)
sce <- runTSNE(sce, dimred = "corrected")
```

Build graph:

```{r}
# think 'buildSNNGraph'


```

## Louvain

Compute Louvain clusters:

```{r}






```

Plot tSNE:

```{r}





```

Per-cluster modularity

```{r}
# compute



# plot


```

## Leiden

Compute Leiden clusters:

```{r}
library("leiden")




```

Plot tSNE:

```{r}


```

## Compare Louvain and Leiden clusters

```{r}
# table


```

```{r}
# heatmap



```




