LocARNA-1.8.11
aligner_n.hh
1 #ifndef LOCARNA_ALIGNER_N_HH
2 #define LOCARNA_ALIGNER_N_HH
3 
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
7 
8 #include "sequence.hh"
9 #include "basepairs.hh"
10 #include "sparsification_mapper.hh"
11 #include "arc_matches.hh"
12 #include "alignment.hh"
13 
14 #include "params.hh"
15 #include "scoring.hh"
16 
17 #include "matrix.hh"
18 
19 #include "aligner_restriction.hh"
20 
21 
22 namespace LocARNA {
23 
37  class AlignerN {
38  public:
39  typedef BasePairs__Arc Arc;
45 
46 
47 
50 
51  private:
52 
53  protected:
55 
56  const Scoring *scoring;
58  const Sequence &seqA;
59  const Sequence &seqB;
60 
63 
65 
66  const BasePairs &bpsA;
67  const BasePairs &bpsB;
68 
71 
74 
79 
80 
85 
90 
96  M_matrix_t M;
97 
102 
107 
108 
109  int min_i;
110  int min_j;
111  int max_i;
112  int max_j;
113 
114  bool D_created;
115 
117 
118  // ============================================================
129  protected:
131  public:
132 
138  explicit
139  UnmodifiedScoringViewN(const AlignerN *alignerN): alignerN_(alignerN) {};
140 
146  const Scoring *scoring() const {return alignerN_->scoring;}
147 
156  infty_score_t D(const Arc &a, const Arc &b) const {
157  return alignerN_->Dmat(a.idx(),b.idx());
158  }
159 
160 
169  infty_score_t D(const Arc &arcX,const Arc &arcY, bool isA) {
170  if (isA)
171  return D(arcX,arcY);
172  else
173  return D(arcY,arcX);
174  }
175 
183  infty_score_t D(const ArcMatch &am) const {
184  return D(am.arcA(),am.arcB());
185  }
186  };
187 
188 
196  //TODO: required? ModifiedScoringView
198  protected:
200 
202 
210  size_t
211  arc_length(const Arc &a) const {
212  return a.right()-a.left()+1;
213  }
214  public:
215 
223  explicit
225  : alignerN_(alignerN),lambda_(0) {}
226 
232  void
233  set_lambda(score_t lambda) {
234  lambda_=lambda;
235  }
236 
242  const Scoring *scoring() const {return alignerN_->mod_scoring;}
243 
252  infty_score_t D(const Arc &a,const Arc &b) const {
253  return alignerN_->Dmat(a.idx(),b.idx())
254  -lambda_*(arc_length(a)+arc_length(b));
255  }
256 
257 
265  infty_score_t D(const ArcMatch &am) const {
266  return alignerN_->Dmat(am.arcA().idx(),am.arcB().idx())
267  -lambda_*(arc_length(am.arcA())+arc_length(am.arcB()));
268  }
269  };
270 
271 
274 
275  // ============================================================
276 
277 
292  template <class ScoringView>
293  void init_M_E_F(pos_type al, pos_type ar, pos_type bl, pos_type br,ScoringView sv);
294 
302  template <class ScoringView>
303  void computeGapCosts(bool isA, ScoringView sv);
304 
305 
313  infty_score_t getGapCostBetween( pos_type leftSide, pos_type rightSide, bool isA);
314 
315 
327  template<class ScoringView>
328  infty_score_t compute_IX(pos_type xl, const Arc& arcY, pos_type i,bool isA, ScoringView sv);
329 
338  void fill_IA_entries ( pos_type al, Arc arcB, pos_type max_ar);
339 
348  void fill_IB_entries ( Arc arcA, pos_type bl, pos_type max_br);
349 
361  template<class ScoringView>
362  infty_score_t compute_E_entry(index_t al, matidx_t i_index, matidx_t j_index, seq_pos_t i_seq_pos, seq_pos_t i_prev_seq_pos, ScoringView sv);
363 
375  template<class ScoringView>
376  infty_score_t compute_F_entry(index_t bl, matidx_t i_index, matidx_t j_index, seq_pos_t i_seq_pos, seq_pos_t i_prev_seq_pos, ScoringView sv);
388  template<class ScoringView>
389  infty_score_t compute_M_entry(index_t al, index_t bl, matidx_t index_i, matidx_t index_j,ScoringView sv);
390 //---------------------------------------------------------------------------------
391 
405 
416  template<class ScoringView>
417  void trace_E(pos_type al, matidx_t i_index, pos_type bl, matidx_t j_index, bool top_level, ScoringView sv);
418 
429  template<class ScoringView>
430  void trace_F(pos_type al, matidx_t i_index, pos_type bl, matidx_t j_index, bool top_level, ScoringView sv);
431 
432 
443  template<class ScoringView>
444  void trace_M(pos_type al, matidx_t i_index, pos_type bl, matidx_t j_index, bool tl, ScoringView sv);
445 
456  template <class ScoringView>
457  void trace_M_noex(pos_type al, pos_type i,
458  pos_type bl,pos_type j,
459  bool top_level,
460  ScoringView sv);
461 
462 
469  template <class ScoringView>
470  void trace_IXD(const Arc &arcA, const Arc &arcB, bool isA, ScoringView sv);
471 
472 
479  template <class ScoringView>
480  void trace_D(const Arc &arcA, const Arc &arcB, ScoringView sv);
481 
482  // /**
483  // * trace D matrix
484  // * @param am the corresponding arcs which defines the D element
485  // * @param sv scoring view
486  // */
487  // template <class ScoringView>
488  // void trace_D(const ArcMatch &am, ScoringView sv);
489 
498  template <class ScoringView>
499  void trace_IX (pos_type xl, pos_type i, const Arc &arcY, bool isA, ScoringView sv);
500 
505  void align_D();
506 
512  void
514 
522  infty_score_t &D(const ArcMatch &am) {
523  return Dmat(am.arcA().idx(),am.arcB().idx());
524  }
525 
526 
535  infty_score_t &D(const Arc &arcX,const Arc &arcY, bool isA) {
536  if (isA)
537  return Dmat(arcX.idx(),arcY.idx());
538  else
539  return Dmat(arcY.idx(),arcX.idx());
540  }
541 
550  infty_score_t &D(const Arc &arcA,const Arc &arcB) {
551  return Dmat(arcA.idx(),arcB.idx());
552  }
553 
554 
563  infty_score_t &IX(const pos_type i, const Arc &arc, bool isA) {
564 
565  if ( isA )
566  return IAmat(i, arc.idx());
567  else
568  return IBmat(arc.idx(), i);
569 
570  }
571 
580  infty_score_t &IXD(const Arc &arc1, const Arc &arc2, bool isA) {
581 
582  if ( isA )
583  return IADmat(arc1.idx(), arc2.idx());
584  else
585  return IBDmat(arc2.idx(), arc1.idx());
586 
587  }
588 
596  infty_score_t &IA(const pos_type i, const Arc &b) {
597  return IAmat(i, b.idx());
598  }
599 
607  infty_score_t &IB(const Arc &a, const pos_type k) {
608  return IBmat(a.idx(), k);
609  }
610 
616  template <class ScoringView>
617  void trace(ScoringView sv);
618 
619  public:
621  AlignerN(const AlignerN &a);
622 
629  AlignerN(const AlignerParams &ap);
630 
635  static
637 
639  ~AlignerN();
640 
642  Alignment const &
643  get_alignment() const {return alignment;}
644 
647  align();
648 
650  void
651  trace();
652 
653  };
654 
655 } //end namespace LocARNA
656 
657 #endif // LOCARNA_ALIGNER_N_HH
void fill_IB_entries(Arc arcA, pos_type bl, pos_type max_br)
fills all IB values using default scoring scheme
Definition: aligner_n.cc:533
size_t left() const
Definition: basepairs.hh:72
M_matrix_t M
M matrix.
Definition: aligner_n.hh:96
infty_score_t compute_M_entry(index_t al, index_t bl, matidx_t index_i, matidx_t index_j, ScoringView sv)
compute M value of single matrix element
Definition: aligner_n.cc:270
SparsificationMapper::index_t index_t
type for an index
Definition: aligner_n.hh:44
size_t right() const
Definition: basepairs.hh:80
~AlignerN()
destructor
Definition: aligner_n.cc:105
AlignerRestriction r
restriction of AlignerN
Definition: aligner_n.hh:70
const BasePairs & bpsA
base pairs of A
Definition: aligner_n.hh:66
void trace_F(pos_type al, matidx_t i_index, pos_type bl, matidx_t j_index, bool top_level, ScoringView sv)
trace back base insertion within a match of arcs
Definition: aligner_n.cc:1253
void trace()
offer trace as public method. Calls trace(def_scoring_view).
Definition: aligner_n.cc:1623
const Scoring * scoring() const
Definition: aligner_n.hh:146
infty_score_t getGapCostBetween(pos_type leftSide, pos_type rightSide, bool isA)
return score of aligning a subsequence to the gap
Definition: aligner_n.cc:151
const AlignerN * alignerN_
aligner object for that the view is provided
Definition: aligner_n.hh:199
void trace_M_noex(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_n.cc:1291
int max_i
subsequence of A right end, not used in sparse
Definition: aligner_n.hh:111
infty_score_t & IX(const pos_type i, const Arc &arc, bool isA)
Definition: aligner_n.hh:563
size_type pos_type
type of a sequence position
Definition: aux.hh:97
UnmodifiedScoringViewN(const AlignerN *alignerN)
Definition: aligner_n.hh:139
pos_type seq_pos_t
type for a sequence position
Definition: sparsification_mapper.hh:41
ModifiedScoringViewN(const AlignerN *alignerN)
Definition: aligner_n.hh:224
Alignment const & get_alignment() const
return the alignment that was computed by trace()
Definition: aligner_n.hh:643
SparsificationMapper::matidx_t matidx_t
type for a matrix position
Definition: aligner_n.hh:42
int min_j
subsequence of B left end, not used in sparse
Definition: aligner_n.hh:110
const Arc & arcA() const
Definition: arc_matches.hh:66
infty_score_t compute_E_entry(index_t al, matidx_t i_index, matidx_t j_index, seq_pos_t i_seq_pos, seq_pos_t i_prev_seq_pos, ScoringView sv)
compute E matrix value of single matrix element
Definition: aligner_n.cc:230
ScoreMatrix Fmat
matrix for the affine gap cost model base insertion
Definition: aligner_n.hh:89
parameters for AlignerN
Definition: params.hh:319
infty_score_t & D(const ArcMatch &am)
Definition: aligner_n.hh:522
void set_lambda(score_t lambda)
Definition: aligner_n.hh:233
void trace_M(pos_type al, matidx_t i_index, pos_type bl, matidx_t j_index, bool tl, ScoringView sv)
trace back within an arc match
Definition: aligner_n.cc:1557
Maintains the relevant arc matches and their scores.
Definition: arc_matches.hh:112
const ArcMatches & arc_matches
the potential arc matches between A and B
Definition: aligner_n.hh:64
Provides the standard view on the scoring.
Definition: aligner_n.hh:128
const Sequence & seqA
sequence A
Definition: aligner_n.hh:58
infty_score_t align()
compute the alignment score
Definition: aligner_n.cc:843
infty_score_t compute_F_entry(index_t bl, matidx_t i_index, matidx_t j_index, seq_pos_t i_seq_pos, seq_pos_t i_prev_seq_pos, ScoringView sv)
compute F matrix value of single matrix element
Definition: aligner_n.cc:249
Provides a modified view on the scoring.
Definition: aligner_n.hh:197
bool D_created
flag, is D already created?
Definition: aligner_n.hh:114
std::vector< ArcIdx > ArcIdxVec
vector of arc indices
Definition: sparsification_mapper.hh:39
Definition: aligner.cc:17
ScoreMatrix gapCostAmat
Definition: aligner_n.hh:101
ModifiedScoringViewN mod_scoring_view
Modified scoring view for normalized alignment.
Definition: aligner_n.hh:273
infty_score_t compute_IX(pos_type xl, const Arc &arcY, pos_type i, bool isA, ScoringView sv)
compute IA/IB value of single element
Definition: aligner_n.cc:166
const Scoring * scoring() const
Definition: aligner_n.hh:242
size_t index_t
type for an index
Definition: sparsification_mapper.hh:49
infty_score_t D(const ArcMatch &am) const
Definition: aligner_n.hh:183
infty_score_t & D(const Arc &arcA, const Arc &arcB)
Definition: aligner_n.hh:550
Scoring * mod_scoring
used in normalized scoring, when we need to modify the scoring
Definition: aligner_n.hh:57
Alignment alignment
resulting alignment
Definition: aligner_n.hh:116
infty_score_t & IB(const Arc &a, const pos_type k)
Definition: aligner_n.hh:607
SparsificationMapper::ArcIdx ArcIdx
type for arc index
Definition: aligner_n.hh:40
void trace_IX(pos_type xl, pos_type i, const Arc &arcY, bool isA, ScoringView sv)
Definition: aligner_n.cc:909
const Sequence & seqB
sequence B
Definition: aligner_n.hh:59
void fill_M_entries(pos_type al, pos_type ar, pos_type bl, pos_type br)
Definition: aligner_n.cc:564
Represents the mapping for sparsification.
Definition: sparsification_mapper.hh:34
void align_D()
Definition: aligner_n.cc:735
score_t lambda_
factor for modifying scoring
Definition: aligner_n.hh:201
int max_j
subsequence of B right end, not used in sparse
Definition: aligner_n.hh:112
void fill_IA_entries(pos_type al, Arc arcB, pos_type max_ar)
fills all IA values using default scoring scheme
Definition: aligner_n.cc:510
ScoreMatrix gapCostBmat
Definition: aligner_n.hh:106
infty_score_t D(const Arc &a, const Arc &b) const
Definition: aligner_n.hh:252
ScoreMatrix Emat
matrix for the affine gap cost model base deletion
Definition: aligner_n.hh:87
int min_i
subsequence of A left end, not used in sparse
Definition: aligner_n.hh:109
Definition: infty_int.hh:344
SparsificationMapper::seq_pos_t seq_pos_t
type for a sequence position
Definition: aligner_n.hh:43
BasePairs__Arc Arc
type for an arc a.k.a base pair
Definition: aligner_n.hh:39
pos_type matidx_t
type for a matrix position
Definition: sparsification_mapper.hh:40
const Arc & arcB() const
Definition: arc_matches.hh:74
infty_score_t D(const Arc &arcX, const Arc &arcY, bool isA)
Definition: aligner_n.hh:169
void trace_E(pos_type al, matidx_t i_index, pos_type bl, matidx_t j_index, bool top_level, ScoringView sv)
trace back base deletion within a match of arcs
Definition: aligner_n.cc:1215
const AlignerN * alignerN_
aligner object for that the view is provided
Definition: aligner_n.hh:130
const UnmodifiedScoringViewN def_scoring_view
Default scoring view.
Definition: aligner_n.hh:272
Implements SPARSE, next generation alignment algorithm for locarna.
Definition: aligner_n.hh:37
Parameter for alignment by Aligner.
Definition: params.hh:101
void trace_IXD(const Arc &arcA, const Arc &arcB, bool isA, ScoringView sv)
Definition: aligner_n.cc:1040
const SparsificationMapper & mapperA
sparsification mapping for seq A
Definition: aligner_n.hh:61
const SparsificationMapper & mapperB
sparsification mapping for seq B
Definition: aligner_n.hh:62
SparsificationMapper::ArcIdxVec ArcIdxVec
vector of arc indices
Definition: aligner_n.hh:41
void init_M_E_F(pos_type al, pos_type ar, pos_type bl, pos_type br, ScoringView sv)
initialize matrices M
Definition: aligner_n.cc:437
infty_score_t D(const ArcMatch &am) const
Definition: aligner_n.hh:265
static AlignerNParams create()
create with named parameters
Definition: aligner_n.hh:636
AlignerN(const AlignerN &a)
copy constructor
Definition: aligner_n.cc:27
Represents a structure-annotated sequence alignment.
Definition: alignment.hh:87
infty_score_t & IXD(const Arc &arc1, const Arc &arc2, bool isA)
Definition: aligner_n.hh:580
Represents a base pair.
Definition: basepairs.hh:40
ScoreMatrix Dmat
matrix indexed by the arc indices of rnas A and B
Definition: aligner_n.hh:73
const BasePairs & bpsB
base pairs of B
Definition: aligner_n.hh:67
infty_score_t & D(const Arc &arcX, const Arc &arcY, bool isA)
Definition: aligner_n.hh:535
Provides methods for the scoring of alignments.
Definition: scoring.hh:285
size_t arc_length(const Arc &a) const
Definition: aligner_n.hh:211
ScoreMatrix M_matrix_t
type of matrix M
Definition: aligner_n.hh:49
ScoreMatrix IADmat
matrix indexed by positions of elements of the seqA positions and the arc indices of RNA B ...
Definition: aligner_n.hh:82
size_t idx() const
Definition: basepairs.hh:88
const AlignerNParams * params
the parameter for the alignment
Definition: aligner_n.hh:54
infty_score_t & IA(const pos_type i, const Arc &b)
Definition: aligner_n.hh:596
size_t ArcIdx
type of arc index
Definition: sparsification_mapper.hh:38
Describes sequence and structure ensemble of an RNA.
Definition: basepairs.hh:107
void computeGapCosts(bool isA, ScoringView sv)
compute and stores score of aligning subsequences to the gap
Definition: aligner_n.cc:114
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
ScoreMatrix IBmat
matrix indexed by positions of elements of the seqB positions and the arc indices of RNA A ...
Definition: aligner_n.hh:78
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
ScoreMatrix IAmat
matrix indexed by positions of elements of the seqA positions and the arc indices of RNA B ...
Definition: aligner_n.hh:76
ScoreMatrix IBDmat
matrix indexed by positions of elements of the seqB positions and the arc indices of RNA A ...
Definition: aligner_n.hh:84
void trace_D(const Arc &arcA, const Arc &arcB, ScoringView sv)
Definition: aligner_n.cc:1102
const Scoring * scoring
the scores
Definition: aligner_n.hh:56
infty_score_t D(const Arc &a, const Arc &b) const
Definition: aligner_n.hh:156
void fill_D_entries(pos_type al, pos_type bl)
Definition: aligner_n.cc:611