---
title: "FROGSSTAT DESeq2: Visualisation (version `r params$version`)"
copyright: "Copyright (C) 2024 INRAE"
license: "GNU General Public License"
version: "5.0.0"
output: 
  html_notebook:
    code_folding: hide
params:
  # Path to abundances table phyloseq_object
  abundance_data:
    value: x
  # DESeq2 preprocessed input
  dds:
    value: x
  # tested variable
  var:
    value: x
  # optionnal value 1 of the variable to be compared, default== "None"
  mod1:
    value: x
  # optionnal value 2 of the variable to be compared, default== "None"
  mod2:
    value: x
  # adjusted pvalue threshold
  padj_th:
    value: x
  # Type of analysis
  analysis:
    value: x
  # iPath functions svg file
  ipath_over:
    value: x
  ipath_under:
    value: x
  svg_file_over:
    value: x
  svg_file_under:
    value: x
  libdir:
    value: x
  version:
    value: x
---

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="author" content="Ta Thi Ngan - SIGENAE/GABI & Mahendra Mariadassou - MaIAGE" />
<meta name="version" content="5.0.0" />
<meta name="copyright" content="Copyright (C) 2024 INRAE" />

<script>
function update_theme(val){
				if(val == "Coral" ){
					/*
					:root {
						--frogsColor: #388697; 
						--frogsColorHover: rgb(12,10,62,0.8);
						--frogsColorShadow: #6c5b64;
						--frogsColor2: #FA8883;
						--frogsColor3: #EFC7C2;
						--frogsColor4: #737f75;
						--frogsColorZoomHighCharts: rgb(191,211,193,0.25);
						--frogsButtonColor: rgb(105,79,93,0.6);
						--frogsButtonBorderColor: rgb(12,10,62,0.6);
						--frogsOddTable: rgba(249,86,79, 0.1);
						--frogsCircleFontColor: #FFF;
						--frogsCircleBackgroundColor: #FA8883;
						--frogsCircleBorderColor: #FA8883;
						--frogsPreColor: rgba(191, 211, 193, 0.25);
					}
					*/
					document.documentElement.style.setProperty('--frogsColor', "#388697");
					document.documentElement.style.setProperty('--frogsColorHover', "rgb(12,10,62,0.8)");
					document.documentElement.style.setProperty('--frogsColorShadow', "#6c5b64");
					document.documentElement.style.setProperty('--frogsColor2', "#FA8883");
					document.documentElement.style.setProperty('--frogsColor3', "#ffef99");
					document.documentElement.style.setProperty('--frogsColor4', "#737f75");
					document.documentElement.style.setProperty('--frogsColorZoomHighCharts', "rgb(191,211,193,0.25)");
					document.documentElement.style.setProperty('--frogsButtonColor', "rgb(12,10,62,0.6)");
					document.documentElement.style.setProperty('--frogsButtonBorderColor', "rgb(12,10,62,0.8)");
					document.documentElement.style.setProperty('--frogsOddTable', "rgba(249,86,79, 0.1)");
					document.documentElement.style.setProperty('--frogsCircleFontColor', "#FFF");
					document.documentElement.style.setProperty('--frogsCircleBackgroundColor',"#FA8883");
					document.documentElement.style.setProperty('--frogsCircleBorderColor',"#FA8883");
					document.documentElement.style.setProperty('--frogsPreColor', "rgba(191, 211, 193, 0.25)");
					
					var root = document.documentElement;
					var style = getComputedStyle(root);
					var frogsColor = style.getPropertyValue('--frogsColor');
					var frogsColor2 = style.getPropertyValue('--frogsColor2');
					var frogsColor3 = style.getPropertyValue('--frogsColor3');
					var frogsColor4 = style.getPropertyValue('--frogsColor4');
					var frogsColorZoomHighCharts = style.getPropertyValue('--frogsColorZoomHighCharts');
					var frogsColorHover = style.getPropertyValue('--frogsColorHover');
					var frogsButtonColor = style.getPropertyValue('--frogsButtonColor');
					var frogsCircleFontColor = style.getPropertyValue('--frogsCircleFontColor');
					var frogsColorShadow = style.getPropertyValue('--frogsColorShadow');
					
					
				}else if(val == "Plum" ){
					/*
					:root {
						--frogsColor: #694F5D; 
						--frogsColorHover: rgb(105,79,93,0.8);
						--frogsColorShadow: #6c5b64;
						--frogsColor2: #BFD3C1;
						--frogsColor3: #EFC7C2;
						--frogsColor4: #737f75;
						--frogsColorZoomHighCharts: rgb(222,159,115,0.25);
						--frogsButtonColor: rgb(105,79,93,0.6);
						--frogsButtonBorderColor: rgb(105,79,93,0.8);
						--frogsOddTable: #f2f2f2;
						--frogsCircleFontColor: #694F5D;
						--frogsCircleBackgroundColor: #BFD3C1;
						--frogsCircleBorderColor: #BFD3C1;
					}*/
					document.documentElement.style.setProperty('--frogsColor', "#694F5D");
					document.documentElement.style.setProperty('--frogsColorHover', "rgb(105,79,93,0.8)");
					document.documentElement.style.setProperty('--frogsColorShadow', "#6c5b64");
					document.documentElement.style.setProperty('--frogsColor2', "#BFD3C1");
					document.documentElement.style.setProperty('--frogsColor3', "#4f5d69");
					document.documentElement.style.setProperty('--frogsColor4', "#737f75");
					document.documentElement.style.setProperty('--frogsColorZoomHighCharts', "rgb(222,159,115,0.25)");
					document.documentElement.style.setProperty('--frogsButtonColor', "rgb(105,79,93,0.6)");
					document.documentElement.style.setProperty('--frogsButtonBorderColor', "rgb(105,79,93,0.8)");
					document.documentElement.style.setProperty('--frogsOddTable', "#f2f2f2");
					document.documentElement.style.setProperty('--frogsCircleFontColor', "#694F5D");
					document.documentElement.style.setProperty('--frogsCircleBackgroundColor',"#BFD3C1");
					document.documentElement.style.setProperty('--frogsCircleBorderColor',"#BFD3C1");
					document.documentElement.style.setProperty('--frogsPreColor', "rgba(191, 211, 193, 0.25)");
					
					var root = document.documentElement;
					var style = getComputedStyle(root);
					var frogsColor = style.getPropertyValue('--frogsColor');
					var frogsColor2 = style.getPropertyValue('--frogsColor2');
					var frogsColor3 = style.getPropertyValue('--frogsColor3');
					var frogsColor4 = style.getPropertyValue('--frogsColor4');
					var frogsColorZoomHighCharts = style.getPropertyValue('--frogsColorZoomHighCharts');
					var frogsColorHover = style.getPropertyValue('--frogsColorHover');
					var frogsButtonColor = style.getPropertyValue('--frogsButtonColor');
					var frogsCircleFontColor = style.getPropertyValue('--frogsCircleFontColor');
					var frogsColorShadow = style.getPropertyValue('--frogsColorShadow');
					
					
				}else if(val == "FROGS4" ){
					/*
					:root {
						--frogsColor: #8eadac; 
						--frogsColorHover: #648a89;
						--frogsColorShadow: #648a89;
						--frogsColor2: #de9f73;
						--frogsColor3: #ad8e9f;
						--frogsColor4: #a2a32f;
						--frogsColorZoomHighCharts: rgb(100, 138, 137, 0.25);
						--frogsButtonColor: #8EADAC;
						--frogsButtonBorderColor: #8EADAC;
						--frogsOddTable: #f2f2f2;
						--frogsCircleFontColor: #FFF;
						--frogsCircleBackgroundColor: #8eadac;
						--frogsCircleBorderColor: #648a89;
					}*/
					document.documentElement.style.setProperty('--frogsColor', "#8eadac");
					document.documentElement.style.setProperty('--frogsColorHover', "#648a89");
					document.documentElement.style.setProperty('--frogsColorShadow', "#648a89");
					document.documentElement.style.setProperty('--frogsColor2', "#de9f73");
					document.documentElement.style.setProperty('--frogsColor3', "#ad8e9f");
					document.documentElement.style.setProperty('--frogsColor4', "#a2a32f");
					document.documentElement.style.setProperty('--frogsColorZoomHighCharts', "rgb(100, 138, 137, 0.25)");
					document.documentElement.style.setProperty('--frogsButtonColor', "#8EADAC");
					document.documentElement.style.setProperty('--frogsButtonBorderColor', "#8EADAC");
					document.documentElement.style.setProperty('--frogsOddTable', "#f2f2f2");
					document.documentElement.style.setProperty('--frogsCircleFontColor', "#FFF");
					document.documentElement.style.setProperty('--frogsCircleBackgroundColor',"#8eadac");
					document.documentElement.style.setProperty('--frogsCircleBorderColor',"#648a89");
					document.documentElement.style.setProperty('--frogsPreColor', "rgba(226, 234, 227, 0.25)");
					
					var root = document.documentElement;
					var style = getComputedStyle(root);
					var frogsColor = style.getPropertyValue('--frogsColor');
					var frogsColor2 = style.getPropertyValue('--frogsColor2');
					var frogsColor3 = style.getPropertyValue('--frogsColor3');
					var frogsColor4 = style.getPropertyValue('--frogsColor4');
					var frogsColorZoomHighCharts = style.getPropertyValue('--frogsColorZoomHighCharts');
					var frogsColorHover = style.getPropertyValue('--frogsColorHover');
					var frogsButtonColor = style.getPropertyValue('--frogsButtonColor');
					var frogsCircleFontColor = style.getPropertyValue('--frogsCircleFontColor');
					var frogsColorShadow = style.getPropertyValue('--frogsColorShadow');
					
				 }
			}
