LocARNA-2.0.0
aligner_p.hh
1 #ifndef LOCARNA_ALIGNER_P_HH
2 #define LOCARNA_ALIGNER_P_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <memory>
9 
10 #include "quadmath.hh"
11 
12 #include "scoring.hh"
13 #include "aligner_params.hh"
14 
15 #include "matrix.hh"
16 
17 #include "sparse_matrix.hh"
18 
19 #include "aligner_restriction.hh"
20 
21 namespace LocARNA {
22 
23  class Sequence;
24  class BasePairs;
25  class BasePairs__Arc;
26  class ArcMatch;
27  class ArcMatches;
28 
31 
34 
37 
53  template <typename T>
54  class AlignerP {
55  public:
56  using pf_score_t = typename PFScoring<T>::pf_score_t;
57  using PFScoreMatrix = typename PFScoring<T>::PFScoreMatrix;
58  using PFScoreVector = typename PFScoring<T>::PFScoreVector;
59 
62 
63  typedef size_t size_type;
64  typedef std::pair<size_type, size_type>
66 
67  typedef BasePairs__Arc Arc;
68  protected:
69  const std::unique_ptr<AlignerPParams<T>> params;
70 
72 
73  const Sequence &seqA;
74  const BasePairs &bpsA;
75  const Sequence &seqB;
76  const BasePairs &bpsB;
77 
79 
90 
96  pf_score_t pf_scale;
97 
98  pf_score_t partFunc;
100 
106  PFScoreMatrix Dmat;
107 
120  PFScoreVector E;
121 
134  pf_score_t F;
135 
141  PFScoreMatrix M;
142 
148  PFScoreMatrix Mrev;
149 
154  PFScoreVector Erev;
155 
160  pf_score_t Frev;
161 
165  PFScoreMatrix Erev_mat;
166 
171  PFScoreMatrix Frev_mat;
172 
178  PFScoreMatrix Dmatprime;
179 
186  PFScoreVector Eprime; // one could slightly optimize space by
187  // PFScoreVector &Eprime = E;
188 
195  pf_score_t Fprime;
196 
202  PFScoreMatrix Mprime;
203 
206 
216 
217  bool D_created;
219 
221  void
223 
225  void
227 
238  void
240 
251  void
253 
255  // void init_Mprime(size_type al, size_type ar, size_type bl, size_type
256  // br);
257 
259  // void init_Eprime(size_type al, size_type ar, size_type bl, size_type
260  // br);
261 
263  pf_score_t
265 
267  pf_score_t
269 
271  pf_score_t
273 
275  pf_score_t
277  size_type bl,
278  size_type i,
279  size_type j,
280  size_type max_ar,
281  size_type max_br);
282 
284  pf_score_t
286 
288  pf_score_t
290 
292  pf_score_t
294 
296  pf_score_t
298 
311  pf_score_t
313 
324  void
326  size_type ar,
327  size_type bl,
328  size_type br);
329 
342  void
344  size_type ar,
345  size_type max_ar,
346  size_type bl,
347  size_type br,
348  size_type max_br);
349 
368  void
370  size_type ar,
371  size_type bl,
372  size_type br,
373  bool copy = false);
374 
379  void
381 
387  void
389 
395  void
396  fill_D(size_type al, size_type bl, size_type max_ar, size_type max_br);
397 
403  void
405  size_type bl,
406  size_type min_ar,
407  size_type min_br,
408  size_type max_ar,
409  size_type max_br);
410 
412  pf_score_t &
413  D(const ArcMatch &am);
414 
416  pf_score_t &
417  D(const Arc &arcA, const Arc &arcB);
418 
420  pf_score_t & // SparsePFScoreMatrix::element
421  Dprime(const ArcMatch &am);
422 
424  pf_score_t & // SparsePFScoreMatrix::element
425  Dprime(const Arc &arcA, const Arc &arcB);
426 
437  size_type
439  const BasePairs &bps,
440  size_type l,
441  size_type r) const;
442 
451  std::pair<size_type, size_type>
453  size_type bl,
454  size_type ar,
455  size_type br) const;
456 
466  size_type
468  size_type l,
469  size_type r,
470  size_type s) const;
471 
480  std::pair<size_type, size_type>
482  size_type bl,
483  size_type ar,
484  size_type br) const;
485 
487  void
489 
491  void
493 
494  public:
502 
506  AlignerP(const AlignerP &p);
507 
512 
517  static AlignerPParams<T>
518  create() {
519  return AlignerPParams<T>();
520  }
521 
527  pf_score_t
529 
535  void
537 
540  void
541  compute_basematch_probabilities(bool basematch_probs_include_arcmatch);
542 
545  void
547 
554  void
555  write_arcmatch_probabilities(std::ostream &out);
556 
563  void
564  write_basematch_probabilities(std::ostream &out);
565 
581  pf_score_t
583  size_type bl,
584  size_type i,
585  size_type j,
586  size_type max_ar,
587  size_type max_br) const;
588 
589  // const Matrix *get_basematch_probabilities(){}
590  // const SparseMatrix *get_arcmatch_probabilities(){}
591 
605  double
607  size_type j,
608  size_type k,
609  size_type l);
610 
612  void
613  freeD() {
614  Dmat.clear();
615  }
616 
618  void
620  Mprime.clear();
621  }
622  };
623 
624 } // end namespace
625 
626 
627 #include "aligner_p.icc"
628 
629 #endif
parameters for AlignerP
Definition: aligner_params.hh:122
Computes partition function of alignment, arc match and base match probabilities.
Definition: aligner_p.hh:54
pf_score_t comp_Mprime_entry(size_type al, size_type bl, size_type i, size_type j, size_type max_ar, size_type max_br)
compute one entry in Mprime (outside recursion cases)
const Sequence & seqA
sequence A
Definition: aligner_p.hh:73
pf_score_t comp_M_entry(size_type al, size_type bl, size_type i, size_type j)
compute one entry in M (inside recursion cases)
void init_Erev(size_type al, size_type ar, size_type bl, size_type br)
std::pair< size_type, size_type > rightmost_covering_arcmatch(size_type al, size_type bl, size_type ar, size_type br) const
void init_M(size_type al, size_type ar, size_type bl, size_type br)
initialize first column and row of M, for inside recursion
void compute_arcmatch_probabilities()
SparseProbMatrix am_prob
probabilities of arc matchs, as computed by the algo
Definition: aligner_p.hh:205
void alloc_outside_matrices()
allocate space for the outside matrices
void write_arcmatch_probabilities(std::ostream &out)
write the arc match probabilities to a stream
SparsePFScoreMatrix bm_prob
Definition: aligner_p.hh:215
pf_score_t Frev
Definition: aligner_p.hh:160
AlignerP(const AlignerPParams< T > &ap)
Construct from parameters.
bool Dprime_created
flag, is Dprime already created?
Definition: aligner_p.hh:218
PFScoreVector Erev
Definition: aligner_p.hh:154
pf_score_t & Dprime(const Arc &arcA, const Arc &arcB)
returns lvalue of matrix D'
~AlignerP()
Destructor.
pf_score_t & Dprime(const ArcMatch &am)
returns lvalue of matrix D'
static AlignerPParams< T > create()
create with named parameters
Definition: aligner_p.hh:518
const BasePairs & bpsB
base pairs B
Definition: aligner_p.hh:76
pf_score_t align_inside()
PFScoreVector Eprime
Definition: aligner_p.hh:186
void fill_Dprime(size_type al, size_type bl, size_type min_ar, size_type min_br, size_type max_ar, size_type max_br)
BasePairs__Arc Arc
arc
Definition: aligner_p.hh:67
bool D_created
flag, is D already created?
Definition: aligner_p.hh:217
SparseMatrix< pf_score_t > SparsePFScoreMatrix
sparse matrix for storing partition functions
Definition: aligner_p.hh:61
void fill_D(size_type al, size_type bl, size_type max_ar, size_type max_br)
PFScoreMatrix Erev_mat
Definition: aligner_p.hh:165
size_type leftmost_covering_arc(size_type s, const BasePairs &bps, size_type l, size_type r) const
void align_inside_arcmatch(size_type al, size_type ar, size_type bl, size_type br)
pf_score_t comp_Eprime_entry(size_type al, size_type bl, size_type i, size_type j)
compute one entry in Eprime (outside recursion cases)
const std::unique_ptr< AlignerPParams< T > > params
the parameter for the alignment
Definition: aligner_p.hh:69
std::pair< size_type, size_type > size_pair
pair of size_type
Definition: aligner_p.hh:65
std::pair< size_type, size_type > leftmost_covering_arcmatch(size_type al, size_type bl, size_type ar, size_type br) const
void freeMprime()
free the space of D, take care!
Definition: aligner_p.hh:619
pf_score_t comp_Frev_entry(size_type i, size_type j)
compute one entry in Frev
void init_Mrev(size_type al, size_type ar, size_type bl, size_type br)
pf_score_t comp_Mrev_entry(size_type i, size_type j, size_type ar, size_type br)
AlignerP(const AlignerP &p)
copy constructor @params p AlignerP object to be copied
AlignerPRestriction r
restriction of alignment
Definition: aligner_p.hh:89
size_type rightmost_covering_arc(const BasePairs &bps, size_type l, size_type r, size_type s) const
void write_basematch_probabilities(std::ostream &out)
write the base match probabilities to a stream
void align_reverse(size_type al, size_type ar, size_type bl, size_type br, bool copy=false)
void freeD()
free the space of D, take care!
Definition: aligner_p.hh:613
pf_score_t comp_Fprime_entry(size_type al, size_type bl, size_type i, size_type j)
compute one entry in Fprime (outside recursion cases)
pf_score_t pf_scale
Definition: aligner_p.hh:96
double compute_fragment_match_prob(size_type i, size_type j, size_type k, size_type l)
Fragment match probability.
const ArcMatches & arc_matches
(potential) arc matches of A and B
Definition: aligner_p.hh:78
PFScoreMatrix Frev_mat
Definition: aligner_p.hh:171
pf_score_t & D(const Arc &arcA, const Arc &arcB)
returns lvalue of matrix D
pf_score_t virtual_Mprime(size_type al, size_type bl, size_type i, size_type j, size_type max_ar, size_type max_br) const
Access virtual Mprime matrix.
PFScoreVector E
Definition: aligner_p.hh:120
PFScoreMatrix M
Definition: aligner_p.hh:141
PFScoreMatrix Mprime
Definition: aligner_p.hh:202
PFScoreMatrix Mrev
Definition: aligner_p.hh:148
pf_score_t comp_E_entry(size_type al, size_type bl, size_type i, size_type j)
initialize first column and row of M' for outside recursion
void compute_basematch_probabilities(bool basematch_probs_include_arcmatch)
pf_score_t Fprime
Definition: aligner_p.hh:195
const Sequence & seqB
sequence B
Definition: aligner_p.hh:75
const PFScoring< T > * scoring
the scores
Definition: aligner_p.hh:71
void init_E(size_type al, size_type ar, size_type bl, size_type br)
initialize E
pf_score_t F
Definition: aligner_p.hh:134
PFScoreMatrix Dmat
Definition: aligner_p.hh:106
pf_score_t & D(const ArcMatch &am)
returns lvalue of matrix D
const BasePairs & bpsA
base pairs A
Definition: aligner_p.hh:74
void align_outside_arcmatch(size_type al, size_type ar, size_type max_ar, size_type bl, size_type br, size_type max_br)
size_t size_type
size
Definition: aligner_p.hh:63
PFScoreMatrix Dmatprime
Definition: aligner_p.hh:178
void alloc_inside_matrices()
allocate space for the inside matrices
pf_score_t comp_Erev_entry(size_type i, size_type j)
compute one entry in Erev
pf_score_t comp_F_entry(size_type al, size_type bl, size_type i, size_type j)
compute one entry in F (inside recursion cases)
pf_score_t partFunc
Definition: aligner_p.hh:98
Restricts range of an alignment in Aligner.
Definition: aligner_restriction.hh:26
Represents a match of two base pairs (arc match)
Definition: arc_matches.hh:35
Maintains the relevant arc matches and their scores.
Definition: arc_matches.hh:116
Represents a base pair.
Definition: basepairs.hh:39
Describes sequence and structure ensemble of an RNA.
Definition: basepairs.hh:108
Definition: scoring.hh:745
std::vector< pf_score_t > PFScoreVector
Vector of partition functions.
Definition: scoring.hh:750
"Sequence View" of multiple alignment as array of column vectors
Definition: sequence.hh:17
Definition: aligner.cc:15
AlignerRestriction AlignerPRestriction
restriction of AlignerP ( same as for Aligner )
Definition: aligner_p.hh:36
SparseMatrix< double > SparseProbMatrix
sparse matrix for storing probabilities
Definition: aligner_p.hh:33
Matrix< double > ProbMatrix
matrix for storing probabilities
Definition: aligner_p.hh:27