LocARNA-2.0.0
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 "aligner_params.hh"
15 #include "scoring.hh"
16 
17 #include "matrix.hh"
18 
19 #include "aligner_restriction.hh"
20 
21 namespace LocARNA {
22 
36  class AlignerN {
37  public:
38  typedef BasePairs__Arc Arc;
47 
50 
51  protected:
52  const std::unique_ptr<AlignerNParams> params;
53 
54  const Scoring *scoring;
57  const Sequence &seqA;
58  const Sequence &seqB;
59 
64 
65  const ArcMatches
67 
68  const BasePairs &bpsA;
69  const BasePairs &bpsB;
70 
73 
76 
83 
90 
95 
103 
109 
115 
116  int min_i;
117  int min_j;
118  int max_i;
119  int max_j;
120 
121  bool D_created;
122 
124 
125  // ============================================================
136  protected:
137  const AlignerN
139  public:
145  explicit UnmodifiedScoringViewN(const AlignerN *alignerN)
146  : alignerN_(alignerN){};
147 
153  const Scoring *
154  scoring() const {
155  return alignerN_->scoring;
156  }
157 
167  D(const Arc &a, const Arc &b) const {
168  return alignerN_->Dmat(a.idx(), b.idx());
169  }
170 
180  D(bool isA, const Arc &arcX, const Arc &arcY) {
181  if (isA)
182  return D(arcX, arcY);
183  else
184  return D(arcY, arcX);
185  }
186 
195  D(const ArcMatch &am) const {
196  return D(am.arcA(), am.arcB());
197  }
198  };
199 
207  // TODO: required? ModifiedScoringView
209  protected:
210  const AlignerN
212 
214 
222  size_t
223  arc_length(const Arc &a) const {
224  return a.right() - a.left() + 1;
225  }
226 
227  public:
236  explicit ModifiedScoringViewN(const AlignerN *alignerN)
237  : alignerN_(alignerN), lambda_(0) {}
238 
244  void
245  set_lambda(score_t lambda) {
246  lambda_ = lambda;
247  }
248 
254  const Scoring *
255  scoring() const {
256  return alignerN_->mod_scoring;
257  }
258 
268  D(const Arc &a, const Arc &b) const {
269  return alignerN_->Dmat(a.idx(), b.idx()) -
270  lambda_ * (arc_length(a) + arc_length(b));
271  }
272 
281  D(const ArcMatch &am) const {
282  return alignerN_->Dmat(am.arcA().idx(), am.arcB().idx()) -
283  lambda_ * (arc_length(am.arcA()) + arc_length(am.arcB()));
284  }
285  };
286 
290 
291  // ============================================================
292 
307  template <class ScoringView>
308  void
309  init_M_E_F(pos_type al,
310  pos_type ar,
311  pos_type bl,
312  pos_type br,
313  ScoringView sv);
314 
323  template <bool isA, class ScoringView>
324  void
325  initGapCostMat(ScoringView sv);
326 
335  template <bool isA>
337  getGapCostBetween(pos_type leftSide, pos_type rightSide);
338 
350  template <bool isA, class ScoringView>
352  compute_IX(pos_type xl, const Arc &arcY, pos_type i, ScoringView sv);
353 
363  void
364  fill_IA_entries(pos_type al, Arc arcB, pos_type max_ar);
365 
375  void
376  fill_IB_entries(Arc arcA, pos_type bl, pos_type max_br);
377 
390  template <class ScoringView>
393  matidx_t i_index,
394  matidx_t j_index,
395  seq_pos_t i_seq_pos,
396  seq_pos_t i_prev_seq_pos,
397  ScoringView sv);
398 
411  template <class ScoringView>
414  matidx_t i_index,
415  matidx_t j_index,
416  seq_pos_t i_seq_pos,
417  seq_pos_t i_prev_seq_pos,
418  ScoringView sv);
432  template <class ScoringView>
435  index_t bl,
436  matidx_t index_i,
437  matidx_t index_j,
438  ScoringView sv);
439  //---------------------------------------------------------------------------------
440 
455  void
457 
468  template <class ScoringView>
469  void
470  trace_E(pos_type al,
471  matidx_t i_index,
472  pos_type bl,
473  matidx_t j_index,
474  bool top_level,
475  ScoringView sv);
476 
487  template <class ScoringView>
488  void
489  trace_F(pos_type al,
490  matidx_t i_index,
491  pos_type bl,
492  matidx_t j_index,
493  bool top_level,
494  ScoringView sv);
495 
506  template <class ScoringView>
507  void
508  trace_M(pos_type al,
509  matidx_t i_index,
510  pos_type bl,
511  matidx_t j_index,
512  bool tl,
513  ScoringView sv);
514 
525  template <class ScoringView>
526  void
528  pos_type i,
529  pos_type bl,
530  pos_type j,
531  bool top_level,
532  ScoringView sv);
533 
542  template <bool isA, class ScoringView>
543  void
544  trace_IXD(const Arc &arcA, const Arc &arcB, ScoringView sv);
545 
552  template <class ScoringView>
553  void
554  trace_D(const Arc &arcA, const Arc &arcB, ScoringView sv);
555 
556  // /**
557  // * trace D matrix
558  // * @param am the corresponding arcs which defines the D element
559  // * @param sv scoring view
560  // */
561  // template <class ScoringView>
562  // void trace_D(const ArcMatch &am, ScoringView sv);
563 
572  template <bool isA, class ScoringView>
573  void
574  trace_IX(pos_type xl, pos_type i, const Arc &arcY, ScoringView sv);
575 
580  void
581  align_D();
582 
588  void
590 
598  infty_score_t &
599  D(const ArcMatch &am) {
600  return Dmat(am.arcA().idx(), am.arcB().idx());
601  }
602 
611  template <bool isA>
612  infty_score_t &
613  D(const Arc &arcX, const Arc &arcY) {
614  if (isA)
615  return Dmat(arcX.idx(), arcY.idx());
616  else
617  return Dmat(arcY.idx(), arcX.idx());
618  }
619 
628  infty_score_t &
629  D(const Arc &arcA, const Arc &arcB) {
630  return Dmat(arcA.idx(), arcB.idx());
631  }
632 
641  template <bool isA>
642  infty_score_t &
643  IX(const pos_type i, const Arc &arc) {
644  if (isA)
645  return IAmat(i, arc.idx());
646  else
647  return IBmat(arc.idx(), i);
648  }
649 
658  template <bool isA>
659  infty_score_t &
660  IXD(const Arc &arc1, const Arc &arc2) {
661  if (isA)
662  return IADmat(arc1.idx(), arc2.idx());
663  else
664  return IBDmat(arc2.idx(), arc1.idx());
665  }
666 
674  infty_score_t &
675  IA(const pos_type i, const Arc &b) {
676  return IAmat(i, b.idx());
677  }
678 
686  infty_score_t &
687  IB(const Arc &a, const pos_type k) {
688  return IBmat(a.idx(), k);
689  }
690 
696  template <class ScoringView>
697  void
698  trace(ScoringView sv);
699 
700  public:
702  AlignerN(const AlignerN &a);
703 
710  AlignerN(const AlignerNParams &ap);
711 
713  ~AlignerN();
714 
716  Alignment const &
717  get_alignment() const {
718  return alignment;
719  }
720 
723  align();
724 
726  void
727  trace();
728  };
729 
730 } // end namespace LocARNA
731 
732 #endif // LOCARNA_ALIGNER_N_HH
parameters for AlignerN
Definition: aligner_params.hh:161
Provides a modified view on the scoring.
Definition: aligner_n.hh:208
void set_lambda(score_t lambda)
Definition: aligner_n.hh:245
score_t lambda_
factor for modifying scoring
Definition: aligner_n.hh:213
infty_score_t D(const Arc &a, const Arc &b) const
Definition: aligner_n.hh:268
size_t arc_length(const Arc &a) const
Definition: aligner_n.hh:223
ModifiedScoringViewN(const AlignerN *alignerN)
Definition: aligner_n.hh:236
const AlignerN * alignerN_
aligner object for that the view is provided
Definition: aligner_n.hh:211
const Scoring * scoring() const
Definition: aligner_n.hh:255
infty_score_t D(const ArcMatch &am) const
Definition: aligner_n.hh:281
Provides the standard view on the scoring.
Definition: aligner_n.hh:135
const Scoring * scoring() const
Definition: aligner_n.hh:154
infty_score_t D(const Arc &a, const Arc &b) const
Definition: aligner_n.hh:167
infty_score_t D(const ArcMatch &am) const
Definition: aligner_n.hh:195
const AlignerN * alignerN_
aligner object for that the view is provided
Definition: aligner_n.hh:138
UnmodifiedScoringViewN(const AlignerN *alignerN)
Definition: aligner_n.hh:145
infty_score_t D(bool isA, const Arc &arcX, const Arc &arcY)
Definition: aligner_n.hh:180
Implements SPARSE, next generation alignment algorithm for locarna.
Definition: aligner_n.hh:36
const ArcMatches & arc_matches
the potential arc matches between A and B
Definition: aligner_n.hh:66
const SparsificationMapper & mapperA
sparsification mapping for seq A
Definition: aligner_n.hh:61
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:220
infty_score_t & D(const Arc &arcA, const Arc &arcB)
Definition: aligner_n.hh:629
ScoreMatrix IBDmat
Definition: aligner_n.hh:89
Alignment alignment
resulting alignment
Definition: aligner_n.hh:123
infty_score_t & IXD(const Arc &arc1, const Arc &arc2)
Definition: aligner_n.hh:660
infty_score_t compute_IX(pos_type xl, const Arc &arcY, pos_type i, ScoringView sv)
compute IA/IB value of single element
Definition: aligner_n.cc:154
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:1668
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:275
infty_score_t getGapCostBetween(pos_type leftSide, pos_type rightSide)
return score of aligning a subsequence to gaps
Definition: aligner_n.cc:139
const Sequence & seqA
sequence A
Definition: aligner_n.hh:57
void align_D()
Definition: aligner_n.cc:773
infty_score_t & IB(const Arc &a, const pos_type k)
Definition: aligner_n.hh:687
void fill_D_entries(pos_type al, pos_type bl)
Definition: aligner_n.cc:643
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:521
const SparsificationMapper & mapperB
sparsification mapping for seq B
Definition: aligner_n.hh:63
const Scoring * scoring
the scores
Definition: aligner_n.hh:54
int max_i
subsequence of A right end, not used in sparse
Definition: aligner_n.hh:118
void trace_D(const Arc &arcA, const Arc &arcB, ScoringView sv)
Definition: aligner_n.cc:1140
~AlignerN()
destructor
Definition: aligner_n.cc:100
ScoreMatrix IADmat
Definition: aligner_n.hh:86
ScoreMatrix Emat
matrix for the affine gap cost model base deletion
Definition: aligner_n.hh:92
ScoreMatrix Fmat
matrix for the affine gap cost model base insertion
Definition: aligner_n.hh:94
void trace()
offer trace as public method. Calls trace(def_scoring_view).
Definition: aligner_n.cc:1757
void initGapCostMat(ScoringView sv)
compute and stores score of aligning subsequences to gaps
Definition: aligner_n.cc:109
int max_j
subsequence of B right end, not used in sparse
Definition: aligner_n.hh:119
SparsificationMapper::ArcIdx ArcIdx
type for arc index
Definition: aligner_n.hh:39
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:1316
infty_score_t & D(const Arc &arcX, const Arc &arcY)
Definition: aligner_n.hh:613
const BasePairs & bpsA
base pairs of A
Definition: aligner_n.hh:68
ScoreMatrix Dmat
matrix indexed by the arc indices of rnas A and B
Definition: aligner_n.hh:75
const Sequence & seqB
sequence B
Definition: aligner_n.hh:58
ScoreMatrix M_matrix_t
type of matrix M
Definition: aligner_n.hh:49
infty_score_t & IX(const pos_type i, const Arc &arc)
Definition: aligner_n.hh:643
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:1267
SparsificationMapper::ArcIdxVec ArcIdxVec
vector of arc indices
Definition: aligner_n.hh:41
const BasePairs & bpsB
base pairs of B
Definition: aligner_n.hh:69
ScoreMatrix IAmat
Definition: aligner_n.hh:79
ModifiedScoringViewN mod_scoring_view
Definition: aligner_n.hh:288
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:552
ScoreMatrix gapCostMatA
Definition: aligner_n.hh:108
void fill_M_entries(pos_type al, pos_type ar, pos_type bl, pos_type br)
Definition: aligner_n.cc:594
BasePairs__Arc Arc
type for an arc a.k.a base pair
Definition: aligner_n.hh:38
int min_j
subsequence of B left end, not used in sparse
Definition: aligner_n.hh:117
Alignment const & get_alignment() const
return the alignment that was computed by trace()
Definition: aligner_n.hh:717
ScoreMatrix IBmat
Definition: aligner_n.hh:82
const std::unique_ptr< AlignerNParams > params
the parameter for the alignment
Definition: aligner_n.hh:52
AlignerN(const AlignerN &a)
copy constructor
Definition: aligner_n.cc:25
SparsificationMapper::index_t index_t
type for an index
Definition: aligner_n.hh:46
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:438
void trace_IXD(const Arc &arcA, const Arc &arcB, ScoringView sv)
Definition: aligner_n.cc:1068
infty_score_t align()
compute the alignment score
Definition: aligner_n.cc:865
void trace_IX(pos_type xl, pos_type i, const Arc &arcY, ScoringView sv)
Definition: aligner_n.cc:937
AlignerRestriction r
restriction of AlignerN
Definition: aligner_n.hh:72
const UnmodifiedScoringViewN def_scoring_view
Default scoring view.
Definition: aligner_n.hh:287
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:248
infty_score_t & IA(const pos_type i, const Arc &b)
Definition: aligner_n.hh:675
bool D_created
flag, is D already created?
Definition: aligner_n.hh:121
infty_score_t & D(const ArcMatch &am)
Definition: aligner_n.hh:599
M_matrix_t M
M matrix.
Definition: aligner_n.hh:102
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:1366
SparsificationMapper::matidx_t matidx_t
type for a matrix position
Definition: aligner_n.hh:43
Scoring * mod_scoring
Definition: aligner_n.hh:55
ScoreMatrix gapCostMatB
Definition: aligner_n.hh:114
int min_i
subsequence of A left end, not used in sparse
Definition: aligner_n.hh:116
SparsificationMapper::seq_pos_t seq_pos_t
type for a sequence position
Definition: aligner_n.hh:45
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: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
Represents the mapping for sparsification.
Definition: sparsification_mapper.hh:30
std::vector< ArcIdx > ArcIdxVec
vector of arc indices
Definition: sparsification_mapper.hh:34
size_t ArcIdx
type of arc index
Definition: sparsification_mapper.hh:33
pos_type seq_pos_t
type for a sequence position
Definition: sparsification_mapper.hh:36
pos_type matidx_t
type for a matrix position
Definition: sparsification_mapper.hh:35
size_t index_t
type for an index
Definition: sparsification_mapper.hh:38
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