ppALIGN API documentation
src/viterbi.hpp
00001 /****************************************************************************** 00002 Copyright 2009 Stefan Wolfsheimer & Gregory Nuel. 00003 00004 This file is part of ppALIGN 00005 00006 ppALIGN is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 ppALIGN is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with ppALIGN; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 *******************************************************************************/ 00020 00021 #ifndef _VITERBI_HPP_ 00022 #define _VITERBI_HPP_ 00023 00024 #include "checkpoint.hpp" 00025 #include "align.hpp" 00026 #include "weights.hpp" 00027 00030 struct OptCell 00031 { 00035 int M,I,D; 00037 00040 int t; 00041 00042 }; 00043 00044 00045 00048 class ViterbiWorkspace : public Workspace<OptCell>, 00049 private CheckpointDriver 00050 { 00051 public: 00052 00056 ViterbiWorkspace(size_t n); 00057 00076 int OptimalAlignment(const Sequence & seq1, 00077 const Sequence & seq2, 00078 const ScoreMatrix & mat, 00079 AlignmentType atype, 00080 int gap_open, 00081 int gap_extension, 00082 bool _allow_DI, 00083 bool _allow_ID, 00084 Align & a, 00085 bool _dangling=true); 00086 00087 int OptimalScore(const Sequence & seq1, 00088 const Sequence & seq2, 00089 const ScoreMatrix & mat, 00090 AlignmentType atype, 00091 int gap_open, 00092 int gap_extension, 00093 bool _allow_DI, 00094 bool _allow_ID); 00095 00096 private: 00097 long length1; 00098 long length2; 00099 AlignmentType atype; 00100 00101 00102 int alpha,beta; 00103 bool allow_ID; 00104 bool allow_DI; 00105 const ScoreMatrix * ptr_mat; 00106 00109 Align * ptr_align; 00110 00111 Sequence::const_iterator begin_seq1; 00112 Sequence::const_iterator begin_seq2; 00113 int score; 00114 Pair pos_max; 00115 00116 // backtrace 00117 Pair pos; 00118 AlignState last_s; 00119 bool dangling; 00120 00121 00122 void LastRow(ViterbiWorkspace::iterator curr); 00123 void Backward(ViterbiWorkspace::const_iterator last, 00124 ViterbiWorkspace::iterator curr, 00125 long i); 00126 void FirstRow(ViterbiWorkspace::const_iterator last, 00127 ViterbiWorkspace::iterator curr); 00128 00129 void ForwardBackward(ViterbiWorkspace::const_iterator curr, 00130 long i); 00131 00132 // virtual functions from checkpoint driver 00133 void FirstPassForward(long last_row, 00134 long current_row, 00135 long row_i); 00136 void Forward(long last_row, 00137 long current_row, 00138 long row_i); 00139 bool Backward(long current_row, 00140 long row_i); 00141 long SpaceAvail(); 00142 long SpaceRequired(); 00143 }; 00144 00145 #endif