static void determineCtab0(GtUword *Ctab, GtScoreHandler *scorehandler, GtUchar vseq0, const GtUchar *useq, GtUword ustart) { GtUword rowindex, repl, mincost = GT_UWORD_MAX; if (Ctab[1] == 0) { Ctab[0] = 0; return; } for (rowindex = 0; rowindex < Ctab[1]; rowindex++) { repl = gt_scorehandler_get_replacement(scorehandler, vseq0, useq[ustart+rowindex]); if (repl == 0) { Ctab[0] = rowindex; return; } if (repl <= mincost) { mincost = repl; Ctab[0] = rowindex; } } if (mincost > 2 * gt_scorehandler_get_gapscore(scorehandler)) { Ctab[0] = (Ctab[1] > 0) ? Ctab[1]-1 : 0; } }
static void nextLStabcolumn(GtWord *Ltabcolumn, GtUwordPair *Starttabcolumn, GtScoreHandler *scorehandler, const GtUchar *useq, GtUword ustart, GtUword ulen, const GtUchar b, GtUword colindex, Gtmaxcoordvalue *max) { GtUword rowindex; GtUwordPair northwestStarttabentry, westStarttabentry; GtWord northwestLtabentry, westLtabentry, gapscore; gt_assert(max != NULL); gapscore = gt_scorehandler_get_gapscore(scorehandler); westLtabentry = Ltabcolumn[0]; westStarttabentry = Starttabcolumn[0]; Ltabcolumn[0] = 0; Starttabcolumn[0].a = 0; Starttabcolumn[0].b = colindex; for (rowindex = 1UL; rowindex <= ulen; rowindex++) { GtWord val; northwestLtabentry = westLtabentry; northwestStarttabentry = westStarttabentry; westLtabentry = Ltabcolumn[rowindex]; westStarttabentry = Starttabcolumn[rowindex]; Ltabcolumn[rowindex] += gapscore; val = northwestLtabentry + gt_scorehandler_get_replacement(scorehandler, useq[ustart + rowindex-1], b); if (val >= Ltabcolumn[rowindex]) { Ltabcolumn[rowindex] = val; Starttabcolumn[rowindex] = northwestStarttabentry; } if ((val = Ltabcolumn[rowindex-1]+gapscore) > Ltabcolumn[rowindex]) { Ltabcolumn[rowindex] = val; Starttabcolumn[rowindex]=Starttabcolumn[rowindex-1]; } if (0 > Ltabcolumn[rowindex]) { Ltabcolumn[rowindex] = 0; Starttabcolumn[rowindex].a = rowindex; Starttabcolumn[rowindex].b = colindex; } if (Ltabcolumn[rowindex] > gt_max_get_value(max)) { gt_max_coord_update(max, Ltabcolumn[rowindex], Starttabcolumn[rowindex], rowindex, colindex); } } }
static void nextEDtabRtabcolumn(GtUword *EDtabcolumn, GtUword *Rtabcolumn, GtUword colindex, GtUword midcolumn, GtUchar b, const GtUchar *useq, GtUword ustart, GtUword ulen, GtScoreHandler *scorehandler) { GtUword rowindex, val, gapcost, northwestEDtabentry, westEDtabentry, northwestRtabentry, westRtabentry = 0; gt_assert(scorehandler); gapcost = gt_scorehandler_get_gapscore(scorehandler); westEDtabentry = EDtabcolumn[0]; EDtabcolumn[0] += gapcost; if (colindex > midcolumn) { Rtabcolumn[0] = 0; } for (rowindex = 1UL; rowindex <= ulen; rowindex++) { northwestEDtabentry = westEDtabentry; northwestRtabentry = westRtabentry; westEDtabentry = EDtabcolumn[rowindex]; westRtabentry = Rtabcolumn[rowindex]; EDtabcolumn[rowindex] += gapcost; /* 1. recurrence */ /* 2. recurrence: */ val = northwestEDtabentry + gt_scorehandler_get_replacement(scorehandler, useq[ustart+rowindex-1], b); if (val <= EDtabcolumn[rowindex]) { EDtabcolumn[rowindex] = val; if (colindex > midcolumn) { Rtabcolumn[rowindex] = northwestRtabentry; } } /* 3. recurrence: */ if ((val = EDtabcolumn[rowindex-1]+gapcost) < EDtabcolumn[rowindex]) { EDtabcolumn[rowindex] = val; if (colindex > midcolumn) { Rtabcolumn[rowindex] = Rtabcolumn[rowindex-1]; } } } }
/*----------------------------local alignment---------------------------------*/ static GtWord fillDPtab_in_square_space_local(GtWord **Ltabcolumn, GtMaxcoordvalue *max, const GtUchar *useq, GtUword ustart, GtUword ulen, const GtUchar *vseq, GtUword vstart, GtUword vlen, const GtScoreHandler *scorehandler) { GtUword i, j; GtWord gapscore, maxscore, overall_maxscore = 0; gapscore = gt_scorehandler_get_gapscore(scorehandler); Ltabcolumn[0][0] = 0; for (i = 1; i <= ulen; i++) { Ltabcolumn[i][0] = 0; } for (j = 1; j <= vlen; j++) { Ltabcolumn[0][j] = 0; for (i = 1; i <= ulen; i++) { GtWord val; Ltabcolumn[i][j] = Ltabcolumn[i][j-1] + gapscore; val = Ltabcolumn[i-1][j-1] + gt_scorehandler_get_replacement(scorehandler, useq[ustart+i-1], vseq[vstart+j-1]); if (val >= Ltabcolumn[i][j]) { Ltabcolumn[i][j] = val; } if ((val = Ltabcolumn[i-1][j] + gapscore) > Ltabcolumn[i][j]) { Ltabcolumn[i][j] = val; } Ltabcolumn[i][j] = MAX(Ltabcolumn[i][j],0); maxscore = Ltabcolumn[i][j]; if (maxscore > (GtWord) overall_maxscore) { overall_maxscore = maxscore; gt_max_coord_update_without_start (max, maxscore,i,j); } } } return overall_maxscore; }
static void evaluate_crosspoints_from_2dimtab( GtUword **E, GtUword *Ctab, const GtScoreHandler *scorehandler, const GtUchar *useq, GtUword ustart, GtUword ulen, const GtUchar *vseq, GtUword vstart, GtUword vlen, GtUword rowoffset) { GtUword gapcost, idx, jdx; gt_assert(E && Ctab); gapcost = gt_scorehandler_get_gapscore(scorehandler); idx = ulen; jdx = vlen; while (jdx > 1 || idx > 0) { if (idx > 0 && jdx > 0 && E[idx][jdx] == E[idx-1][jdx-1] + gt_scorehandler_get_replacement(scorehandler, useq[ustart+idx-1], vseq[vstart+jdx-1])) { idx--; jdx--; Ctab[jdx] = idx + rowoffset; } else if (idx > 0 && E[idx][jdx] == E[idx-1][jdx] + gapcost) { idx--; /*continue*/ } else if (jdx > 0 && E[idx][jdx] == E[idx][jdx-1] + gapcost) { jdx--; Ctab[jdx] = idx + rowoffset; } else gt_assert(false); } }
/*----------------------------global alignment--------------------------------*/ static void fillDPtab_in_square_space(GtUword **E, const GtUchar *useq, GtUword ustart, GtUword ulen, const GtUchar *vseq, GtUword vstart, GtUword vlen, const GtScoreHandler *scorehandler) { GtUword i, j, gapcost; gapcost = gt_scorehandler_get_gapscore(scorehandler); E[0][0] = 0; for (i = 1; i <= ulen; i++) { E[i][0] = E[i-1][0] + gapcost; } for (j = 1; j <= vlen; j++) { E[0][j] = E[0][j-1] + gapcost; for (i = 1; i <= ulen; i++) { GtUword val; E[i][j] = E[i][j-1] + gapcost; val = E[i-1][j-1] + gt_scorehandler_get_replacement(scorehandler, useq[ustart+i-1], vseq[vstart+j-1]); if (val <= E[i][j]) { E[i][j] = val; } if ((val = E[i-1][j] + gapcost) < E[i][j]) { E[i][j] = val; } } } }