Commit dcdeca66 authored by Mikael Salson's avatar Mikael Salson

tools: Method for displaying average stats.

The function by @magiraud in Stats is moved in tools to be shared by both Stats and BinReadStorage
parent 2918a5e9
#include "read_storage.h" #include "read_storage.h"
#include "tools.h"
size_t VirtualReadStorage::getMaxNbReadsStored() const{ size_t VirtualReadStorage::getMaxNbReadsStored() const{
return maxNbStored; return maxNbStored;
...@@ -151,6 +152,10 @@ void BinReadStorage::setLabel(string &label) { ...@@ -151,6 +152,10 @@ void BinReadStorage::setLabel(string &label) {
this->label = label; this->label = label;
} }
void BinReadStorage::out_average_scores(ostream &out) {
output_label_average(out, getLabel(), getNbScores(), getAverageScore());
}
size_t BinReadStorage::scoreToBin(float score) { size_t BinReadStorage::scoreToBin(float score) {
assert(score >= 0); assert(score >= 0);
if (score > max_score) if (score > max_score)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "read_score.h" #include "read_score.h"
#include <list> #include <list>
#include <iostream>
using namespace std; using namespace std;
/** /**
...@@ -167,6 +168,8 @@ public: ...@@ -167,6 +168,8 @@ public:
*/ */
void setLabel(string &label); void setLabel(string &label);
void out_average_scores(ostream &out);
private: private:
/** /**
* @return the bin a sequence of the given score must lie. * @return the bin a sequence of the given score must lie.
...@@ -181,4 +184,5 @@ public: ...@@ -181,4 +184,5 @@ public:
friend void testBinReadStorage(); friend void testBinReadStorage();
}; };
#endif #endif
#include "stats.h" #include "stats.h"
#include "tools.h"
Stats::Stats() Stats::Stats()
{ {
...@@ -24,17 +25,6 @@ float Stats::getAverage() ...@@ -24,17 +25,6 @@ float Stats::getAverage()
ostream &operator<<(ostream &out, Stats &stats) ostream &operator<<(ostream &out, Stats &stats)
{ {
out << " "; output_label_average(out, stats.label, stats.nb, stats.getAverage());
if (stats.label.size())
out << left << setw(18) << stats.label << "->" ;
out << right << setw(9) << stats.nb ;
out << " " << setw(5) ;
if (stats.nb)
out << fixed << setprecision(1) << stats.getAverage() ;
else
out << "-" ;
return out; return out;
} }
...@@ -256,3 +256,18 @@ double nChoosek(unsigned n, unsigned k) ...@@ -256,3 +256,18 @@ double nChoosek(unsigned n, unsigned k)
} }
return nChoosek_stored[n][k]; return nChoosek_stored[n][k];
} }
void output_label_average(ostream &out, string label, long long int nb, double average)
{
out << " ";
if (label.size())
out << left << setw(18) << label << "->" ;
out << right << setw(9) << nb ;
out << " " << setw(5) ;
if (nb)
out << fixed << setprecision(1) << average ;
else
out << "-" ;
}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <iomanip>
#include <string> #include <string>
#include <cassert> #include <cassert>
#include "fasta.h" #include "fasta.h"
...@@ -165,6 +166,13 @@ const Sequence NULL_SEQUENCE = create_sequence("", "", "NULL", ""); ...@@ -165,6 +166,13 @@ const Sequence NULL_SEQUENCE = create_sequence("", "", "NULL", "");
bool operator==(const Sequence &s1, const Sequence &s2); bool operator==(const Sequence &s1, const Sequence &s2);
bool operator!=(const Sequence &s1, const Sequence &s2); bool operator!=(const Sequence &s1, const Sequence &s2);
/***
Outputs
***/
void output_label_average(ostream &out, string label, long long int nb, double average);
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Template code // Template code
////////////////////////////////////////////////// //////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment