---
title: "R Notebook"
output: html_notebook
---

```{r, echo=FALSE, message=F, warning=F}
# Preamble
library(tidyverse)
# setwd("~/assemblycomparator2/tests/E._faecium_plasmids/")
```


```{r, echo=FALSE, message=F, warning=F}
# Register inputs
file_prefix = "../tests/E._faecium_plasmids/output_asscom2/"
possible_inputs = tribble(
    ~section,       ~file,
    "metadata",     paste0(file_prefix, "metadata.tsv"),
    
    "abricate",     paste0(file_prefix, "abricate/card_detailed.tsv"),
    "abricate",     paste0(file_prefix, "abricate/card_summarized.tsv"),
    
    "fse",          paste0(file_prefix, "fse/data.txt"),
)
```


```{r, echo=FALSE, message=F, warning=F}
# Mark if the files exist
inputs_df = possible_inputs %>%
    mutate(section = factor(section, levels = unique(section)), # keep the initial ordering of the sections.
           exists = file.exists(file), 
           basename = basename(file)) |> 
    select(section, basename, exists, file)

inputs_df

```


```{r, echo=FALSE, message=F, warning=F}

# Make a list that can easily be intuitively accessed with R base syntax
inputs = inputs_df |> 
    group_by(name = section) |> 
    summarize(value = all(exists)) |> 
    pivot_wider()

inputs
```

`r if (inputs$metadata) { "" }`
`r if (inputs$metadata) { "# Section Metadata" }`
`r if (inputs$metadata) { "In this section the metadata will briefly be presented." }`




```{r, echo=FALSE, message=F, warning=F}
active = inputs$abricate
```

`r if (active) { "" }`
`r if (active) { "# Section Abricate" }`
`r if (active) { "In this section we will present the output from abricate." }`
```{r echo=FALSE, message=F, warning=F}

tibble(a = 1:6, b = letters[1:6])

```
`r if (active) { "---"}`

####################################################################

`r if (inputs$fse) { "" }`
`r if (inputs$fse) { "# Section Abricate" }`
`r if (inputs$fse) { "In this section we will present the output from fse." }`


I just realized that the v2 report is better in the way that it doesn't simply check if the input file exists -- It uses trycatch in each block to minimize the probability of failing if there is a corruption of the input file.

