LocARNA-2.0.0
trace_controller.hh
1 #ifndef LOCARNA_TRACE_CONTROLLER_HH
2 #define LOCARNA_TRACE_CONTROLLER_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <vector>
9 #include <assert.h>
10 
11 #include "aux.hh"
12 #include "multiple_alignment.hh"
13 
14 namespace LocARNA {
15 
16  class Sequence;
17  class AnchorConstraints;
18  class TraceProbs;
19 
27  class TraceRange {
28  public:
31 
33  typedef std::pair<SeqEntry, SeqEntry> seqentry_pair_t;
34 
45  static seqentry_pair_t
46  remove_common_gaps(const SeqEntry &aliA, const SeqEntry &aliB);
47 
69  TraceRange(const SeqEntry &pseqA,
70  const SeqEntry &pseqB,
71  const SeqEntry &aliA,
72  const SeqEntry &aliB,
73  size_type delta);
74 
89  TraceRange(size_type lenA,
90  size_type lenB,
91  const std::vector<TraceRange> &trs,
92  size_type delta);
93 
102  size_type
104  size_type j,
105  const std::vector<TraceRange> &trs) const;
106 
111  size_t
112  rows() const {
113  assert(min_col_.size()>0);
114  return min_col_.size() - 1;
115  }
116 
122  size_t
123  min_col(size_t i) const {
124  assert(i>=0);
125  assert(i<min_col_.size());
126  return min_col_[i];
127  }
128 
134  size_t
135  max_col(size_t i) const {
136  assert(i>=0);
137  assert(i<max_col_.size());
138  return max_col_[i];
139  }
140 
145  TraceRange
146  reverse() const;
147 
153  void
154  print_debug(std::ostream &out=std::cerr) const;
155 
156  protected:
161  TraceRange(size_t lenA, size_t lenB)
162  : lenA_(lenA),
163  lenB_(lenB)
164  {}
165 
166  size_t lenA_;
167  size_t lenB_;
168 
169  using idx_vec_t = std::vector<size_t>;
170  idx_vec_t min_col_;
171  idx_vec_t max_col_;
172  };
173 
176  public:
183  virtual bool
184  is_valid_match(size_t i, size_t j) const = 0;
185 
186  virtual ~MatchController();
187  };
188 
200  class TraceController : public TraceRange, public MatchController {
201  public:
216  TraceController(const Sequence &seqA,
217  const Sequence &seqB,
218  const MultipleAlignment *ma,
219  int delta,
220  bool relaxed_merging = false);
221 
223  virtual ~TraceController();
224 
231  void
232  restrict_by_anchors(const AnchorConstraints &constraints);
233 
244  void
245  restrict_by_trace_probabilities(const TraceProbs &trace_probs,
246  double min_prob);
247 
254  reverse() const;
255 
262  bool
263  is_valid(size_type i, size_type j) const;
264 
271  virtual bool
272  is_valid_match(size_type i, size_type j) const;
273 
278  size_type
279  get_delta() const {
280  return delta_;
281  }
282 
283  private:
284  // The delimiter character separating the two sequences in the alignment
285  // string
286  static const char delimiter = '&';
287 
292  void
293  merge_in_trace_range(const TraceRange &tr);
294 
296  const size_type delta_;
297 
298  TraceController(TraceRange &&trace_range, size_type delta)
299  : TraceRange(trace_range), delta_(delta) {}
300 
301  // /**
302  // * switch between strict and relaxed merging of pairwise trace
303  // * ranges
304  // */
305  // const bool relaxed_merging_;
306 
319  void
320  constrain_wo_ref(size_type lenA, size_type lenB, size_type delta);
321  };
322 
328  inline bool
330  return min_col(i) <= j && j <= max_col(i);
331  }
332 
333  inline bool
335  return is_valid(i, j) && is_valid(i - 1, j - 1);
336  }
337 
338 } // end namespace
339 
340 #endif /* LOCARNA_TRACE_CONTROLLER_HH */
Represents anchor constraints between two sequences.
Definition: anchor_constraints.hh:66
abstract class that declares the method is_valid_match()
Definition: trace_controller.hh:175
virtual bool is_valid_match(size_t i, size_t j) const =0
A row in a multiple alignment.
Definition: multiple_alignment.hh:111
Represents a multiple alignment.
Definition: multiple_alignment.hh:65
"Sequence View" of multiple alignment as array of column vectors
Definition: sequence.hh:17
Controls the matrix cells valid for traces.
Definition: trace_controller.hh:200
void restrict_by_trace_probabilities(const TraceProbs &trace_probs, double min_prob)
Restrict by anchor constraints.
Definition: trace_controller.cc:566
TraceController(const Sequence &seqA, const Sequence &seqB, const MultipleAlignment *ma, int delta, bool relaxed_merging=false)
Constructs for the general case of alignment of alignments.
Definition: trace_controller.cc:406
TraceController reverse() const
Controller for the reversed sequences.
Definition: trace_controller.cc:600
virtual ~TraceController()
Virtual destructor.
Definition: trace_controller.cc:358
void restrict_by_anchors(const AnchorConstraints &constraints)
Restrict by anchor constraints.
Definition: trace_controller.cc:542
size_type get_delta() const
Read deviation.
Definition: trace_controller.hh:279
virtual bool is_valid_match(size_type i, size_type j) const
Definition: trace_controller.hh:334
bool is_valid(size_type i, size_type j) const
Is (i,j) a valid cell of the DP matrices (i.e. on some possible trace)?
Definition: trace_controller.hh:329
Provide trace probabilities.
Definition: edge_probs.hh:210
Represents a range of traces.
Definition: trace_controller.hh:27
MultipleAlignment::SeqEntry SeqEntry
alias for MultipleAlignment::SeqEntry
Definition: trace_controller.hh:30
idx_vec_t max_col_
maximal column in row
Definition: trace_controller.hh:171
std::pair< SeqEntry, SeqEntry > seqentry_pair_t
pair of sequence entries
Definition: trace_controller.hh:33
TraceRange(const SeqEntry &pseqA, const SeqEntry &pseqB, const SeqEntry &aliA, const SeqEntry &aliB, size_type delta)
Construct from pair of alignment strings.
Definition: trace_controller.cc:43
TraceRange(size_t lenA, size_t lenB)
Construct "empty".
Definition: trace_controller.hh:161
static seqentry_pair_t remove_common_gaps(const SeqEntry &aliA, const SeqEntry &aliB)
Definition: trace_controller.cc:25
void print_debug(std::ostream &out=std::cerr) const
Definition: trace_controller.cc:341
idx_vec_t min_col_
minimal column in row
Definition: trace_controller.hh:170
size_t max_col(size_t i) const
Maximal column of trace in a row.
Definition: trace_controller.hh:135
size_t rows() const
Read number of rows.
Definition: trace_controller.hh:112
size_type consensus_cost(size_type i, size_type j, const std::vector< TraceRange > &trs) const
Computes cost of a cut in the consensus trace of a trace range set.
Definition: trace_controller.cc:215
size_t min_col(size_t i) const
Minimal column of trace in a row.
Definition: trace_controller.hh:123
size_t lenA_
length of sequence A
Definition: trace_controller.hh:166
TraceRange reverse() const
Ranges for reversed sequences.
Definition: trace_controller.cc:320
size_t lenB_
length of sequence B
Definition: trace_controller.hh:167
Definition: aligner.cc:15
size_t size_type
general size type
Definition: aux.hh:120