Commit dcdeca66 authored by Mikaël Salson's avatar Mikaël 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 "tools.h"
size_t VirtualReadStorage::getMaxNbReadsStored() const{
return maxNbStored;
......@@ -151,6 +152,10 @@ void BinReadStorage::setLabel(string &label) {
this->label = label;
}
void BinReadStorage::out_average_scores(ostream &out) {
output_label_average(out, getLabel(), getNbScores(), getAverageScore());
}
size_t BinReadStorage::scoreToBin(float score) {
assert(score >= 0);
if (score > max_score)
......
......@@ -3,6 +3,7 @@
#include "read_score.h"
#include <list>
#include <iostream>
using namespace std;
/**
......@@ -167,6 +168,8 @@ public:
*/
void setLabel(string &label);
void out_average_scores(ostream &out);
private:
/**
* @return the bin a sequence of the given score must lie.
......@@ -181,4 +184,5 @@ public:
friend void testBinReadStorage();
};
#endif
#include "stats.h"
#include "tools.h"
Stats::Stats()
{
......@@ -24,17 +25,6 @@ float Stats::getAverage()
ostream &operator<<(ostream &out, Stats &stats)
{
out << " ";
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 << "-" ;
output_label_average(out, stats.label, stats.nb, stats.getAverage());
return out;
}
......@@ -256,3 +256,18 @@ double nChoosek(unsigned n, unsigned 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 @@
#include <sstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cassert>
#include "fasta.h"
......@@ -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);
/***
Outputs
***/
void output_label_average(ostream &out, string label, long long int nb, double average);
//////////////////////////////////////////////////
// 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