---
title: "Quick Start: An Introduction to wompwomp"
output:
    rmarkdown::html_vignette:
        toc: true
        toc_depth: 2
vignette: >
  %\VignetteIndexEntry{Quick Start: An Introduction to wompwomp}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r}
library(wompwomp)

set.seed(43)
```

We create a toy data frame that maps tissues (BRAIN, STOMACH, HEART, T CELL, B CELL) to clustering (1-4)
```{r}
df <- data.frame(
    tissue = c(
        "BRAIN", "BRAIN", "BRAIN",
        "STOMACH", "STOMACH", "STOMACH", "STOMACH", "STOMACH", "STOMACH",
        "HEART", "HEART", "HEART", "HEART", "HEART", "HEART", "HEART",
        "T CELL", "T CELL",
        "B CELL", "B CELL", "B CELL", "B CELL", "B CELL", "B CELL", "B CELL", "B CELL", "B CELL"
    ),
    cluster = c(
        1, 1, 2,
        1, 2, 2, 2, 2, 2,
        1, 3, 3, 3, 3, 3, 3,
        4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4
    )
)
graphing_columns <- c("tissue", "cluster")

# write.csv(df, file = "vignette_intro_df_ungrouped.csv", row.names = FALSE, quote = FALSE)
print(df)
```

Group by tissue and cluster, counting the values in a new column value
```{r}
clus_df_gather <- prep_for_lodes(df, cols = graphing_columns)

# write.csv(clus_df_gather, file = "vignette_intro_df_grouped.csv", row.names = FALSE, quote = FALSE)
print(clus_df_gather)
```

```{r}
clus_df_gather_tsp <- sort_to_uncross(clus_df_gather, cols = graphing_columns, wt = "value", method = "tsp")
print(clus_df_gather_tsp)
```

```{r}
# clus_df_gather_tsp <- clus_df_gather_tsp
stratum_to_color_mapping <- get_lode_clusters(clus_df_gather_tsp, cols = graphing_columns, wt = "value", method = "advanced")
print(stratum_to_color_mapping)
# jsonlite::toJSON(stratum_to_color_mapping, pretty = TRUE, auto_unbox = TRUE)
```

```{r}
crossing_edges_out <- compute_crossing_objective(clus_df_gather_tsp, cols = graphing_columns, wt = "value")
print(crossing_edges_out$output_objective)
```

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