Skip to content

Commit

Permalink
show GC content in summary table
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed Dec 7, 2017
1 parent 58c8636 commit a50468c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/htmlreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void HtmlReporter::printSummary(ofstream& ofs, FilterResult* result, Stats* preS
if(preStats2)
pre_q30_bases += preStats2->getQ30();

long pre_total_gc = preStats1->getGCNumber();
if(preStats2)
pre_total_gc += preStats2->getGCNumber();

long post_total_reads = postStats1->getReads();
if(postStats2)
post_total_reads += postStats2->getReads();
Expand All @@ -74,6 +78,10 @@ void HtmlReporter::printSummary(ofstream& ofs, FilterResult* result, Stats* preS
if(postStats2)
post_q30_bases += postStats2->getQ30();

long post_total_gc = postStats1->getGCNumber();
if(postStats2)
post_total_gc += postStats2->getGCNumber();

string sequencingInfo = mOptions->isPaired()?"paired end":"single end";
if(mOptions->isPaired()) {
sequencingInfo += " (" + to_string(preStats1->getCycles()) + " cycles + " + to_string(preStats2->getCycles()) + " cycles)";
Expand All @@ -98,6 +106,7 @@ void HtmlReporter::printSummary(ofstream& ofs, FilterResult* result, Stats* preS
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 class='subsection_title'>After filtering</div>\n";
Expand All @@ -106,6 +115,7 @@ void HtmlReporter::printSummary(ofstream& ofs, FilterResult* result, Stats* preS
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";

if(result) {
Expand Down
14 changes: 12 additions & 2 deletions src/jsonreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ void JsonReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
if(preStats2)
pre_q30_bases += preStats2->getQ30();

long pre_total_gc = preStats1->getGCNumber();
if(preStats2)
pre_total_gc += preStats2->getGCNumber();

long post_total_reads = postStats1->getReads();
if(postStats2)
post_total_reads += postStats2->getReads();
Expand All @@ -46,6 +50,10 @@ void JsonReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
if(postStats2)
post_q30_bases += postStats2->getQ30();

long post_total_gc = postStats1->getGCNumber();
if(postStats2)
post_total_gc += postStats2->getGCNumber();

// summary
ofs << "\t" << "\"summary\": {" << endl;

Expand All @@ -55,7 +63,8 @@ void JsonReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
ofs << "\t\t\t" << "\"q20_bases\":" << pre_q20_bases << "," << endl;
ofs << "\t\t\t" << "\"q30_bases\":" << pre_q30_bases << "," << endl;
ofs << "\t\t\t" << "\"q20_rate\":" << (pre_total_bases == 0?0.0:(double)pre_q20_bases / (double)pre_total_bases) << "," << endl;
ofs << "\t\t\t" << "\"q30_rate\":" << (pre_total_bases == 0?0.0:(double)pre_q30_bases / (double)pre_total_bases) << endl;
ofs << "\t\t\t" << "\"q30_rate\":" << (pre_total_bases == 0?0.0:(double)pre_q30_bases / (double)pre_total_bases) << "," << endl;
ofs << "\t\t\t" << "\"gc_content\":" << (pre_total_bases == 0?0.0:(double)pre_total_gc / (double)pre_total_bases) << endl;
ofs << "\t\t" << "}," << endl;

ofs << "\t\t" << "\"after_filtering\": {" << endl;
Expand All @@ -64,7 +73,8 @@ void JsonReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
ofs << "\t\t\t" << "\"q20_bases\":" << post_q20_bases << "," << endl;
ofs << "\t\t\t" << "\"q30_bases\":" << post_q30_bases << "," << endl;
ofs << "\t\t\t" << "\"q20_rate\":" << (post_total_bases == 0?0.0:(double)post_q20_bases / (double)post_total_bases) << "," << endl;
ofs << "\t\t\t" << "\"q30_rate\":" << (post_total_bases == 0?0.0:(double)post_q30_bases / (double)post_total_bases) << endl;
ofs << "\t\t\t" << "\"q30_rate\":" << (post_total_bases == 0?0.0:(double)post_q30_bases / (double)post_total_bases) << "," << endl;
ofs << "\t\t\t" << "\"gc_content\":" << (post_total_bases == 0?0.0:(double)post_total_gc / (double)post_total_bases) << endl;
ofs << "\t\t" << "}" << endl;

ofs << "\t" << "}," << endl;
Expand Down
10 changes: 8 additions & 2 deletions src/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ long Stats::getQ30() {
return mQ30Total;
}

long Stats::getGCNumber() {
if(!summarized)
summarize();
return mBaseContents['G' & 0x07] + mBaseContents['C' & 0x07];
}

void Stats::print() {
if(!summarized) {
summarize();
Expand Down Expand Up @@ -474,8 +480,8 @@ void Stats::reportHtmlKMER(ofstream& ofs, string filteringType, string readName)
string title = "";

ofs << "<div class='subsection_title'>" + subsection + "</div>\n";
ofs << "<div class='sub_section_tips'>Darker background means higher counts. The count will be shown on mouse over.</div>\n";
ofs << "<table class='kmer_table'>\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>";
ofs << "<td></td>";
// the heading row
Expand Down
1 change: 1 addition & 0 deletions src/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Stats{
long getBases();
long getQ20();
long getQ30();
long getGCNumber();
// by default the qualified qual score is Q20 ('5')
void statRead(Read* r, int& lowQualNum, int& nBaseNum, char qualifiedQual = '5');

Expand Down

0 comments on commit a50468c

Please sign in to comment.