LocARNA-1.9.2
src/LocARNA/aligner_impl.hh
00001 #ifndef LOCARNA_ALIGNER_IMPL_HH
00002 #define LOCARNA_ALIGNER_IMPL_HH
00003 
00004 #ifdef HAVE_CONFIG_H
00005 #include <config.h>
00006 #endif
00007 
00008 #include "aligner.hh"
00009 
00010 #include "aligner_restriction.hh"
00011 #include "scoring.hh"
00012 #include "alignment.hh"
00013 #include "arc_matches.hh"
00014 #include "params.hh"
00015 
00016 namespace LocARNA {
00017 
00018     class Sequence;
00019     template <class T>
00020     class Matrix;
00021 
00025     class AlignerImpl {
00026     public:
00032         typedef ScoreMatrix M_matrix_t;
00033 
00035         typedef BasePairs__Arc Arc;
00036 
00037         const AlignerParams *params_; 
00038 
00039         const Scoring *scoring_; 
00040         Scoring *mod_scoring_; 
00041 
00042 
00043         const Sequence &seqA_; 
00044         const Sequence &seqB_; 
00045 
00046         const ArcMatches
00047             &arc_matches_; 
00048 
00049         const BasePairs &bpsA_; 
00050         const BasePairs &bpsB_; 
00051 
00068         AlignerRestriction r_;
00069 
00071         ScoreMatrix Dmat_;
00072 
00078         std::vector<M_matrix_t> Ms_;
00079 
00088         std::vector<ScoreVector> Es_;
00089 
00094         std::vector<infty_score_t> Fs_;
00095 
00096         int min_i_; 
00097         int min_j_; 
00098 
00099         int max_i_; 
00100         int max_j_; 
00101 
00102         bool D_created_; 
00103 
00104         Alignment alignment_; 
00105 
00114         enum {
00115             E_NO_NO,
00116             E_X_NO,
00117             E_NO_X,
00118             E_X_X,
00119             E_OP_NO,
00120             E_NO_OP,
00121             E_OP_X,
00122             E_X_OP
00123         };
00124 
00125         // ============================================================
00135         class UnmodifiedScoringView {
00136         private:
00137             const AlignerImpl *
00138                 aligner_impl_; 
00139         public:
00145             explicit UnmodifiedScoringView(const AlignerImpl *aligner_impl)
00146                 : aligner_impl_(aligner_impl){};
00147 
00153             const Scoring *
00154             scoring() const {
00155                 return aligner_impl_->scoring_;
00156             }
00157 
00166             infty_score_t
00167             D(const Arc &a, const Arc &b) const {
00168                 return aligner_impl_->Dmat_(a.idx(), b.idx());
00169             }
00170 
00178             infty_score_t
00179             D(const ArcMatch &am) const {
00180                 return D(am.arcA(), am.arcB());
00181             }
00182         };
00183 
00191         class ModifiedScoringView {
00192         private:
00193             const AlignerImpl *
00194                 aligner_impl_; 
00195 
00196             score_t lambda_; 
00197 
00205             size_t
00206             arc_length(const Arc &a) const {
00207                 return a.right() - a.left() + 1;
00208             }
00209 
00210         public:
00219             explicit ModifiedScoringView(const AlignerImpl *aligner_impl)
00220                 : aligner_impl_(aligner_impl), lambda_(0) {}
00221 
00227             void
00228             set_lambda(score_t lambda) {
00229                 lambda_ = lambda;
00230             }
00231 
00237             const Scoring *
00238             scoring() const {
00239                 return aligner_impl_->mod_scoring_;
00240             }
00241 
00250             infty_score_t
00251             D(const Arc &a, const Arc &b) const {
00252                 return aligner_impl_->Dmat_(a.idx(), b.idx()) -
00253                     FiniteInt(lambda_ * (arc_length(a) + arc_length(b)));
00254             }
00255 
00263             infty_score_t
00264             D(const ArcMatch &am) const {
00265                 return aligner_impl_->Dmat_(am.arcA().idx(), am.arcB().idx()) -
00266                     FiniteInt(lambda_ *
00267                               (arc_length(am.arcA()) + arc_length(am.arcB())));
00268             }
00269         };
00270 
00271         const UnmodifiedScoringView def_scoring_view_; 
00272         ModifiedScoringView mod_scoring_view_; 
00273 
00274         FreeEndgapsDescription free_endgaps_;
00275 
00276         // ============================================================
00277 
00283         AlignerImpl(const AlignerImpl &a);
00284 
00294         AlignerImpl(const Sequence &seqA,
00295                     const Sequence &seqB,
00296                     const ArcMatches &arc_matches,
00297                     const AlignerParams *ap,
00298                     const Scoring *s);
00299 
00303         ~AlignerImpl();
00304 
00305         // ============================================================
00306 
00331         template <class ScoringView>
00332         void
00333         init_state(int state,
00334                    pos_type al,
00335                    pos_type ar,
00336                    pos_type bl,
00337                    pos_type br,
00338                    bool globalA,
00339                    bool exclA,
00340                    bool globalB,
00341                    bool exclB,
00342                    ScoringView sv);
00343 
00364         template <class ScoringView>
00365         infty_score_t
00366         align_noex(int state,
00367                    pos_type al,
00368                    pos_type bl,
00369                    pos_type i,
00370                    pos_type j,
00371                    ScoringView sv);
00372 
00386         void
00387         align_in_arcmatch(pos_type al,
00388                           pos_type ar,
00389                           pos_type bl,
00390                           pos_type br,
00391                           bool allow_exclusion);
00392 
00397         infty_score_t
00398         align_top_level_free_endgaps();
00399 
00404         template <class ScoringView>
00405         infty_score_t
00406         align_top_level_locally(ScoringView sv);
00407 
00409         // infty_score_t align_top_level_localB();
00410 
00423         template <class ScoringView>
00424         void
00425         trace_in_arcmatch(int state,
00426                           int al,
00427                           int i,
00428                           int bl,
00429                           int j,
00430                           bool top_level,
00431                           ScoringView sv);
00432 
00445         template <class ScoringView>
00446         void
00447         trace_noex(int state,
00448                    pos_type al,
00449                    pos_type i,
00450                    pos_type bl,
00451                    pos_type j,
00452                    bool top_level,
00453                    ScoringView sv);
00454 
00459         void
00460         trace_arcmatch(const ArcMatch &am);
00461 
00466         void
00467         trace_arcmatch_noLP(const ArcMatch &am);
00468 
00470         infty_score_t
00471         align();
00472 
00477         void
00478         align_D();
00479 
00483         void
00484         fill_D_entries(pos_type al, pos_type bl);
00485 
00494         void
00495         fill_D_entries_noLP(pos_type al, pos_type bl);
00496 
00504         infty_score_t &
00505         D(const ArcMatch &am) {
00506             return Dmat_(am.arcA().idx(), am.arcB().idx());
00507         }
00508 
00517         infty_score_t &
00518         D(const Arc &arcA, const Arc &arcB) {
00519             return Dmat_(arcA.idx(), arcB.idx());
00520         }
00521 
00527         template <class ScoringView>
00528         void
00529         trace(ScoringView sv);
00530     };
00531 
00532 } // end namespace LocARNA
00533 
00534 #endif // LOCARNA_ALIGNER_IMPL_HH
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends