LocARNA-1.8.11
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 "scoring.hh"
9 #include "params.hh"
10 
11 #include "matrix.hh"
12 
13 #include "sparse_matrix.hh"
14 
15 #include "aligner_restriction.hh"
16 
17 
18 namespace LocARNA {
19 
20  class Sequence;
21  class BasePairs;
22  class BasePairs__Arc;
23  class ArcMatch;
24  class ArcMatches;
25 
27  typedef Matrix<double> ProbMatrix;
28 
31 
34 
37 
52  class AlignerP {
53  public:
54  typedef size_t size_type;
55  typedef std::pair<size_type,size_type> size_pair;
56 
57  typedef BasePairs__Arc Arc;
58  protected:
60 
61  const Scoring *scoring;
62 
63  const Sequence &seqA;
64  const BasePairs &bpsA;
65  const Sequence &seqB;
66  const BasePairs &bpsB;
67 
69 
79  AlignerPRestriction r;
80 
81 
88 
89 
91 
97 
98 
109 
119 
120 
126 
127 
133 
139 
145 
150 
156 
157 
163 
169  PFScoreVector Eprime; // one could slightly optimize space by PFScoreVector &Eprime = E;
170 
177 
183 
185  SparseProbMatrix am_prob;
186 
193  SparsePFScoreMatrix bm_prob;
194 
195  bool D_created;
197 
198 
200  void init_M(size_type al, size_type ar, size_type bl, size_type br);
201 
203  void init_E(size_type al, size_type ar, size_type bl, size_type br);
204 
215  void init_Mrev(size_type al, size_type ar, size_type bl, size_type br);
216 
227  void init_Erev(size_type al, size_type ar, size_type bl, size_type br);
228 
230  // void init_Mprime(size_type al, size_type ar, size_type bl, size_type br);
231 
233  // void init_Eprime(size_type al, size_type ar, size_type bl, size_type br);
234 
236  pf_score_t comp_E_entry(size_type al, size_type bl, size_type i, size_type j);
237 
239  pf_score_t comp_F_entry(size_type al, size_type bl, size_type i, size_type j);
240 
242  pf_score_t comp_M_entry(size_type al, size_type bl, size_type i, size_type j);
243 
245  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);
246 
248  pf_score_t comp_Eprime_entry(size_type al, size_type bl, size_type i, size_type j);
249 
251  pf_score_t comp_Fprime_entry(size_type al, size_type bl, size_type i, size_type j);
252 
254  pf_score_t comp_Erev_entry( size_type i, size_type j );
255 
257  pf_score_t comp_Frev_entry( size_type i, size_type j );
258 
270  pf_score_t comp_Mrev_entry( size_type i, size_type j, size_type ar, size_type br);
271 
282  void align_inside_arcmatch(size_type al,size_type ar,size_type bl,size_type br);
283 
294  void
295  align_outside_arcmatch(size_type al,size_type ar,size_type max_ar,size_type bl,size_type br,size_type max_br);
296 
315  void align_reverse(size_type al, size_type ar, size_type bl, size_type br, bool copy=false);
316 
321  void align_D();
322 
328  void align_Dprime();
329 
335  void
336  fill_D(size_type al, size_type bl,
337  size_type max_ar, size_type max_br);
338 
344  void
345  fill_Dprime(size_type al, size_type bl,
346  size_type min_ar, size_type min_br,
347  size_type max_ar, size_type max_br
348  );
349 
351  pf_score_t &//SparsePFScoreMatrix::element
352  D(const ArcMatch &am);
353 
355  pf_score_t &//SparsePFScoreMatrix::element
356  D(const Arc &arcA,const Arc &arcB);
357 
359  pf_score_t &//SparsePFScoreMatrix::element
360  Dprime(const ArcMatch &am);
361 
363  pf_score_t &//SparsePFScoreMatrix::element
364  Dprime(const Arc &arcA,const Arc &arcB);
365 
375  size_type
376  leftmost_covering_arc(size_type s,const BasePairs &bps,size_type l,size_type r) const;
377 
386  std::pair<size_type,size_type>
387  leftmost_covering_arcmatch(size_type al,size_type bl,size_type ar,size_type br) const;
388 
397  size_type
398  rightmost_covering_arc(const BasePairs &bps,size_type l,size_type r,size_type s) const;
399 
408  std::pair<size_type,size_type>
409  rightmost_covering_arcmatch(size_type al,size_type bl,size_type ar,size_type br) const;
410 
411 
413  void
415 
417  void
419 
420  public:
421 
427  AlignerP(const AlignerParams &ap);
428 
432  AlignerP(const AlignerP &p);
433 
437  ~AlignerP();
438 
443  static
445 
451  pf_score_t
452  align_inside();
453 
459  void
460  align_outside();
461 
463  void
464  compute_basematch_probabilities( bool basematch_probs_include_arcmatch );
465 
467  void
469 
476  void
477  write_arcmatch_probabilities(std::ostream &out);
478 
479 
486  void
487  write_basematch_probabilities(std::ostream &out);
488 
504  pf_score_t
505  virtual_Mprime(size_type al, size_type bl, size_type i, size_type j, size_type max_ar, size_type max_br) const;
506 
507  // const Matrix *get_basematch_probabilities(){}
508  // const SparseMatrix *get_arcmatch_probabilities(){}
509 
510 
523  double
524  compute_fragment_match_prob(size_type i,size_type j,size_type k,size_type l);
525 
526 
528  void freeD() { Dmat.clear(); }
529 
531  void freeMprime() { Mprime.clear(); }
532 
533  };
534 
535 } //end namespace
536 
537 #endif
Computes partition function of alignment, arc match and base match probabilities. ...
Definition: aligner_p.hh:52
void freeD()
free the space of D, take care!
Definition: aligner_p.hh:528
pf_score_t F
Definition: aligner_p.hh:118
SparseProbMatrix am_prob
probabilities of arc matchs, as computed by the algo
Definition: aligner_p.hh:185
void init_Mrev(size_type al, size_type ar, size_type bl, size_type br)
Definition: aligner_p.cc:437
size_type leftmost_covering_arc(size_type s, const BasePairs &bps, size_type l, size_type r) const
Definition: aligner_p.cc:616
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)
Definition: aligner_p.cc:706
size_type rightmost_covering_arc(const BasePairs &bps, size_type l, size_type r, size_type s) const
Definition: aligner_p.cc:640
void freeMprime()
free the space of D, take care!
Definition: aligner_p.hh:531
std::vector< pf_score_t > PFScoreVector
Vector of partition functions.
Definition: scoring.hh:41
void align_outside_arcmatch(size_type al, size_type ar, size_type max_ar, size_type bl, size_type br, size_type max_br)
Definition: aligner_p.cc:818
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)
Definition: aligner_p.cc:718
AlignerP(const AlignerParams &ap)
Construct from parameters.
Definition: aligner_p.cc:64
void compute_basematch_probabilities(bool basematch_probs_include_arcmatch)
computes the probabilitites of all base matches and stores them internally (in a 2D-matrix), no probability filtering
Definition: aligner_p.cc:1085
Matrix< double > ProbMatrix
matrix for storing probabilities
Definition: aligner_p.hh:24
~AlignerP()
Destructor.
Definition: aligner_p.cc:122
Maintains the relevant arc matches and their scores.
Definition: arc_matches.hh:112
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)
Definition: aligner_p.cc:742
Definition: aligner.cc:17
void compute_arcmatch_probabilities()
computes the probabilitites of all arc matches and stores them internally (in a sparse matrix)...
Definition: aligner_p.cc:1043
PFScoreVector Erev
Definition: aligner_p.hh:138
size_t size_type
size
Definition: aligner_p.hh:54
BasePairs__Arc Arc
arc
Definition: aligner_p.hh:57
void align_outside()
Definition: aligner_p.cc:1008
void init_E(size_type al, size_type ar, size_type bl, size_type br)
initialize E
Definition: aligner_p.cc:197
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)
Definition: aligner_p.cc:917
const BasePairs & bpsA
base pairs A
Definition: aligner_p.hh:64
const ArcMatches & arc_matches
(potential) arc matches of A and B
Definition: aligner_p.hh:68
PFScoreMatrix Dmatprime
Definition: aligner_p.hh:162
const Sequence & seqB
sequence B
Definition: aligner_p.hh:65
double pf_score_t
type of partition functions
Definition: scoring_fwd.hh:26
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)
Definition: aligner_p.cc:238
PFScoreMatrix Dmat
Definition: aligner_p.hh:96
SparsePFScoreMatrix bm_prob
Definition: aligner_p.hh:193
static AlignerPParams create()
create with named parameters
Definition: aligner_p.hh:444
bool D_created
flag, is D already created?
Definition: aligner_p.hh:195
AlignerRestriction AlignerPRestriction
restriction of AlignerP ( same as for Aligner )
Definition: aligner_p.hh:36
pf_score_t comp_Erev_entry(size_type i, size_type j)
compute one entry in Erev
Definition: aligner_p.cc:493
double compute_fragment_match_prob(size_type i, size_type j, size_type k, size_type l)
Fragment match probability.
Definition: aligner_p.cc:1303
void clear()
Definition: matrix.hh:178
const Scoring * scoring
the scores
Definition: aligner_p.hh:61
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.
Definition: aligner_p.cc:727
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&#39; for outside recursion
Definition: aligner_p.cc:214
Parameter for alignment by Aligner.
Definition: params.hh:101
PFScoreMatrix M
Definition: aligner_p.hh:125
pf_score_t Frev
Definition: aligner_p.hh:144
void align_inside_arcmatch(size_type al, size_type ar, size_type bl, size_type br)
Definition: aligner_p.cc:283
PFScoreVector Eprime
Definition: aligner_p.hh:169
void fill_D(size_type al, size_type bl, size_type max_ar, size_type max_br)
Definition: aligner_p.cc:317
void align_D()
Definition: aligner_p.cc:347
void write_basematch_probabilities(std::ostream &out)
write the base match probabilities to a stream
Definition: aligner_p.cc:1265
void align_Dprime()
Definition: aligner_p.cc:949
void init_Erev(size_type al, size_type ar, size_type bl, size_type br)
Definition: aligner_p.cc:485
pf_score_t & D(const ArcMatch &am)
returns lvalue of matrix D
Definition: aligner_p.cc:137
parameters for AlignerP
Definition: params.hh:290
pf_score_t comp_Mrev_entry(size_type i, size_type j, size_type ar, size_type br)
Definition: aligner_p.cc:513
std::pair< size_type, size_type > leftmost_covering_arcmatch(size_type al, size_type bl, size_type ar, size_type br) const
Definition: aligner_p.cc:629
pf_score_t & Dprime(const ArcMatch &am)
returns lvalue of matrix D&#39;
Definition: aligner_p.cc:602
SparseMatrix< double > SparseProbMatrix
sparse matrix for storing probabilities
Definition: aligner_p.hh:30
SparseMatrix< pf_score_t > SparsePFScoreMatrix
sparse matrix for storing partition functions
Definition: aligner_p.hh:33
AlignerPRestriction r
restriction of alignment
Definition: aligner_p.hh:79
bool Dprime_created
flag, is Dprime already created?
Definition: aligner_p.hh:196
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
Definition: aligner_p.cc:158
pf_score_t Fprime
Definition: aligner_p.hh:176
PFScoreVector E
Definition: aligner_p.hh:108
PFScoreMatrix Mprime
Definition: aligner_p.hh:182
Represents a base pair.
Definition: basepairs.hh:40
pf_score_t align_inside()
Definition: aligner_p.cc:402
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)
Definition: aligner_p.cc:224
void write_arcmatch_probabilities(std::ostream &out)
write the arc match probabilities to a stream
Definition: aligner_p.cc:1281
Provides methods for the scoring of alignments.
Definition: scoring.hh:285
const Sequence & seqA
sequence A
Definition: aligner_p.hh:63
Describes sequence and structure ensemble of an RNA.
Definition: basepairs.hh:107
pf_score_t pf_scale
Definition: aligner_p.hh:87
pf_score_t comp_Frev_entry(size_type i, size_type j)
compute one entry in Frev
Definition: aligner_p.cc:502
PFScoreMatrix Erev_mat
Definition: aligner_p.hh:149
PFScoreMatrix Mrev
Definition: aligner_p.hh:132
const AlignerPParams * params
the parameter for the alignment
Definition: aligner_p.hh:59
void alloc_inside_matrices()
allocate space for the inside matrices
Definition: aligner_p.cc:23
void alloc_outside_matrices()
allocate space for the outside matrices
Definition: aligner_p.cc:41
"Sequence View" of multiple alignment as array of column vectors
Definition: sequence.hh:29
std::pair< size_type, size_type > size_pair
pair of size_type
Definition: aligner_p.hh:55
void align_reverse(size_type al, size_type ar, size_type bl, size_type br, bool copy=false)
Definition: aligner_p.cc:548
std::pair< size_type, size_type > rightmost_covering_arcmatch(size_type al, size_type bl, size_type ar, size_type br) const
Definition: aligner_p.cc:654
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
const BasePairs & bpsB
base pairs B
Definition: aligner_p.hh:66
pf_score_t partFunc
the total partition function (only defined after call of align_inside())
Definition: aligner_p.hh:90
PFScoreMatrix Frev_mat
Definition: aligner_p.hh:155