#!/usr/bin/env perl
########################
#Tsute Chen
#The Forsyth Institute
#2021-03-04
########################
use strict;
use Roman;
use Number::Format 'format_number';
use Excel::Writer::XLSX;
########################
if(!$ARGV[0]||!$ARGV[1]||!$ARGV[2]){
	print "#################\n";
	print "./01_createHTMLreport.pl tier projectid [V1V3|V3V4]\n";
	print "Parameters:\n";
	print "tier: 1 or 2\n";
	print "projectid: FOMCXXXX\n";
	print "[V1V3|V3V4]: either V1V3 or V3V4"

	exit;
}
my $version="V1.0";
my $date=`date +'%B %d, %Y'`; chomp $date;
my @levels=qw( domain phylum class order family genus species );

my $tier=$ARGV[0];
my $prjid=$ARGV[1];
my $V=$ARGV[2];
# my $prjid=`pwd`;
# $prjid=~/(FOMC\d+)/;
# $prjid=$1;
print "Project ID: $prjid\n";
#################################
my $fld="report";
system("rm -rf $fld") if -e $fld;
mkdir($fld);
mkdir("$fld/images/");
system("cp banner.png $fld/images/");
system("cp barplot1.png $fld/images/");
system("cp barplot2.png $fld/images/");
system("cp alpha1.png $fld/images/");
system("cp alpha2.png $fld/images/");
system("cp emperor1.png $fld/images/");
system("cp emperor2.png $fld/images/");
system("cp heatmap1.png $fld/images/");
system("cp heatmap2.png $fld/images/");
system("cp ../zymo/absolute_abundance.png $fld/images/");
system("cp ../zymo/absolute.abundance.csv $fld/");
mkdir("$fld/dada2");
system("cp ../dada2/results/track_*.txt $fld/dada2/");
system("cp ../dada2/results/best_trim_pair.txt $fld/dada2/");
system("cp ../dada2/results/trim_pair.txt $fld/dada2/");
system("cp ../dada2/results/quality_plots/quality_plot_1.png $fld/dada2/");
system("cp ../dada2/results/quality_plots/quality_plots_all.pdf $fld/dada2/");
#################################
system("cp ../dada2/results/err_plots/* $fld/dada2/");
system("cp ../dada2/results/seqtab/* $fld/dada2/");
################################# Files for Taxonomy results
mkdir("$fld/qiime");
system("cp ../qiime/count_summary.txt $fld/qiime/");
system("cp Species-Level_BALSTN-QIIME-Pipeline-Flowchart.png $fld/images/");
system("cp Species-Level_BALSTN-QIIME-Pipeline-Flowchart.pdf $fld/images/");
system("cp Species-Level_BALSTN-QIIME-Pipeline-Flowchart_600.png $fld/images/");
##################################
system("cp ../qiime/meta.txt $fld/qiime/");
system("cp ../qiime/sample_readcount.txt $fld/qiime/");
mkdir("$fld/qiime/data_mc100");
system("cp ../qiime/qiime_results/data_mc100/* $fld/qiime/data_mc100/ 2>1");
mkdir("$fld/qiime/data_mc100/qiime2");
my @qiime2=qw( ancom alpha_rare barplot braycurtis_emperor_pcoa euclidean_emperor_pcoa correlation_emperor_pcoa heatmap otu_table otu_table_tax summary );
foreach my $ea(@qiime2){
system("cp -ra ../qiime/qiime_results/data_mc100/qiime2/$ea $fld/qiime/data_mc100/qiime2/");
}
mkdir("$fld/qiime/data_mc100/qiime2/otu_table_levels");
my $L=1;
foreach my $level(@levels){
system("cp ../qiime/qiime_results/data_mc100/qiime2/otu_levels/level_$L/feature-table.biom $fld/qiime/data_mc100/qiime2/otu_table_levels/$level\_otu_table.biom");
system("cp ../qiime/qiime_results/data_mc100/qiime2/otu_levels/$level\_otu_table.tsv $fld/qiime/data_mc100/qiime2/otu_table_levels/");
$L++;
}
#################################
system("mkdir $fld/R");
system("cp ../R/*.pdf $fld/R/");
system("cp ../R/*.svg $fld/R/");
system("cp ../R/*.png $fld/R/");
system("cp ../R/otu_table.txt $fld/R/");
system("cp ../R/tax_table.txt $fld/R/");
system("cp ../R/meta_table.txt $fld/R/");
#################################
system("mkdir $fld/lefse");
system("cp -r ../lefse/lefse_results/* $fld/lefse/");
system("cp ../lefse/lefse_L7.txt $fld/lefse/");
#################################
my $checklist_file=($tier eq "2")?"workflow_checklist_t2.txt":"workflow_checklist_t1.txt";
my $i=1;
my $workflow_checklist="<table class=\"basictable\">\n";
open(IN,$checklist_file)||die;
while(my $line=<IN>){
chomp $line;
my ($check,$item)=split("\t",$line);
$item=~s/(\(service not requested\))/<span style=\"color:red\">$1<\/span>/;
$workflow_checklist.="<tr><td>$check</td><td>$i.</td><td>$item</td></tr>\n";
$i++;
}
$workflow_checklist.="</table>\n";


#################################
my $ngs_file=($V eq "V1V3")?"ngs_sequencing_V1V3.html":"ngs_sequencing_V3V4.html";
my $ngs_sequencing;
open(IN,$ngs_file)||die;
while(my $line=<IN>){
	$ngs_sequencing.=$line;
}
close IN;

#################################
my $sampleid_filename_table="<pre><table class=\"basictable\">\n";
open(IN,"../dada2/sampleid_filename.txt")||die;
my $s;
while(my $line=<IN>){
chomp $line;
my ($sid,$r1,$r2)=split("\t",$line);
if($s){
$sampleid_filename_table.="<tr><td>".$sid."</td><td>".$r1."</td><td>".$r2."</td></tr>\n";
}else{
$sampleid_filename_table.="<tr><th>".$sid."</th><th>".$r1."</th><th>".$r2."</th></tr>\n";
}
$s++;
}
$sampleid_filename_table.="</table></pre>\n";
close IN;
#################################
my $rawreadzipfile=$prjid."_rawdata.zip";
my $reportzipfile =$prjid."_report.zip";

#################################
my $dada2_result="will be here";
#################################
my $dada2_result;
##################################
system("cp ../dada2/best_trim_pair.txt $fld/dada2/");
my $test=`head -n 2 $fld/dada2/best_trim_pair.txt|tail -n 1 `; chomp $test;
my ($trim1,$trim2,$trimper)=split("\t",$test);

my $trimming_results="<table class=\"basictableblue\">\n";

