5aa96722c0548d51c76a430c576d1e7823c30ef7 chmalee Wed Aug 25 11:32:44 2021 -0700 Get double sided gaps supported in building of LRG track, refs #24672 diff --git src/hg/lib/lrg.c src/hg/lib/lrg.c index ffb13f3..cb523c6 100644 --- src/hg/lib/lrg.c +++ src/hg/lib/lrg.c @@ -387,47 +387,60 @@ lrg->chrom, chromSize, lrg->chromStart, lrg->chromEnd, lrg->strand, blockCount, opts); psl->blockCount = blockCount; psl->misMatch = slCount(mismatches); boolean isRc = (lrg->strand[0] == '-'); // Translate gap coords from indels into block coords: psl->qStarts[0] = isRc ? (lrg->lrgSize - lrgEnd) : lrgStart; psl->tStarts[0] = lrg->chromStart; int alignedBaseCount = 0; int blockIx = 1; struct lrgDiff *diff; for (diff = indels; diff != NULL; diff = diff->next) { // now we know the size of the previous block: int lrgStartPosStrand = isRc ? (lrg->lrgSize - diff->lrgEnd) : diff->lrgStart; - psl->blockSizes[blockIx-1] = calcBlockSize(diff->chromStart, lrgStartPosStrand, psl, blockIx-1); - alignedBaseCount += psl->blockSizes[blockIx-1]; - // Insertion on t or q? + // Insertion on t or q, or both? int lrgLen = diff->lrgEnd - diff->lrgStart; int refLen = diff->chromEnd - diff->chromStart; - if (lrgLen > refLen) + if (refLen == 0 || lrgLen == 0) // insertion only on t or q + { + if (refLen == 0) { psl->qNumInsert++; psl->qBaseInsert += (lrgLen - refLen); } - else if (refLen > lrgLen) + else if (lrgLen == 0) { psl->tNumInsert++; psl->tBaseInsert += (refLen - lrgLen); } psl->qStarts[blockIx] = lrgStartPosStrand + lrgLen; psl->tStarts[blockIx] = diff->chromEnd; + } + else // double sided insertion + { + psl->tNumInsert++; + psl->tBaseInsert += refLen; + psl->qNumInsert++; + psl->qBaseInsert += lrgLen; + // the qStart needs to account for the lrg insertion AND the prev block + psl->qStarts[blockIx] = diff->lrgStart + lrgLen; + } + psl->tStarts[blockIx] = diff->chromEnd; + psl->blockSizes[blockIx-1] = calcBlockSize(diff->chromStart, lrgStartPosStrand, psl, blockIx-1); + alignedBaseCount += psl->blockSizes[blockIx-1]; blockIx++; } // size of last block: psl->blockSizes[blockIx-1] = calcBlockSize(lrg->chromEnd, lrg->lrgSize, psl, blockIx-1); alignedBaseCount += psl->blockSizes[blockIx-1]; if (blockIx != psl->blockCount) errAbort("lrgToPsl: expected %d blocks but somehow ended up with %d", psl->blockCount, blockIx); psl->match = alignedBaseCount - psl->misMatch; return psl; } static int sumInsertions(struct lrgDiff *indels) /* Return the sum of insertions of lrg into reference sequence, ignoring deletions. * That is the max headroom that we will need while shifting bases around. */