vdj_pipe
pipeline for processing DNA sequence data
best_match_pair.hpp
Go to the documentation of this file.
1 
7 #ifndef BEST_MATCH_PAIR_HPP_
8 #define BEST_MATCH_PAIR_HPP_
9 #include <limits>
10 #include "boost/assert.hpp"
11 
12 namespace vdj_pipe{
13 
16 template<class ID, class Score = int> class Best_match_pair {
17  static Score default_score() {return std::numeric_limits<Score>::min();}
18 public:
19  typedef ID id_type;
20  typedef Score score_type;
21 
23  : id1_(),
25  id2_(),
27  {}
28 
29  id_type const& id1() const {return id1_;}
30  id_type const& id2() const {return id2_;}
31  bool has_score() const {return score1_ != default_score();}
32  score_type score1() const {return score1_;}
33  score_type score2() const {return score2_;}
34 
35  bool is_acceptable(const score_type min_score, const bool require_best) const {
36  return
37  id1_ &&
38  score1_>= min_score &&
39  ( ! require_best || score1_ != score2_ )
40  ;
41  }
42 
49  bool combine(id_type const& id, const score_type score) {
50  BOOST_ASSERT(score2_ <= score1_);
51  if( score1_ < score ) {
52  score2_ = score1_;
53  id2_ = id1_;
54  score1_ = score;
55  id1_ = id;
56  return true;
57  }
58 
59  if( score2_ < score ) {
60  score2_ = score;
61  id2_ = id;
62  }
63  return false;
64  }
65 
71  bool combine( Best_match_pair const& bmp) {
72  BOOST_ASSERT(score2_ <= score1_);
73  BOOST_ASSERT(bmp.score2_ <= bmp.score1_);
74 
75  if( score1_ < bmp.score1_ ) {
76  if( score1_ < bmp.score2_ ) {
77  score2_ = bmp.score2_;
78  id2_ = bmp.id2_;
79  } else {
80  score2_ = score1_;
81  id2_ = id1_;
82  }
83  score1_ = bmp.score1_;
84  id1_ = bmp.id1_;
85  return true;
86  }
87 
88  if( score2_ < bmp.score1_ ) {
89  score2_ = bmp.score1_;
90  id2_ = bmp.id1_;
91  }
92 
93  return false;
94  }
95 
96 private:
97  ID id1_;
98  Score score1_;
99  ID id2_;
100  Score score2_;
101 };
102 
103 }//namespace vdj_pipe
104 #endif /* BEST_MATCH_PAIR_HPP_ */
ID id1_
Definition: best_match_pair.hpp:97
id_type const & id2() const
Definition: best_match_pair.hpp:30
Definition: best_match_pair.hpp:16
ID id_type
Definition: best_match_pair.hpp:19
Score score1_
Definition: best_match_pair.hpp:98
bool combine(Best_match_pair const &bmp)
Definition: best_match_pair.hpp:71
ID id2_
Definition: best_match_pair.hpp:99
score_type score2() const
Definition: best_match_pair.hpp:33
Score score2_
Definition: best_match_pair.hpp:100
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
Best_match_pair()
Definition: best_match_pair.hpp:22
static Score default_score()
Definition: best_match_pair.hpp:17
bool is_acceptable(const score_type min_score, const bool require_best) const
Definition: best_match_pair.hpp:35
id_type const & id1() const
Definition: best_match_pair.hpp:29
score_type score1() const
Definition: best_match_pair.hpp:32
Score score_type
Definition: best_match_pair.hpp:20
bool combine(id_type const &id, const score_type score)
Definition: best_match_pair.hpp:49
bool has_score() const
Definition: best_match_pair.hpp:31