open(IN,"$fld/dada2/trim_pair.txt")||die;
my @R2trims; my @R1trims;
$s=0;
while(my $line=<IN>){
	chomp $line;
	my @tmp=split("\t",$line);
	if($s){
		my $ttt=shift(@tmp);
		my @tmp1;
		my $i=0;
		foreach my $ea(@tmp){
			if($ttt eq $trim1 && $R2trims[$i] eq $trim2){
			push(@tmp1,"<b><span style=\"background-color:pink\">".sprintf("%.2f",$ea)."\%</span></b>");
			}else{
			push(@tmp1,sprintf("%.2f",$ea)."\%");
			}
			$i++;
		}
		$trimming_results.="<tr><th>".$ttt."</th><td>".join("</td><td>",@tmp1)."</td></tr>\n";
	}else{
		$trimming_results.="<tr><th>".join("</th><th>",@tmp)."</th></tr>\n";
		shift @tmp;
		@R2trims=@tmp;
	}
	$s++;
}
$trimming_results.="</table>\n";
close IN;

#################################
my $dada2_summary="<table class=\"basictablegreen\">\n";
my $trackfile=`ls $fld/dada2/track_*.txt`; chomp $trackfile;
open(IN,$trackfile)||die;
my @headerrow; my @headercolumn;
$s=0;
while(my $line=<IN>){
	chomp $line;
	my @tmp=split("\t",$line);
	if($s){
		my $ttt=shift(@tmp);
		my $per=pop(@tmp);
		$per=sprintf("%.2f",$per)."%";
		my @tmp1;
		foreach my $ea(@tmp){
			push(@tmp1,format_number($ea));
		}
		$dada2_summary.="<tr><th>".$ttt."</th><td>".join("</td><td>",(@tmp1,$per))."</td></tr>\n";
	}else{
		$dada2_summary.="<tr><th>".join("</th><th>",("Sample ID",@tmp))."</th></tr>\n";
		shift @tmp;
		@R2trims=@tmp;
	}
	$s++;
}
$dada2_summary.="</table>\n";
close IN;

#################################
my $workbook  = Excel::Writer::XLSX->new("$fld/dada2/seqtab_nochime.xlsx");
$workbook->set_properties(
        title    => 'Forsyth Bioinformatics Sequence Analysis Report',
        author   => 'Forsyth',
        comments => 'Created with Perl and Spreadsheet::WriteExcel',
);
my $navy1 = $workbook->set_custom_color(41,0,51,102);
my $headerfmt=$workbook->add_format(color=>'white',bg_color=>$navy1,bold=>1,align=>'center');
my $ws=$workbook->add_worksheet("ASV Count Table");
$ws->freeze_panes(1,0);
$ws->set_column( 1, 1, 50 );

my $asvtablefile=`ls $fld/dada2/seqtab_nochime_*.txt`; chomp $asvtablefile;
my $asvcount=`grep -c '' $asvtablefile`; chomp $asvcount;
open(IN,$asvtablefile)||die;
my $row=0;
while(my $line=<IN>){
	chomp $line;
	my @tmp=split("\t",$line);
	if($row){
		unshift(@tmp,"ASV".$row);
	}else{
		unshift(@tmp,("ASV_ID","Sequence"));
	}
	my $format=$headerfmt if $row==0;
	$ws->write_row($row,0,\@tmp,$format);
	$row++;
}
close IN;
$workbook->close();
#################################
open(IN,"dada2_result.html")||die;
while(my $line=<IN>){
	$dada2_result.=$line;
}
close IN;
##################################
my $tax_writeup;
my $tax_result1;
my $tax_result2;
my $tax_result3;
my $otu_table;
my $otu_tables;
my $alpha_result;
my $beta_result;
my $comp_result;
my $heatmap_result;
my $network_result;