</script>

<style type="text/css">
:root {
			--frogsColor: #388697; 
			--frogsColorHover: rgb(12,10,62,0.8);
			--frogsColorShadow: #6c5b64;
			--frogsColor2: #FA8883;
			--frogsColor3: #EFC7C2;
			--frogsColor4: #737f75;
			--frogsColorZoomHighCharts: rgb(191,211,193,0.25);
			--frogsButtonColor: rgb(12,10,62,0.6);
			--frogsButtonBorderColor: rgb(12,10,62,0.25);
			--frogsPreColor: rgba(191, 211, 193, 0.25);
		}
h1{
	color: var(--frogsColor);
}
h2{
	color: var(--frogsColor);
}
a {
	color: var(--frogsColor);
}
a:hover{
	color: var(--frogsColorHover);
}
.nav-pills > li.active > a, .nav-pills > li.active > a:focus{
	color: #fff;
	background-color: var(--frogsColor);
	border-color: #dee2e6 #dee2e6 #fff;
}
.nav-pills > li.active > a:hover {
	background-color: var(--frogsColorHover);
}
.button {
    background-color: var(--frogsButtonColor)
    border          : none;
    color           : white;
    padding         : 5px 10px;
    text-align      : center;
    text-decoration : none;
    display         : inline-block;
    font-size       : 12px;
    margin          : 4px 2px;
    cursor          : pointer;
    border-radius   : 8px;
}
h4 { 
    display      : block;
    font-size    : 1em;
    margin-top   : 1.33em;
    margin-bottom: 1.33em;
    margin-left  : 0;
    margin-right : 0;
    font-weight  : bold;
    color        : var(--frogsColor);
}
code.r{ /* Code block */
  font-size: 11px;
}
pre{
  font-size: 11px ;
  background-color: var(--frogsPreColor) !important;
}
.frogsversion{
	position: absolute;
	right: 5%;
	color: var(--frogsColor);
	font-style: italic;
	font-size: smaller;
	padding:8px;
}
.frogsversion > a{
	border: none !important;
	display: inline-block;
}
</style>

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
```
Phyloseq `r packageVersion("phyloseq")` and DESeq2 `r packageVersion("DESeq2")`

```{=html}
<select id="themechoice" class="form-select" onchange="update_theme($(this).val())" style="font-size: smaller;" aria-label="Default select example">
	<option selected disabled>Switch theme</option>
	<option value="Plum">Plum</option>
	<option value="Coral">Coral</option>
	<option value="FROGS4">FROGS4</option>
