LocARNA-2.0.0
aligner_impl.hh
1 #ifndef LOCARNA_ALIGNER_IMPL_HH
2 #define LOCARNA_ALIGNER_IMPL_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <memory>
9 
10 #include "aligner.hh"
11 
12 #include "aligner_restriction.hh"
13 #include "scoring.hh"
14 #include "alignment.hh"
15 #include "aligner_params.hh"
16 
17 namespace LocARNA {
18 
19  class Sequence;
20  template <class T>
21  class Matrix;
22 
26  class AlignerImpl {
27  public:
34 
37 
38  const std::unique_ptr<AlignerParams> params_;
39 
40  const Scoring *scoring_;
41 
44 
45  const Sequence &seqA_;
46  const Sequence &seqB_;
47 
48  const BasePairs &bpsA_;
49  const BasePairs &bpsB_;
50 
68 
71 
77  std::vector<M_matrix_t> Ms_;
78 
87  std::vector<ScoreVector> Es_;
88 
93  std::vector<infty_score_t> Fs_;
94 
95  int min_i_;
96  int min_j_;
97 
98  int max_i_;
99  int max_j_;
100 
101  bool D_created_;
102 
104 
113  enum {
114  E_NO_NO,
115  E_X_NO,
116  E_NO_X,
117  E_X_X,
118  E_OP_NO,
119  E_NO_OP,
120  E_OP_X,
121  E_X_OP
122  };
123 
124  // ============================================================
135  public:
141  explicit UnmodifiedScoringView(const AlignerImpl *aligner_impl)
142  : aligner_impl_(aligner_impl){};
143 
149  const Scoring *
150  scoring() const {
151  return aligner_impl_->scoring_;
152  }
153 
163  D(const Arc &a, const Arc &b) const {
164  return aligner_impl_->Dmat_(a.idx(), b.idx());
165  }
166 
175  D(const ArcMatch &am) const {
176  return D(am.arcA(), am.arcB());
177  }
178  private:
179  const AlignerImpl *
180  aligner_impl_;
181  };
182 
191  public:
200  explicit ModifiedScoringView(const AlignerImpl *aligner_impl)
201  : aligner_impl_(aligner_impl),
202  mod_scoring_(
203  std::make_unique<Scoring>(*aligner_impl->scoring_)),
204  lambda_(0) {}
205 
211  void
212  set_lambda(score_t lambda) {
213  lambda_ = lambda;
214  mod_scoring_->modify_by_parameter(lambda);
215  }
216 
222  const Scoring *
223  scoring() const {
224  return mod_scoring_.get();
225  }
226 
236  D(const Arc &a, const Arc &b) const {
237  return aligner_impl_->Dmat_(a.idx(), b.idx()) -
238  FiniteInt(lambda_ * (arc_length(a) + arc_length(b)));
239  }
240 
249  D(const ArcMatch &am) const {
250  return aligner_impl_->Dmat_(am.arcA().idx(), am.arcB().idx()) -
251  FiniteInt(lambda_ *
252  (arc_length(am.arcA()) + arc_length(am.arcB())));
253  }
254  private:
256  const AlignerImpl *aligner_impl_;
257 
259  const std::unique_ptr<Scoring> mod_scoring_;
260 
261  score_t lambda_;
262 
270  size_t
271  arc_length(const Arc &a) const {
272  return a.right() - a.left() + 1;
273  }
274 
275  };
276 
278 
279  // ============================================================
280 
286  AlignerImpl(const AlignerImpl &a);
287 
296  AlignerImpl(const Sequence &seqA,
297  const Sequence &seqB,
298  const AlignerParams *ap,
299  const Scoring *s);
300 
304  ~AlignerImpl();
305 
306  // ============================================================
307 
332  template <class ScoringView>
333  void
334  init_state(int state,
335  pos_type al,
336  pos_type ar,
337  pos_type bl,
338  pos_type br,
339  bool globalA,
340  bool exclA,
341  bool globalB,
342  bool exclB,
343  const ScoringView *sv);
344 
365  template <class ScoringView>
367  align_noex(int state,
368  pos_type al,
369  pos_type bl,
370  pos_type i,
371  pos_type j,
372  const ScoringView *sv);
373 
387  void
389  pos_type ar,
390  pos_type bl,
391  pos_type br,
392  bool allow_exclusion);
393 
398  template <class ScoringView>
400  align_top_level_free_endgaps(const ScoringView *s);
401 
406  template <class ScoringView>
408  align_top_level_locally(const ScoringView *sv);
409 
411  // infty_score_t align_top_level_localB();
412 
425  template <class ScoringView>
426  void
427  trace_in_arcmatch(int state,
428  int al,
429  int i,
430  int bl,
431  int j,
432  bool top_level,
433  const ScoringView *sv);
434 
447  template <class ScoringView>
448  void
449  trace_noex(int state,
450  pos_type al,
451  pos_type i,
452  pos_type bl,
453  pos_type j,
454  bool top_level,
455  const ScoringView *sv);
456 
461  void
462  trace_arcmatch(const ArcMatch &am);
463 
468  void
469  trace_arcmatch_noLP(const ArcMatch &am);
470 
473  align();
474 
479  void
480  align_D();
481 
485  void
487 
496  void
498 
506  infty_score_t &
507  D(const ArcMatch &am) {
508  return Dmat_(am.arcA().idx(), am.arcB().idx());
509  }
510 
519  infty_score_t &
520  D(const Arc &arcA, const Arc &arcB) {
521  return Dmat_(arcA.idx(), arcB.idx());
522  }
523 
529  template <class ScoringView>
530  void
531  trace(const ScoringView *sv);
532 
533 
536  normalized_align(score_t L, bool verbose);
537 
541  penalized_align(score_t position_penalty);
542 
543  };
544 
545 } // end namespace LocARNA
546 
547 #endif // LOCARNA_ALIGNER_IMPL_HH
Provides a modified view on the scoring.
Definition: aligner_impl.hh:190
infty_score_t D(const Arc &a, const Arc &b) const
Definition: aligner_impl.hh:236
infty_score_t D(const ArcMatch &am) const
Definition: aligner_impl.hh:249
void set_lambda(score_t lambda)
Definition: aligner_impl.hh:212
const Scoring * scoring() const
Definition: aligner_impl.hh:223
ModifiedScoringView(const AlignerImpl *aligner_impl)
Definition: aligner_impl.hh:200
Provides the standard view on the scoring.
Definition: aligner_impl.hh:134
UnmodifiedScoringView(const AlignerImpl *aligner_impl)
Definition: aligner_impl.hh:141
infty_score_t D(const Arc &a, const Arc &b) const
Definition: aligner_impl.hh:163
infty_score_t D(const ArcMatch &am) const
Definition: aligner_impl.hh:175
const Scoring * scoring() const
Definition: aligner_impl.hh:150
Implementation of Aligner.
Definition: aligner_impl.hh:26
std::vector< infty_score_t > Fs_
Definition: aligner_impl.hh:93
const Scoring * scoring_
the scores
Definition: aligner_impl.hh:40
infty_score_t align()
compute the alignment score
Definition: aligner.cc:925
std::vector< ScoreVector > Es_
Definition: aligner_impl.hh:87
int max_i_
subsequence of A right end, computed by align_top_level
Definition: aligner_impl.hh:98
void init_state(int state, pos_type al, pos_type ar, pos_type bl, pos_type br, bool globalA, bool exclA, bool globalB, bool exclB, const ScoringView *sv)
initialize matrices M and E
Definition: aligner.cc:266
const Sequence & seqB_
sequence B
Definition: aligner_impl.hh:46
int max_j_
subsequence of B right end, computed by align_top_level
Definition: aligner_impl.hh:99
const UnmodifiedScoringView def_scoring_view_
Default scoring view.
Definition: aligner_impl.hh:277
void trace_noex(int state, pos_type al, pos_type i, pos_type bl, pos_type j, bool top_level, const ScoringView *sv)
standard cases in trace back (without handling of exclusions)
Definition: aligner.cc:1084
void align_D()
Definition: aligner.cc:661
int min_i_
subsequence of A left end, computed by trace back
Definition: aligner_impl.hh:95
ScoreMatrix M_matrix_t
Definition: aligner_impl.hh:33
infty_score_t penalized_align(score_t position_penalty)
Definition: aligner.cc:1604
BasePairs__Arc Arc
an arc
Definition: aligner_impl.hh:36
const ArcMatches & arc_matches_
hold arc matches ref for convenience; equals scoring_->arc_matches()
Definition: aligner_impl.hh:43
void trace_arcmatch(const ArcMatch &am)
Definition: aligner.cc:968
infty_score_t normalized_align(score_t L, bool verbose)
perform normalized local alignment with parameter L
Definition: aligner.cc:1527
void trace(const ScoringView *sv)
Definition: aligner.cc:1347
~AlignerImpl()
Definition: aligner.cc:133
infty_score_t align_noex(int state, pos_type al, pos_type bl, pos_type i, pos_type j, const ScoringView *sv)
standard cases for alignment (without exlusion handling).
Definition: aligner.cc:155
Alignment alignment_
resulting alignment
Definition: aligner_impl.hh:103
ScoreMatrix Dmat_
matrix indexed by the arc indices of rnas A and B
Definition: aligner_impl.hh:70
const std::unique_ptr< AlignerParams > params_
the parameter for the alignment
Definition: aligner_impl.hh:38
const BasePairs & bpsB_
base pairs of B
Definition: aligner_impl.hh:49
infty_score_t & D(const Arc &arcA, const Arc &arcB)
Definition: aligner_impl.hh:520
AlignerRestriction r_
restriction of alignment for k-best
Definition: aligner_impl.hh:67
bool D_created_
flag, is D already created?
Definition: aligner_impl.hh:101
int min_j_
subsequence of B left end, computed by trace back
Definition: aligner_impl.hh:96
AlignerImpl(const AlignerImpl &a)
copy constructor
Definition: aligner.cc:78
std::vector< M_matrix_t > Ms_
Definition: aligner_impl.hh:77
void fill_D_entries(pos_type al, pos_type bl)
Definition: aligner.cc:575
void trace_arcmatch_noLP(const ArcMatch &am)
Definition: aligner.cc:1031
void align_in_arcmatch(pos_type al, pos_type ar, pos_type bl, pos_type br, bool allow_exclusion)
Definition: aligner.cc:374
const BasePairs & bpsA_
base pairs of A
Definition: aligner_impl.hh:48
infty_score_t align_top_level_free_endgaps(const ScoringView *s)
Definition: aligner.cc:738
void trace_in_arcmatch(int state, int al, int i, int bl, int j, bool top_level, const ScoringView *sv)
align top level in the scanning version
Definition: aligner.cc:1235
const Sequence & seqA_
sequence A
Definition: aligner_impl.hh:45
void fill_D_entries_noLP(pos_type al, pos_type bl)
Definition: aligner.cc:613
infty_score_t & D(const ArcMatch &am)
Definition: aligner_impl.hh:507
infty_score_t align_top_level_locally(const ScoringView *sv)
Definition: aligner.cc:825
Parameter for alignment by Aligner.
Definition: aligner_params.hh:49
Restricts range of an alignment in Aligner.
Definition: aligner_restriction.hh:26
Represents a structure-annotated sequence alignment.
Definition: alignment.hh:83
Represents a match of two base pairs (arc match)
Definition: arc_matches.hh:35
const Arc & arcB() const
Definition: arc_matches.hh:72
const Arc & arcA() const
Definition: arc_matches.hh:62
Maintains the relevant arc matches and their scores.
Definition: arc_matches.hh:116
Represents a base pair.
Definition: basepairs.hh:39
size_t right() const
Definition: basepairs.hh:77
size_t idx() const
Definition: basepairs.hh:87
size_t left() const
Definition: basepairs.hh:67
Describes sequence and structure ensemble of an RNA.
Definition: basepairs.hh:108
Definition: infty_int.hh:437
Definition: infty_int.hh:325
Provides methods for the scoring of alignments.
Definition: scoring.hh:271
"Sequence View" of multiple alignment as array of column vectors
Definition: sequence.hh:17
Definition: aligner.cc:15
size_type pos_type
type of a sequence position
Definition: aux.hh:126
long int score_t
type of the locarna score as defined by the class Scoring
Definition: scoring_fwd.hh:13