int ffGapPenalty(struct ffAli *left, struct ffAli *right, enum ffStringency stringency) /* What is penalty for gap between two given stringency? */ { int hGap = right->hStart - left->hEnd; int nGap = right->nStart - left->nEnd; return ffCalcGapPenalty(hGap, nGap, stringency); }
static int scoreAli(struct ffAli *ali, boolean isProt, enum ffStringency stringency, struct dnaSeq *tSeq, struct trans3 *t3List) /* Score alignment. */ { int (*scoreFunc)(char *a, char *b, int size); struct ffAli *ff, *nextFf; int score = 0; if (isProt) scoreFunc = aaScoreMatch; else scoreFunc = dnaScoreMatch; for (ff = ali; ff != NULL; ff = nextFf) { nextFf = ff->right; score += scoreFunc(ff->nStart, ff->hStart, ff->nEnd-ff->nStart); if (nextFf != NULL) { int nhStart = trans3GenoPos(nextFf->hStart, tSeq, t3List, FALSE); int ohEnd = trans3GenoPos(ff->hEnd, tSeq, t3List, TRUE); int hGap = nhStart - ohEnd; int nGap = nextFf->nStart - ff->nEnd; score -= ffCalcGapPenalty(hGap, nGap, stringency); } } return score; }
static int ssGapCost(int dq, int dt, void *data) /* Return gap penalty. This just need be a lower bound on * the penalty actually. */ { int cost; if (dt < 0) dt = 0; if (dq < 0) dq = 0; cost = ffCalcGapPenalty(dt, dq, ssStringency); return cost; }
static int trimGapPenalty(int hGap, int nGap, char *iStart, char *iEnd, int orientation) /* Calculate gap penalty for routine below. */ { int penalty = ffCalcGapPenalty(hGap, nGap, ffCdna); if (hGap > 2 || nGap > 2) /* Not just a local extension. */ /* Score gap to favor introns. */ { penalty <<= 1; if (nGap > 0) /* Intron gaps are not in n side at all. */ penalty += 3; /* Good splice sites give you bonus 2, * bad give you penalty of six. */ penalty += 6 - 2*ffScoreIntron(iStart[0], iStart[1], iEnd[-2], iEnd[-1], orientation); } return penalty; }
static struct ssGraph *ssGraphMake(struct ffAli *ffList, bioSeq *qSeq, enum ffStringency stringency, boolean isProt, struct trans3 *t3List) /* Make a graph corresponding to ffList */ { int nodeCount = ffAliCount(ffList); int maxEdgeCount = (nodeCount+1)*(nodeCount)/2; int edgeCount = 0; struct ssEdge *edges, *e; struct ssNode *nodes; struct ssGraph *graph; struct ffAli *ff, *mid; int i, midIx; int overlap; boolean canFollow; if (nodeCount == 1) maxEdgeCount = 1; AllocVar(graph); graph->nodeCount = nodeCount; graph->nodes = AllocArray(nodes, nodeCount+1); for (i=1, ff = ffList; i<=nodeCount; ++i, ff = ff->right) { nodes[i].ff = ff; nodes[i].nodeScore = bioScoreMatch(isProt, ff->nStart, ff->hStart, ff->hEnd - ff->hStart); } graph->edges = AllocArray(edges, maxEdgeCount); for (mid = ffList, midIx=1; mid != NULL; mid = mid->right, ++midIx) { int midScore; struct ssNode *midNode = &nodes[midIx]; e = &edges[edgeCount++]; assert(edgeCount <= maxEdgeCount); e->nodeIn = &nodes[0]; e->score = midScore = midNode->nodeScore; midNode->waysIn = e; for (ff = ffList,i=1; ff != mid; ff = ff->right,++i) { int mhStart = 0, mhEnd = 0; if (t3List) { canFollow = tripleCanFollow(ff, mid, qSeq, t3List); trans3Offsets(t3List, mid->hStart, mid->hEnd, &mhStart, &mhEnd); } else { canFollow = (ff->nStart < mid->nStart && ff->nEnd < mid->nEnd && ff->hStart < mid->hStart && ff->hEnd < mid->hEnd); } if (canFollow) { struct ssNode *ffNode = &nodes[i]; int score; int hGap; int nGap; int crossover; nGap = mid->nStart - ff->nEnd; if (t3List) { int fhStart, fhEnd; trans3Offsets(t3List, ff->hStart, ff->hEnd, &fhStart, &fhEnd); hGap = mhStart - fhEnd; } else { hGap = mid->hStart - ff->hEnd; } e = &edges[edgeCount++]; assert(edgeCount <= maxEdgeCount); e->nodeIn = ffNode; e->overlap = overlap = -nGap; if (overlap > 0) { int midSize = mid->hEnd - mid->hStart; int ffSize = ff->hEnd - ff->hStart; int newMidScore, newFfScore; e->crossover = crossover = findCrossover(ff, mid, overlap, isProt); newMidScore = bioScoreMatch(isProt, mid->nStart, mid->hStart, midSize-overlap+crossover); newFfScore = bioScoreMatch(isProt, ff->nStart+crossover, ff->hStart+crossover, ffSize-crossover); score = newMidScore - ffNode->nodeScore + newFfScore; nGap = 0; hGap -= overlap; } else { score = midScore; } score -= ffCalcGapPenalty(hGap, nGap, stringency); e->score = score; slAddHead(&midNode->waysIn, e); } } slReverse(&midNode->waysIn); } return graph; }