```{r "{{funsys}}_plots_gsea", echo=FALSE, message=FALSE, warning=FALSE, results='asis'}

n_category <- 30
default_width <- set_default_width(enrich_obj = enrich_obj, showCategory=n_category)

	cat(paste("\n\n## **{{funsys}} - Gene Set Enrichment Analysis**\n",sep=""),
		"In this method, all the genes are sorted by their fold-change and the algorithm scan which genes with similar fold-change shares a term of the selected functional category.\n\n"
	)

	cat("\n\n**Dotplot**\n\n",
		"The plot shows the top functional terms in descendant order by gene ratio. This ratio is the proportion of the known genes for a given functional term that are identified in the expression data. The color represents the associated adjusted pvalue. 
		The X axis represents the gene ratio and the dot size the number of DEG genes associated to the functional term.\n\n"
	)
	go_pp <- enrichplot::dotplot(enrich_obj, showCategory=n_category)
	invisible(plot_in_div(go_pp, fig_width = default_width))

	cat("\n\n**Gene-Concept Network**\n\n", 
		"The network connects the top functional terms (brown nodes) to their associated genes (grey or colored nodes).
		The size of the functional terms shows the number of connected genes.\n\n"
	)
	# We must do it this way until we can figure out what's up with ridgePlot
	enrich_go_gsea_symb <- DOSE::setReadable(enrich_obj, OrgDb = current_organism_info$Bioconductor_DB[1], keyType="ENTREZID")

	if(length(get_genes(enrich_go_gsea_symb)) <= 200){
		go_pp <- enrichplot::cnetplot(enrich_go_gsea_symb, showCategory=n_category, foldChange=attr_vector) +
				   ggplot2::scale_color_gradient2(name = "fold change", low = "#0000BF", high = "#bf0000", na.value = "#50EA55")
		invisible(plot_in_div(go_pp, fig_width = default_width))
	}else{
		cat("\n\nCnetplot is not readable because more than 200 genes has been enriched in this nomenclature, so is not printed\n\n")
	}

	cat("\n\n**Enrich Map plot**\n\n", 
		"The network connects the top functional terms (nodes) between them trought their associates genes (grey edges, thickness represents the number of shared genes.).
		The size of the functional terms shows the number of connected genes and the color the adjusted pvalue of the functional term.\n\n"
	)
	if(nrow(as.data.frame(enrich_obj) > 1)) {

		go_pp <- enrichplot::emapplot(enrich_obj, showCategory=n_category)
		invisible(plot_in_div(go_pp, fig_width = default_width))
	} else {
		cat("\nThis graph can not be plotted because only one functional category was enriched\n")
	}
	cat("\n\n**Heatplot**\n\n", 
		"Top functional terms are show in the Y axis whereas in the X axis are show the associated genes to them. The coloured squares indicates the fold change value.\n\n"
	)
	go_pp <- enrichplot::heatplot(enrich_go_gsea_symb, showCategory=n_category, foldChange=attr_vector)
	width_size <- calc_width(enrich_go_gsea_symb)
	height_size <- calc_height(enrich_go_gsea_symb) 
	invisible(plot_in_div(go_pp, height_size, width_size))

	cat("\n\n**Ridgeplot**\n\n",
		"Top functional terms are show in the Y axis and for each one of them a fold-change distribution is shown.
		The distribution colours indicates the adjusted pvalue.\n\n"
	)
	go_pp <- enrichplot::ridgeplot(enrich_obj, showCategory=n_category)
	invisible(plot_in_div(go_pp, fig_width = default_width))

	cat("\n\n**Rank plot**\n\n", 
		"The enrichment score evolution trought the ranked genes by fold-change are show for the top functional terms. 
		Y axis shows the enrichment score and the X axis shows the genes ranked by fold-change.\n\n"
	)
	go_pp <- enrichplot::gseaplot2(enrich_obj, geneSetID=ifelse(nrow(enrich_obj@result) < 4, seq(nrow(enrich_obj@result)), seq(4)), pvalue_table = TRUE) 
	invisible(plot_in_div(go_pp, fig_width = default_width))
	cat("\n \n")
```