</select>
```

# {.tabset .tabset-fade .tabset-pills}
## Differentially abundant ASV/FUNCTION table

```{r packages, echo=FALSE, code_folding="show"}
library(phyloseq)
# dealing with plots
library(ggplot2)
# dealing with table
library(DT)
library(dplyr)
source(file.path(params$libdir, "process_ipath.R")) 
```

```{r import}
# Import input files
abundances_input <- get(load(params$abundance_data))
dds_input     <- get(load(params$dds))
base_name <- dirname(params$dds)
run_ipath <- ifelse(params$analysis == "ASV", FALSE, TRUE)
result_names <- DESeq2::resultsNames(dds_input)

# doc <- ""
# if(length(result_names) == 2 || params$mod1 == "None"){
#      results <- DESeq2::results(dds, name = result_names[1])
# } else if(length(result_names)>=3){
#      results <- DESeq2::results(dds_input, contrast = c(params$var, params$mod1, params$mod2) )
#      doc <- paste0("You chose to compare ", params$mod1, " to the reference modality ", params$mod2, ". This implies that a positive log2FoldChange means more abundant in ", params$mod1, " than in ", params$mod2, ".")
#      cat(doc)
# }
doc <- ""
# quantitative variable
if(params$mod1 == "None"){
     results <- DESeq2::results(dds, name = result_names[1])
# qualitative variable
} else {
     results <- DESeq2::results(dds_input, contrast = c(params$var, params$mod1, params$mod2) )
     doc <- paste0("You chose to compare ", params$mod1, " to the reference modality ", params$mod2, ". This implies that a positive log2FoldChange means more abundant in ", params$mod1, " than in ", params$mod2, ".")
     cat(doc)
}

