struct splatAlign *splatExtendTag(struct splatTag *tag, struct dnaSeq *qSeqF, struct dnaSeq *qSeqR, struct splix *splix, struct axtScoreScheme *scoreScheme) /* Convert a single tag to an alignment. */ { int maxSingleGap = 9; int maxTotalGap = maxSingleGap * 3; struct splatAlign *ali = tagToAlign(tag, qSeqF, qSeqR, splix, scoreScheme); struct chain *chain = ali->chain; chainAddAxtScore(chain, ali->qDna, ali->tDna, scoreScheme); int qxSize = chain->qSize - chain->qEnd; /* extra q size. */ int txSize = chain->tSize - chain->tEnd; /* extra t size. */ if (qxSize > 0 && txSize > 0) { int qxStart = chain->qEnd; int qxEnd = chain->qSize; int txStart = chain->tEnd; int txEnd = chain->tSize; int txMaxSize = qxSize + maxTotalGap; if (txSize > txMaxSize) txSize = txMaxSize; int symAlloc = qxSize + txSize; char *qSym, *tSym; AllocArray(qSym, symAlloc); AllocArray(tSym, symAlloc); int symCount, revStartQ, revStartT; if (bandExt(FALSE, scoreScheme, 9, ali->qDna + qxStart, qxSize, ali->tDna + txStart, txSize, 1, symAlloc, &symCount, qSym, tSym, &revStartQ, &revStartT)) { struct cBlock *newBlocks = cBlocksFromAliSym(symCount, qSym, tSym, qxStart, txStart); struct cBlock *lastOldBlock = slLastEl(chain->blockList); lastOldBlock->next = newBlocks; chainMergeAbutting(chain); chainCalcBounds(chain); chainAddAxtScore(chain, ali->qDna, ali->tDna, scoreScheme); } freeMem(qSym); freeMem(tSym); } return ali; }
static boolean smoothOneGap(struct ffAli *left, struct ffAli *right, struct ffAli *ffList) /* If and necessary connect left and right - either directly or * with a small intermediate ffAli inbetween. Do not bother to * merge directly abutting regions, this happens later. Returns * TRUE if any smoothing done. */ { int nGap = right->nStart - left->nEnd; int hGap = right->hStart - left->hEnd; if (nGap > 0 && hGap > 0 && nGap < 10 && hGap < 10) { int sizeDiff = nGap - hGap; if (sizeDiff < 0) sizeDiff = -sizeDiff; if (sizeDiff <= 3) { struct axtScoreScheme *ss = axtScoreSchemeRnaDefault(); char hSym[20], nSym[20]; int symCount; if (bandExt(TRUE, ss, 3, left->nEnd, nGap, left->hEnd, hGap, 1, sizeof(hSym), &symCount, nSym, hSym, NULL, NULL)) { int gapPenalty = -ffCalcCdnaGapPenalty(hGap, nGap) * ss->matrix['a']['a']; int score = axtScoreSym(ss, symCount, nSym, hSym); if (score >= gapPenalty) { struct ffAli *l, *r; l = ffAliFromSym(symCount, nSym, hSym, NULL, left->nEnd, left->hEnd); r = ffRightmost(l); left->right = l; l->left = left; r->right = right; right->left = r; return TRUE; } } } } return FALSE; }
static struct cBlock *extendInRegion( DNA *qDna, int qStart, int qEnd, DNA *tDna, int tStart, int tEnd, int dir, char *qSym, char *tSym, int symAlloc, struct axtScoreScheme *scoreScheme, int maxGap) /* Do banded extension in region and return as a list of blocks. */ { int symCount; int qSize = qEnd - qStart; int tSize = tEnd - tStart; int qs, ts, qExtStart, tExtStart; if (qSize > 0 && tSize > 0) { if (dir < 0) { qStart = qEnd - qSize; tStart = tEnd - tSize; } bandExt(FALSE, scoreScheme, maxGap, qDna + qStart, qSize, tDna + tStart, tSize, dir, symAlloc, &symCount, qSym, tSym, &qs, &ts); if (dir > 0) { qExtStart = qStart; tExtStart = tStart; } else { qExtStart = qEnd - qs - 1; tExtStart = tEnd - ts - 1; } return cBlocksFromAliSym(symCount, qSym, tSym, qExtStart, tExtStart); } else return NULL; }
static struct ffAli *hardRefineSplice(struct ffAli *left, struct ffAli *right, struct dnaSeq *qSeq, struct dnaSeq *tSeq, struct ffAli *ffList, int orientation) /* Do difficult refinement of splice site. See if * can get nice splice sites without breaking too much. */ { /* Strategy: peel back about 6 bases on either side of intron. * Then try positioning the intron at each position in the * peeled area and assessing score. */ int peelSize = 12; char nSeq[12+1], hSeq[12+1+1]; char nSym[25], hSym[25]; int symCount; int seqScore, spliceScore, score, maxScore = 0; int nGap = right->nStart - left->nEnd; int hGap = right->hStart - left->hEnd; int peelLeft = (peelSize - nGap)/2; int intronSize = hGap - nGap; char *npStart = left->nEnd - peelLeft; char *npEnd = npStart + peelSize; char *hpStart = left->hEnd - peelLeft; char *hpEnd = npEnd + (right->hStart - right->nStart); struct axtScoreScheme *ss = axtScoreSchemeRnaDefault(); static int modSize[3] = {0, 1, -1}; int modIx; int bestPos = -1, bestMod = 0; int iPos; memcpy(nSeq, npStart, peelSize); nSeq[peelSize] = 0; for (modIx=0; modIx < ArraySize(modSize); ++modIx) { int modOne = modSize[modIx]; int modPeelSize = peelSize - modOne; int iSize = intronSize + modOne; for (iPos=0; iPos <= modPeelSize; iPos++) { grabAroundIntron(hpStart, iPos, iSize, modPeelSize, hSeq); if (bandExt(TRUE, ss, 2, nSeq, peelSize, hSeq, modPeelSize, 1, sizeof(hSym), &symCount, nSym, hSym, NULL, NULL)) { seqScore = axtScoreSym(ss, symCount, nSym, hSym); spliceScore = calcSpliceScore(ss, hpStart[iPos], hpStart[iPos+1], hpStart[iPos+iSize-2], hpStart[iPos+iSize-1], orientation); score = seqScore + spliceScore; if (score > maxScore) { maxScore = score; bestPos = iPos; bestMod = modOne; } } } } if (maxScore > 0) { int modPeelSize = peelSize - bestMod; int i,diff, cutSymIx = 0; int nIx, hIx; struct ffAli *ff; /* Regenerate the best alignment. */ grabAroundIntron(hpStart, bestPos, intronSize + bestMod, modPeelSize, hSeq); bandExt(TRUE, ss, 2, nSeq, peelSize, hSeq, modPeelSize, 1, sizeof(hSym), &symCount, nSym, hSym, NULL, NULL); /* Peel back surrounding ffAli's */ if (left->nStart > npStart || right->nEnd < npEnd) { /* It would take a lot of code to handle this case. * I believe it is rare enough that it's not worth * it. This verbosity will help keep track of how * often it comes up. */ verbose(2, "Unable to peel in hardRefineSplice\n"); return ffList; } diff = left->nEnd - npStart; left->nEnd -= diff; left->hEnd -= diff; diff = right->nStart - npEnd; right->nStart -= diff; right->hStart -= diff; /* Step through base by base alignment from the left until * hit intron, converting it into ffAli format. */ nIx = hIx = 0; ff = left; for (i=0; i<symCount; ++i) { if (hIx == bestPos) { cutSymIx = i; break; } if (hSym[i] == '-') { ff = NULL; nIx += 1; } else if (nSym[i] == '-') { ff = NULL; hIx += 1; } else { if (ff == NULL) { AllocVar(ff); ff->left = left; ff->right = right; left->right = ff; right->left = ff; left = ff; ff->nStart = ff->nEnd = npStart + nIx; ff->hStart = ff->hEnd = hpStart + hIx; } ++nIx; ++hIx; ff->nEnd += 1; ff->hEnd += 1; } } /* Step through base by base alignment from the right until * hit intron, converting it into ffAli format. */ ff = right; hIx = nIx = 0; /* Index from right side. */ for (i = symCount-1; i >= cutSymIx; --i) { if (hSym[i] == '-') { ff = NULL; nIx += 1; } else if (nSym[i] == '-') { ff = NULL; hIx += 1; } else { if (ff == NULL) { AllocVar(ff); ff->left = left; ff->right = right; left->right = ff; right->left = ff; left = ff; ff->nStart = ff->nEnd = npEnd - nIx; ff->hStart = ff->hEnd = hpEnd - hIx; } ++nIx; ++hIx; ff->nStart -= 1; ff->hStart -= 1; } } } return ffList; }