Skip to content

Commit

Permalink
report mean read length
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed Jun 26, 2018
1 parent f0deacf commit 06548fd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/htmlreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ void HtmlReporter::printSummary(ofstream& ofs, FilterResult* result, Stats* preS
ofs << "<table class='summary_table'>\n";
outputRow(ofs, "fastp version:", string(FASTP_VER)+ " (<a href='https://github.com/OpenGene/fastp'>https://github.com/OpenGene/fastp</a>)");
outputRow(ofs, "sequencing:", sequencingInfo);

// report read length change
if(mOptions->isPaired()) {
outputRow(ofs, "mean length before filtering:", to_string(preStats1->getMeanLength()) + "bp, " + to_string(preStats2->getMeanLength()) + "bp");
outputRow(ofs, "mean length after filtering:", to_string(postStats1->getMeanLength()) + "bp, " + to_string(postStats2->getMeanLength()) + "bp");
} else {
outputRow(ofs, "mean length before filtering:", to_string(preStats1->getMeanLength()) + "bp");
outputRow(ofs, "mean length after filtering:", to_string(postStats1->getMeanLength()) + "bp");
}

if(mOptions->duplicate.enabled) {
string dupStr = to_string(mDupRate*100) + "%";
if(!mOptions->isPaired())
Expand Down Expand Up @@ -367,7 +377,7 @@ void HtmlReporter::printCSS(ofstream& ofs){
ofs << "<style type=\"text/css\">" << endl;
ofs << "td {border:1px solid #dddddd;padding:5px;font-size:12px;}" << endl;
ofs << "table {border:1px solid #999999;padding:2x;border-collapse:collapse; width:800px}" << endl;
ofs << ".col1 {width:200px; font-weight:bold;}" << endl;
ofs << ".col1 {width:240px; font-weight:bold;}" << endl;
ofs << ".adapter_col {width:500px; font-size:10px;}" << endl;
ofs << "img {padding:30px;}" << endl;
ofs << "#menu {font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;}" << endl;
Expand Down
6 changes: 6 additions & 0 deletions src/jsonreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ void JsonReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
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" << "\"read1_mean_length\":" << preStats1->getMeanLength() << "," << endl;
if(mOptions->isPaired())
ofs << "\t\t\t" << "\"read2_mean_length\":" << preStats2->getMeanLength() << "," << 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;

Expand All @@ -86,6 +89,9 @@ void JsonReporter::report(FilterResult* result, Stats* preStats1, Stats* postSta
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" << "\"read1_mean_length\":" << postStats1->getMeanLength() << "," << endl;
if(mOptions->isPaired())
ofs << "\t\t\t" << "\"read2_mean_length\":" << postStats2->getMeanLength() << "," << 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" << "}";

Expand Down
11 changes: 11 additions & 0 deletions src/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Stats::Stats(Options* opt, bool isRead2, int guessedCycles, int bufferMargin){
mOptions = opt;
mIsRead2 = isRead2;
mReads = 0;
mLengthSum = 0;

mEvaluatedSeqLen = mOptions->seqLen1;
if(mIsRead2)
Expand Down Expand Up @@ -214,9 +215,18 @@ void Stats::summarize(bool forced) {
summarized = true;
}

int Stats::getMeanLength() {
if(mReads == 0)
return 0.0;
else
return mLengthSum/mReads;
}

void Stats::statRead(Read* r) {
int len = r->length();

mLengthSum += len;

if(mBufLen < len) {
extendBuffer(max(len + 100, (int)(len * 1.5)));
}
Expand Down Expand Up @@ -888,6 +898,7 @@ Stats* Stats::merge(vector<Stats*>& list) {
int curCycles = list[t]->getCycles();
// merge read number
s->mReads += list[t]->mReads;
s->mLengthSum += list[t]->mLengthSum;

// merge per cycle counting for different bases
for(int i=0; i<8; i++){
Expand Down
2 changes: 2 additions & 0 deletions src/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Stats{
void reportHtmlORA(ofstream& ofs, string filteringType, string readName);
bool isLongRead();
void initOverRepSeq();
int getMeanLength();

public:
static string list2string(double* list, int size);
Expand Down Expand Up @@ -93,6 +94,7 @@ class Stats{
long mKmerMax;
long mKmerMin;
int mKmerBufLen;
int mLengthSum;
};

#endif

0 comments on commit 06548fd

Please sign in to comment.