Commit 5bf47aae authored by Mikaël Salson's avatar Mikaël Salson Committed by Mathieu Giraud
Browse files

core/read_storage, core/window: Average read length

The average read length was obtained through getAverageScore() which is
not very robust as nothing guarantees the score to be the read length.
There is now a method in ReadStorage to get the average read length
which can be called from the outside.
parent aaa970f2
......@@ -17,6 +17,7 @@ BinReadStorage::BinReadStorage()
nb_inserted(0), nb_stored(0), smallest_bin_not_empty(~0),label() {}
void BinReadStorage::init(size_t nb_bins, size_t max_score, const VirtualReadScore *vrs, bool no_list) {
this->all_read_lengths = 0;
this->nb_bins = nb_bins;
this->max_score = max_score;
if (no_list)
......@@ -61,6 +62,7 @@ void BinReadStorage::add(Sequence &s) {
float score = scorer->getScore(s);
size_t bin = scoreToBin(score);
addScore(bin, score);
all_read_lengths += s.sequence.length();
if (nb_stored < getMaxNbReadsStored()) {
bins[bin].push_back(s);
nb_stored++;
......@@ -99,6 +101,10 @@ double BinReadStorage::getAverageScoreByScore(float score) {
return getAverageScore(scoreToBin(score));
}
double BinReadStorage::getAverageLength() const{
return all_read_lengths *1. / getNbScores();
}
double BinReadStorage::getAverageScore(size_t bin) {
return getScore(bin) / getNbScores(bin);
}
......
......@@ -14,7 +14,7 @@ class VirtualReadStorage {
protected:
size_t maxNbStored;
const VirtualReadScore *scorer;
int64_t all_read_lengths;
public:
virtual ~VirtualReadStorage() {}
......@@ -31,6 +31,11 @@ class VirtualReadStorage {
*/
void setMaxNbReadsStored(size_t nb);
/**
* @return the average read length of all the sequences that have been added
*/
virtual double getAverageLength() const = 0;
/**
* @return the maximal number of reads stored
*/
......@@ -115,6 +120,11 @@ public:
*/
void addScore(size_t bin, float score);
/**
* @inherited from VirtualReadScore
*/
double getAverageLength() const;
/**
* @return the average score stored in the bin corresponding to the score
* obtained for the provided sequence.
......
......@@ -23,7 +23,7 @@ map<junction, BinReadStorage>::iterator WindowsStorage::end() {
float WindowsStorage::getAverageLength(junction window) {
assert(hasWindow(window));
return seqs_by_window[window].getAverageScore();
return seqs_by_window[window].getAverageLength();
}
Germline *WindowsStorage::getGermline(junction window) {
......
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