##################################
if($tier eq "1"){
	$tax_result1  ="<font style=\"font-size:1.2em;color:red\">Service not requested</font>";
	$alpha_result="<font style=\"font-size:1.2em;color:red\">Service not requested</font>";
	$beta_result ="<font style=\"font-size:1.2em;color:red\">Service not requested</font>";
	$comp_result ="<font style=\"font-size:1.2em;color:red\">Service not requested</font>";
	$heatmap_result ="<font style=\"font-size:1.2em;color:red\">Service not requested</font>";
	$network_result ="<font style=\"font-size:1.2em;color:red\">Service not requested</font>";
}else{
################################## Taxonomy
	open(IN,"tax_writeup.html")||die;
	while(my $line=<IN>){
		$tax_writeup.=$line;
	}
	close IN;

	$tax_result1="<table class=\"basictablewhite\">\n";
	open(IN,"$fld/qiime/count_summary.txt")||die;
	my $i=0;
	while(my $line=<IN>){
		chomp $line;
		my @tmp=split("\t",$line);
		my $head=shift @tmp;
		my $bgcolor;
		if($head eq "H"){
			$bgcolor="style=\"background-color:#99FFB3;font-weight:bold\"";
		}elsif($head eq "I"||$head eq "J"||$head eq "K"){
			$bgcolor="style=\"background-color:#BFFFCF\"";
		}elsif($head eq "P"){
			$bgcolor="style=\"background-color:#FFBFBF;font-weight:bold\"";
		}elsif($head eq "Q"||$head eq "R"||$head eq "S"){
			$bgcolor="style=\"background-color:#FFDFDF\"";
		}elsif($head eq "L"){
			$bgcolor="style=\"background-color:#73B9FF;font-weight:bold\"";
		}elsif($head eq "M"||$head eq "N"||$head eq "O"){
			$bgcolor="style=\"background-color:#BFDFFF\"";
		}elsif($head eq "E"){
			$bgcolor="style=\"background-color:#CC99FF;font-weight:bold\"";
		}elsif($head eq "F"||$head eq "G"){
			$bgcolor="style=\"background-color:#DFBFFF\"";
		}elsif($head eq "A"){
			$bgcolor="style=\"background-color:#FFFF73;font-weight:bold\"";
		}elsif($head eq "B"){
			$bgcolor="style=\"background-color:#CCCCCC;font-weight:bold\"";
		}

		if($i){
			if($head){
				my $head1=shift(@tmp); my @tmp1;
				foreach my $ea(@tmp){
				push(@tmp1,format_number($ea));
				}
				$tax_result1.="<tr $bgcolor><th>".$head."</th><td>".join("</td><td>",($head1,@tmp1))."</td></tr>\n";
			}else{
				my $colspan=scalar(@tmp);
				$tax_result1.="<tr><th>".$head."</th><td colspan=\"$colspan\" align=\"left\">".$tmp[0]."</td></tr>\n";
			}
		}else{
			my @tmp1;
			foreach my $ea(@tmp){
			$ea=~s/mc(\d+)/Read Count \(MC=$1\)\*/;
			$ea=~s/all/Read Count \(MC=1\)\*/;
			push(@tmp1,$ea);
			}
			$tax_result1.="<tr><th>".$head."</th><th>".join("</th><th>",@tmp1)."</th></tr>\n";
		}
		$i++;
	}
	$tax_result1.="</table>\n";
	close IN;

	open(IN,"$fld/qiime/meta.txt")||die;
	$tax_result2.="<table class=\"basictableblue\">\n";
	my $token=0;
	while(my $line=<IN>){
		chomp $line;
		my @tmp=split("\t",$line);
		if($token){
			my $head=shift(@tmp);
			$tax_result2.="<tr><th>".$head."</th><td>".join("</td><td>",@tmp)."</td></tr>\n";
		}else{
			$tax_result2.="<tr><th>".join("</th><th>",@tmp)."</td></tr>\n";
		}
		$token++;
	}
	$tax_result2.="</table>\n";
	close IN;

	open(IN,"$fld/qiime/sample_readcount.txt")||die;
	$tax_result3.="<table class=\"basictableblue\">\n";
	$tax_result3.="<tr><th>#Sample ID</th><td>Read Count</th></tr>\n";
	while(my $line=<IN>){
		chomp $line;
		my @tmp=split("\t",$line);
			my $head=shift(@tmp);
			$tax_result3.="<tr><th>".$head."</th><td>".join("</td><td>",@tmp)."</td></tr>\n";
	}
	$tax_result3.="</table>\n";
	close IN;

	open(IN,"$fld/qiime/data_mc100/final_otu_table_fullfax_mc100.txt")||die;
	$otu_table.="<table class=\"basictableblue\">\n";
	$token=0;
	while(my $line=<IN>){
		chomp $line;
		my @tmp=split("\t",$line);
		if($token){
			my $head=shift(@tmp);
			my $tax=shift(@tmp);
			$otu_table.="<tr><th>".$head."</th><td align=\"left\">".$tax."</td><td>".join("</td><td>",@tmp)."</td></tr>\n";
		}else{
			$otu_table.="<tr><th>".join("</th><th>",@tmp)."</td></tr>\n";
		}
		$token++;
	}
	$otu_table.="</table>\n";
	close IN;

	$otu_tables="<table class=\"basictableblue\"><tr><th colspan=\"3\">Download Read Count Tables at Different Taxonomy Levels</th></tr>\n";
	foreach my $level(@levels){
		$otu_tables.="<tr><th>$level</th><td>";
		$otu_tables.="<a href=\"qiime/data_mc100/qiime2/otu_table_levels/$level\_otu_table.biom\"><input type=\"button\" class=\"downloadbutton\" value=\"BIOM Format\"></a>";
		$otu_tables.="</td><td>";
		$otu_tables.="<a href=\"qiime/data_mc100/qiime2/otu_table_levels/$level\_otu_table.tsv\"><input type=\"button\" class=\"downloadbutton\" value=\"TEXT Format\"></a>";
		$otu_tables.="</td></tr>\n";
	}
	$otu_tables.="</table>\n";

	########################
	$comp_result ="<font style=\"font-size:1.2em;color:red\">Results coming soon</font>";
	$heatmap_result ="<font style=\"font-size:1.2em;color:red\">Results coming soon</font>";
	$network_result ="<font style=\"font-size:1.2em;color:red\">Results coming soon</font>";
}

#################################
#################################
#################################
make_html();


#################################
open(IN,"02.template")||die;
open(OUT,">02_copy_report_zip_ftp.sh")||die;
while(my $line=<IN>){
	my $replace=$prjid;
	$replace.="_full" if $tier eq "2";
	$line=~s/XXXXXX/$replace/;
	$line=~s/YYYYYY/$prjid/;
	print OUT $line;
}
close OUT;

print "Done! Next run the following shell script to copy to ftp:\n\n";
print "sh 02_copy_report_zip_ftp.sh\n\n";


#######################################
sub make_html(){
my $htmlfile="$fld/REPORT.html";

open(HTML,">$htmlfile")||die;
my $header=insert_header();
print HTML $header;
my $footer=insert_footer();
print HTML $footer;
close HTML;

}


