Skip to content

Commit

Permalink
Show base content percentage in base content graph
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed Dec 7, 2017
1 parent fb3fae8 commit 58c8636
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Stats::Stats(int guessedCycles, int bufferMargin){
for(int i=0; i<8; i++){
mQ20Bases[i] = 0;
mQ30Bases[i] = 0;
mBaseContents[i] = 0;

mCycleQ30Bases[i] = new long[mBufLen];
memset(mCycleQ30Bases[i], 0, sizeof(long) * mBufLen);
Expand Down Expand Up @@ -135,16 +136,18 @@ void Stats::summarize(bool forced) {
if(mCycleTotalBase[mBufLen-1]>0)
mCycles = mBufLen;

// Q20 Q30
// Q20, Q30, base content
for(int i=0; i<8; i++) {
for(int c=0; c<mCycles; c++) {
mQ20Bases[i] += mCycleQ20Bases[i][c];
mQ30Bases[i] += mCycleQ30Bases[i][c];
mBaseContents[i] += mCycleBaseContents[i][c];
}
mQ20Total += mQ20Bases[i];
mQ30Total += mQ30Bases[i];
}


// quality curve for mean qual
double* meanQualCurve = new double[mCycles];
memset(meanQualCurve, 0, sizeof(double)*mCycles);
Expand Down Expand Up @@ -663,10 +666,22 @@ void Stats::reportHtmlContents(ofstream& ofs, string filteringType, string readN
// four bases
for (int b = 0; b<6; b++) {
string base = alphabets[b];
long count = 0;
if(base.size()==1) {
char b = base[0] & 0x07;
count = mBaseContents[b];
} else {
count = mBaseContents['G' & 0x07] + mBaseContents['C' & 0x07] ;
}
string percentage = to_string((double)count * 100.0 / mBases);
if(percentage.length()>5)
percentage = percentage.substr(0,5);
string name = base + "(" + percentage + "%)";

json_str += "{";
json_str += "x:[" + list2string(x, total) + "],";
json_str += "y:[" + list2string(mContentCurves[base], total, x) + "],";
json_str += "name: '" + base + "',";
json_str += "name: '" + name + "',";
json_str += "mode:'lines',";
json_str += "line:{color:'" + colors[b] + "', width:1}\n";
json_str += "},";
Expand Down
1 change: 1 addition & 0 deletions src/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Stats{
long mBases;
long mQ20Bases[8];
long mQ30Bases[8];
long mBaseContents[8];
long mQ20Total;
long mQ30Total;
bool summarized;
Expand Down

0 comments on commit 58c8636

Please sign in to comment.