Commit a15c5cd7 authored by Mathieu Giraud's avatar Mathieu Giraud
Browse files

core/affectanalyser.{h,cpp}: sortLeftRight()

Giving two KmerAffects, which one is the more on the left ?
parent d14d4f25
...@@ -191,6 +191,35 @@ const string &KmerAffectAnalyser::getSequence() const{ ...@@ -191,6 +191,35 @@ const string &KmerAffectAnalyser::getSequence() const{
} }
pair <KmerAffect, KmerAffect> KmerAffectAnalyser::sortLeftRight(const pair <KmerAffect, KmerAffect> ka12) const {
KmerAffect ka1 = ka12.first;
KmerAffect ka2 = ka12.second;
int ka1_count = 0; int ka1_pos = 0;
int ka2_count = 0; int ka2_pos = 0;
for (size_t i = 0; i < affectations.size(); i++) {
if (affectations[i] == ka1)
{
ka1_count++ ; ka1_pos += i ;
}
else if (affectations[i] == ka2)
{
ka2_count++ ; ka2_pos += i ;
}
}
// Is ka1 'more on the left' than ka2 ?
// We check for (k1_pos / ka1_count > ka2_pos / ka2_count), but without floats
if (ka1_pos * ka2_count < ka2_pos * ka1_count)
return make_pair(ka1, ka2);
else
return make_pair(ka2, ka1);
}
int KmerAffectAnalyser::first(const KmerAffect &affect) const{ int KmerAffectAnalyser::first(const KmerAffect &affect) const{
for (size_t i = 0; i < affectations.size(); i++) for (size_t i = 0; i < affectations.size(); i++)
if (affect == affectations[i]) if (affect == affectations[i])
......
...@@ -186,6 +186,13 @@ class KmerAffectAnalyser: public AffectAnalyser { ...@@ -186,6 +186,13 @@ class KmerAffectAnalyser: public AffectAnalyser {
const string &getSequence() const; const string &getSequence() const;
/**
* @param A pair of KmerAffects
* @return The same pair of KmerAffects, but sorted.
* The first one is 'more on the left' than the second one.
*/
pair <KmerAffect, KmerAffect> sortLeftRight(const pair <KmerAffect, KmerAffect> ka12) const;
int first(const KmerAffect &affect) const; int first(const KmerAffect &affect) const;
int last(const KmerAffect &affect) const ; int last(const KmerAffect &affect) const ;
......
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