<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">

<html>
<head>
<title>metaseqR report</title>
<meta http-equiv="Content-Type" content="text/html;">
<link type="text/css" rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<link type="text/css" rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables_themeroller.css">
<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/redmond/jquery-ui.min.css">
<link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/fancybox/2.1.5/helpers/jquery.fancybox-buttons.css">
<link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/fancybox/2.1.5/helpers/jquery.fancybox-thumbs.css">
<link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.css">
<link type="text/css" rel="stylesheet" href="media/styles.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.pack.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/fancybox/2.1.5/helpers/jquery.fancybox-buttons.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/fancybox/2.1.5/helpers/jquery.fancybox-media.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/fancybox/2.1.5/helpers/jquery.fancybox-thumbs.js"></script>
<script type="text/javascript">// <![CDATA[
    function preloader() {
        document.getElementById("loading").style.display="none";
        document.getElementById("report").style.display="block";
        //document.getElementById("contents").style.display="inline";
    }//preloader
    window.onload = preloader;
// ]]>
</script>
</head>
<body>
<table class="headContainer">
    <tr> 
        <td style="padding:0px; border-width:0px; width:20%;">
            <img src="media/logo.png" alt="logo here" height="100%">
        </td>
        <td style="padding:5px; border-width:0px; text-align:center; width:80%">
            <span class="pageTitle"><span style="font-size:1.4em; font-weight:bold">metaseqR analysis report</span></br></br><%=basename(PROJECT.PATH$main)%></span>
        </td>
    </tr>
    <tr> 
        <td colspan=2 style="height:5px; background-color:#0E38C4; padding:0px; border-width:0px;"></td>
    </tr>
</table>
<!--<table class="menuContainer">
    <tr>
        <td>
            <table class="menuContainer" style="width:100%">
                <tr>
                    <td class="menuCell"><a href="#summary">Summary</a></td>
                    <td class="menuCell"><a href="#figures">Figures</a></td>
                    <td class="menuCell"><a href="#results">Results</a></td>
                    <td class="menuCell"><a href="#references">References</a></td>
                </tr>
            </table>
        </td>
    </tr>
