LocARNA-1.9.2
src/LocARNA/aligner_p.hh
00001 #ifndef LOCARNA_ALIGNER_P_HH
00002 #define LOCARNA_ALIGNER_P_HH
00003 
00004 #ifdef HAVE_CONFIG_H
00005 #include <config.h>
00006 #endif
00007 
00008 #include "scoring.hh"
00009 #include "params.hh"
00010 
00011 #include "matrix.hh"
00012 
00013 #include "sparse_matrix.hh"
00014 
00015 #include "aligner_restriction.hh"
00016 
00017 namespace LocARNA {
00018 
00019     class Sequence;
00020     class BasePairs;
00021     class BasePairs__Arc;
00022     class ArcMatch;
00023     class ArcMatches;
00024 
00026     typedef Matrix<double> ProbMatrix;
00027 
00029     typedef SparseMatrix<double> SparseProbMatrix;
00030 
00032     typedef SparseMatrix<pf_score_t> SparsePFScoreMatrix;
00033 
00035     typedef AlignerRestriction AlignerPRestriction;
00036 
00052     class AlignerP {
00053     public:
00054         typedef size_t size_type; 
00055         typedef std::pair<size_type, size_type>
00056             size_pair; 
00057 
00058         typedef BasePairs__Arc Arc; 
00059     protected:
00060         const AlignerPParams *params; 
00061 
00062         const Scoring *scoring; 
00063 
00064         const Sequence &seqA;  
00065         const BasePairs &bpsA; 
00066         const Sequence &seqB;  
00067         const BasePairs &bpsB; 
00068 
00069         const ArcMatches &arc_matches; 
00070 
00080         AlignerPRestriction r;
00081 
00087         pf_score_t pf_scale;
00088 
00089         pf_score_t partFunc; 
00090 
00091 
00097         PFScoreMatrix Dmat;
00098 
00111         PFScoreVector E;
00112 
00125         pf_score_t F;
00126 
00132         PFScoreMatrix M;
00133 
00139         PFScoreMatrix Mrev;
00140 
00145         PFScoreVector Erev;
00146 
00151         pf_score_t Frev;
00152 
00156         PFScoreMatrix Erev_mat;
00157 
00162         PFScoreMatrix Frev_mat;
00163 
00169         PFScoreMatrix Dmatprime;
00170 
00177         PFScoreVector Eprime; // one could slightly optimize space by
00178                               // PFScoreVector &Eprime = E;
00179 
00186         pf_score_t Fprime;
00187 
00193         PFScoreMatrix Mprime;
00194 
00196         SparseProbMatrix am_prob;
00197 
00206         SparsePFScoreMatrix bm_prob;
00207 
00208         bool D_created;      
00209         bool Dprime_created; 
00210 
00212         void
00213         init_M(size_type al, size_type ar, size_type bl, size_type br);
00214 
00216         void
00217         init_E(size_type al, size_type ar, size_type bl, size_type br);
00218 
00229         void
00230         init_Mrev(size_type al, size_type ar, size_type bl, size_type br);
00231 
00242         void
00243         init_Erev(size_type al, size_type ar, size_type bl, size_type br);
00244 
00246         // void init_Mprime(size_type al, size_type ar, size_type bl, size_type
00247         // br);
00248 
00250         // void init_Eprime(size_type al, size_type ar, size_type bl, size_type
00251         // br);
00252 
00254         pf_score_t
00255         comp_E_entry(size_type al, size_type bl, size_type i, size_type j);
00256 
00258         pf_score_t
00259         comp_F_entry(size_type al, size_type bl, size_type i, size_type j);
00260 
00262         pf_score_t
00263         comp_M_entry(size_type al, size_type bl, size_type i, size_type j);
00264 
00266         pf_score_t
00267         comp_Mprime_entry(size_type al,
00268                           size_type bl,
00269                           size_type i,
00270                           size_type j,
00271                           size_type max_ar,
00272                           size_type max_br);
00273 
00275         pf_score_t
00276         comp_Eprime_entry(size_type al, size_type bl, size_type i, size_type j);
00277 
00279         pf_score_t
00280         comp_Fprime_entry(size_type al, size_type bl, size_type i, size_type j);
00281 
00283         pf_score_t
00284         comp_Erev_entry(size_type i, size_type j);
00285 
00287         pf_score_t
00288         comp_Frev_entry(size_type i, size_type j);
00289 
00302         pf_score_t
00303         comp_Mrev_entry(size_type i, size_type j, size_type ar, size_type br);
00304 
00315         void
00316         align_inside_arcmatch(size_type al,
00317                               size_type ar,
00318                               size_type bl,
00319                               size_type br);
00320 
00333         void
00334         align_outside_arcmatch(size_type al,
00335                                size_type ar,
00336                                size_type max_ar,
00337                                size_type bl,
00338                                size_type br,
00339                                size_type max_br);
00340 
00359         void
00360         align_reverse(size_type al,
00361                       size_type ar,
00362                       size_type bl,
00363                       size_type br,
00364                       bool copy = false);
00365 
00370         void
00371         align_D();
00372 
00378         void
00379         align_Dprime();
00380 
00386         void
00387         fill_D(size_type al, size_type bl, size_type max_ar, size_type max_br);
00388 
00394         void
00395         fill_Dprime(size_type al,
00396                     size_type bl,
00397                     size_type min_ar,
00398                     size_type min_br,
00399                     size_type max_ar,
00400                     size_type max_br);
00401 
00403         pf_score_t & // SparsePFScoreMatrix::element
00404             D(const ArcMatch &am);
00405 
00407         pf_score_t & // SparsePFScoreMatrix::element
00408             D(const Arc &arcA, const Arc &arcB);
00409 
00411         pf_score_t & // SparsePFScoreMatrix::element
00412             Dprime(const ArcMatch &am);
00413 
00415         pf_score_t & // SparsePFScoreMatrix::element
00416             Dprime(const Arc &arcA, const Arc &arcB);
00417 
00428         size_type
00429         leftmost_covering_arc(size_type s,
00430                               const BasePairs &bps,
00431                               size_type l,
00432                               size_type r) const;
00433 
00442         std::pair<size_type, size_type>
00443         leftmost_covering_arcmatch(size_type al,
00444                                    size_type bl,
00445                                    size_type ar,
00446                                    size_type br) const;
00447 
00457         size_type
00458         rightmost_covering_arc(const BasePairs &bps,
00459                                size_type l,
00460                                size_type r,
00461                                size_type s) const;
00462 
00471         std::pair<size_type, size_type>
00472         rightmost_covering_arcmatch(size_type al,
00473                                     size_type bl,
00474                                     size_type ar,
00475                                     size_type br) const;
00476 
00478         void
00479         alloc_inside_matrices();
00480 
00482         void
00483         alloc_outside_matrices();
00484 
00485     public:
00492         AlignerP(const AlignerParams &ap);
00493 
00497         AlignerP(const AlignerP &p);
00498 
00502         ~AlignerP();
00503 
00508         static AlignerPParams
00509         create() {
00510             return AlignerPParams();
00511         }
00512 
00518         pf_score_t
00519         align_inside();
00520 
00526         void
00527         align_outside();
00528 
00531         void
00532         compute_basematch_probabilities(bool basematch_probs_include_arcmatch);
00533 
00536         void
00537         compute_arcmatch_probabilities();
00538 
00545         void
00546         write_arcmatch_probabilities(std::ostream &out);
00547 
00554         void
00555         write_basematch_probabilities(std::ostream &out);
00556 
00572         pf_score_t
00573         virtual_Mprime(size_type al,
00574                        size_type bl,
00575                        size_type i,
00576                        size_type j,
00577                        size_type max_ar,
00578                        size_type max_br) const;
00579 
00580         // const Matrix *get_basematch_probabilities(){}
00581         // const SparseMatrix *get_arcmatch_probabilities(){}
00582 
00596         double
00597         compute_fragment_match_prob(size_type i,
00598                                     size_type j,
00599                                     size_type k,
00600                                     size_type l);
00601 
00603         void
00604         freeD() {
00605             Dmat.clear();
00606         }
00607 
00609         void
00610         freeMprime() {
00611             Mprime.clear();
00612         }
00613     };
00614 
00615 } // end namespace
00616 
00617 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends