Skip to content

Commit

Permalink
support hide/show
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed Dec 13, 2017
1 parent 666e5dc commit a53aa21
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
8 changes: 6 additions & 2 deletions src/filterresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,15 @@ void FilterResult::reportHtml(ofstream& ofs, long totalReads, long totalBases) {
}

void FilterResult::reportAdapterHtml(ofstream& ofs, long totalBases) {
ofs << "<div class='subsection_title'>Adapter or bad ligation of read1</div>\n";
ofs << "<div class='subsection_title' onclick=showOrHide('read1_adapters')>Adapter or bad ligation of read1</div>\n";
ofs << "<div id='read1_adapters'>\n";
outputAdaptersHtml(ofs, mAdapter1, totalBases);
ofs << "</div>\n";
if(mOptions->isPaired()) {
ofs << "<div class='subsection_title'>Adapter or bad ligation of read2</div>\n";
ofs << "<div class='subsection_title' onclick=showOrHide('read2_adapters')>Adapter or bad ligation of read2</div>\n";
ofs << "<div id='read2_adapters'>\n";
outputAdaptersHtml(ofs, mAdapter2, totalBases);
ofs << "</div>\n";
}
}

Expand Down
36 changes: 26 additions & 10 deletions src/htmlreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,46 +92,58 @@ void HtmlReporter::printSummary(ofstream& ofs, FilterResult* result, Stats* preS
ofs << endl;
ofs << "<h1 style='text-align:left;'><a href='https://github.com/OpenGene/fastp' target='_blank' style='color:#663355;text-decoration:none;'>" + mOptions->reportTitle + "</a>"<<endl;
ofs << "<div class='section_div'>\n";
ofs << "<div class='section_title'><a name='summary'>Summary</a></div>\n";
ofs << "<div class='section_title' onclick=showOrHide('summary')><a name='summary'>Summary</a></div>\n";
ofs << "<div id='summary'>\n";

ofs << "<div class='subsection_title'>General</div>\n";
ofs << "<div class='subsection_title' onclick=showOrHide('general')>General</div>\n";
ofs << "<div id='general'>\n";
ofs << "<table class='summary_table'>\n";
outputRow(ofs, "fastp version:", FASTP_VER);
outputRow(ofs, "sequencing:", sequencingInfo);
ofs << "</table>\n";
ofs << "</div>\n";

ofs << "<div class='subsection_title'>Before filtering</div>\n";
ofs << "<div class='subsection_title' onclick=showOrHide('before_filtering_summary')>Before filtering</div>\n";
ofs << "<div id='before_filtering_summary'>\n";
ofs << "<table class='summary_table'>\n";
outputRow(ofs, "total reads:", formatNumber(pre_total_reads));
outputRow(ofs, "total bases:", formatNumber(pre_total_bases));
outputRow(ofs, "Q20 bases:", formatNumber(pre_q20_bases) + " (" + getPercents(pre_q20_bases,pre_total_bases) + "%)");
outputRow(ofs, "Q30 bases:", formatNumber(pre_q30_bases) + " (" + getPercents(pre_q30_bases, pre_total_bases) + "%)");
outputRow(ofs, "GC content:", getPercents(pre_total_gc,pre_total_bases) + "%");
ofs << "</table>\n";
ofs << "</div>\n";

ofs << "<div class='subsection_title'>After filtering</div>\n";
ofs << "<div class='subsection_title' onclick=showOrHide('after_filtering_summary')>After filtering</div>\n";
ofs << "<div id='after_filtering_summary'>\n";
ofs << "<table class='summary_table'>\n";
outputRow(ofs, "total reads:", formatNumber(post_total_reads));
outputRow(ofs, "total bases:", formatNumber(post_total_bases));
outputRow(ofs, "Q20 bases:", formatNumber(post_q20_bases) + " (" + getPercents(post_q20_bases, post_total_bases) + "%)");
outputRow(ofs, "Q30 bases:", formatNumber(post_q30_bases) + " (" + getPercents(post_q30_bases, post_total_bases) + "%)");
outputRow(ofs, "GC content:", getPercents(post_total_gc,post_total_bases) + "%");
ofs << "</table>\n";
ofs << "</div>\n";

if(result) {
ofs << "<div class='subsection_title'>Filtering result</div>\n";
ofs << "<div class='subsection_title' onclick=showOrHide('filtering_result')>Filtering result</div>\n";
ofs << "<div id='filtering_result'>\n";
result -> reportHtml(ofs, pre_total_reads, pre_total_bases);
ofs << "</div>\n";
}

ofs << "</div>\n";
ofs << "</div>\n";

if(result && mOptions->adapterCuttingEnabled()) {
ofs << "<div class='section_div'>\n";
ofs << "<div class='section_title'><a name='summary'>Adapters</a></div>\n";
ofs << "<div class='section_title' onclick=showOrHide('adapters')><a name='summary'>Adapters</a></div>\n";
ofs << "<div id='adapters'>\n";

result->reportAdapterHtml(ofs, pre_total_bases);

ofs << "</div>\n";
ofs << "</div>\n";
}
}

