---
title: "Test Modular Functions"
output: html_document
---

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

```{r}
library(nipalsMCIA)
data("NCI60")

metadata_NCI60 <- data.frame(cancerType = unlist(metadata_NCI60))
row.names(metadata_NCI60) <- rownames(data_blocks[[1]])

# Adding metadata as part of the nipals_multiblock() function
mcia_results <- nipals_multiblock(data_blocks, preprocMethod = "colprofile",
                                  metadata = metadata_NCI60, plots = "none",
                                  num_PCs = 10, tol = 1e-12)

# Alternative method for adding metadata
mcia_results$metadata <- metadata_NCI60
```

# Test projection_plot with NO colors

```{r, fig.dim = c(4, 4), fig.align = "center"}
plot_type <- "projection_global"
orders <- c(1, 2)
projection_plot(mcia_results, projection = plot_type,
                orders = c(1, 2), color_col = NULL,
                legend_loc = "bottomleft")
```

```{r, fig.dim = c(6, 4), fig.align = "center"}
plot_type <- "projection"
projection_plot(mcia_results, projection = plot_type,
                orders = c(1, 2), color_col = NULL,
                legend_loc = "bottomleft")
```

# Test projection_plot with the default color settings (uses scales::\<function\>)

```{r}
color_col <- "cancerType"
```

```{r, fig.dim = c(4, 4), fig.align = "center"}
plot_type <- "projection_global"
orders <- c(1, 2)
projection_plot(mcia_results, projection = plot_type,
                orders = c(1, 2), color_col = "cancerType",
                legend_loc = "bottomleft")
```

```{r, fig.dim = c(6, 4), fig.align = "center"}
plot_type <- "projection"
projection_plot(mcia_results, projection = plot_type,
                orders = c(1, 2), color_col = "cancerType",
                legend_loc = "bottomleft")
```

# Test projection_plot with the user specified colors

```{r, fig.dim = c(4, 4), fig.align = "center"}
plot_type <- "projection_global"
orders <- c(1, 2)
projection_plot(mcia_results, projection = plot_type,
                orders = c(1, 2), color_col = "cancerType",
                color_pal = c("red", "green", "blue"),
                legend_loc = "bottomleft")
```

```{r, fig.dim = c(6, 4), fig.align = "center"}
plot_type <- "projection"
projection_plot(mcia_results, projection = plot_type,
                orders = c(1, 2), color_col = "cancerType",
                color_pal = c("orange", "purple", "pink"),
                legend_loc = "bottomleft")
```

# Test global_scores_eigenvalues_plot(mcia_results)

```{r, fig.dim = c(6, 4)}
global_scores_eigenvalues_plot(mcia_results)
```

# Test block_weights_heatmap

```{r, fig.dim = c(6, 4)}
block_weights_heatmap(mcia_results)
```
