19 alignment::alignment():gap(0),gap_ext(0),high_score(0),start_position(0),target(NULL),query(NULL),tr(NULL){
50 std::cerr <<
"Either target or query sequence must be set before defining match matrix" << std::endl;
56 std::vector<double> row (alphaSize, 0.0);
62 else if (
mMatrix->size()!=alphaSize){
65 std::vector<double> row (alphaSize,0.0);
70 for(
size_t i=0;i<alphaSize;++i){
71 (*mMatrix)[i][i]=value;
80 std::cerr <<
"Either target or query sequence must be set before defining match matrix" << std::endl;
98 std::cerr <<
"Either target or query sequence must be set before defining match matrix" << std::endl;
104 std::vector<double> row (0.0,alphaSize);
108 else if (
mMatrix->size()!=alphaSize){
111 std::vector<double> row (0.0,alphaSize);
116 for(
size_t row=0;row<alphaSize;++row){
117 for(
size_t col=0;col<alphaSize;++col){
119 (*mMatrix)[row][col]=value;
173 if ( (*
trellis)[queryIndex][targetIndex].getTraceback() ==
LEFT){
181 if ( (*
trellis)[queryIndex][targetIndex].getTraceback() ==
UP){
204 std::vector<cell> row (columns+1,x);
205 trellis=
new std::vector<std::vector<cell> > (rows+1, row);
207 (*trellis)[0][0].setTraceback(
NONE);
208 (*trellis)[0][1].setScore(
gap);
209 (*trellis)[0][1].setTraceback(
LEFT);
210 (*trellis)[1][0].setScore(
gap);
211 (*trellis)[1][0].setTraceback(
UP);
213 for(
size_t i=2;i<=columns;i++){
215 (*trellis)[0][i].setTraceback(
LEFT);
218 for(
size_t j=2;j<=rows;j++){
220 (*trellis)[j][0].setTraceback(
UP);
227 for (
size_t row=0;row<
trellis->size();++row){
228 for (
size_t col = 0; col<(*trellis)[row].size();++col){
229 std::cout << (*trellis)[row][col].getScore() <<
" " << (*trellis)[row][col].getTraceback() <<
"\t";
231 std::cout << std::endl;
253 double max_score(-INFINITY);
254 size_t max_row_index(0);
255 size_t max_col_index(0);
258 for(
size_t top_index=1;top_index<=top_size;top_index++){
259 for(
size_t side_index=1;side_index<=side_size;side_index++){
265 double diagonal_score = (*trellis)[side_index-1][top_index-1].getScore() + (*mMatrix)[queryLetter][targetLetter];
269 double left_score=(*trellis)[side_index][top_index-1].getScore()+
_getGapScore(side_index, top_index-1,
LEFT);
272 double up_score=(*trellis)[side_index-1][top_index].getScore()+
_getGapScore(side_index-1, top_index,
UP);
277 if (diagonal_score<0.0){
280 else if (diagonal_score>max_score){
281 max_score = diagonal_score;
282 max_row_index=side_index;
283 max_col_index=top_index;
289 else if (left_score>max_score){
290 max_score = left_score;
291 max_row_index=side_index;
292 max_col_index=top_index;
298 else if (up_score>max_score){
299 max_score = up_score;
300 max_row_index=side_index;
301 max_col_index=top_index;
306 if (diagonal_score>=up_score && diagonal_score >= left_score){
307 (*trellis)[side_index][top_index].setScore(diagonal_score);
308 (*trellis)[side_index][top_index].setTraceback(
DIAGONAL);
310 else if(up_score>=left_score){
311 (*trellis)[side_index][top_index].setScore(up_score);
312 (*trellis)[side_index][top_index].setTraceback(
UP);
315 (*trellis)[side_index][top_index].setScore(left_score);
316 (*trellis)[side_index][top_index].setTraceback(
LEFT);
321 std::string align_top;
322 std::string align_side;
323 std::string align_status;
333 top_iter=max_col_index;
334 side_iter=max_row_index;
338 while (top_iter!=0 || side_iter!=0){
340 std::cout << side_iter <<
"," << top_iter <<
"\t" << (*trellis)[side_iter][top_iter].getScore() << std::endl;
342 switch ((*
trellis)[side_iter][top_iter].getTraceback()){
366 if (typ ==
cLocal && fabs((*
trellis)[side_iter][top_iter].getScore())<0.001){
371 std::reverse(align_top.begin(), align_top.end());
372 std::reverse(align_side.begin(), align_side.end());
373 std::reverse(align_status.begin(), align_status.end());
375 std::cout << align_top << std::endl << align_status << std::endl << align_side << std::endl;
378 return (*
trellis)[side_size][top_size].getScore();
388 size_t alphaSize =
mMatrix->size();
389 double estimatedFreq= 1/
static_cast<double>(alphaSize);
391 double expectedScore(0);
392 for (
size_t row=0; row<alphaSize; ++row){
393 for (
size_t col=0; col<alphaSize; ++col){
401 std::vector<double> scores;
403 for(
int i=0;i<100;++i){
408 scores.push_back(score);
409 std::cout<< score << std::endl;