LocARNA-1.8.11
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 "aligner.hh"
9 
10 #include "aligner_restriction.hh"
11 #include "scoring.hh"
12 #include "alignment.hh"
13 #include "arc_matches.hh"
14 #include "params.hh"
15 
16 namespace LocARNA {
17 
18  class Sequence;
19  template <class T> class Matrix;
20 
24  class AlignerImpl {
25  public:
31 
34 
36 
37  const Scoring *scoring_;
39 
40  const Sequence &seqA_;
41  const Sequence &seqB_;
42 
44 
45  const BasePairs &bpsA_;
46  const BasePairs &bpsB_;
47 
65 
68 
74  std::vector<M_matrix_t> Ms_;
75 
84  std::vector<ScoreVector> Es_;
85 
90  std::vector<infty_score_t> Fs_;
91 
92  int min_i_;
93  int min_j_;
94 
95  int max_i_;
96  int max_j_;
97 
98  bool D_created_;
99 
101 
108  enum {E_NO_NO, E_X_NO, E_NO_X, E_X_X,
109  E_OP_NO, E_NO_OP, E_OP_X, E_X_OP};
110 
111 
112  // ============================================================
123  private:
124  const AlignerImpl *aligner_impl_;
125  public:
126 
132  explicit
133  UnmodifiedScoringView(const AlignerImpl *aligner_impl): aligner_impl_(aligner_impl) {};
134 
140  const Scoring *scoring() const {return aligner_impl_->scoring_;}
141 
150  infty_score_t D(const Arc &a, const Arc &b) const {
151  return aligner_impl_->Dmat_(a.idx(),b.idx());
152  }
153 
161  infty_score_t D(const ArcMatch &am) const {
162  return D(am.arcA(),am.arcB());
163  }
164  };
165 
166 
175  private:
176  const AlignerImpl *aligner_impl_;
177 
178  score_t lambda_;
179 
187  size_t
188  arc_length(const Arc &a) const {
189  return a.right()-a.left()+1;
190  }
191  public:
192 
200  explicit
201  ModifiedScoringView(const AlignerImpl *aligner_impl)
202  : aligner_impl_(aligner_impl),lambda_(0) {}
203 
209  void
210  set_lambda(score_t lambda) {
211  lambda_=lambda;
212  }
213 
219  const Scoring *scoring() const {return aligner_impl_->mod_scoring_;}
220 
229  infty_score_t D(const Arc &a,const Arc &b) const {
230  return aligner_impl_->Dmat_(a.idx(),b.idx())
231  -FiniteInt(lambda_*(arc_length(a)+arc_length(b)));
232  }
233 
241  infty_score_t D(const ArcMatch &am) const {
242  return aligner_impl_->Dmat_(am.arcA().idx(),am.arcB().idx())
243  -FiniteInt(lambda_*(arc_length(am.arcA())+arc_length(am.arcB())));
244  }
245  };
246 
247 
250  FreeEndgapsDescription free_endgaps_;
251 
252  // ============================================================
253 
259  AlignerImpl(const AlignerImpl &a);
260 
270  AlignerImpl(const Sequence &seqA,
271  const Sequence &seqB,
272  const ArcMatches &arc_matches,
273  const AlignerParams *ap,
274  const Scoring *s
275  );
276 
280  ~AlignerImpl();
281 
282  // ============================================================
283 
284 
308  template <class ScoringView>
309  void init_state(int state, pos_type al, pos_type ar,
310  pos_type bl, pos_type br,
311  bool globalA, bool exclA,
312  bool globalB, bool exclB,
313  ScoringView sv);
314 
315 
333  template<class ScoringView>
334  infty_score_t align_noex(int state, pos_type al, pos_type bl, pos_type i, pos_type j, ScoringView sv);
335 
349  bool allow_exclusion);
350 
351 
358 
359 
364  template<class ScoringView>
365  infty_score_t align_top_level_locally(ScoringView sv);
366 
368  // infty_score_t align_top_level_localB();
369 
381  template<class ScoringView>
382  void trace_in_arcmatch(int state,int al,int i,int bl,int j,bool top_level,ScoringView sv);
383 
395  template <class ScoringView>
396  void trace_noex(int state,
397  pos_type al, pos_type i,
398  pos_type bl,pos_type j,
399  bool top_level,
400  ScoringView sv);
401 
406  void trace_arcmatch(const ArcMatch &am);
407 
412  void trace_arcmatch_noLP(const ArcMatch &am);
413 
416  align();
417 
422  void align_D();
423 
427  void
429 
438  void
440 
448  infty_score_t &D(const ArcMatch &am) {
449  return Dmat_(am.arcA().idx(),am.arcB().idx());
450  }
451 
460  infty_score_t &D(const Arc &arcA,const Arc &arcB) {
461  return Dmat_(arcA.idx(),arcB.idx());
462  }
463 
469  template <class ScoringView>
470  void trace(ScoringView sv);
471 
472 
473  };
474 
475 } // end namespace LocARNA
476 
477 #endif // LOCARNA_ALIGNER_IMPL_HH
size_t left() const
Definition: basepairs.hh:72
void trace_noex(int state, pos_type al, pos_type i, pos_type bl, pos_type j, bool top_level, ScoringView sv)
standard cases in trace back (without handling of exclusions)
Definition: aligner.cc:1073
size_t right() const
Definition: basepairs.hh:80
Scoring * mod_scoring_
used in normalized scoring, when we need to modify the scoring
Definition: aligner_impl.hh:38
bool D_created_
flag, is D already created?
Definition: aligner_impl.hh:98
Provides the standard view on the scoring.
Definition: aligner_impl.hh:122
Description of free end gaps.
Definition: params.hh:28
size_type pos_type
type of a sequence position
Definition: aux.hh:97
void align_in_arcmatch(pos_type al, pos_type ar, pos_type bl, pos_type br, bool allow_exclusion)
Definition: aligner.cc:434
infty_score_t align()
compute the alignment score
Definition: aligner.cc:928
const AlignerParams * params_
the parameter for the alignment
Definition: aligner_impl.hh:35
const Arc & arcA() const
Definition: arc_matches.hh:66
AlignerRestriction r_
restriction of alignment for k-best
Definition: aligner_impl.hh:64
ModifiedScoringView(const AlignerImpl *aligner_impl)
Definition: aligner_impl.hh:201
void align_D()
Definition: aligner.cc:691
void fill_D_entries(pos_type al, pos_type bl)
Definition: aligner.cc:597
Maintains the relevant arc matches and their scores.
Definition: arc_matches.hh:112
infty_score_t D(const Arc &a, const Arc &b) const
Definition: aligner_impl.hh:229
const UnmodifiedScoringView def_scoring_view_
Default scoring view.
Definition: aligner_impl.hh:248
int max_i_
subsequence of A right end, computed by align_top_level
Definition: aligner_impl.hh:95
std::vector< infty_score_t > Fs_
Definition: aligner_impl.hh:90
const Scoring * scoring() const
Definition: aligner_impl.hh:219
int min_i_
subsequence of A left end, computed by trace back
Definition: aligner_impl.hh:92
Definition: aligner.cc:17
UnmodifiedScoringView(const AlignerImpl *aligner_impl)
Definition: aligner_impl.hh:133
const Sequence & seqB_
sequence B
Definition: aligner_impl.hh:41
const Scoring * scoring_
the scores
Definition: aligner_impl.hh:37
Implementation of Aligner.
Definition: aligner_impl.hh:24
Alignment alignment_
resulting alignment
Definition: aligner_impl.hh:100
const ArcMatches & arc_matches_
the potential arc matches between A and B
Definition: aligner_impl.hh:43
ModifiedScoringView mod_scoring_view_
Modified scoring view for normalized alignment.
Definition: aligner_impl.hh:249
BasePairs__Arc Arc
an arc
Definition: aligner_impl.hh:33
const BasePairs & bpsA_
base pairs of A
Definition: aligner_impl.hh:45
infty_score_t align_top_level_free_endgaps()
Definition: aligner.cc:760
Definition: infty_int.hh:344
void trace_arcmatch(const ArcMatch &am)
Definition: aligner.cc:965
const Arc & arcB() const
Definition: arc_matches.hh:74
~AlignerImpl()
Definition: aligner.cc:158
Parameter for alignment by Aligner.
Definition: params.hh:101
Definition: infty_int.hh:464
infty_score_t D(const ArcMatch &am) const
Definition: aligner_impl.hh:241
const Scoring * scoring() const
Definition: aligner_impl.hh:140
infty_score_t align_top_level_locally(ScoringView sv)
Definition: aligner.cc:837
Provides a modified view on the scoring.
Definition: aligner_impl.hh:174
void trace_arcmatch_noLP(const ArcMatch &am)
Definition: aligner.cc:1026
simple 2D matrix class, provides access via operator (int,int)
Definition: aligner_impl.hh:19
infty_score_t D(const ArcMatch &am) const
Definition: aligner_impl.hh:161
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, ScoringView sv)
initialize matrices M and E
Definition: aligner.cc:341
const BasePairs & bpsB_
base pairs of B
Definition: aligner_impl.hh:46
std::vector< ScoreVector > Es_
Definition: aligner_impl.hh:84
ScoreMatrix Dmat_
matrix indexed by the arc indices of rnas A and B
Definition: aligner_impl.hh:67
int min_j_
subsequence of B left end, computed by trace back
Definition: aligner_impl.hh:93
void set_lambda(score_t lambda)
Definition: aligner_impl.hh:210
const Sequence & seqA_
sequence A
Definition: aligner_impl.hh:40
Represents a structure-annotated sequence alignment.
Definition: alignment.hh:87
infty_score_t & D(const ArcMatch &am)
Definition: aligner_impl.hh:448
Represents a base pair.
Definition: basepairs.hh:40
void trace_in_arcmatch(int state, int al, int i, int bl, int j, bool top_level, ScoringView sv)
align top level in the scanning version
Definition: aligner.cc:1219
void trace(ScoringView sv)
Definition: aligner.cc:1338
infty_score_t D(const Arc &a, const Arc &b) const
Definition: aligner_impl.hh:150
infty_score_t align_noex(int state, pos_type al, pos_type bl, pos_type i, pos_type j, ScoringView sv)
standard cases for alignment (without exlusion handling).
Definition: aligner.cc:189
Provides methods for the scoring of alignments.
Definition: scoring.hh:285
infty_score_t & D(const Arc &arcA, const Arc &arcB)
Definition: aligner_impl.hh:460
size_t idx() const
Definition: basepairs.hh:88
AlignerImpl(const AlignerImpl &a)
copy constructor
Definition: aligner.cc:88
Describes sequence and structure ensemble of an RNA.
Definition: basepairs.hh:107
long int score_t
type of the locarna score as defined by the class Scoring
Definition: scoring_fwd.hh:13
"Sequence View" of multiple alignment as array of column vectors
Definition: sequence.hh:29
Represents a match of two base pairs (arc match)
Definition: arc_matches.hh:35
Restricts range of an alignment in Aligner.
Definition: aligner_restriction.hh:26
std::vector< M_matrix_t > Ms_
Definition: aligner_impl.hh:74
int max_j_
subsequence of B right end, computed by align_top_level
Definition: aligner_impl.hh:96
ScoreMatrix M_matrix_t
Definition: aligner_impl.hh:30
void fill_D_entries_noLP(pos_type al, pos_type bl)
Definition: aligner.cc:641