Commit 0de26304 authored by Mikaël Salson's avatar Mikaël Salson

getIndexLoad: Now depends on the kmer

We calculate the index load depending on the type of Affectation stored.
Thus we now need just one type of getIndexLoad() as the other one doesn't make sense any more.

This change should allow to compute a confident e-value using the
Aho-Corasick automaton
parent 1d84a40d
......@@ -24,7 +24,7 @@ class AbstractACAutomaton: public IKmerStore<Info> {
protected:
void *initialState;
size_t kmers_inserted_by_length[MAX_KMER_SIZE];
map<Info, size_t> kmers_inserted;
public:
AbstractACAutomaton();
......@@ -39,6 +39,11 @@ public:
*/
void finish_building();
/**
* @inherited from IKMerStore
*/
float getIndexLoad(Info kmer) const;
/**
* @return the information stored for this state
*/
......
......@@ -7,16 +7,19 @@
//////////////////// IMPLEMENTATIONS ////////////////////
template <class Info>
AbstractACAutomaton<Info>::AbstractACAutomaton():IKmerStore<Info>() {
for (size_t i = 0; i < MAX_KMER_SIZE; i++)
kmers_inserted_by_length[i] = 0;
}
AbstractACAutomaton<Info>::AbstractACAutomaton():IKmerStore<Info>() {}
template <class Info>
void AbstractACAutomaton<Info>::finish_building() {
build_failure_functions();
}
template<class Info>
float AbstractACAutomaton<Info>::getIndexLoad(Info kmer) const {
float load = kmers_inserted.at(kmer) / pow(4.0, kmer.getLength());
return (kmer.isUnknown()) ? 1 - load : load;
}
template <class Info>
bool AbstractACAutomaton<Info>::isInitialState(void *state) {
return state == initialState;
......@@ -168,9 +171,11 @@ void PointerACAutomaton<Info>::insert(const seqtype &seq, Info info) {
}
}
state->is_final = true;
this->nb_kmers_inserted++;
assert(info.getLength() <= MAX_KMER_SIZE);
this->kmers_inserted_by_length[info.getLength()]++;
if (state->informations.front().isNull()) {
this->nb_kmers_inserted++;
this->kmers_inserted[info]++;
}
state->informations.front() += info;
}
......
......@@ -110,8 +110,7 @@ public:
/**
* @return the percentage of kmers that are set in the index
*/
float getIndexLoad(T kmer) const;
float getIndexLoad() const;
virtual float getIndexLoad(T kmer) const;
/**
* @return the given integer (size of a read),
......@@ -324,11 +323,8 @@ void IKmerStore<T>::finish_building() {}
template<class T>
float IKmerStore<T>::getIndexLoad(const T kmer) const {
return kmer.isUnknown() ? 1 - getIndexLoad() : getIndexLoad();
}
template<class T>
float IKmerStore<T>::getIndexLoad() const {
return nb_kmers_inserted / pow(4.0, k);
float index_load = nb_kmers_inserted / pow(4.0, kmer.getLength());
return (kmer.isUnknown()) ? 1 - index_load : index_load;
}
template<class T>
......
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