vdj_pipe
pipeline for processing DNA sequence data
min_match_length.hpp
Go to the documentation of this file.
1 
7 #ifndef MIN_MATCH_LENGTH_HPP_
8 #define MIN_MATCH_LENGTH_HPP_
9 #include <algorithm>
10 #include <functional>
11 #include "vdj_pipe/exception.hpp"
12 
13 namespace vdj_pipe{
14 
18  public std::unary_function<std::string, std::size_t> {
19  int operator()(const int sz) const {return sz;}
20 };
21 
25  public std::unary_function<std::string, std::size_t> {
26 public:
27  Match_min_length(const std::size_t min)
28  : min_(min)
29  {}
30 
31  int operator()(const int sz) const {
32  return std::min(sz, min_);
33  }
34 
35 private:
36  int min_;
37 };
38 
43  public std::unary_function<std::string, std::size_t> {
44 public:
45  Match_ignore_ends(const int min, const int end)
46  : min_(min), end_(end)
47  {}
48 
49  int operator()(const int sz) const {
50  return std::min(
51  sz,
52  std::max(
53  min_,
54  sz - end_
55  )
56  );
57  }
58 
59 private:
60  int min_;
61  int end_;
62 };
63 
67  public std::unary_function<std::string, std::size_t> {
68 public:
69  struct Err : public base_exception {};
70  Match_fraction_length(const int min, const double f)
71  : min_(min), f_(f)
72  {
73  BOOST_ASSERT(f_ > 0.0 && f_ <= 1.0 && "invalid fraction");
74  }
75 
76  int operator()(const int sz) const {
77  return std::min(
78  sz,
79  std::max(
80  min_,
81  (int)(sz * f_ + 0.5)
82  )
83  );
84  }
85 
86 private:
87  int min_;
88  double f_;
89 };
90 
94  public std::unary_function<std::string, std::size_t> {
95 public:
96  struct Err : public base_exception {};
97 
99  const int min = 0,
100  const int end = 0,
101  const double f = 0.0
102  )
103  : min_(min),
104  end_(end),
105  f_(f)
106  {
107  if( min_ == 0 && end_ == 0 && f_ == 0.0 ) f_ = 1.0;
108 
109  if( min_ < 0 ) BOOST_THROW_EXCEPTION(
110  Err()
111  << Err::msg_t("invalid minimal match length")
112  << Err::int1_t(min_)
113  );
114 
115  if( end_ < 0 ) BOOST_THROW_EXCEPTION(
116  Err()
117  << Err::msg_t("invalid ignore end length")
118  << Err::int1_t(end_)
119  );
120 
121  if( f_ < 0.0 || f_ > 1.0 ) BOOST_THROW_EXCEPTION(
122  Err()
123  << Err::msg_t("invalid minimal match fraction")
124  << Err::float1_t(f_)
125  );
126  }
127 
128  int operator()(const int sz) const {
129  return std::min(
130  sz,
131  std::max(
132  min_,
133  std::max(
134  sz - end_,
135  (int)(sz * f_ + 0.5)
136  )
137  )
138  );
139  }
140 
141 private:
142  int min_;
143  int end_;
144  double f_;
145 };
146 
147 }//namespace vdj_pipe
148 #endif /* MIN_MATCH_LENGTH_HPP_ */
Match_min_length(const std::size_t min)
Definition: min_match_length.hpp:27
Match_fraction_length(const int min, const double f)
Definition: min_match_length.hpp:70
int operator()(const int sz) const
Definition: min_match_length.hpp:19
int operator()(const int sz) const
Definition: min_match_length.hpp:49
int operator()(const int sz) const
Definition: min_match_length.hpp:31
int operator()(const int sz) const
Definition: min_match_length.hpp:128
Require full sequence to match.
Definition: min_match_length.hpp:17
int operator()(const int sz) const
Definition: min_match_length.hpp:76
double f_
Definition: min_match_length.hpp:144
boost::error_info< struct errinfo_int1_, int > int1_t
Definition: exception.hpp:28
int end_
Definition: min_match_length.hpp:143
Definition: min_match_length.hpp:96
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
double f_
Definition: min_match_length.hpp:88
int min_
Definition: min_match_length.hpp:142
Get_match_length(const int min=0, const int end=0, const double f=0.0)
Definition: min_match_length.hpp:98
int min_
Definition: min_match_length.hpp:36
Match_ignore_ends(const int min, const int end)
Definition: min_match_length.hpp:45
boost::error_info< struct errinfo_float1_, double > float1_t
Definition: exception.hpp:31
Set a fraction of sequence length to match.
Definition: min_match_length.hpp:66
Definition: exception.hpp:23
boost::error_info< struct errinfo_message_, std::string > msg_t
Definition: exception.hpp:24
int min_
Definition: min_match_length.hpp:87
Set a minimal sequence length to match allowing for some mismatch at ends.
Definition: min_match_length.hpp:42
Set a fraction of sequence length to match.
Definition: min_match_length.hpp:93
int end_
Definition: min_match_length.hpp:61
int min_
Definition: min_match_length.hpp:60
Set a minimal sequence length to match.
Definition: min_match_length.hpp:24
Definition: min_match_length.hpp:69
const std::size_t sz
Definition: vector_set_test.cpp:27