void quilt(Image *target, Image *target_crsp, int rows, int cols, Image *source, Image *source_crsp) { for (int n = 0; n < numIterations; n++) { //alpha = 0.8 * (n / float(numIterations)) + .1; alpha = .1; const int numTrials = sqrt((source->width - blockWidth) * (source->height - blockHeight)); std::cout << "quilting with " << numTrials << " trials" << std::endl; // %%% for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { int x, y; findOverlap(&x, &y, target, target_crsp, i, j, source, source_crsp, numTrials); int vertCut[blockHeight]; int horizCut[blockWidth]; findErrorSurface(vertCut, horizCut, target, i, j, source, x, y); pasteBlock(target, i, j, vertCut, horizCut, source, x, y); } } blockHeight /= 3; //hmmmmm } }
static int ssConnectCost(struct cBlock *a, struct cBlock *b, void *data) /* Calculate connection cost - including gap score * and overlap adjustments if any. */ { struct ffAli *aFf = a->data, *bFf = b->data; int overlapAdjustment = 0; int overlap = findOverlap(a, b); int dq = b->qStart - a->qEnd; int dt = b->tStart - a->tEnd; if (overlap > 0) { int aSize = aFf->hEnd - aFf->hStart; int bSize = bFf->hEnd - bFf->hStart; if (overlap >= bSize || overlap >= aSize) { /* Give stiff overlap adjustment for case where * one block completely enclosed in the other on * either sequence. This will make it never happen. */ overlapAdjustment = a->score + b->score; } else { /* More normal case - partial overlap on one or both strands. */ int crossover = findCrossover(aFf, bFf, overlap, ssIsProt); int remain = overlap - crossover; overlapAdjustment = bioScoreMatch(ssIsProt, aFf->nEnd - remain, aFf->hEnd - remain, remain) + bioScoreMatch(ssIsProt, bFf->nStart, bFf->hStart, crossover); dq -= overlap; dt -= overlap; } } return overlapAdjustment + ssGapCost(dq, dt, data); }
static void ssFindBestBig(struct ffAli *ffList, bioSeq *qSeq, bioSeq *tSeq, enum ffStringency stringency, boolean isProt, struct trans3 *t3List, struct ffAli **retBestAli, int *retScore, struct ffAli **retLeftovers) /* Go set up things to call chainBlocks to find best way to string together * blocks in alignment. */ { struct cBlock *boxList = NULL, *box, *prevBox; struct ffAli *ff, *farRight = NULL; struct lm *lm = lmInit(0); int boxSize; DNA *firstH = tSeq->dna; struct chain *chainList, *chain, *bestChain; int tMin = BIGNUM, tMax = -BIGNUM; /* Make up box list for chainer. */ for (ff = ffList; ff != NULL; ff = ff->right) { lmAllocVar(lm, box); boxSize = ff->nEnd - ff->nStart; box->qStart = ff->nStart - qSeq->dna; box->qEnd = box->qStart + boxSize; if (t3List) { trans3Offsets(t3List, ff->hStart, ff->hEnd, &box->tStart, &box->tEnd); } else { box->tStart = ff->hStart - firstH; box->tEnd = box->tStart + boxSize; } box->data = ff; box->score = bioScoreMatch(isProt, ff->nStart, ff->hStart, boxSize); if (tMin > box->tStart) tMin = box->tStart; if (tMax < box->tEnd) tMax = box->tEnd; slAddHead(&boxList, box); } /* Adjust boxes so that tMin is always 0. */ for (box = boxList; box != NULL; box = box->next) { box->tStart -= tMin; box->tEnd -= tMin; } tMax -= tMin; ssStringency = stringency; ssIsProt = isProt; chainList = chainBlocks(qSeq->name, qSeq->size, '+', "tSeq", tMax, &boxList, ssConnectCost, ssGapCost, NULL, NULL); /* Fixup crossovers on best (first) chain. */ bestChain = chainList; prevBox = bestChain->blockList; for (box = prevBox->next; box != NULL; box = box->next) { int overlap = findOverlap(prevBox, box); if (overlap > 0) { struct ffAli *left = prevBox->data; struct ffAli *right = box->data; int crossover = findCrossover(left, right, overlap, isProt); int remain = overlap - crossover; left->nEnd -= remain; left->hEnd -= remain; right->nStart += crossover; right->hStart += crossover; } prevBox = box; } /* Copy stuff from first chain to bestAli. */ farRight = NULL; for (box = chainList->blockList; box != NULL; box = box->next) { ff = box->data; ff->left = farRight; farRight = ff; } *retBestAli = ffMakeRightLinks(farRight); /* Copy stuff from other chains to leftovers. */ farRight = NULL; for (chain = chainList->next; chain != NULL; chain = chain->next) { for (box = chain->blockList; box != NULL; box = box->next) { ff = box->data; ff->left = farRight; farRight = ff; } } *retLeftovers = ffMakeRightLinks(farRight); *retScore = bestChain->score; for (chain = chainList; chain != NULL; chain = chain->next) chain->blockList = NULL; /* Don't want to free this, it's local. */ chainFreeList(&chainList); lmCleanup(&lm); }