Commit b14ff728 authored by Mathieu Giraud's avatar Mathieu Giraud

core/germline.{h,cpp}, vidjil.cpp: refactor code, separating index updating / index setting

No-modification change
 - set_index(index) sets the index
 - update_index(index) may be used on any index (including other indexes than the index set)
 - insert_in_one_index and build_with_one_index take a boolean 'set_indexes'

We want to be able to update any index (for example a global one) with sequences of a germline,
without changing the index of this germline.
parent f5ba19b2
......@@ -92,22 +92,22 @@ void Germline::new_index(string seed)
update_index();
}
void Germline::use_index(IKmerStore<KmerAffect> *_index)
void Germline::set_index(IKmerStore<KmerAffect> *_index)
{
index = _index;
update_index();
}
void Germline::update_index()
void Germline::update_index(IKmerStore<KmerAffect> *_index)
{
index->insert(rep_5, affect_5);
if (!_index) _index = index ;
_index->insert(rep_5, affect_5);
if (affect_4.size())
index->insert(rep_4, affect_4);
_index->insert(rep_4, affect_4);
index->insert(rep_3, affect_3);
_index->insert(rep_3, affect_3);
}
void Germline::mark_as_ambiguous(Germline *other)
......@@ -146,6 +146,7 @@ ostream &operator<<(ostream &out, const Germline &germline)
MultiGermline::MultiGermline(bool _one_index_per_germline)
{
index = NULL;
one_index_per_germline = _one_index_per_germline;
}
......@@ -210,7 +211,7 @@ void MultiGermline::build_incomplete_set(string path)
}
/* if 'one_index_per_germline' was not set, this should be called once all germlines have been loaded */
void MultiGermline::insert_in_one_index(IKmerStore<KmerAffect> *_index)
void MultiGermline::insert_in_one_index(IKmerStore<KmerAffect> *_index, bool set_index)
{
for (list<Germline*>::const_iterator it = germlines.begin(); it != germlines.end(); ++it)
{
......@@ -219,15 +220,18 @@ void MultiGermline::insert_in_one_index(IKmerStore<KmerAffect> *_index)
if (germline->rep_4.size())
germline->affect_4 = string(1, 14 + germline->shortcut) + "-" + germline->code + "D";
germline->use_index(_index) ;
germline->update_index(_index);
if (set_index)
germline->set_index(_index);
}
}
void MultiGermline::build_with_one_index(string seed)
void MultiGermline::build_with_one_index(string seed, bool set_index)
{
bool rc = true ;
index = KmerStoreFactory::createIndex<KmerAffect>(seed, rc);
insert_in_one_index(index);
insert_in_one_index(index, set_index);
}
void MultiGermline::out_stats(ostream &out)
......
......@@ -18,8 +18,6 @@ class Germline {
void init(string _code, char _shortcut,
int _delta_min, int _delta_max);
void update_index();
public:
/*
* @param delta_min: the minimal distance between the right bound and the left bound
......@@ -51,7 +49,9 @@ class Germline {
char shortcut ;
void new_index(string seed);
void use_index(IKmerStore<KmerAffect> *index);
void set_index(IKmerStore<KmerAffect> *index);
void update_index(IKmerStore<KmerAffect> *_index = NULL);
void mark_as_ambiguous(Germline *other);
......@@ -99,8 +99,10 @@ class MultiGermline {
void build_default_set(string path);
void build_incomplete_set(string path);
void insert_in_one_index(IKmerStore<KmerAffect> *_index);
void build_with_one_index(string seed);
// Creates and update an unique index for all the germlines
// If 'set_index' is set, set this index as the index for all germlines
void insert_in_one_index(IKmerStore<KmerAffect> *_index, bool set_index);
void build_with_one_index(string seed, bool set_index);
void mark_cross_germlines_as_ambiguous();
......
......@@ -788,7 +788,7 @@ int main (int argc, char **argv)
cout << endl ;
if (!multi_germline_one_index_per_germline) {
multigermline->build_with_one_index(seed);
multigermline->build_with_one_index(seed, true);
if (multi_germline_unexpected_recombinations) {
Germline *pseudo = new Germline(PSEUDO_GERMLINE_MAX12, 'x', -10, 80);
......
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