#This implies that a positive log2FoldChange means more abundant in low than in high.")
```

Then we extract significant ASVs or FUNCTIONs at the p-value adjusted threshold (after Benjamini Hochberg correction) and enrich results with taxonomic/functional classification and sort the results by pvalue.

```{r da_abundances}

da.abundances_table <- results %>% as_tibble(rownames = "ID") %>% 
	inner_join(tax_table(abundances_input) %>% as.data.frame() %>% mutate(ID = taxa_names(abundances_input)), by = "ID") %>% 
    filter(padj < params$padj_th) %>% 
    arrange(padj)

```

Using customize datatable we can explore the table of differentially expressed abundances
```{r datatable, message=FALSE}

DT_foldchange <- da.abundances_table %>% datatable(filter = "top",                # ==> add filter for each column
                                             extensions = 'Buttons' , 
                                             options = list(dom = '<fBtlip>', 
                                                scrollX = TRUE, 
                                                 # lengthMenu = list(c(5,10,25,50,100,-1),c(5,10,25,50,100,"All")), # ==> trop couteux en mÃ©moire, mÃªme sur petit jeu
                                                 buttons = list(list(
                                                    extend = 'collection',
                                                    buttons = c('csv', 'excel'),
                                                    text = 'Download')
                                                 )
                                             )) %>% 
  formatSignif(columns = c("baseMean", "log2FoldChange", "lfcSE", "stat", "padj", "pvalue"), digits = 6) %>% 
  formatStyle(columns = "log2FoldChange", color = DT::styleInterval(0, c('#759493', '#C6792B')))

DT_foldchange
```

```{r prepare_ipath3, eval=run_ipath, echo=run_ipath}

func_sign_over <- da.abundances_table %>% 
  filter(log2FoldChange > 0 ) %>%
  select(ID, log2FoldChange, padj) %>%
  mutate(ID = gsub("EC:", "EC", ID))

func_sign_under <- da.abundances_table %>% 
  filter(log2FoldChange < 0 ) %>%
  select(ID, log2FoldChange, padj) %>%
  mutate(ID = gsub("EC:", "EC", ID))
# gsub for create valid EC numbers for iPath3.

func_sign_over <- func_sign_over %>% 
  mutate(Color = if_else(log2FoldChange < 1, "#DE894E",
   if_else(log2FoldChange < 2, "#B26E3E ", "#9B6037 "))) %>%
  mutate(Width = if_else(padj < 0.001, "W11",
   if_else(padj < 0.01, "W10", "W9")))

# func_sign_over <- func_sign_over %>% 
#   mutate(Color = if_else(log2FoldChange < 1, "#9B6037",
#    if_else(log2FoldChange < 2, "#B26E3E ", "#DE894E "))) %>%
#   mutate(Width = if_else(padj < 0.001, "W12",
#    if_else(padj < 0.01, "W10", "W8")))

func_sign_under <- func_sign_under %>% 
  mutate(Color = if_else(log2FoldChange > -1, "#B0C6C5",
   if_else(log2FoldChange > -2, "#8EADAC", "#637978")))%>%
  mutate(Width = if_else(padj < 0.001, "W11",
   if_else(padj < 0.01, "W10", "W9")))

# func_sign_over <- func_sign_over %>% 
#   mutate(Color = if_else(log2FoldChange < 1, "#B0C6C5",
#    if_else(log2FoldChange < 2, "#8EADAC	", "#637978	"))) %>%
#   mutate(Width = if_else(padj < 0.001, "W12",
#    if_else(padj < 0.01, "W10", "W8")))

