#' <% visualizations.ShotGun.print_qc_intro_caption(len(dna_samples), dna_columns[2:]) %>

#' ## DNA Samples Quality Control

#' ### DNA Samples Tables of Filtered Reads

#+ echo=False

# create a table of the paired counts
document.write_table(["# Sample"] + dna_columns, dna_samples, dna_data,
                     files.ShotGunVis.path("qc_counts", document.data_folder))

table_message = visualizations.show_table_max_rows(
    document,
    dna_data,
    dna_samples,
    dna_columns,
    "DNA reads",
    files.ShotGunVis.path("qc_counts"),
    format_data_comma=True)

#' <%= table_message %>

#+ echo=False
# compute and plot the microbial reads ratios
# compute ratios for each database used for qc
dna_microbial_reads, dna_microbial_labels = utilities.microbial_read_proportion_multiple_databases(
    dna_data, dna_columns)

# create a table of the microbial reads
document.write_table(["# Sample"] + dna_microbial_labels, dna_samples,
                     dna_microbial_reads,
all_taxa_counts = [[
    a, b, c, d
] for a, b, c, d in zip(species_counts, species_counts_after_filter,
                        genera_counts, genera_counts_after_filter)]

# create a table of the data in the output folder
taxa_counts_column_names = [
    "# Sample", "Species", "Species filtered", "Genera", "Genera filtered"
]
document.write_table(
    taxa_counts_column_names, samples, all_taxa_counts,
    files.ShotGunVis.path("taxa_counts", document.data_folder))

# show the table, reducing the rows if there are lots of samples
table_message = visualizations.show_table_max_rows(
    document, all_taxa_counts, samples, taxa_counts_column_names[1:],
    "Total taxa per sample", files.ShotGunVis.path("taxa_counts"))

#' <%= table_message %>

#' ## Ordination

#' ### Species

#+ echo=False
# get the top species by average abundance
top_taxonomy, top_data = utilities.top_rows(species_taxonomy,
                                            species_data,
                                            max_sets_heatmap,
                                            function="average")
#' <%= visualizations.ShotGun.format_caption("pathway_abundance_heatmap",norm="z-score") %>

#' <% if pdf_format: print("\clearpage") %>

#+ echo=False

# write a table of the pathways average and variance
pathway_file_name = "top_average_pathways_names.tsv"
average_abundance_variance = visualizations.write_pathway_average_variance_table(
    document, pathway_file_name, dna_top_average_data,
    top_names_and_descriptions)

table_message = visualizations.show_table_max_rows(
    document,
    average_abundance_variance,
    top_names_and_descriptions, [" Average ", " Variance "],
    "Top " + str(max_sets) + " pathways by average abundance",
    pathway_file_name,
    font=7)

#' <%= table_message %>

#' <% visualizations.print_pathways_urls(dna_top_average_pathways,top_names_and_descriptions,3) %>

#+ echo=False
# check for then rna/dna norm files
show_norm_ratio = False
if vars["genefamilies_norm_ratio"] and vars["ecs_norm_ratio"] and vars[
        "paths_norm_ratio"]:
    show_norm_ratio = True
#+ echo=False

#' ## DNA Samples Quality Control

#' ### DNA Samples Tables of Filtered Reads

#+ echo=False
document.write_table(["# Sample"] + dna_paired_columns, dna_samples,
                     dna_paired_data,
                     files.ShotGunVis.path("qc_counts_paired",
                                           document.data_folder))

table_message = visualizations.show_table_max_rows(
    document,
    dna_paired_data,
    dna_samples,
    dna_paired_columns,
    "DNA Paired end reads",
    files.ShotGunVis.path("qc_counts_paired"),
    format_data_comma=True)

#' <%= table_message %>

#+ echo=False
document.write_table(["# Sample"] + dna_orphan_columns, dna_samples,
                     dna_orphan_data,
                     files.ShotGunVis.path("qc_counts_orphan",
                                           document.data_folder))

table_message = visualizations.show_table_max_rows(
    document,
    dna_orphan_data,