#######################################
sub insert_header(){
my $i=1;my $j=1;
my $html= qq@
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="The Forsyth Institute" />
<meta name="date" content="@.$date.qq@" />
<title>FOMC Service Report</title>
<style>
body {
	font-family: sans-serif;
	font-size: 1.2em;
}
a {
	text-decoration: none;
}
a:hover {
	color: blue;
}

h1, h2, h3 {
	font-size: 1.5em;
	font-weight: bold;
	color: navy;
	text-align: center;
	padding: 2px;
	spacing: 2px;
}
h1 {
	font-size: 1.8em;
	padding: 5px;
	spacing: 5px;
}
h3 {
	font-size: 1.4em;
	color:brown;
	padding: 5px;
	spacing: 5px;
}

.bggray{
	background-color: #DDDDDD;
}
.left{
	text-align:left;
}

.xybox{
	overflow-x:auto;
	overflow-y:auto;
	height:400px;
	width:800px;
	background-color:#DDDDDD;
}

.basictable {
	border: 1px gray solid;
	spacing: 10px;
	padding: 10px;
	background-color: white;
}
.basictable tr:nth-child(odd) {
	background-color: #EEEEEE;
}
.basictable tr:nth-child(even) {
	background-color: #FFFFFF;
}
.basictable tr:hover {
	background-color: #CCCCCC;
}

.basictableblue {
	border: 1px #0059B2 solid;
	spacing: 10px;
	padding: 10px;
	text-align: right;
	background-color: white;
}
.basictableblue tr:nth-child(odd) {
	background-color: #BFDFFF;
}
.basictableblue tr:nth-child(even) {
	background-color: #FFFFFF;
}
.basictableblue tr:hover {
	background-color: #73B9FF;
}
.basictableblue th{
	background-color: #CCCCCC;
	padding: 5px;
	text-align:center;
}
.basictableblue td{
	padding: 5px;
}

.basictablegreen {
	border: 1px #0059B2 solid;
	spacing: 10px;
	padding: 10px;
	text-align: right;
	background-color: white;
}
.basictablegreen tr:nth-child(odd) {
	background-color: #D7FFE1;
}
.basictablegreen tr:nth-child(even) {
	background-color: #FFFFFF;
}
.basictablegreen tr:hover {
	background-color: #BFFFCF;
}
.basictablegreen th{
	background-color: #BBBBBB;
	padding: 5px;
	text-align:center;
}
.basictablegreen td{
	padding: 5px;
}

.basictablewhite {
	border: 1px gray solid;
	spacing: 10px;
	padding: 10px;
	background-color: white;
}
.basictablewhite th{
	background-color: #BBBBBB;
	padding: 5px;
	text-align:center;
}

.downloadbutton{
	padding: 5px;
	font-size: 1.2em;
	color: blue;
	background-color: #99CCFF;
	border: 1px blue solid;
}
.downloadbutton:hover{
	color: red;
	background-color: #4DA6FF;
}

.floating-menu {
	z-index: 5;
	position: fixed;
	padding: 10px;
}
.floating-menu table {
	padding:10px;
	spacing:10px;
	width: 220px;
	color: navy;
	border: 1px navy solid;
	background: white;
}
.floating-menu tr:nth-child(odd) {
	background: #DBEDFF;
}
.floating-menu tr:nth-child(even) {
	background: white;
}
.floating-menu tr:hover {
background: yellow;
}
.floating-menu th {
	color: white;
	background: navy;
	padding: 3px;
	vertical-align: top;
}
.floating-menu td {
	padding: 3px;
	vertical-align: top;
}
.floating-menu a {
	text-decoration: none;
	color: navy;
}
.floating-menu a:hover {
	color: red;
}
.floating-menu a:active {
	color: red;
}

.t1 {
	font-size: 1.1em;
	color: navy;
	font-weight: bold;
	background: #E1F0FF;
	height: 40px;
}
.banner {
	background-color: #B5DAFF;
	background-image:
	linear-gradient(rgba(255,255,255,.18) 1px, transparent 1px),
	linear-gradient(90deg, rgba(255,255,255,.18) 1px, transparent 1px);
	background-size: 20px 20px, 20px 20px, 20px 20px, 20px 20px;
	background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
}
.sidebg {
	background-color: #D0E8FF;
	background-image:
	linear-gradient(rgba(255,255,255,.18) 1px, transparent 1px),
	linear-gradient(90deg, rgba(255,255,255,.18) 1px, transparent 1px);
	background-size: 20px 20px, 20px 20px, 20px 20px, 20px 20px;
	background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
}
.tb1 td {
	text-align: center;
}
.tb1 th {
	text-align: center;
}
.tb2 {
	border-spacing: 2px;
}
.tb2 td {
	background: #E1F8FF;
	padding: 10px;
}
.tb2 th {
	text-align: center;
	background: #BFDFFF;
	padding: 10px;
}
</style>
</head>
<body>
<div align="center">
	<table width="1200px">
	<tr><td colspan="2"><img src="images/banner.png"></td></tr>
	<tr><td class="sidebg" width="240px" valign="top">
	<div class="floating-menu">
		<table>
		<tr><th colspan="2">Table of Content</th></tr>
	@;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#WC\">Workflow Checklist</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#NGS\">NGS Sequencing Results</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#DL1\">Complete Report Download</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#DL2\">Raw Sequence Data Download</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#DADA2\">Analysis - DADA2 Read Processing</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#TAX\">Analysis - Read Taxonomy Assignment</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#ALPHA\">Analysis - Alpha Diversity</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#BETA\">Analysis - Beta Diversity</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#COMP\">Analysis - Differential Abundance</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#HEAT\">Analysis - Heatmap Profile</a></td></tr>";$i++;
	$html.="<tr><td align=\"right\">".uc(roman($i)).".</td><td><a href=\"#NET\">Analysis - Network Association</a></td></tr>";$i++;
	$html.=qq@
		</table>
		<div align="center">(Click to navigate)</div>
	</div>
	</td><td align="center">
	<table width="960px"><tr><td align="center">
		<table width="100%">
		<tr><td><h2>FOMC Service Report</h2>
		<h1>16S rRNA Gene V1V3 Amplicon Sequencing</h1>
		<h2>Version $version</h2>
		</h1>
		</td></tr>
		<tr><td align="center"><i>The Forsyth Institute, Cambridge, MA, USA</i></td></tr>
		<tr><td  align="center">$date</td></tr>
		<tr><td><hr></td></tr>
		<tr><td><h1>Project ID: <span style="color:brown">$prjid</span></td></tr>
		<tr><td><hr></td></tr>
		<tr><td>
		<table width="100%">
		<!-- ######################### -->
		<tr>
		<td><a name="WC"><h1 class="bggray left">@.uc(roman($j++)).qq@. Workflow Checklist</h1></td></tr>
		<tr><td align="center">
			<table>
			<tr><td>$workflow_checklist</td><tr>
			</table>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<!-- ######################### -->
		<tr>
		<td><a name="NGS"><h1 class="bggray left">@.uc(roman($j++)).qq@. NGS Sequencing</h1></td></tr>
		<tr><td>
			<table>
			<tr><td>$ngs_sequencing</td><tr>
			</table>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<!-- ######################### -->
		<tr>
		<td><a name="DL1"><h1 class="bggray left">@.uc(roman($j++)).qq@. Complete Report Download</h1></td></tr>
		<tr><td>
			<table>
			<tr><td>
<p>The complete report of your project, including all links in this report, can be downloaded by clicking the link provided below. The downloaded file is a compressed ZIP file and once unzipped, open the file “REPORT.html” (may only shown as "REPORT" in your computer) by double clicking it. Your default web browser will open it and you will see the exact content of this report.</p>
<p>Please download and save the file to your computer storage device. The download link will expire after <font style="color:red">60 days </font>  upon your receiving of this report.</p>
<p>Complete report download link:</p>
<p><div align="center"><a href="$reportzipfile">
<input class="downloadbutton" type="button" value="Download Complete Report"></a></div></p>
<p>
To view the report, please follow the following steps:
<table class="basictable">
<tr><td>1.</td><td>Download the .zip file from the report link above.</td></tr>
<tr><td>2.</td><td>Extract all the contents of the downloaded .zip file to your desktop.</td></tr>
<tr><td>3.</td><td>Open the extracted folder and find the "REPORT.html" (may shown as only "REPORT").</td></tr>
<tr><td>4.</td><td>Open (double-clicking) the REPORT.html file. Your default browser will open the top age of the complete report. Within the
report, there are links to view all the analyses performed for the project.</td></tr>
</table>
<br>
</p>

			</td><tr>
			</table>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<!-- ######################### -->
		<tr>
		<td><a name="DL2"><h1 class="bggray left">@.uc(roman($j++)).qq@. Raw Sequence Data Download</h1></td></tr>
		<tr><td>
			<table>
			<tr><td>
<p>The raw NGS sequence data is available for download with the link provided below. The data is a compressed ZIP file and can be unzipped to individual sequence files.
Since this is a pair-end sequencing, each of your samples is represented by two sequence files, one for READ 1,
with the file extension “*_R1.fastq.gz”, another READ 2, with the file extension “*_R1.fastq.gz”.
The files are in FASTQ format and are compressed. FASTQ format is a text-based data format for storing both a biological sequence
and its corresponding quality scores. Most sequence analysis software will be able to open them.
The Sample IDs associated with the R1 and R2 fastq files are listed in the table below:</p>
<div align="center">
$sampleid_filename_table
</div>
<p>Please download and save the file to your computer storage device. The download link will expire after <font style="color:red">60 days </font> upon your receiving of this report.</p>
<p>Raw sequence data download link:</p>
<p><div align="center"><a href="$rawreadzipfile">
<input class="downloadbutton" type="button" value="Download Raw Sequence Data"></a></div></p>

			</td><tr>
			</table>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<!-- ######################### -->
		<tr>
		<td><a name="DADA2"><h1 class="bggray left">@.uc(roman($j++)).qq@. Analysis - DADA2 Read Processing</h1></td></tr>
		<tr><td>
			<table>
			<tr><td>$dada2_result</td><tr>
			<tr><td align="center">$trimming_results</td><tr>
			<tr><td>
			<p>Based on the above result, the trim length combination of R1 = @.$trim1.qq@ bases and R2 = @.$trim2.qq@ bases (highlighted red above), was chosen for generating final ASVs for all sequences.
			This combination generated highest number of merged non-chimeric ASVs and was used for downstream analyses, if requested.</p>

			<p><b>3. Error plots from learning the error rates</b>
			After DADA2 bulding the error model for the set of data, it is always worthwhile, as a sanity check if nothing else, to visualize the estimated error rates.
			The error rates for each possible transition (A→C, A→G, …) are shown below. Points are the observed error rates for each consensus quality score.
			The black line shows the estimated error rates after convergence of the machine-learning algorithm.
			The red line shows the error rates expected under the nominal definition of the Q-score.
			The ideal result would be the estimated error rates (black line) are a good fit to the observed rates (points), and the error rates drop
			with increased quality as expected. </p>
			<p><div align="center">
			<b>Forward Read R1 Error Plot</b><br>
			<a href="dada2/errF.pdf"><img src="dada2/errF.png"></a><br><br>
			<b>Reverse Read R2 Error Plot</b><br>
			<a href="dada2/errR.pdf"><img src="dada2/errR.png"></a></div>
			</p>
			<p>The PDF version of these plots are available here:</p>
			<p><div align="center"><a href="dada2/errF.pdf"><input class="downloadbutton" type="button" value="R1 Error Plot in PDF"></a></div></p>
			<p><div align="center"><a href="dada2/errR.pdf"><input class="downloadbutton" type="button" value="R2 Error Plot in PDF"></a></div></p>
			</td></tr>

			<tr><td>&nbsp;</td></tr>
			<tr><td>
			<p><b>4. DADA2 Result Summary</b> The table below shows the summary of the DADA2 analysis,
			tracking paired read counts of each samples for all the steps during DADA2 denoising process -
			including end-trimming (<b>filtered</b>), denoising (<b>denoisedF, denoisedF</b>), pair merging (<b>merged</b>) and chimera removal (<b>nonchim</b>).</p>
			</td><tr>
			<tr><td align="center">
			<div class="xybox" align="center">
			$dada2_summary
			</div>
			</td></tr>

			<tr><td><p>This table can be downloaded as an Excel table below:</p>
			<p><div align="center"><a href="dada2/dada2_summary.xlsx"><input class="downloadbutton" type="button" value="DADA2 Summary Table in Excel format"></a></div></p>
			</td></tr>

			<tr><td>&nbsp;</td></tr>
			<tr><td>
			<p><b>5. DADA2 Amplicon Sequence Variants (ASVs)</b>. A total of $asvcount unique merged and chimera-free ASV sequences were identified, and their corresponding
			read counts for each sample are available in the "ASV Read Count Table" with rows for the ASV sequences and columns for sample. This read count table can be used for
			microbial profile comparison among different samples and the sequences provided in the table can be used to taxonomy assignment.</p>
			</td></tr>
			<tr><td>&nbsp;</td></tr>
			<tr><td>
			<p>The table can be downloaded from this link:</p>
			<p><div align="center"><a href="dada2/seqtab_nochime.xlsx"><input class="downloadbutton" type="button" value="ASV Read Count Table in Excel format"></a></div></p>
			</td></tr>
			<tr><td>&nbsp;</td></tr>

			<tr><td>&nbsp;</td></tr>
			<tr><td align="center">
			<a href="qiime/data_mc100/qiime2/summary/index.thml"><input class="downloadbutton" type="button" value="ASV Read Summary Information"></a>
			</td></tr>
			<tr><td>&nbsp;</td></tr>

			</table>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<!-- ######################### -->
		@;
###################################### Taxonomy
$html.=qq@
		<tr>
		<td><a name="TAX"><h1 class="bggray left">@.uc(roman($j++)).qq@. Analysis - Read Taxonomy Assignment</h1></td></tr>
		<tr><td><h3>Read Taxonomy Assignment - Methods</h3></td></tr>
		<tr><td>
			<table><tr><td width="50px">&nbsp;</td><td>
		$tax_writeup
			</td></tr></table>
		</td></tr>
		<tr><td>&nbsp;</td></tr>
		<tr><td align="center"><h3>Read Taxonomy Assignment - Result Summary</h3></td></tr>
		<tr><td align="center">
			<table>
			<tr><td>$tax_result1</td><tr>
			<tr><td>* MC = Minimal Count per species, species with total read count < MC were removed.</td></tr>
			<tr><td>* <font style="color:red">The assignment result from MC=100 was used in the downstream analyses.</font></td></tr>
			</table>
		</td></tr>
		<tr><td>&nbsp;</td></tr>
		<tr><td>&nbsp;</td></tr>

		<tr><td align="center"><h3>Read Taxonomy Assignment - Sample Meta Information</h3></td></tr>
		<tr><td align="center">
			<table>
			<tr><td><div class="xybox" align="center">$tax_result2</div></td></tr>
			</table>
		</td></tr>
		<tr><td>&nbsp;</td></tr>
		<tr><td>&nbsp;</td></tr>

		<tr><td align="center"><h3>Read Taxonomy Assignment - ASV Read Counts by Samples</h3></td></tr>
		<tr><td align="center">
			<table>
			<tr><td><div class="xybox" align="center">$tax_result3</div></td></tr>
			</table>
		</td></tr>
		<tr><td>&nbsp;</td></tr>
		<tr><td>&nbsp;</td></tr>

		<tr><td align="center"><h3>Read Taxonomy Assignment - ASV Read Counts Table</h3></td></tr>
		<tr><td align="center">
			<table>
			<tr><td><div class="xybox" align="center">$otu_table</div></td></tr>
			</table>
		</td></tr>
		<tr><td>&nbsp;</td></tr>

		<tr><td align="center">
		<a href="qiime/data_mc100/final_otu_table_fullfax_mc100.txt">
		<input class="downloadbutton" type="button" value="Downalod Species Read Count Table (Text)"></a>
		</tr></tr>

		<tr><td>&nbsp;</td></tr>
		<tr><td align="center">
		$otu_tables;
		</td></tr>
		<tr><td>&nbsp;</td></tr>

		<tr><td align="center"><h3>Sample Taxonomy Bar Plots</h3></td></tr>
		<tr><td align="center">
		<a href="qiime/data_mc100/qiime2/barplot/index.html"><img src="images/barplot1.png" onmouseover="this.src='images/barplot2.png';" onmouseout="this.src='images/barplot1.png';"></a>
		</td></tr>
		<tr><td>&nbsp;</td></tr>


		<!-- ######################### -->
		<tr>
		<td><a name="ALPHA"><h1 class="bggray left">@.uc(roman($j++)).qq@. Analysis - Alpha Diversity</h1></td></tr>
		<tr><td><table><tr><td>&nbsp;</td><td>
		<p>In ecology, alpha diversity (α-diversity) is the mean species diversity in sites or habitats at a local scale.
		The term was introduced by R. H. Whittaker[1][2] together with the terms beta diversity (β-diversity)
		and gamma diversity (γ-diversity). Whittaker's idea was that the total species diversity in a landscape
		(gamma diversity) is determined by two different things, the mean species diversity in sites or habitats
		at a more local scale (alpha diversity) and the differentiation among those habitats (beta diversity).</p>
		<p><b>References:</b><br>
		<a href="https://esajournals.onlinelibrary.wiley.com/doi/10.2307/1943563">Whittaker, R. H. (1960) Vegetation of the Siskiyou Mountains, Oregon and California. Ecological Monographs, 30, 279–338. doi:10.2307/1943563</a><br>
		<a href="https://onlinelibrary.wiley.com/doi/abs/10.2307/1218190">Whittaker, R. H. (1972). Evolution and Measurement of Species Diversity. Taxon, 21, 213-251. doi:10.2307/1218190</a>
		</p>
		</td></tr></table>
		</td></tr>


		<tr><td>&nbsp</td></tr>
		<tr><td><h3>Boxplot of Alpha-diversity indices</h3></td></tr>
		<tr><td>
		<p>The two main factors taken into account when measuring diversity are richness and evenness.
		Richness is a measure of the number of different kinds of organisms present in a particular area.
		Evenness compares the similarity of the population size of each of the species present. There are
		many different ways to measure the richness and evenness. These measurements are called "estimators" or "indices".

		Below is a diversity of 3 commonly used indices showing the values for  all the samples (dots) and in groups (boxes).
		</p>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/alpha_diversity_plots.svg"><img src="R/alpha_diversity_plots.png"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/alpha_diversity_plots.svg"><input type="button" class="downloadbutton" value="Download alpha diversity box plots in SVG"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/alpha_diversity_plots.png"><input type="button" class="downloadbutton" value="Download alpha diversity box plots in PNG"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/alpha_diversity_plots.pdf"><input type="button" class="downloadbutton" value="Download alpha diversity box plots in PDF"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td><h3>Alpha diversity analysis by rarefaction</h3></td></tr>
		<tr><td>
		<p>Diversity measures are affected by the sampling depth. Rarefaction is a technique to assess species richness from the results of sampling. Rarefaction allows
		the calculation of species richness for a given number of individual samples, based on the construction
		of so-called rarefaction curves. This curve is a plot of the number of species as a function of the
		number of samples. Rarefaction curves generally grow rapidly at first, as the most common species are found,
		but the curves plateau as only the rarest species remain to be sampled.</p>
		<p><b>References:</b><br>
		<a href="https://www.frontiersin.org/articles/10.3389/fmicb.2019.02407/full">Willis AD. Rarefaction, Alpha Diversity, and Statistics. Front Microbiol. 2019 Oct 23;10:2407. doi: 10.3389/fmicb.2019.02407. PMID: 31708888; PMCID: PMC6819366.</a><br>
		</p>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="qiime/data_mc100/qiime2/alpha_rare/index.html">
		<img src="images/alpha1.png" onmouseover="this.src='images/alpha2.png';" onmouseout="this.src='images/alpha1.png';"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>


		<!-- ######################### -->
		<tr>
		<td><a name="BETA"><h1 class="bggray left">@.uc(roman($j++)).qq@. Analysis - Beta Diversity</h1></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td><h3>NMDS and PCoA Plots</h3></td></tr>

		<tr><td>
		<p>Beta diversity compares the similarity (or dissimilarity) of microbial profiles between different
		groups of samples. There are many different similarity/dissimilarity metrics.
		In general, they can be quantitative (using sequence abundance, e.g., Bray-Curtis or weighted UniFrac)
		or binary (considering only presence-absence of sequences, e.g., binary Jaccard or unweighted UniFrac).
		They can be even based on phylogeny (e.g., UniFrac metrics) or not (non-UniFrac metrics, such as Bray-Curtis, etc.).</p>

		<p>For microbiome studies, species profiles of samples can be compared with the Bray-Curtis dissimilarity,
		which is based on the count data type. The pair-wise Bray-Curtis dissimilarity matrix of all samples can then be
		subject to either multi-dimentional scaling (MDS, also known as PCoA) or non-metric MDS (NMDS). </p>

		<p>MDS/PCoA is a
		scaling or ordination method that starts with a matrix of similarities or dissimilarities
		between a set of samples and aims to produce a low-dimensional graphical plot of the data
		in such a way that distances between points in the plot are close to original dissimilarities.</p>

		<p>NMDS is similar to MDS, however it does not use the dissimilarities data, instead it converts them into
		the ranks and use these ranks in the calculation. </p>

		<p>In our beta diversity analysis, Bray-Curtis dissimilarity matrix was first calculated and then plotted by the PCoA and
		NMDS seperately. The results are shown below:</p>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/NMDS_bray.svg"><img src="R/NMDS_bray.png"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/NMDS_bray.svg">
		<input type="button" class="downloadbutton" value="Download SVG"></a>
		<a href="R/NMDS_bray.pdf">
		<input type="button" class="downloadbutton" value="Download PDF"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/PCoA_bray.svg"><img src="R/PCoA_bray.png"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/PCoA_bray.svg">
		<input type="button" class="downloadbutton" value="Download SVG"></a>
		<a href="R/PCoA_bray.pdf">
		<input type="button" class="downloadbutton" value="Download PDF"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td>
		<p>The above PCoA and NMDS plots are based on count data. The count data can also be transformed into centered log ratio (CLR)
		for each species. The CLR data is no longer count data and cannot be used in Bray-Curtis dissimilarity calculation. Instead
		CLR can be compared with Euclidean distances. When CLR data are compared by Euclidean distance, the distance is also called
		Aitchison distance.</p>

		<p>Below are the NMDS and PCoA plots of the Aitchison distances of the samples:</p>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/NMDS_clr_euclidean.svg"><img src="R/NMDS_clr_euclidean.png"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/NMDS_clr_euclidean.svg">
		<input type="button" class="downloadbutton" value="Download SVG"></a>
		<a href="R/NMDS_clr_euclidean.pdf">
		<input type="button" class="downloadbutton" value="Download PDF"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/PCoA_clr_euclidean.svg"><img src="R/PCoA_clr_euclidean.png"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/PCoA_clr_euclidean.svg">
		<input type="button" class="downloadbutton" value="Download SVG"></a>
		<a href="R/PCoA_clr_euclidean.pdf">
		<input type="button" class="downloadbutton" value="Download PDF"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td><h3>Interative 3D PCoA Plots - Bray-Curtis Dissimilarity </h3></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="qiime/data_mc100/qiime2/braycurtis_emperor_pcoa/index.html">
		<img src="images/emperor1.png" onmouseover="this.src='images/emperor2.png';" onmouseout="this.src='images/emperor1.png';"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td><h3>Interative 3D PCoA Plots - Euclidean Distance </h3></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="qiime/data_mc100/qiime2/euclidean_emperor_pcoa/index.html">
		<img src="images/emperor1.png" onmouseover="this.src='images/emperor2.png';" onmouseout="this.src='images/emperor1.png';"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td><h3>Interative 3D PCoA Plots - Correlation Coefficients </h3></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="qiime/data_mc100/qiime2/correlation_emperor_pcoa/index.html">
		<img src="images/emperor1.png" onmouseover="this.src='images/emperor2.png';" onmouseout="this.src='images/emperor1.png';"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>

		<tr><td>&nbsp</td></tr>
		<!-- ######################### -->

		<tr>
		<td><a name="COMP"><h1 class="bggray left">@.uc(roman($j++)).qq@. Analysis - Differential Abundance</h1></td></tr>
		<tr><td>
		<p>16S rRNA next generation sequencing (NGS) generates a fixed number of reads that reflect the proportion of different species in a sample, i.e., the relative abundance of species, instead of the absolute abundance. In Mathematics, measurements involving probabilities, proportions, percentages, and ppm can all be thought of as compositional data. This makes the microbiome read count data “compositional” (Gloor <i>et al</i>, 2017). In general, compositional data represent parts of a whole which only carry relative information (http://www.compositionaldata.com/). </p>
		<p>The problem of microbiome data being compositional arises when comparing two groups of samples for identifying “differentially abundant” species. A species with the same absolute abundance between two conditions, its relative abundances in the two conditions (e.g., percent abundance) can become different if the relative abundance of other species change greatly. This problem can lead to incorrect conclusion in terms of differential abundance for microbial species in the samples. </p>
		<p>When studying differential abundance (DA), the current better approach is to transform the read count data into log ratio data. The ratios are calculated between read counts of all species in a sample to a “reference” count (e.g., mean read count of the sample). The log ratio data allow the detection of DA species without being affected by percentage bias mentioned above</p>
		<p>In this report, a compositional DA analysis tool “ANCOM” (analysis of composition of microbiomes) was used. ANCOM transforms the count data into log-ratios and thus is more suitable for comparing the composition of microbiomes in two or more populations</p>
		</td></tr>
		<tr><td>
		<p>References:</p>
		<p>Gloor GB, Macklaim JM, Pawlowsky-Glahn V, Egozcue JJ. Microbiome Datasets Are Compositional: And This Is Not Optional. Front Microbiol.
		2017 Nov 15;8:2224. doi: 10.3389/fmicb.2017.02224. PMID: 29187837; PMCID: PMC5695134.</p>
		<p>Mandal S, Van Treuren W, White RA, Eggesbø M, Knight R, Peddada SD. Analysis of composition of
		microbiomes: a novel method for studying microbial composition. Microb Ecol Health Dis.
		2015 May 29;26:27663. doi: 10.3402/mehd.v26.27663. PMID: 26028277; PMCID: PMC4450248.</p>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td><h3>ANCOM differetial abundance analysis</h3></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="qiime/data_mc100/qiime2/ancom/index.html">
		<input type="button" class="downloadbutton" value="View ANCOM Differential Abundance Analysis"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>
		<tr><td>&nbsp</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td><h3>LEfSe - Linear Discriminant Analysis Effect Size</h3></td></tr>
		<tr><td>
		<p>
		LEfSe (Linear Discriminant Analysis Effect Size) is an alternative method to find "organisms, genes, or
		pathways that consistently explain the differences between two or more microbial communities" (Segata <i>et al.</i>, 2011).
		Specifically, LEfSe uses rank-based Kruskal-Wallis (KW) sum-rank test to detect features with significant
		differential (relative) abundance with respect to the class of interest. Since it is rank-based, instead of proportional based,
		the differential species identified among the comparison groups is less biased (than percent abundance based).
		</p>

		<p>Reference:</p>
		<p>Segata N, Izard J, Waldron L, Gevers D, Miropolsky L, Garrett WS, Huttenhower C. Metagenomic biomarker discovery and explanation. Genome Biol. 2011 Jun 24;12(6):R60. doi: 10.1186/gb-2011-12-6-r60. PMID: 21702898; PMCID: PMC3218848.</p>
		</td></tr>


		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="lefse/lefse.plot.png">
		<img src="lefse/lefse.plot.png"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
			<table><tr><td>
			<a href="lefse/lefse.plot.svg">
			<input type="button" class="downloadbutton" value="Download image in SVG"></a>
			</td><td>
			<a href="lefse/lefse.plot.pdf">
			<input type="button" class="downloadbutton" value="Download image in PDF"></a>
			</td></tr></table>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="lefse/lefse.cladogram.species.png">
		<img src="lefse/lefse.cladogram.species.png"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
			<table><tr><td>
			<a href="lefse/lefse.cladogram.species.svg">
			<input type="button" class="downloadbutton" value="Download image in SVG"></a>
			</td><td>
			<a href="lefse/lefse.cladogram.species.pdf">
			<input type="button" class="downloadbutton" value="Download image in PDF"></a>
			</td></tr></table>
		</td></tr>
		<tr><td>&nbsp</td></tr>

		<tr><td align="center">
		<a href="lefse/all_diff_features/">
		<input type="button" class="downloadbutton" value="View all LEfSe differential species plots"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="lefse/">
		<input type="button" class="downloadbutton" value="View all LEfSe results"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>

		<tr><td>&nbsp</td></tr>

		<!-- ######################### -->

		<tr>
		<td><a name="HEAT"><h1 class="bggray left">@.uc(roman($j++)).qq@. Analysis - Heatmap Profile</h1></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td><h3>Species vs sample abundance heatmap</h3></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="qiime/data_mc100/qiime2/heatmap/index.html">
		<img src="images/heatmap1.png" onmouseover="this.src='images/heatmap2.png';" onmouseout="this.src='images/heatmap1.png';"></a>
		</td></tr>
		<tr><td>&nbsp</td></tr>



		<tr><td>&nbsp</td></tr>
		<!-- ######################### -->

		<tr>
		<td><a name="NET"><h1 class="bggray left">@.uc(roman($j++)).qq@. Analysis - Network Association</h1></td></tr>
		<tr><td>
		<p>To analyze the co-occurrence or co-exclusion between microbial species among different samples, network correlation
		analysis tools are ususally used for this purpose. However, microbiome count data are compositional. If count data are normalized to the total number of counts in the
		sample, the data become not independent and traditional statistical metrics (e.g., correlation) for the detection
		of specie-species relationships can lead to spurious results. In addition, sequencing-based studies typically
		measure hundreds of OTUs (species) on few samples; thus, inference of OTU-OTU association networks is severely
		under-powered. @;

		if(-e "$fld/R/network_mb.png"){
		$html.=qq@Here we use SPIEC-EASI (<b>SP</b>arse <b>I</b>nvers<b>E</b> <b>C</b>ovariance Estimation
		for <b>E</b>cological <b>A</b>ssociation <b>I</b>nference), a statistical method for the inference of microbial
		ecological networks from amplicon sequencing datasets that addresses both of these issues (Kurtz <i>et al.</i>, 2015).
		SPIEC-EASI combines data transformations developed for compositional data analysis with a graphical model
		inference framework that assumes the underlying ecological association network is sparse. SPIEC-EASI provides
		two algorithms for network inferencing – 1) Meinshausen-Bühlmann's neighborhood selection (MB method) and inverse covariance selection
		(GLASSO method, i.e., grahical least absolute shrinkage and selection operator). This is fundamentally distinct from SparCC, which essentially estimate pairwise correlations. In addition
		to these two methods, we provide the results of a third method - SparCC (Sparse Correlations for Compositional data)(Friedman & Alm 2012), which
		is also a method for inferring correlations from compositional data. SparCC estimates the linear Pearson correlations between
		the log-transformed components.
		</p>
		<p>References:</p>
		<p>Kurtz ZD, Müller CL, Miraldi ER, Littman DR, Blaser MJ, Bonneau RA. Sparse and compositionally robust inference of microbial ecological networks. PLoS Comput Biol. 2015 May 7;11(5):e1004226. doi: 10.1371/journal.pcbi.1004226. PMID: 25950956; PMCID: PMC4423992.</p>
		<p>Friedman J, Alm EJ. Inferring correlation networks from genomic survey data. PLoS Comput Biol. 2012;8(9):e1002687. doi: 10.1371/journal.pcbi.1002687. Epub 2012 Sep 20. PMID: 23028285; PMCID: PMC3447976.</p>
		</td></tr>
		@;

		}else{

		$html.=qq@We provide the network association result with SparCC (Sparse Correlations for Compositional data)(Friedman & Alm 2012), which
		is a method for inferring correlations from compositional data. SparCC estimates the linear Pearson correlations between
		the log-transformed components.
		</p>
		<p>References:</p>
		<p>Friedman J, Alm EJ. Inferring correlation networks from genomic survey data. PLoS Comput Biol. 2012;8(9):e1002687. doi: 10.1371/journal.pcbi.1002687. Epub 2012 Sep 20. PMID: 23028285; PMCID: PMC3447976.</p>
		</td></tr>
		@;
		}

		if(-e "$fld/R/network_mb.png"){
		$html.=qq@
		<tr><td>&nbsp</td></tr>
		<tr><td><h3>SPIEC-EASI network inference by neighborhood selection (MB method)</h3></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/network_mb.svg">
		<img src="R/network_mb.png"><br>
		<img src="R/network_mb_legend.png">
		</a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/network_mb.svg">
		<input type="button" class="downloadbutton" value="Download SVG"></a>
		<a href="R/network_mb.pdf">
		<input type="button" class="downloadbutton" value="Download PDF"></a><br>
		<a href="R/network_mb_legend.svg">
		<input type="button" class="downloadbutton" value="Download Legend SVG"></a>
		<a href="R/network_mb_legend.pdf">
		<input type="button" class="downloadbutton" value="Download Legend PDF"></a>
		</td></tr>


		<tr><td>&nbsp</td></tr>
		<tr><td><h3>SPIEC-EASI network inference by inverse covariance selection (GLASSO method)</h3></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/network_glasso.svg">
		<img src="R/network_glasso.png"><br>
		<img src="R/network_glasso_legend.png">
		</a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/network_glasso.svg">
		<input type="button" class="downloadbutton" value="Download SVG"></a>
		<a href="R/network_glasso.pdf">
		<input type="button" class="downloadbutton" value="Download PDF"></a><br>
		<a href="R/network_glasso_legend.svg">
		<input type="button" class="downloadbutton" value="Download Legend SVG"></a>
		<a href="R/network_glasso_legend.pdf">
		<input type="button" class="downloadbutton" value="Download Legend PDF"></a>
		</td></tr>
		@
		}

		$html.=qq@
		<tr><td>&nbsp</td></tr>
		<tr><td><h3>Association network inference by SparCC</h3></td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/network_sparcc.svg">
		<img src="R/network_sparcc.png"><br>
		<img src="R/network_sparcc_legend.png">
		</a>
		</td></tr>

		<tr><td>&nbsp</td></tr>
		<tr><td align="center">
		<a href="R/network_sparcc.svg">
		<input type="button" class="downloadbutton" value="Download SVG"></a>
		<a href="R/network_sparcc.pdf">
		<input type="button" class="downloadbutton" value="Download PDF"></a><br
		<a href="R/network_sparcc_legend.svg">
		<input type="button" class="downloadbutton" value="Download Legend SVG"></a>
		<a href="R/network_sparcc_legend.pdf">
		<input type="button" class="downloadbutton" value="Download Legend PDF"></a>
		</td></tr>

		<tr><td>&nbsp</td></tr>



		</td></tr>
		<tr><td>&nbsp</td></tr>
		<!-- ######################### -->

		</table>
		</td></tr>
		</table>
	</td></tr>
@;
return $html;
}
#######################################
sub insert_footer(){
my $year=`date +'%Y'`;
return qq@
	<tr><td><hr></td></tr>
	<tr><td align="center">Copyright FOMC $year</td></tr>
	</table>
</td></tr>
</table>
</div>
</body></html>
@;
}
#######################################