# func_sign_under <- func_sign_under %>% 
#   mutate(Color = if_else(log2FoldChange > -1, "#9B6037",
#    if_else(log2FoldChange > -2, "#B26E3E", "#DE894E")))%>%
#   mutate(Width = if_else(padj < 0.001, "W12",
#    if_else(padj < 0.01, "W10", "W8")))

func_sign_over <- func_sign_over %>% select(ID, Color, Width)
func_sign_under <- func_sign_under %>% select(ID, Color, Width)

dir_name <- dirname(params$svg_file_over)

write.table(func_sign_over, file= params$ipath_over, sep=" ", quote=FALSE, row.names = FALSE)
write.table(func_sign_under, file= params$ipath_under, sep=" ", quote=FALSE, row.names = FALSE)
svg_file_over <- params$svg_file_over
svg_file_under <- params$svg_file_under
```

```{asis, eval=run_ipath, echo=run_ipath}
## iPath3

### Differentially abundant functions visualized with iPath 3.
```
```{r doc_path, eval=run_ipath, echo=run_ipath, message=FALSE}
# Import input files
if(params$mod1 != "None") {
     doc <- paste0("You chose to compare ", params$mod1, " to the reference modality ", params$mod2, ". This implies that the over-abundants pathways (first image) and under-abundant pathways (second image) are involved in ", params$mod1, " condition.")
     cat(doc)
} else {
     doc <- paste0("The first image (green paths) represents the over-abundants involved pathways. The second image (red paths) represents the under-abundant pathways.")
     cat(doc)
}
```

```{asis, eval=run_ipath, echo=run_ipath}
The darker the path, the higher the absolute log2 fold change (<=1, <=2, or >2).