Expand All @@ -144,7 +156,8 @@ void HtmlReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
printSummary(ofs, result, preStats1, postStats1, preStats2, postStats2);

ofs << "<div class='section_div'>\n";
ofs << "<div class='section_title'><a name='summary'>Before filtering</a></div>\n";
ofs << "<div class='section_title' onclick=showOrHide('before_filtering')><a name='summary'>Before filtering</a></div>\n";
ofs << "<div id='before_filtering'>\n";

if(preStats1) {
preStats1 -> reportHtml(ofs, "Before filtering", "read1");
Expand All @@ -154,10 +167,12 @@ void HtmlReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
preStats2 -> reportHtml(ofs, "Before filtering", "read2");
}

ofs << "</div>";
ofs << "</div>\n";
ofs << "</div>\n";

ofs << "<div class='section_div'>\n";
ofs << "<div class='section_title'><a name='summary'>After filtering</a></div>\n";
ofs << "<div class='section_title' onclick=showOrHide('after_filtering')><a name='summary'>After filtering</a></div>\n";
ofs << "<div id='after_filtering'>\n";

if(postStats1) {
postStats1 -> reportHtml(ofs, "After filtering", "read1");
Expand All @@ -167,7 +182,8 @@ void HtmlReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
postStats2 -> reportHtml(ofs, "After filtering", "read2");
}

ofs << "</div>";
ofs << "</div>\n";
ofs << "</div>\n";

printFooter(ofs);

Expand Down
22 changes: 15 additions & 7 deletions src/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ void Stats::reportHtmlORA(ofstream& ofs, string filteringType, string readName)
string title = "";

ofs << "<div class='subsection_title'><a title='click to hide/show' onclick=showOrHide('" << divName << "')>" + subsection + "</a></div>\n";
ofs << "<div id='" << divName << "'>\n";
ofs << "<div class='sub_section_tips'>Sampling rate: 1 / " << mOptions->overRepAnalysis.sampling << "</div>\n";
ofs << "<table class='summary_table'>\n";
ofs << "<tr style='font-weight:bold;'><td>overrepresented sequence</td><td>count (% of bases)</td><td>distribution: cycle 1 ~ cycle " << mEvaluatedSeqLen << "</td></tr>"<<endl;
Expand All @@ -572,6 +573,7 @@ void Stats::reportHtmlORA(ofstream& ofs, string filteringType, string readName)
if(found == 0)
ofs << "<tr><td style='text-align:center' colspan='3'>not found</td></tr>" << endl;
ofs << "</table>\n";
ofs << "</div>\n";

// output the JS
ofs << "<script language='javascript'>" << endl;
Expand Down Expand Up @@ -634,7 +636,8 @@ void Stats::reportHtmlKMER(ofstream& ofs, string filteringType, string readName)
divName = replace(divName, ":", "_");
string title = "";