</table>-->
<table class="mainContainer">
    <tr>
        <td class="mainContainer" style="height:80%;">
            <table class="mainContainer">
                <tr>
                    <td class="leftContainer">
                        <!--We want the TOC here-->
                        <div id="contents">
                            <div><span class="title" style="font-size:1em;">Contents</span></div>
                            <div id="toc" style="float: left; width:160px; word-wrap: break-word;">
                                <%
                                cat("<h5>Summary</h5>")
                                cat("<div><ul class=\"tocul\">")
                                #cat("<ul class=\"tocul\"><li class=\"tocli\"><a href=\"#summary\">Summary</a><ul>")
                                cat("<li class=\"tocli\"><a href=\"#summary_summary\">Input options</a></li>")
                                cat("<li class=\"tocli\"><a href=\"#summary_input\">Input options</a></li>")
                                cat("<li class=\"tocli\"><a href=\"#summary_analysis_filtered\">Filtered genes</a></li>")
                                cat("<li class=\"tocli\"><a href=\"#summary_analysis_nde\">DE genes</a></li>")
                                if (run.log)
                                    cat("<li class=\"tocli\"><a href=\"#summary_analysis_log\">Run log</a></li>")
                                #cat("</ul></li></ul>")
                                cat("</ul></div>")
                                if (exists("fig.raw") || exists("fig.unorm") || exists("fig.norm") || exists("fig.other")) {
                                    cat("<h5>Figures</h5>")
                                    cat("<div><ul class=\"tocul\">")
                                    #cat("<ul class=\"tocul\">")
                                    cat("<li class=\"tocli\"><a href=\"#figures\">Figures</a><ul>")
                                    if (!is.null(fig.raw$mds))
                                        cat("<li class=\"tocli\"><a href=\"#figures_mds\">MDS</a></li>")
                                    if (!is.null(fig.raw$biodetection))
                                        cat("<li class=\"tocli\"><a href=\"#figures_biodetection\">Biotype detection</a></li>")
                                    if (!is.null(fig.raw$countsbio))
                                        cat("<li class=\"tocli\"><a href=\"#figures_countsbio\">Biotype counts</a></li>")
                                    if (!is.null(fig.raw$saturation))
                                        cat("<li class=\"tocli\"><a href=\"#figures_saturation\">Biotype saturation</a></li>")
                                    if (!is.null(fig.raw$readnoise))
                                        cat("<li class=\"tocli\"><a href=\"#figures_readnoise\">Reads noise</a></li>")
                                    if (!is.null(fig.raw$correl))
                                        cat("<li class=\"tocli\"><a href=\"#figures_correl\">Correlation plots</a></li>")
                                    if (!is.null(fig.raw$pairwise))
                                        cat("<li class=\"tocli\"><a href=\"#figures_pairwise\">Pairwise scatterplots</a></li>")
                                    if (!is.null(fig.raw$rnacomp))
                                        cat("<li class=\"tocli\"><a href=\"#figures_rnacomp\">RNA composition</a></li>")
                                    if (!is.null(fig.unorm$boxplot) || !is.null(fig.norm$boxplot))
                                        cat("<li class=\"tocli\"><a href=\"#figures_boxplot\">Boxplots</a></li>")
                                    if (!is.null(fig.unorm$gcbias) || !is.null(fig.norm$gcbias))
                                        cat("<li class=\"tocli\"><a href=\"#figures_gcbias\">GC-bias</a></li>")
                                    if (!is.null(fig.unorm$lengthbias) || !is.null(fig.norm$lengthbias))
                                        cat("<li class=\"tocli\"><a href=\"#figures_lengthbias\">Length bias</a></li>")
                                    if (!is.null(fig.unorm$meandiff) || !is.null(fig.norm$meandiff))
                                        cat("<li class=\"tocli\"><a href=\"#figures_meandiff\">Mean-difference</a></li>")
                                    if (!is.null(fig.unorm$meanvar) || !is.null(fig.norm$meanvar))
                                        cat("<li class=\"tocli\"><a href=\"#figures_meanvar\">Mean-variance</a></li>")
                                    if (!is.null(fig.other$filtered))
                                        cat("<li class=\"tocli\"><a href=\"#figures_filtered\">Filtered genes</a></li>")
                                    if (!is.null(fig.stat$volcano)) {
                                        cat("<li class=\"tocli\"><a href=\"#figures_filtered\">Volcano plots</a><ul>")
                                        nn <- names(fig.stat$volcano)
                                        counter <- 1
                                        for (n in nn) {
                                            cat("<li class=\"tocli\"><a href=\"#volcano_",counter,"\">",n,"</a></li>",sep="")
                                            counter <- counter + 1
                                        }
                                        cat("</ul></li>")
                                    }
                                    if (!is.null(fig.stat$deheatmap)) {
                                        cat("<li class=\"tocli\"><a href=\"#figures_heatmap\">DEG heatmaps</a><ul>")
                                        nn <- names(fig.stat$deheatmap)
                                        counter <- 1
                                        for (n in nn) {
                                            cat("<li class=\"tocli\"><a href=\"#deheatmap_",counter,"\">",n,"</a></li>",sep="")
                                            counter <- counter + 1
                                        }
                                        cat("</ul></li>")
                                    }
                                    if (!is.null(fig.stat$biodist)) {
                                        cat("<li class=\"tocli\"><a href=\"#figures_biodist\">DEG biotypes</a><ul>")
                                        nn <- names(fig.stat$biodist)
                                        counter <- 1
                                        for (n in nn) {
                                            if (fig.stat$biodist[[n]] != "error") {
                                                cat("<li class=\"tocli\"><a href=\"#biodist_",counter,"\">",n,"</a></li>",sep="")
                                                counter <- counter + 1
                                            }
                                        }
                                        cat("</ul></li>")
                                    }
                                    if (!is.null(fig.venn$venn)) {
                                        cat("<li class=\"tocli\"><a href=\"#figures_venn\">Venn diagrams</a><ul>")
                                        nn <- names(fig.venn$venn)
                                        counter <- 1
                                        for (n in nn) {
                                            cat("<li class=\"tocli\"><a href=\"#venn_",counter,"\">",n,"</a></li>",sep="")
                                            counter <- counter + 1
                                        }
                                        cat("</ul></li>")
                                    }
                                }
                                #cat("</ul></li></ul>")
                                cat("</ul></div>")
                                cat("<h5>Results</h5>")
                                cat("<div><ul class=\"tocul\">")
                                #cat("<ul class=\"tocul\"><li class=\"tocli\"><a href=\"#results\">Results</a><ul>")
                                nn <- names(html)
                                counter <- 1
                                for (n in nn) {
                                    cat("<li class=\"tocli\"><a href=\"#table_",counter,"\">",n,"</a></li>",sep="")
                                    counter <- counter + 1
                                }
                                #cat("</ul></li></ul>")
                                cat("</ul></div>")
                                cat("<h5>References</h5>")
                                cat("<div><ul class=\"tocul\">")                            
                                cat("<li class=\"tocli\"><a href=\"#references\">References</a></li>")
                                cat("</ul></div>")
                                %>
                            </div>
                        </div>
                    </td>
                    <td class="mainContainer">
                        <div id="loading" style="margin:auto; position:absolute; z-index:1000; width:350px; height:350px; background:url(media/loader.gif) no-repeat; cursor:wait;"></div>
                        <div id="report" style="display:none; width:75%;"> <!-- Start main accordion container -->
                            <h3 id="summary" class="title">Summary </h3>
                            <div id="summary_container"> <!-- Start summary container -->
                                <h4 id="summary_summary" class="subtitle">Analysis summary </h4>
                                <div id="summary_summary_container" style="text-align:justify;">
                                    <strong>Summary: </strong>
                                    <%
                                    if (from.raw) {
                                        cat("The raw ",file.type," files, one for each RNA-Seq sample, were summarized to ")
                                        if (count.type=="exon") cat("an exon ") else if (count.type=="gene") cat("a gene ")
                                        cat("read counts table, ")
                                        if (file.type=="bam" || file.type=="sam")
                                            cat("using the Bioconductor package GenomicRanges. ")
                                        else if (file.type=="bed")
                                            cat("using the Bioconductor packages rtracklayer and GenomicRanges. ")
                                        cat("In the final read counts table, each row represented ")
                                        if (count.type=="exon") cat("one exon, ") else if (count.type=="gene") cat("one gene, ")
                                        cat("each column one RNA-Seq sample and each cell, the corresponding read counts associated with each row and column.")
                                    }
                                    if (count.type=="exon") {
                                        if (!is.null(exon.filters)) {
                                            cat("The exon read counts were filtered for artifacts that could affect the subsequent normalization and statistical ")
                                            cat("testing procedures as follows: ")
                                            msg.exon.filters.min.active.exons <- NULL
                                            if (!is.null(exon.filters$min.active.exons)) {
                                                msg.exon.filters.min.active.exons <- paste(
                                                    "if an annotated gene had up to ",exon.filters$min.active.exons$exons.per.gene," exons, read presence was required in at ",
                                                    "least ",exon.filters$min.active.exons$min.exons," of the exons, else if an annotated gene had more than ",
                                                    exon.filters$min.active.exons$exons.per.gene," exons, then read presence was required in at least ",exon.filters$min.active.exons$frac,
                                                    "x&lceil;E&rceil; exons, where &lceil;<sup>.</sup>&rceil; is the <em>ceiling</em> mathematical function. The application ",
                                                    "of this filter resulted in the exclusion of ",length(exon.filter.result$min.active.exons)," genes from further analysis. ",
                                                    sep=""
                                                )
                                            }
                                            cat(msg.exon.filters.min.active.exons,sep=", ")
                                            cat("The total number of genes excluded due to the application of exon filters was ",sum(as.numeric(sapply(exon.filter.result,length))),". ",sep="")
                                        }
                                        cat("The final read counts for each gene model were calculated as the sums of their exon reads, creating a gene counts ")
                                        cat("table where each row corresponded to an Ensembl gene model and each column corresponded to an RNA-Seq sample. ")
                                    }
                                    cat("The gene counts table was normalized for inherent systematic or experimental biases (e.g. sequencing depth, gene length, ")
                                    cat("GC content bias etc.) using the Bioconductor package",report.messages$norm[[normalization]],"after removing genes that had ")
                                    cat("zero counts over all the RNA-Seq samples (",length(the.zeros)," genes). The output of the normalization algorithm ",sep="")
                                    cat("was a table with normalized counts, which can be used for differential expression analysis with statistical algorithms ")
                                    cat("developed specifically for count data. ")
                                    if (!is.null(gene.filters)) {
                                        cat("Prior to the statistical testing procedure, the gene read counts were filtered for possible artifacts that could affect ")
                                        cat("the subsequent statistical testing procedures. Genes presenting any of the following were excluded from further analysis: ")
                                        latin.numbered <- c("i)","ii)","iii)","iv)","v)","vi)","vii)","viii)","ix)","x)","xi)","xii)","xiii)","xiv)","xv)")
                                        counter <- 0
                                        msg.gene.filters.length <- msg.gene.filters.expression.median <- msg.gene.filters.expression.mean <-
                                        msg.gene.filters.expression.quantile <- msg.gene.filters.expression.known <- msg.gene.filters.expression.custom <-
                                        msg.gene.filters.biotype <- msg.gene.filters.avg.reads <- NULL
                                        if (!is.null(gene.filters$length)) {
                                            counter <- counter + 1
                                            msg.gene.filters.length <- paste(
                                                latin.numbered[counter]," genes with length less than ",gene.filters$length$length," (",length(gene.filter.result$length),
                                                " genes)",sep=""
                                            )
                                        }
                                        if (!is.null(gene.filters$avg.reads)) {
                                            counter <- counter + 1
                                            msg.gene.filters.avg.reads <- paste(
                                                latin.numbered[counter]," genes whose average reads per ",gene.filters$avg.reads$average.per.bp," bp was less than the ",
                                                100*gene.filters$avg.reads$quantile,"<sup>th</sup> quantile of the total normalized distribution of average reads per ",
                                                gene.filters$avg.reads$average.per.bp,"bp (",length(gene.filter.result$average.per.bp)," genes with cutoff value ",
                                                round(gene.filter.cutoff$avg.reads,digits=5)," average reads per ",gene.filters$avg.reads$average.per.bp," bp)",sep=""
                                            )
                                        }
                                        if (!is.null(gene.filters$expression)) {
                                            if (!is.null(gene.filters$expression$median) && gene.filters$expression$median) {
                                                counter <- counter + 1
                                                msg.gene.filters.expression.median <- paste(
                                                    latin.numbered[counter]," genes with read counts below the median read counts of the total normalized count distribution ",
                                                    "(",length(gene.filter.result$expression$median)," genes with cutoff value ",gene.filter.cutoff$expression$median,
                                                    " normalized read counts)",sep=""
                                                )
                                            }
                                            if (!is.null(gene.filters$expression$mean) && gene.filters$expression$mean) {
                                                counter <- counter + 1
                                                msg.gene.filters.expression.mean <- paste(
                                                    latin.numbered[counter]," genes with read counts below the mean read counts of the total normalized counts distribution ",
                                                    "(",length(gene.filter.result$expression$mean)," genes with cutoff value ",gene.filter.cutoff$expression$mean,
                                                    " normalized read counts)",sep=""
                                                )
                                            }
                                            if (!is.null(gene.filters$expression$quantile) && !is.na(gene.filters$expression$quantile)) {
                                                counter <- counter + 1
                                                msg.gene.filters.expression.quantile <- paste(
                                                    latin.numbered[counter]," genes with read counts below the ",100*gene.filters$expression$quantile,"<sup>th</sup> ",
                                                    "quantile of the normalized counts distribution (",length(gene.filter.result$expression$quantile)," genes with cutoff value ",
                                                    gene.filter.cutoff$expression$quantile," normalized read counts)",sep=""
                                                )
                                            }
                                            if (!is.null(gene.filters$expression$known) && !is.na(gene.filters$expression$known)) {
                                                counter <- counter + 1
                                                msg.gene.filters.expression.known <- paste(
                                                    latin.numbered[counter]," genes with read counts below the 90<sup>th</sup> quantile of the counts of the following ",
                                                    "genes, known to not being expressed from the related literature: ",paste(gene.filters$expression$known,collapse=", "),
                                                    "(",length(gene.filter.result$expression$known)," genes with cutoff value",gene.filter.cutoff$expression$known,
                                                    " normalized read counts)",sep=""
                                                )
                                            }
                                            if (!is.null(gene.filters$expression$custom) && !is.na(gene.filters$expression$custom)) {
                                                counter <- counter + 1
                                                msg.gene.filters.expression.custom <- paste(
                                                    latin.numbered[counter]," genes not passing the user defined filter provided to the metaseqr pipeline ",
                                                    "(",length(gene.filter.result$expression$custom)," genes with cutoff value",gene.filter.cutoff$expression$custom,
                                                    ")",sep=""
                                                )
                                            }
                                        }
                                        if (!is.null(gene.filters$biotype)) {
                                            counter <- counter + 1
                                            msg.gene.filters.biotype <- paste(
                                                latin.numbered[counter]," genes whose biotype matched the following: ",
                                                paste(names(gene.filters$biotype)[which(unlist(gene.filters$biotype))],collapse=", "),
                                                " (",length(gene.filter.result$biotype)," genes)",sep=""
                                            )
                                        }
                                        cat(msg.gene.filters.length,msg.gene.filters.avg.reads,msg.gene.filters.expression.median,msg.gene.filters.expression.mean,
                                            msg.gene.filters.expression.quantile,msg.gene.filters.expression.known,msg.gene.filters.expression.custom,sep=", ")
                                        cat(". The total number of genes excluded due to the application of gene filters was ",sum(as.numeric(sapply(gene.filter.result,length))),". ",sep="")
                                        cat("The total (unified) number of genes excluded due to the application of all filters was ",length(the.zeros) + length(the.dead),". ",sep="")
                                    }
                                    cat("The resulting gene counts table was subjected to differential expression analysis for the contrasts ",
                                        paste(gsub("_vs_"," versus ",contrast),collapse=", "),sep="")
                                    if (length(statistics)>1) {
                                        cat(" using the Bioconductor packages ",paste(unlist(report.messages$stat[statistics],use.names=FALSE),collapse=", "),". ",sep="")
                                        if (meta.p!="none") {
                                            cat("In order to combine the statistical significance from multiple algorithms and perform meta-analysis, the ")
                                            cat(report.messages$meta[[meta.p]],"method was applied. ")
                                        }
                                    } else {
                                        cat(" using the Bioconductor package ",report.messages$stat[[statistics]],". ",sep="")
                                    }
                                    if (!is.na(pcut))
                                        if (pcut==1) plasm <- 0.05 else plasm <- pcut
                                    cat("The final numbers of differentially expressed genes were (per contrast): ")
                                    msg.contrast <- character(length(contrast))
                                    names(msg.contrast) <- contrast
                                    for (cnt in contrast) {
                                        if (!is.na(pcut) && length(which(sum.p.list[[cnt]]<plasm))==0) {
                                            msg.contrast[cnt] <- paste("for the contrast ",gsub("_vs_"," versus ",cnt),", no differentially expressed genes were found",
                                                " with a p-value threshold of ",plasm,sep="")
                                        } else if (is.na(pcut)) {
                                            msg.contrast[cnt] <- paste("for the contrast ",gsub("_vs_"," versus ",cnt),", no statistical threshold defined",sep="")
                                        } else {
                                            if (adjust.method!="none") {
                                                add.text.p <- paste(" (",length(which(p.adjust(sum.p.list[[cnt]],adjust.method)<plasm)),")",sep="")
                                                has.fdr.text <- " (FDR or adjusted p-value)"
                                            }
                                            else
                                                add.text.p <- has.fdr.text <- NULL
                                            if (length(strsplit(cnt,"_vs_")[[1]])==2) {
                                                tmp <- log2(make.fold.change(cnt,sample.list,norm.genes.expr[which(sum.p.list[[cnt]]<plasm),],log.offset))
                                                if (adjust.method!="none") {
                                                    are.there <- which(p.adjust(sum.p.list[[cnt]],adjust.method)<plasm)
                                                    if (length(are.there)>0) {
                                                        if (length(are.there)==1) {
                                                            tmp.f <- log2(make.fold.change(cnt,sample.list,norm.genes.expr[are.there,,drop=FALSE],log.offset))
                                                            add.text.fu <- paste(" (",length(which(tmp.f>=1)),")",sep="")
                                                            add.text.fd <- paste(" (",length(which(tmp.f<=-1)),")",sep="")
                                                            add.text.fn <- paste(" (",length(which(abs(tmp.f)<1)),")",sep="")
                                                        }
                                                        else {
                                                            tmp.f <- log2(make.fold.change(cnt,sample.list,norm.genes.expr[are.there,],log.offset))
                                                            add.text.fu <- paste(" (",length(which(tmp.f>=1)),")",sep="")
                                                            add.text.fd <- paste(" (",length(which(tmp.f<=-1)),")",sep="")
                                                            add.text.fn <- paste(" (",length(which(abs(tmp.f)<1)),")",sep="")
                                                        }
                                                    }
                                                    else
                                                        add.text.fu <- add.text.fd <- add.text.fn <- NULL
                                                }
                                                else
                                                    add.text.fu <- add.text.fd <- add.text.fn <- NULL
                                                msg.contrast[cnt] <- paste("for the contrast ",gsub("_vs_"," versus ",cnt),", ",length(which(sum.p.list[[cnt]]<plasm)),add.text.p,
                                                " statistically significant genes were found with a p-value",has.fdr.text," threshold of ",plasm," and of these, ",length(which(tmp>=1)),
                                                add.text.fu," were up-regulated, ",length(which(tmp<=-1)),add.text.fd," were down-regulated and ",length(which(abs(tmp)<1)),add.text.fn,
                                                " were not differentially expressed according to an absolute fold change cutoff value of 1 in log<sub>2</sub> scale",sep="")
                                            }
                                            else
                                                msg.contrast[cnt] <- paste("for the contrast ",gsub("_vs_"," versus ",cnt),", ",length(which(sum.p.list[[cnt]]<plasm)),add.text.p,
                                                " differentially expressed genes were found with a p-value",has.fdr.text," threshold of ",plasm," at least in one condition",sep="")
                                        }
                                    }
                                    cat(paste(msg.contrast,collapse=", "))
                                    cat(". Literature references for all the algorithms used can be found at the end of this report.")
                                    %>
                                </div>
                                <h4 id="summary_input" class="subtitle">Input options </h4>
                                <div id="summary_input_container">
                                    <strong>Read counts file:</strong> <%=counts.name%></br>
                                    <strong>Conditions:</strong> <%=paste(names(sample.list),collapse=", ")%></br>
                                    <strong>Samples included:</strong> <%=paste(unlist(sample.list),collapse=", ")%></br>
                                    <strong>Samples excluded:</strong> 
                                    <%=
                                    if (!is.null(exclude.list) && !is.na(exclude.list))
                                        cat(paste(unlist(exclude.list),collapse=", "))
                                    else
                                        cat("none")
                                    %></br>
                                    <strong>Requested contrasts:</strong> <%=paste(contrast,collapse=", ")%></br>
                                    <strong>Library sizes:</strong>
                                    <%=
                                    if (!is.null(libsize.list)) {
                                        cat("<ul>")
                                        for (n in names(libsize.list)) cat("<li>",paste(n,libsize.list[[n]],sep=": "),"</li>")
                                        cat("</ul>")
                                    } else cat("not available","</br>")
                                    %>
                                    <strong>Annotation:</strong> <%=annotation%></br>
                                    <strong>Organism:</strong> <%=report.messages$org[[org]]%></br>
                                    <strong>Annotation source:</strong> <%=report.messages$refdb[[refdb]]%></br>
                                    <strong>Count type:</strong> <%=count.type%></br>
                                    <strong>Exon filters:</strong>
                                    <%=
                                    if (!is.null(exon.filters)) {
                                        cat(paste(names(exon.filters),collapse=", "),"</br>")
                                        for (ef in names(exon.filters)) {
                                            cat("<ul>")
                                            cat("<li><em><span style=\"font-size:1em\">",ef,"</span></em><ul>",sep="")
                                            for (efp in names(exon.filters[[ef]])) {
                                                if (length(exon.filters[[ef]][[efp]])==1 && is.function(exon.filters[[ef]][[efp]]))
                                                    cat("<li>custom function</li>")
                                                else if (length(exon.filters[[ef]][[efp]])==1)
                                                    cat("<li>",paste(efp,exon.filters[[ef]][[efp]],sep=": "),"</li>",sep="")
                                                else if (length(exon.filters[[ef]][[efp]])>1)
                                                    cat("<li>",paste(efp,paste(exon.filters[[ef]][[efp]],collapse=", "),sep=": "),"</li>",sep="")
                                            }
                                            cat("</ul></li>")
                                            cat("</ul>")
                                        }
                                    } else cat("none applied","</br>")
                                    %>
                                    <%=
                                    if (!is.null(preset))
                                        cat("<strong>Analysis preset:</strong>",report.messages$preset[[preset]],"</br>")
                                    %>
                                    <strong>Gene filters:</strong>
                                    <%=
                                    if (!is.null(gene.filters)) {
                                        cat(paste(names(gene.filters),collapse=", "),"</br>")
                                        for (gf in names(gene.filters)) {
                                            cat("<ul>")
                                            cat("<li><em><span style=\"font-size:1em\">",gf,"</span></em><ul>",sep="")
                                            for (gfp in names(gene.filters[[gf]])) {
                                                if (length(gene.filters[[gf]][[gfp]])==1 && is.function(gene.filters[[gf]][[gfp]]))
                                                    cat("<li>custom function</li>")
                                                else if (length(gene.filters[[gf]][[gfp]])==1)
                                                    cat("<li>",paste(gfp,gene.filters[[gf]][[gfp]],sep=": "),"</li>",sep="")
                                                else if (length(gene.filters[[gf]][[gfp]])>1)
                                                    cat("<li>",paste(gfp,paste(gene.filters[[gf]][[gfp]],collapse=", "),sep=": "),"</li>",sep="")
                                            }
                                            cat("</ul></li>")
                                            cat("</ul>")
                                        }
                                    } else cat("none applied","</br>")
                                    %>
                                    <strong>Filter application:</strong> <%=report.messages$whenfilter[[when.apply.filter]]%></br>
                                    <strong>Normalization algorithm:</strong> <%=report.messages$norm[[normalization]]%></br>
                                    <strong>Normalization arguments:</strong>
                                    <%=
                                    if (!is.null(norm.args)) {
                                        if (normalization=="each") {
                                            for (n in names(norm.args)) {
                                                cat("<strong>Statistical arguments for</strong> ",report.messages$norm[[n]],": ",paste(names(norm.args[[n]]),collapse=", "))
                                                if (length(norm.args[[n]])>0) {
                                                    cat("<ul>")
                                                    for (na in names(norm.args[[n]])) {
                                                        if (length(norm.args[[n]][[na]])==1 && is.function(norm.args[[n]][[na]]))
                                                            cat("<li>",na,": ",as.character(substitute(norm.args[[na]])),"</li>",sep="")
                                                        else if (length(norm.args[[n]][[na]])==1)
                                                            cat("<li>",paste(na,norm.args[[n]][[na]],sep=": "),"</li>")
                                                        else if (length(norm.args[[n]][[na]])>1)
                                                            cat("<li>",paste(na,paste(norm.args[[n]][[na]],collapse=", "),sep=": "),"</li>")
                                                        }
                                                        cat("</ul>")
                                                    }
                                                else cat("not available or not required</br>")
                                            }
                                        }
                                        else {
                                            cat(paste(names(norm.args),collapse=", "),"</br>")
                                            cat("<ul>")
                                            for (na in names(norm.args)) {
                                                if (length(norm.args[[na]])==1 && is.function(norm.args[[na]]))
                                                    cat("<li>",as.character(substitute(norm.args[[na]])),"</li>",sep="")
                                                else if (length(norm.args[[na]])==1)
                                                    cat("<li>",paste(na,norm.args[[na]],sep=": "),"</li>")
                                                else if (length(norm.args[[na]])>1)
                                                    cat("<li>",paste(na,paste(norm.args[[na]],collapse=", "),sep=": "),"</li>")
                                            }
                                            cat("</ul>")
                                        }
                                    } else cat("not available")
                                    %>
                                    <strong>Statistical algorithm(s): </strong> <%=paste(unlist(report.messages$stat[statistics],use.names=FALSE),collapse=", ")%></br>
                                    <%=
                                    if (!is.null(stat.args)) {
                                        for (s in names(stat.args)) {
                                            cat("<strong>Statistical arguments for ",report.messages$stat[[s]],": </strong>",paste(names(stat.args[[s]]),collapse=", "),sep="")
                                            if (length(stat.args[[s]])>0) {
                                                cat("<ul>")
                                                for (sa in names(stat.args[[s]])) {
                                                    if (length(stat.args[[s]][[sa]])==1 && is.function(stat.args[[s]][[sa]]))
                                                        cat("<li>",sa,": ",as.character(substitute(stat.args[[na]])),"</li>",sep="")
                                                    else if (length(stat.args[[s]][[sa]])==1)
                                                        cat("<li>",paste(sa,stat.args[[s]][[sa]],sep=": "),"</li>")
                                                    else if (length(stat.args[[s]][[sa]])>1)
                                                        cat("<li>",paste(sa,paste(stat.args[[s]][[sa]],collapse=", "),sep=": "),"</li>")
                                                    }
                                                    cat("</ul>")
                                                }
                                            else cat("not available or not required</br>")
                                        }
                                    } else cat("<strong>Statistical arguments not available</strong>")
                                    %>
                                    <strong>Meta-analysis method:</strong> <%=report.messages$meta[[meta.p]]%></br>
                                    <strong>Multiple testing correction: </strong> <%=report.messages$adjust[[tolower(adjust.method)]]%></br>
                                    <strong>p-value threshold: </strong> <%=if (!is.na(pcut)) cat(pcut) else cat("not available")%></br>
                                    <strong>Logarithmic tranformation offset: </strong> <%=log.offset%></br>
                                    <strong>Analysis preset: </strong> <%=if (!is.null(preset)) cat(preset) else ("not available")%></br>
                                    <strong>Quality control plots: </strong><%=paste(unlist(report.messages$plots[qc.plots],use.names=FALSE),collapse=", ")%></br>
                                    <strong>Figure format: </strong> <%=paste(fig.format,collapse=", ")%></br>
                                    <strong>Output directory: </strong> <%=if (!is.na(export.where)) cat(export.where) else cat("default")%></br>
                                    <strong>Output data: </strong> <%=paste(unlist(report.messages$export[export.what],use.names=FALSE),collapse=", ")%></br>
                                    <strong>Output scale(s): </strong> <%=paste(unlist(report.messages$export[export.scale],use.names=FALSE),collapse=", ")%></br>
                                    <strong>Output values: </strong> <%=paste(unlist(report.messages$export[export.values],use.names=FALSE),collapse=", ")%></br>
                                    <strong>Output statistics: </strong><%=paste(unlist(report.messages$export[export.stats],use.names=FALSE),collapse=", ")%></br>
                                    <strong>Total run time: </strong><%=exec.time%></br>
                                </div>
                                <h4 id="summary_analysis_filtered" class="subtitle">Filtered genes </h4>
                                <div id="summary_filtered_container">
                                    <strong>Number of filtered genes: </strong><%=length(the.zeros) + length(the.dead)%><em> which is the <strong>union</strong> of</em>
                                    <ul>
                                        <li>Filtered because of zero reads: <%=length(the.zeros)%></li>
                                        <li>
                                            Filtered because of exon filters: <%=sum(as.numeric(sapply(exon.filter.result,length)))%>
                                            <%=
                                                if (sum(as.numeric(sapply(exon.filter.result,length)))!=0) {
                                                    cat("<em> which is the <strong>union</strong> of</em>")
                                                    cat("<ul>")
                                                    for (n in names(exon.filter.result)) {
                                                        cat("<li>",n,": ",length(exon.filter.result[[n]]),"</li>")
                                                    }
                                                    cat("</ul>")
                                                }
                                            %>
                                        </li>
                                        <li>
                                            Filtered because of gene filters: <%=length(unique(unlist(gene.filter.result)))%>
                                            <em> which is the <strong>union</strong> of</em>
                                            <ul>
                                                <%=
                                                for (n in names(gene.filter.result)) {
                                                    if (!is.list(gene.filter.result[[n]])) {
                                                        if (!is.null(gene.filter.result[[n]]))
                                                            cat("<li>",n,": ",length(unlist(gene.filter.result[[n]])),
                                                                " genes with filter cutoff value ",gene.filter.cutoff[[n]],"</li>",sep="")
                                                    }
                                                    else {
                                                        cat("<li>",n,": ",length(unlist(gene.filter.result[[n]])),
                                                            " genes further decomposed to (filter name, filtered genes, filter cutoff):</li>",sep="")
                                                        cat("<li><ul>")
                                                        for (nn in names(gene.filter.result[[n]])) {
                                                            if (!is.null(gene.filter.result[[n]][[nn]]))
                                                                cat("<li>",nn,": ",length(unlist(gene.filter.result[[n]][[nn]])),
                                                                " genes with filter cutoff value ",paste(gene.filter.cutoff[[n]][[nn]],
                                                                collapse=", "),"</li>",sep="")
                                                        }
                                                        cat("</ul></li>")
                                                    }
                                                }
                                                %>
                                            </ul>
                                        </li>
                                    </ul>
                                </div>
                                <h4 id="summary_analysis_nde" class="subtitle">Differentially expressed genes</h4>
                                <div id="summary_nde_container">
                                    <strong>Number of differentially expressed genes per contrast: </strong>
                                    <%
                                    if (!is.na(pcut) && pcut==1)
                                        cat("The p-value cutoff during the analysis was set to 1 so as to retrieve the total gene list which passed the ",
                                            "filtering procedure. Each gene in the list is accompanied by its statistical scores (p-value, FDR, etc.)</br>")
                                    %>
                                    <ul>
                                        <%
                                        for (cnt in contrast) {
                                            cat("<li><strong>",cnt,": </strong>",sep="")
                                            if (!is.na(pcut) && length(which(sum.p.list[[cnt]]<pcut))==0)
                                                cat("no differentially expressed genes","</li>")
                                            else if (is.na(pcut))
                                                cat("no statistical threshold defined","</li>")
                                            else {
                                                if (!is.na(pcut) && pcut==1)
                                                    plasm <- 0.05
                                                else
                                                    plasm <- pcut
                                                if (adjust.method!="none") {
                                                    add.text.p <- paste("(",length(which(p.adjust(sum.p.list[[cnt]],adjust.method)<plasm)),")",sep="")
                                                    has.fdr.text <- "(FDR or adjusted p-value)"
                                                }
                                                else
                                                    add.text.p <- has.fdr.text <- NULL
                                                if (length(strsplit(cnt,"_vs_")[[1]])==2) {
                                                    tmp.p <- log2(make.fold.change(cnt,sample.list,norm.genes.expr[which(sum.p.list[[cnt]]<plasm),],log.offset))
                                                    if (adjust.method!="none") {
                                                        are.there <- which(p.adjust(sum.p.list[[cnt]],adjust.method)<plasm)
                                                        if (length(are.there)>0) {
                                                            if (length(are.there)==1) {
                                                                tmp.f <- log2(make.fold.change(cnt,sample.list,norm.genes.expr[are.there,,drop=FALSE],log.offset))
                                                                add.text.fu <- paste(" (",length(which(tmp.f>=1)),")",sep="")
                                                                add.text.fd <- paste(" (",length(which(tmp.f<=-1)),")",sep="")
                                                                add.text.fn <- paste(" (",length(which(abs(tmp.f)<1)),")",sep="")
                                                            }
                                                            else {
                                                                tmp.f <- log2(make.fold.change(cnt,sample.list,norm.genes.expr[are.there,],log.offset))
                                                                add.text.fu <- paste(" (",length(which(tmp.f>=1)),")",sep="")
                                                                add.text.fd <- paste(" (",length(which(tmp.f<=-1)),")",sep="")
                                                                add.text.fn <- paste(" (",length(which(abs(tmp.f)<1)),")",sep="")
                                                            }
                                                        }
                                                        else
                                                            add.text.fu <- add.text.fd <- add.text.fn <- NULL
                                                    }
                                                    else
                                                        add.text.fu <- add.text.fd <- add.text.fn <- NULL
                                                    cat(length(which(sum.p.list[[cnt]]<plasm)),add.text.p,"statistically significant genes of which",length(which(tmp.p>=1)),
                                                        add.text.fu,"up regulated,",length(which(tmp.p<=-1)),add.text.fd,"down regulated and",length(which(abs(tmp.p)<1)),
                                                        add.text.fn,"not differentially expressed according to a p-value",has.fdr.text,"threshold of",plasm,"and an absolute",
                                                        "fold change cutoff value of 1 in log<sub>2</sub> scale.")
                                                }
                                                else
                                                    cat(length(which(sum.p.list[[cnt]]<plasm))," ",add.text.p," statistically significant, differentially expressed in at",
                                                    " least one condition at a p-value ",has.fdr.text," threshold of ",plasm,".",sep="")
                                                if (length(statistics)>1 && meta.p!="none") {
                                                    cat(" These numbers refer to the combined analysis performed by metaseqR. Per statistical algorithm, the differentially expressed genes are:")
                                                    cat("<ul>")
                                                    for (s in statistics) {
                                                        cat("<li><em>",report.messages$stat[[s]],": </em>",sep="")
                                                        if (adjust.method!="none") {
                                                            add.text.p <- paste("(",length(which(p.adjust(cp.list[[cnt]][,s],adjust.method)<plasm)),")",sep="")
                                                            has.fdr.text <- "(FDR or adjusted p-value)"
                                                        }
                                                        else
                                                            add.text.p <- has.fdr.text <- NULL
                                                        if (length(strsplit(cnt,"_vs_")[[1]])==2) {
                                                            tmp.p <- log2(make.fold.change(cnt,sample.list,norm.genes.expr[which(cp.list[[cnt]][,s]<plasm),],log.offset))
                                                            if (adjust.method!="none") {
                                                                tmp.f <- log2(make.fold.change(cnt,sample.list,norm.genes.expr[which(p.adjust(cp.list[[cnt]][,s],adjust.method)<plasm),],log.offset))
                                                                add.text.fu <- paste("(",length(which(tmp.f>=1)),")",sep="")
                                                                add.text.fd <- paste("(",length(which(tmp.f<=-1)),")",sep="")
                                                                add.text.fn <- paste("(",length(which(abs(tmp.f)<1)),")",sep="")
                                                            }
                                                            else
                                                                add.text.fu <- add.text.fd <- add.text.fn <- NULL
                                                            cat(length(which(cp.list[[cnt]][,s]<plasm)),add.text.p,"statistically significant genes of which",length(which(tmp.p>=1)),
                                                                add.text.fu,"up regulated,",length(which(tmp.p<=-1)),add.text.fd,"down regulated and",length(which(abs(tmp.p)<1)),
                                                                add.text.fn,"not differentially expressed according to a p-value",has.fdr.text,"threshold of",plasm,"and an absolute",
                                                                "fold change cutoff value of 1 in log<sub>2</sub> scale.")
                                                        }
                                                        else
                                                            cat(length(which(cp.list[[cnt]][,s]<plasm))," ",add.text.p," statistically significant, differentially expressed in at",
                                                            " least one condition at a p-value ",has.fdr.text," threshold of ",plasm,".",sep="")
                                                        cat("</li>")
                                                    }
                                                    cat("</ul>")
                                                }
                                            }
                                        }
                                        %>
                                    </ul>
                                </div>
                                <%
                                if (run.log) {
                                    cat("<h4 id=\"summary_analysis_log\" class=\"subtitle\">Run log</h4>")
                                    cat("<div id=\"summary_log_container\">")
                                    log.string <- paste(readLines(file.path(PROJECT.PATH$logs,"metaseqr_run.log")),collapse="---EOL---")
                                    cat(gsub("---EOL---","</br>",log.string))
                                    cat("</div>")
                                }
                                %>
                            </div> <!-- End summary container -->
                            <h3 id="figures" class="title">Figures </h3>
                            <div id="figures_container">  <!-- Start figures container -->                              
                                <%
                                if (!is.null(fig.raw$mds)) {
                                    cat("<h4 class=\"subtitle\">Multidimensional scaling</h4>")
                                    cat("<div id=\"figures_mds\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$mds,"</br></br></div>",sep="")
                                    cat("<div class=\"imageContainerRect\">")
                                    cat("<a class=\"fancybox\" href=\"",gsub(PROJECT.PATH$main,".",fig.raw$mds),"\" title=\"MDS\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.raw$mds),"\" alt=\"MDS\">",sep="")
                                    cat("</a></div></div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.raw$biodetection)) {
                                    cat("<h4 class=\"subtitle\">Biotype detection</h4>")
                                    cat("<div id=\"figures_biodetection\"> ")
                                    cat("<div class=\"figureHint\">",report.messages$explain$biodetection,"</br></br></div>",sep="")
                                    for (s in gsub(PROJECT.PATH$main,".",fig.raw$biodetection)) {
                                        cat("<div class=\"imageContainerRect\">")
                                        cat("<a class=\"fancybox\" rel=\"biodetection\" href=\"",s,"\" title=\"Biotype detection\">",sep="")
                                        cat("<img src=\"",s,"\" alt=\"biotype detection\">",sep="")
                                        cat("</a></div>")
                                    }
                                    cat("</div>")
                                }
                                %>                              
                                <%
                                if (!is.null(fig.raw$countsbio)) {
                                    cat("<h4 class=\"subtitle\">Biotype detection counts</h4>")
                                    cat("<div id=\"figures_countsbio\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$countsbio,"</br></br></div>",sep="")
                                    for (s in gsub(PROJECT.PATH$main,".",fig.raw$countsbio)) {
                                        cat("<div class=\"imageContainerRect\">")
                                        cat("<a class=\"fancybox\" rel=\"countsbio\" href=\"",s,"\" title=\"Biotype detection counts\">",sep="")
                                        cat("<img src=\"",s,"\" alt=\"biotype detection counts\">",sep="")
                                        cat("</a></div>")
                                    }
                                    cat("</div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.raw$saturation)) {
                                    cat("<h4 class=\"subtitle\">Read and biotype saturation</h4>")
                                    cat("<div id=\"figures_saturation\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$saturation,"</br></br></div>",sep="")
                                    cat("<div class=\"figCaption\">Read saturation per biotype for all samples</div></br>",sep="")
                                    cat("<div class=\"imageContainerSq\" style=\"width: 680px; height: 680px;\">",sep="")
                                    cat("<a class=\"fancybox\" href=\"",gsub(PROJECT.PATH$main,".",fig.raw$saturation$biotype),"\" title=\"Biotype saturation per sample\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.raw$saturation$biotype),"\" alt=\"sample biotype saturation\">",sep="")
                                    cat("</a></div>")
                                    cat("<div class=\"figCaption\">Read saturation per sample for all biotypes </div></br>",sep="")
                                    for (s in gsub(PROJECT.PATH$main,".",fig.raw$saturation$sample)) {
                                        cat("<div class=\"imageContainerRect\">")
                                        cat("<a class=\"fancybox\" rel=\"saturation_sample\" href=\"",s,"\" title=\"Biotype saturation per sample\">",sep="")
                                        cat("<img src=\"",s,"\" alt=\"sample biotype saturation\">",sep="")
                                        cat("</a></div>")
                                    }
                                    cat("</div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.raw$readnoise)) {
                                    cat("<h4 class=\"subtitle\">RNA-Seq reads noise </h4>")
                                    cat("<div id=\"figures_readnoise\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$readnoise,"</br></br></div>",sep="")
                                    cat("<div class=\"imageContainerSq\" style=\"width:50%; height:50%;\">")
                                    cat("<a class=\"fancybox\" href=\"",gsub(PROJECT.PATH$main,".",fig.raw$readnoise),"\" title=\"Read noise\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.raw$readnoise),"\" alt=\"Read noise\">",sep="")
                                    cat("</a></div></div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.raw$correl)) {
                                    cat("<h4 class=\"subtitle\">Correlation plots</h4>")
                                    cat("<div id=\"figures_correl\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$correl,"</br></br></div>",sep="")
                                    cat("<table class=\"innerTable\"><tr>")
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">Correlation heatmap </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"correl\" href=\"",gsub(PROJECT.PATH$main,".",fig.raw$correl$heatmap),"\" title=\"Correlation heatmap\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.raw$correl$heatmap),"\" alt=\"Correlation heatmap\">",sep="")
                                    cat("</a></div></td>")
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">Data correlogram </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"correl\" href=\"",gsub(PROJECT.PATH$main,".",fig.raw$correl$correlogram),"\" title=\"Correlogram\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.raw$correl$correlogram),"\" alt=\"Correlogram\"></td>",sep="")
                                    cat("</a></div></td>")
                                    cat("</tr></table></div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.raw$pairwise)) {
                                    cat("<h4 class=\"subtitle\">Pairwise scatterplots</h4>")
                                    cat("<div id=\"figures_pairwise\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$pairwise,"</br></br></div>",sep="")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" href=\"",gsub(PROJECT.PATH$main,".",fig.raw$pairwise),"\" title=\"Pairwise sample scatterplots\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.raw$pairwise),"\" alt=\"Pairwise scatterplots\">",sep="")
                                    cat("</a></div></div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.unorm$boxplot) || !is.null(fig.norm$boxplot)) {
                                    cat("<h4 class=\"subtitle\">Boxplots</h4>")
                                    cat("<div id=\"figures_boxplot\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$boxplot,"</br></br></div>",sep="")
                                    cat("<table class=\"innerTable\"><tr>")
                                }
                                if (!is.null(fig.unorm$boxplot)) {
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">Boxplot of un-normalized data </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"boxplot\" href=\"",gsub(PROJECT.PATH$main,".",fig.unorm$boxplot),"\" title=\"Un-normalized boxplot\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.unorm$boxplot),"\" alt=\"Un-normalized boxplot\">",sep="")
                                    cat("</a></div></td>")
                                }
                                if (!is.null(fig.unorm$boxplot)) {
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">Boxplot of normalized data </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"boxplot\" href=\"",gsub(PROJECT.PATH$main,".",fig.norm$boxplot),"\" title=\"Normalized boxplot\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.norm$boxplot),"\" alt=\"Normalized boxplot\">",sep="")
                                    cat("</a></div></td>")
                                }
                                if (!is.null(fig.unorm$boxplot) || !is.null(fig.norm$boxplot))
                                    cat("</tr></table></div>")
                                %>
                                <%
                                if (!is.null(fig.unorm$rnacomp) || !is.null(fig.norm$rnacomp)) {
                                    cat("<h4 class=\"subtitle\">RNA composition</h4>")
                                    cat("<div id=\"figures_rnacomp\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$rnacomp,"</br></br></div>",sep="")
                                    cat("<table class=\"innerTable\"><tr>")
                                }
                                if (!is.null(fig.unorm$rnacomp)) {
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">RNA composition of un-normalized data </div></br>",sep="")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"rnacomp\" href=\"",gsub(PROJECT.PATH$main,".",fig.unorm$rnacomp),"\" title=\"Un-normalized RNA composition\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.unorm$rnacomp),"\" alt=\"Un-normalized rnacomp\">",sep="")
                                    cat("</a></div></td>")
                                }
                                if (!is.null(fig.unorm$rnacomp)) {
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">RNA composition of normalized data </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"rnacomp\" href=\"",gsub(PROJECT.PATH$main,".",fig.norm$rnacomp),"\" title=\"Normalized RNA composition\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.norm$rnacomp),"\" alt=\"Normalized rnacomp\">",sep="")
                                    cat("</a></div></td>")
                                }
                                if (!is.null(fig.unorm$rnacomp) || !is.null(fig.norm$rnacomp))
                                    cat("</tr></table></div>")
                                %>
                                <%
                                if (!is.null(fig.unorm$gcbias) || !is.null(fig.norm$gcbias)) {
                                    cat("<h4 class=\"subtitle\">GC content bias</h4>")
                                    cat("<div id=\"figures_gcbias\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$gcbias,"</br></br></div>",sep="")
                                    cat("<table class=\"innerTable\"><tr>")
                                }
                                if (!is.null(fig.unorm$gcbias)) {
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">GC content bias un-normalized </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"gcbias\" href=\"",gsub(PROJECT.PATH$main,".",fig.unorm$gcbias),"\" title=\"Un-normalized GC-content bias\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.unorm$gcbias),"\" alt=\"Un-normalized gcbias\">",sep="")
                                    cat("</a></div></td>")
                                }
                                if (!is.null(fig.norm$gcbias)) {
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">GC content bias normalized </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"gcbias\" href=\"",gsub(PROJECT.PATH$main,".",fig.norm$gcbias),"\" title=\"Normalized GC-content bias\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.norm$gcbias),"\" alt=\"Normalized gcbias\">",sep="")
                                    cat("</a></div></td>")
                                }
                                if (!is.null(fig.unorm$gcbias) || !is.null(fig.norm$gcbias))
                                    cat("</tr></table></div>")
                                %>
                                <%
                                if (!is.null(fig.unorm$lengthbias) || !is.null(fig.norm$lengthbias)) {
                                    cat("<h4 class=\"subtitle\">Gene/transcript length bias</h4>")
                                    cat("<div id=\"figures_lengthbias\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$lengthbias,"</br></br></div>",sep="")
                                    cat("<table class=\"innerTable\"><tr>") 
                                }
                                if (!is.null(fig.unorm$lengthbias)) {
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">Gene/transcript length bias un-normalized </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"lengthbias\" href=\"",gsub(PROJECT.PATH$main,".",fig.unorm$lengthbias),"\" title=\"Un-normalized gene/transcript length bias\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.unorm$lengthbias),"\" alt=\"Un-normalized lengthbias\">",sep="")
                                    cat("</a></div></td>")
                                }
                                if (!is.null(fig.norm$lengthbias)) {
                                    cat("<td class=\"innerCell\"><div class=\"figCaption\">Gene/transcript length bias normalized </div></br>")
                                    cat("<div class=\"imageContainerSq\">")
                                    cat("<a class=\"fancybox\" rel=\"lengthbias\" href=\"",gsub(PROJECT.PATH$main,".",fig.norm$lengthbias),"\" title=\"Normalized gene/transcript length bias\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.norm$lengthbias),"\" alt=\"Normalized lengthbias\">",sep="")
                                    cat("</a></div></td>")
                                }
                                if (!is.null(fig.unorm$lengthbias) || !is.null(fig.norm$lengthbias))
                                    cat("</tr></table></div>")
                                %>
                                <%
                                if (!is.null(fig.unorm$meandiff) || !is.null(fig.norm$meandiff)) {
                                    cat("<h4 class=\"subtitle\">Mean-difference</h4>")
                                    cat("<div id=\"figures_meandiff\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$meandiff,"</br></br></div>",sep="")
                                    if (is.null(fig.unorm$meandiff))
                                        nn <- names(fig.norm$meandiff)
                                    else
                                        nn <- names(fig.unorm$meandiff)
                                    for (n in nn) {
                                        cat("<table class=\"innerTable\"><tr><td colspan=2 class=\"innerCell\"><div class=\"figCaption\">Mean-difference plots for the replicates of ",n,"</div></td></tr>",sep="")
                                        if (!is.null(fig.unorm$meandiff[[n]]) && !is.null(fig.norm$meandiff[[n]])) {
                                            for (i in 1:length(fig.norm$meandiff[[n]])) {
                                                cat("<tr><td class=\"innerCell\">")
                                                cat("<div class=\"imageContainerSq\">")
                                                cat("<a class=\"fancybox\" rel=\"meandiff\" href=\"",gsub(PROJECT.PATH$main,".",fig.unorm$meandiff[[n]][i]),"\" title=\"Un-normalized mean-difference plots\">",sep="")
                                                cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.unorm$meandiff[[n]][i]),"\" alt=\"unnorm meandiff\">",sep="")
                                                cat("</a></div></td>")
                                                cat("<td class=\"innerCell\">")
                                                cat("<div class=\"imageContainerSq\">")
                                                cat("<a class=\"fancybox\" rel=\"meandiff\" href=\"",gsub(PROJECT.PATH$main,".",fig.norm$meandiff[[n]][i]),"\" title=\"Normalized mean-difference plots\">",sep="")
                                                cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.norm$meandiff[[n]][i]),"\" alt=\"norm meandiff\">",sep="")
                                                cat("</a></div></td></tr>")
                                            }
                                        }
                                        else if (is.null(fig.unorm$meandiff[[n]]) && !is.null(fig.norm$meandiff[[n]])) {
                                            for (i in 1:length(fig.norm$meandiff[[n]])) {
                                                cat("<tr><td class=\"innerCell\">")
                                                cat("<div class=\"imageContainerSq\">")
                                                cat("<a class=\"fancybox\" rel=\"meandiff\" href=\"",gsub(PROJECT.PATH$main,".",fig.norm$meandiff[[n]][i]),"\" title=\"Normalized mean-difference plots\">",sep="")
                                                cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.norm$meandiff[[n]][i]),"\" alt=\"norm meandiff\">",sep="")
                                                cat("</a></div></td><td class=\"innerCell\"></td></tr>")
                                            }
                                        }
                                        else if (!is.null(fig.unorm$meandiff[[n]]) && is.null(fig.norm$meandiff[[n]])) {
                                            for (i in 1:length(fig.unorm$meandiff[[n]])) {
                                                cat("<tr><td class=\"innerCell\">")
                                                cat("<div class=\"imageContainerSq\">")
                                                cat("<a class=\"fancybox\" rel=\"meandiff\" href=\"",gsub(PROJECT.PATH$main,".",fig.unorm$meandiff[[n]][i]),"\" title=\"Un-normalized mean-difference plots\">",sep="")
                                                cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.unorm$meandiff[[n]][i]),"\" alt=\"unorm meandiff\">",sep="")
                                                cat("</a></div></td><td class=\"innerCell\"></td></tr>")
                                            }
                                        }
                                        cat("</table>")
                                    }
                                    cat("</div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.unorm$meanvar) || !is.null(fig.norm$meanvar)) {
                                    cat("<h4 class=\"subtitle\">Mean-variance</h4>")
                                    cat("<div id=\"figures_meanvar\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$meanvar,"</br></br></div>",sep="")
                                    if (is.null(fig.unorm$meanvar))
                                        nn <- names(fig.norm$meanvar)
                                    else
                                        nn <- names(fig.unorm$meanvar)
                                    for (n in nn) {
                                        cat("<table class=\"innerTable\"><tr><td colspan=2 class=\"innerCell\"><div class=\"figCaption\">Mean-variance plots for the replicates of ",n,"</div></td></tr>",sep="")
                                        if (!is.null(fig.unorm$meanvar[[n]]) && !is.null(fig.norm$meanvar[[n]])) {
                                            for (i in 1:length(fig.norm$meanvar[[n]])) {
                                                cat("<tr><td class=\"innerCell\">")
                                                cat("<div class=\"imageContainerSq\">")
                                                cat("<a class=\"fancybox\" rel=\"meanvar\" href=\"",gsub(PROJECT.PATH$main,".",fig.unorm$meanvar[[n]][i]),"\" title=\"Un-normalized mean-variane plots\">",sep="")
                                                cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.unorm$meanvar[[n]][i]),"\" alt=\"unnorm meanvar\">",sep="")
                                                cat("</a></div></td>")
                                                cat("<td class=\"innerCell\">")
                                                cat("<div class=\"imageContainerSq\">")
                                                cat("<a class=\"fancybox\" rel=\"meanvar\" href=\"",gsub(PROJECT.PATH$main,".",fig.norm$meanvar[[n]][i]),"\" title=\"Normalized mean-variance plots\">",sep="")
                                                cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.norm$meanvar[[n]][i]),"\" alt=\"norm meanvar\">",sep="")
                                                cat("</a></div></td></tr>")
                                            }
                                        }
                                        else if (is.null(fig.unorm$meanvar[[n]]) && !is.null(fig.norm$meanvar[[n]])) {
                                            for (i in 1:length(fig.norm$meanvar[[n]])) {
                                                cat("<tr><td class=\"innerCell\">")
                                                cat("<div class=\"imageContainerSq\">")
                                                cat("<a class=\"fancybox\" rel=\"meanvar\" href=\"",gsub(PROJECT.PATH$main,".",fig.norm$meanvar[[n]][i]),"\" title=\"Normalized mean-variance plots\">",sep="")
                                                cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.norm$meanvar[[n]][i]),"\" alt=\"norm meanvar\">",sep="")
                                                cat("</a></div></td><td class=\"innerCell\"></td></tr>")
                                            }
                                        }
                                        else if (!is.null(fig.unorm$meanvar[[n]]) && is.null(fig.norm$meanvar[[n]])) {
                                            for (i in 1:length(fig.unorm$meanvar[[n]])) {
                                                cat("<tr><td class=\"innerCell\">")
                                                cat("<div class=\"imageContainerSq\">")
                                                cat("<a class=\"fancybox\" rel=\"meanvar\" href=\"",gsub(PROJECT.PATH$main,".",fig.unorm$meanvar[[n]][i]),"\" title=\"Un-normalized mean-variance plots\">",sep="")
                                                cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.unorm$meanvar[[n]][i]),"\" alt=\"unorm meanvar\">",sep="")
                                                cat("</a></div></td><td class=\"innerCell\"></td></tr>")
                                            }
                                        }
                                        cat("</table>")
                                    }
                                    cat("</div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.other$filtered)) {
                                    cat("<h4 class=\"subtitle\">Chromosome and biotype distribution of filtered genes</h4>")
                                    cat("<div id=\"figures_filtered\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$filtered,"</br></br></div>",sep="")
                                    cat("<div class=\"imageContainerRect\">")
                                    cat("<a class=\"fancybox\" href=\"",gsub(PROJECT.PATH$main,".",fig.other$filtered),"\" title=\"Filtered genes\">",sep="")
                                    cat("<img src=\"",gsub(PROJECT.PATH$main,".",fig.other$filtered),"\" alt=\"filtered\">",sep="")
                                    cat("</a></div></div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.stat$volcano)) {
                                    cat("<h4 class=\"subtitle\">Volcano plots</h4>")
                                    cat("<div id=\"figures_volcano\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$volcano,"</br></br></div>",sep="")
                                    nn <- names(contrast.list)
                                    counter <- 1
                                    for (n in nn) {
                                        cat("<div class=\"figCaption\">Volcano plot for the contrast ",n,"</div></br>",sep="")
                                        cat("<div class=\"volcano\" id=\"volcano_",counter,"\" ></div></br></br>",sep="")
                                        fc <- log2(make.fold.change(n,sample.list,norm.genes.expr,1))
                                        for (contrast in colnames(fc)) {
                                            json <- diagplot.volcano(fc[,contrast],sum.p.list[[n]],contrast,alt.names=gene.data.expr$gene_name,output="json")
                                            cat("<script>$('#volcano_",counter,"').highcharts(",json,");</script>",sep="")
                                            counter <- counter+1
                                        }
                                    }
                                    cat("</div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.stat$deheatmap)) {
                                    cat("<h4 class=\"subtitle\">DEG heatmaps</h4>")
                                    cat("<div id=\"figures_deheatmap\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$deheatmap,"</br></br></div>",sep="")
                                    nn <- names(fig.stat$deheatmap)
                                    counter <- 1
                                    for (n in nn) {
                                        cat("<div id=\"deheatmap_",counter,"\"><div class=\"figCaption\">DEG heatmap for the contrast ",n,"</div></br>",sep="")
                                        s <- gsub(PROJECT.PATH$main,".",fig.stat$deheatmap[n])
                                        #ss <- gsub("de_heatmap","iframe_de_heatmap",s)
                                        #ss <- gsub(".png",".html",ss)
                                        cat("<div class=\"imageContainerRect\">")
                                        cat("<a class=\"fancybox\" rel=\"deheatmap\" href=\"",s,"\" title=\"DEG heatmap\">",sep="")
                                        #cat("<a class=\"fancybox\" data-fancybox-type=\"iframe\" rel=\"deheatmap\" href=\"",ss,"\" title=\"DEG heatmap\">",sep="")
                                        cat("<img src=\"",s,"\" alt=\"deg heatmap\">",sep="")
                                        cat("</a></div></div></br>")
                                        counter <- counter + 1
                                    }
                                    cat("</div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.stat$biodist)) {
                                    cat("<h4 class=\"subtitle\">Chromosome and biotype distributions of DEGs</h4>")
                                    cat("<div id=\"figures_biodist\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$biodist,"</br></br></div>",sep="")
                                    nn <- names(fig.stat$biodist)
                                    counter <- 1
                                    for (n in nn) {
                                        if (fig.stat$biodist[[n]] != "error") {
                                            cat("<div id=\"biodist_",counter,"\"><div class=\"figCaption\">Biotype distribution in DEG for the contrast ",n,"</div></br>",sep="")
                                            s <- gsub(PROJECT.PATH$main,".",fig.stat$biodist[n])
                                            cat("<div class=\"imageContainerRect\">")
                                            cat("<a class=\"fancybox\" rel=\"biodist\" href=\"",s,"\" title=\"DEG biotype distribution\">",sep="")
                                            cat("<img src=\"",s,"\" alt=\"deg biodist\">",sep="")
                                            cat("</a></div></div></br>")
                                            counter <- counter + 1
                                        }
                                    }
                                    cat("</div>")
                                }
                                %>
                                <%
                                if (!is.null(fig.venn$venn)) {
                                    cat("<h4 class=\"subtitle\">Meta-analysis Venn diagrams</h4>")
                                    cat("<div id=\"figures_venn\">")
                                    cat("<div class=\"figureHint\">",report.messages$explain$venn,"</br></br></div>",sep="")
                                    nn <- names(fig.venn$venn)
                                    counter <- 1
                                    for (n in nn) {
                                        cat("<div id=\"venn_",counter,"\"><div class=\"figCaption\">Venn diagram for the contrast ",n,"</div></br>",sep="")
                                        s <- gsub(PROJECT.PATH$main,".",fig.venn$venn[n])
                                        cat("<div class=\"imageContainerRect\">")
                                        cat("<a class=\"fancybox\" rel=\"venn\" href=\"",s,"\" title=\"Venn diagram\">",sep="")
                                        cat("<img src=\"",s,"\" alt=\"deg heatmap\">",sep="")
                                        cat("</a></div>")
                                        cat("Get the genes in each category <a href=\"lists/venn_categories_",n,".txt\" download>here</a>",sep="")
                                        counter <- counter + 1
                                        cat("</br></div></br>")
                                    }
                                    cat("</div>")
                                }
                                %>
                                </br>
                                <div id="get_figures" style="background-color:#D2EBFF; border-style:solid; border-color:#8F8BFF; border-width:1px; width:400px; padding:10px;">
                                    <strong>Get all the figures in 
                                    <%=paste(paste("<a href=\"plots/metaseqr_figures_",fig.format,".zip\" download>",fig.format,"</a>",sep=""),collapse=", ")%>
                                    format.</strong>
                                </div>
                            </div> <!-- End figures container -->
                            <h3 id="results" class="title">Results</h3>
                            <div id="results_container"> <!-- Start results container -->
                                <%
                                if (!is.null(html)) {
                                    nn <- names(html)
                                    for (n in nn) {
                                        if (is.null(report.top))
                                            top.text <- "all the statistically significant genes"
                                        else
                                            top.text <- paste("the top ",round(100*report.top),"% statistically significant genes (use the download links below the table to retrieve the whole list)",sep="")
                                        cat("<div style=\"width:720px;\">")
                                        cat("<h4 class=\"subtitle\">DEG table for the contrast ",n,"</h4>",sep="")
                                        cat("<div>")
                                        cat("<div class=\"figureHint\">The following table presents ",top.text," for the contrast <strong>",n,"</strong>. The fields of the table correspond to the ",
                                        "requested features to be exported. The table can be searched using the search field on the top right.</br></br></div>",sep="")
                                        cat(html[[n]],"</br>")
                                        cat("<strong><a href=\"lists/metaseqr_sig_out_",n,".txt.gz\" download>Download</a> the DEG result list for ",n,".</strong></br>",sep="")
                                        if (!is.null(gene.counts.zero) || !is.null(gene.counts.dead))
                                            cat("<strong><a href=\"lists/metaseqr_all_out_",n,".txt.gz\" download>Download</a> the whole result list for ",n,".</strong></br>",sep="")
                                        cat("</br></div></div>")
                                    }
                                    if (export.counts.table) {
                                        cat("</br><div style=\"background-color:#D2EBFF; border-style:solid; border-color:#8F8BFF; border-width:1px; width:400px; padding:10px;\">")
                                        if (file.exists(file.path(PROJECT.PATH[["lists"]],"raw_counts_table.txt.gz")))
                                            cat("<strong><a href=\"lists/raw_counts_table.txt.gz\" download>Download</a> the raw read counts table for the experiment.</strong></br>",sep="")
                                        cat("<strong><a href=\"lists/normalized_counts_table.txt.gz\" download>Download</a> the normalized read counts table for the experiment.</strong></br>",sep="")
                                        cat("</div>")
                                    }
                                    
                                    counter <- 1
                                    cat("<script type=\"text/javascript\">")
                                    for (n in nn) {
                                        cat("$('#table_",counter,"').dataTable({\"aaSorting\": [], \"sScrollY\": 400,\"sScrollX\": 900,\"bJQueryUI\": true,\"sPaginationType\": \"full_numbers\",\"bStateSave\": true,\"iDisplayLength\": 50});",sep="")
                                        counter <- counter + 1
                                    }
                                    cat("</script>")
                                }
                                %>
                            </div> <!-- End results container -->
                            <h3 id="references" class="title">References</h3>
                            <div id="references_container"> <!-- Start references container -->
                                <%
                                    refs <- unique(c(
                                        report.messages$references$filein[[file.type]],
                                        report.messages$references$norm[[normalization]],
                                        unlist(report.messages$references$stat[statistics],use.names=FALSE),
                                        unlist(report.messages$references$figure[qc.plots],use.names=FALSE),
                                        report.messages$references$multiple[[adjust.method]],
                                        report.messages$references$meta[[meta.p]]
                                    ))
                                    cat("<div class=\"figureHint\" style=\"margin-left:25px\"><ol>")
                                    for (r in refs)
                                        cat("<li>",r,"</li>",sep="")
                                    cat("</ol></div>")
                                %>
                            </div> <!-- End references container -->
                        </div> <!-- End main accordion container -->

                        <!--Finally, render the accordions-->
                        <script type="text/javascript">
                            $.fn.togglepanels_h3 = function() {
                                return this.each(function() {
                                    $(this).addClass("ui-accordion ui-accordion-icons ui-widget ui-helper-reset")
                                        .find("h3")
                                        .addClass("ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-all ui-state-focus")
                                        .attr("role","tab")
                                        .attr("aria-controls","summary_container")
                                        .attr("aria-selected","false")
                                        .attr("tabindex","0")
                                        .hover(function() { $(this).toggleClass("ui-state-hover"); })
                                        .prepend('<span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>')
                                        .click(function() {
                                            $(this)
                                                .toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom")
                                                .find("> .ui-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s").end()
                                                .next().slideToggle();
                                            return false;
                                        })
                                        .next()
                                        .addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom")
                                        .hide();
                                });
                            };
                            $.fn.togglepanels_h4 = function() {
                                return this.each(function() {
                                    $(this).addClass("ui-accordion ui-accordion-icons ui-widget ui-helper-reset")
                                        .find("h4")
                                        .addClass("ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-all ui-state-focus")
                                        .attr("role","tab")
                                        .attr("aria-controls","summary_container")
                                        .attr("aria-selected","false")
                                        .attr("tabindex","0")
                                        .hover(function() { $(this).toggleClass("ui-state-hover"); })
                                        .prepend('<span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>')
                                        .click(function() {
                                            $(this)
                                                .toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom")
                                                .find("> .ui-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s").end()
                                                .next().slideToggle();
                                            return false;
                                        })
                                        .next()
                                        .addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom")
                                        .hide();
                                });
                            };
                            $.fn.togglepanels_h5 = function() {
                                return this.each(function() {
                                    $(this).addClass("ui-accordion ui-accordion-icons ui-widget ui-helper-reset")
                                        .find("h5")
                                        .addClass("ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-all ui-state-focus")
                                        .attr("role","tab")
                                        .attr("aria-controls","summary_container")
                                        .attr("aria-selected","false")
                                        .attr("tabindex","0")
                                        .hover(function() { $(this).toggleClass("ui-state-hover"); })
                                        .prepend('<span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>')
                                        .click(function() {
                                            $(this)
                                                .toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom")
                                                .find("> .ui-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s").end()
                                                .next().slideToggle();
                                            return false;
                                        })
                                        .next()
                                        .addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom")
                                        .hide();
                                });
                            };

                            $("#report").togglepanels_h3();
                            $("#summary_container").togglepanels_h4();
                            $("#figures_container").togglepanels_h4();
                            $("#results_container").togglepanels_h4();
                            $("#toc").togglepanels_h5().css("font-size","0.9em");

                            // Small hack to recalcluate the column widths of the datatable objects because they are being changed
                            // after the application of accordion
                            $("#results_container").each(function() {
                                $(this).find(".ui-accordion-header")
                                .each(function() {
                                    $(this).click(function() {
                                        if ($(this).next().hasClass("ui-accordion-content")) {
                                            var table = $.fn.dataTable.fnTables();
                                            $(table).each(function() {
                                                $(this).dataTable().fnAdjustColumnSizing()
                                            });
                                        }
                                    })
                                })
                            });

                            $(".fancybox").fancybox({
                                openEffect: "none",
                                closeEffect: "none",
                                helpers: {
                                    title: {
                                        type: "float"
                                    },
                                    thumbs: {
                                        width: 48,
                                        height: 48
                                    },
                                    buttons: {
                                        position: "top" 
                                    }
                                }
                            });
                            
                            /*var el = $("#contents");
                            var pos = el.position().top;
                            $(window).scroll(function() {
                                el.toggleClass("fixed", $(this).scrollTop() >= pos);
                            });*/
                            
                            var offset = $("#contents").offset().top - parseFloat($("#contents").css('margin-top').replace(/auto/, 0));
                            $(window).scroll(function() {
                                if (jQuery(window).scrollTop() >= offset) {
                                    $("#contents").addClass('detached-independent');
                                } 
                                else { 
                                    $("#contents").removeClass('detached-independent');
                                };
                            });
                        </script>
                    </td>
                    <td class="rightContainer"></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr> 
        <td class="footer">
            Copyright &copy; 2013 <a href="http://www.fleming.gr/research/molecular-biology/talianidis-lab" class="whitetext" target="_blank">Talianidis Lab</a>/<a href="http://www.fleming.gr/" class="whitetext" target="_blank">BSRC Alexander Fleming</a>,  Designed by <a href="http://epigenomics.fleming.gr/pmoulos/" class="whitetext" target="_blank">Panagiotis Moulos</a>
        </td>
    </tr>
    <tr>
        <td style="height:5px; background-color:#0E38C4; padding:0px; border-width:0px;"></td>
    </tr>
</table>
</body>
</html>