To visualise and explore metabolic pathways with [IPATH3 website](https://pathways.embl.de/),  use the two files 
**ipath_under.tsv** and **ipath_over.tsv** as inputs. 
```

```{r ipath3, eval=run_ipath, echo=run_ipath}
process_iPath(params$ipath_over, svg_file_over)
process_iPath(params$ipath_under, svg_file_under)
```

```{r, eval=run_ipath, echo=run_ipath}
setwd(dir_name)
knitr::include_graphics(basename(params$svg_file_over))

knitr::include_graphics(basename(params$svg_file_under))
```

## Pie chart
```{r pie, fig.width=8, fig.height=6}

da_pie <- data.frame(
    IDs=c("Differentially Abundant (log-fold change > 0)",
            "Differentially Abundant (log-fold change < 0)",
            "Not Differentially Abundant"
        ),
    Number=c(sum(da.abundances_table$log2FoldChange > 0), 
        sum(da.abundances_table$log2FoldChange < 0), 
        nrow(results) - nrow(da.abundances_table)
        )
    )

Pie <- ggplot(da_pie, aes(x="", y=Number, fill=IDs)) + 
           geom_bar(stat = "identity") + 
           coord_polar("y", start=0) + 
           scale_fill_manual(values=c('#8EADAC', '#DE9F73', '#C0C0C0')) + 
           geom_text(aes(label = Number), position = position_stack(vjust = 0.5), color = "white") +
           labs(x = NULL, y = NULL, fill = NULL, title = "Pie chart to view ASVs or FUNCTIONs number of Differential Abundance test") +
           theme_classic() + theme(
                axis.line = element_blank(), 
                axis.text = element_blank(),
                axis.ticks = element_blank())

Pie
```

## Volcano plot
```{r volcano, fig.width=10, fig.height=8}
## Volcano plot by DESeq2
# Add ASV/FUNCTION names
# Add the -log10 pvalue 
# Add the pre-calculated log2 fold change
da_volcano <- data.frame(
    id      = row.names(results),
    evidence = -log10(results$padj), 
    lfc      = results$log2FoldChange)

# Remove rows that have NA values
da_volcano <- na.omit(da_volcano)
# add a threshol line
y_axix_volcano_line <- -log10(params$padj_th)

# Modify dataset to add new coloumn of colors
da_volcano <- da_volcano %>%
    mutate(
    	color = case_when(
    		lfc > 0 & evidence > y_axix_volcano_line ~ "More", 
    		lfc < 0 & evidence > y_axix_volcano_line ~ "Less", 
    		TRUE                                     ~ "Equal"
    	)
    )

# Color corresponds to fold change directionality
volcano_plot <- ggplot(da_volcano, aes(x = lfc, y = evidence)) + 
    geom_point(aes(color = factor(color)), size = 1.75, alpha = 0.8, na.rm = T) + # add gene points
    theme_bw(base_size = 16) +                                                    # clean up theme
    theme(legend.position = "none") +                                             # remove legend 
    ggtitle(label = "Volcano Plot", subtitle = "Colored by effect sign") +        # add title
    xlab(expression(log[2]("FoldChange"))) +                                      # x-axis label
    ylab(expression(-log[10]("adjusted p-value"))) +                              # y-axis label
    geom_vline(xintercept = 0, colour = "grey80", linetype = 2) +                                # add line at 0
    geom_hline(aes(yintercept = y_axix_volcano_line), yintercept = y_axix_volcano_line, colour = "grey80", linetype = 2) +
    annotate(geom = "text", 
        label = paste("padj =", params$padj_th), 
        x = min(da_volcano$lfc), 
        y = y_axix_volcano_line + 0.25, 
        size = 4,
        colour = "black",
        vjust = 0,
        hjust = 0) + # add pvalue threshold           
    scale_color_manual(values = c("More" = "#C6792B", "Less" = "#759493", "Equal" = "#C0C0C0")) # change colors

# Plot figure
volcano_plot + scale_y_continuous(trans = "log1p")
```

## MA plot
```{r ma}

## Could do with built-in DESeq2 function:
DESeq2::plotMA(results, ylim = c(-10,10),
    ylab = "log2 fold change", alpha=params$padj_th,
    cex  = 0.8, colNonSig="#C0C0C0", colSig="#A2A32F", colLine="#C0C0C0",
    main = "Post Normalisation DESeq2: MA plot of log2FoldChange",
    legend = TRUE)
```

## Heatmap plot

```{r echo = FALSE, eval = (nrow(da.abundances_table) <= 1)}
cat("There is not engough (0 or 1) differentially abundant ASVs or FUNCTIONs to produce heatmap plot.")
```

```{r heatmap, fig.width=10, fig.height=8, eval = (nrow(da.abundances_table) > 1)}

da.abundances_table <- da.abundances_table %>% arrange(log2FoldChange)
y_title <- ifelse(params$analysis == "ASV", "ASV", "Functions")

abundances_input2 <- prune_samples(get_variable(abundances_input, params$var) %in% c(params$mod1, params$mod2), abundances_input)
abundances_input3 <- prune_taxa(da.abundances_table$ID, abundances_input2)

# Be sure there is no more samples or taxa with 0 value
empty_samples <- sample_names(abundances_input3)[which(sample_sums(abundances_input3)==0)]
sample_to_keep <- sample_names(abundances_input3)[which(sample_sums(abundances_input3)>0)]
data <- prune_samples(sample_to_keep, abundances_input3)

empty_taxa <- taxa_names(data)[which(taxa_sums(data)==0)]
taxa_to_keep <- taxa_names(data)[which(taxa_sums(data)>0)]
hplot_input <- prune_taxa(taxa_to_keep, data)

if ( length(result_names)==2 || params$mod1 != "None"){

    subtitle <- result_names[2]
    if ( params$mod1!= "None" ){
    	#abundances_input <- prune_samples(get_variable(abundances_input, params$var) %in% c(params$mod1, params$mod2), abundances_input)
        subtitle <- paste(sep="", params$var, "_", params$mod1, "_vs_", params$mod2)
    }

    ##Heatmap plot with 2 conditions
	hplot <- plot_heatmap(hplot_input, 
						  taxa.label = NULL,
						  taxa.order = da.abundances_table$ID, low = "yellow", high = "red", na.value = "white") +
                scale_y_discrete(y_title) +  
				facet_grid(as.formula(paste("~", params$var)), scales = "free_x") + 
				ggtitle("Heatmap plot of DA asv or functions, between 2 conditions", subtitle = subtitle)
## Quantitative variable
} else {
    idx <- order(get_variable(abundances_input, params$var))
    my.sample.order <- sample_names(abundances_input)[idx]
    ##Heatmap plot with all conditions of variable
    hplot <- plot_heatmap(hplot_input, 
    					  taxa.label = NULL,
    	                  taxa.order = da.abundances_table$ID, sample.order = my.sample.order, 
    	                  low = "yellow", high = "red", na.value = "white") + 
             scale_y_discrete(y_title) +
             ggtitle(paste0("Heatmap plot of DA asv or functions with samples ordered according to ", params$var))
}
# ggplotly(hplot)
hplot
```