ofs << "<div class='subsection_title'>" + subsection + "</div>\n";
ofs << "<div class='subsection_title'><a title='click to hide/show' onclick=showOrHide('" << divName << "')>" + subsection + "</a></div>\n";
ofs << "<div id='" << divName << "'>\n";
ofs << "<div class='sub_section_tips'>Darker background means larger counts. The count will be shown on mouse over.</div>\n";
ofs << "<table class='kmer_table' style='width:680px;'>\n";
ofs << "<tr>";
Expand All @@ -654,6 +657,7 @@ void Stats::reportHtmlKMER(ofstream& ofs, string filteringType, string readName)
ofs << "</tr>\n";
}
ofs << "</table>\n";
ofs << "</div>\n";
}

string Stats::makeKmerTD(int i, int j) {
Expand Down Expand Up @@ -717,9 +721,11 @@ void Stats::reportHtmlQuality(ofstream& ofs, string filteringType, string readNa
string title = "";

ofs << "<div class='subsection_title'><a title='click to hide/show' onclick=showOrHide('" << divName << "')>" + subsection + "</a></div>\n";
ofs << "<div id='" + divName + "'>\n";
ofs << "<div class='sub_section_tips'>Value of each position will be shown on mouse over.</div>\n";
ofs << "<div class='figure' id='" + divName + "'></div>\n";

ofs << "<div class='figure' id='plot_" + divName + "'></div>\n";
ofs << "</div>\n";

string alphabets[5] = {"A", "T", "C", "G", "mean"};
string colors[5] = {"rgba(128,128,0,1.0)", "rgba(128,0,128,1.0)", "rgba(0,255,0,1.0)", "rgba(0,0,255,1.0)", "rgba(20,20,20,1.0)"};
ofs << "\n<script type=\"text/javascript\">" << endl;
Expand Down Expand Up @@ -773,7 +779,7 @@ void Stats::reportHtmlQuality(ofstream& ofs, string filteringType, string readNa
json_str += ",type:'log'";
}
json_str += "}, yaxis:{title:'quality'}};\n";
json_str += "Plotly.newPlot('" + divName + "', data, layout);\n";
json_str += "Plotly.newPlot('plot_" + divName + "', data, layout);\n";

ofs << json_str;
ofs << "</script>" << endl;
Expand All @@ -790,9 +796,11 @@ void Stats::reportHtmlContents(ofstream& ofs, string filteringType, string readN
string title = "";

ofs << "<div class='subsection_title'><a title='click to hide/show' onclick=showOrHide('" << divName << "')>" + subsection + "</a></div>\n";
ofs << "<div id='" + divName + "'>\n";
ofs << "<div class='sub_section_tips'>Value of each position will be shown on mouse over.</div>\n";
ofs << "<div class='figure' id='" + divName + "'></div>\n";

ofs << "<div class='figure' id='plot_" + divName + "'></div>\n";
ofs << "</div>\n";

string alphabets[6] = {"A", "T", "C", "G", "N", "GC"};
string colors[6] = {"rgba(128,128,0,1.0)", "rgba(128,0,128,1.0)", "rgba(0,255,0,1.0)", "rgba(0,0,255,1.0)", "rgba(255, 0, 0, 1.0)", "rgba(20,20,20,1.0)"};
ofs << "\n<script type=\"text/javascript\">" << endl;
Expand Down Expand Up @@ -858,7 +866,7 @@ void Stats::reportHtmlContents(ofstream& ofs, string filteringType, string readN
json_str += ",type:'log'";
}
json_str += "}, yaxis:{title:'base content ratios'}};\n";
json_str += "Plotly.newPlot('" + divName + "', data, layout);\n";
json_str += "Plotly.newPlot('plot_" + divName + "', data, layout);\n";

ofs << json_str;
ofs << "</script>" << endl;
Expand Down

0 comments on commit a53aa21

Please sign in to comment.