Commit 08a9fcc4 authored by Mikaël Salson's avatar Mikaël Salson Committed by Mathieu Giraud

read_score.{h,cpp}: Don't allocate memory for qualities each time

The array always has the same length.
A static version is enough and avoids allocating/free-ing at each call.
parent 06cfbd27
#include "read_score.h"
#include <cstdlib>
#include <cstring>
KmerAffectReadScore::KmerAffectReadScore(IKmerStore<KmerAffect> &idx,
float unambiguous_score,
......@@ -74,8 +75,10 @@ float ReadLengthScore::getScore(const Sequence &sequence) const {
ReadQualityScore::ReadQualityScore(){}
ReadQualityScore::~ReadQualityScore(){}
size_t ReadQualityScore::qualities[MAX_QUALITY];
float ReadQualityScore::getScore(const Sequence &sequence) const {
size_t *qualities = (size_t *)calloc(MAX_QUALITY, sizeof(size_t));
memset(qualities, 0, MAX_QUALITY * sizeof(size_t));
for (size_t i = 0; i < sequence.quality.size(); i++) {
int current_quality = (sequence.quality[i]) - '!';
assert(current_quality < MAX_QUALITY);
......@@ -91,7 +94,6 @@ float ReadQualityScore::getScore(const Sequence &sequence) const {
break;
}
}
free(qualities);
if (! percent_quality)
percent_quality = GOOD_QUALITY;
return percent_quality * sequence.sequence.size() / GOOD_QUALITY;
......
......@@ -80,6 +80,8 @@ class ReadLengthScore: public VirtualReadScore {
* The score is a trade-off between quality and length of the read
*/
class ReadQualityScore: public VirtualReadScore {
private:
static size_t qualities[MAX_QUALITY];
public:
ReadQualityScore();
~ReadQualityScore();
......
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