8d75ef6f07f9f12f7c84bb01d04da1012d606e07 braney Tue Apr 26 17:13:41 2022 -0700 fix a one-again off-again off-by-one error in sequence logos diff --git src/hg/hgTracks/wigTrack.c src/hg/hgTracks/wigTrack.c index 5c09ac3..1563fd6 100644 --- src/hg/hgTracks/wigTrack.c +++ src/hg/hgTracks/wigTrack.c @@ -1194,38 +1194,36 @@ struct dnaSeq *seq = hChromSeq(database, chromName, seqStart, seqEnd); struct pixelCountBin *pixelBins = wgo->pixelBins; double *yOffsets = wgo->yOffsets; int numTrack = wgo->numTrack; Color clipColor = MG_MAGENTA; WigVerticalLineVirtual vLine = wgo->vLine; void *image = wgo->image; #define doLine(image, x, y, height, color) {vLine(image, x, y, height, color); } int h = tg->lineHeight; /* the height of our drawing window */ double scaleFactor = h/graphRange; struct wigMouseOver *mouseOverData = getMouseOverData(tg, preDraw, width, xOff, preDrawZero); double xIncr = (double)width / numBases; unsigned baseNum; -int lastX = xOff; for(baseNum = 0; baseNum < numBases; baseNum++) { - int x1 = baseNum * xIncr; + int x1 = ceil(baseNum * xIncr); int x = x1 + xOff; - int width = x - lastX; + int width = xIncr; int base = seq->dna[baseNum]; - lastX = x; int preDrawIndex = x1 + preDrawZero; struct preDrawElement *p = &preDraw[preDrawIndex]; assert(x1/pixelBins->binSize < pixelBins->binCount); unsigned long *bitCount = &pixelBins->bins[x1/pixelBins->binSize]; /* count is non-zero meaning valid data exists here */ if (p->count) { /* data value has been picked by previous scanning. * Could be smoothed, maybe not. */ double dataValue = p->smooth; /* save a number that represents how many pixels that would be set if we were drawing bars. @@ -1278,44 +1276,44 @@ char string[2]; string[0] = toupper(base); string[1] = 0; MgFont *font = tl.font; int height = dataValue * scaleFactor; unsigned color = MG_BLACK; if (base == 'a') color = MG_RED; else if (base == 't') color = MG_GREEN; else if (base == 'c') color = MG_BROWN; else if (base == 'g') color = MG_BLUE; - //if (abs(dataValue) > 0.1) // I have no idea why this check is here, so I'll leave it in just in case I'm just being forgetful + if (height != 0) { if (dataValue < 0) { // useful for debug, fills a box where letter goes // hvGfxBox(hvg, x, yOff+graphUpperLimit * scaleFactor, width, -height, MG_BLACK); - hvGfxTextInBox(hvg, x, yOff+graphUpperLimit * scaleFactor, width - 1, dataValue * scaleFactor, + hvGfxTextInBox(hvg, x, yOff+graphUpperLimit * scaleFactor, width - 1, height, color, font, string); } else { // useful for debug, fills a box where letter goes // hvGfxBox(hvg, x, yOff-height+graphUpperLimit * scaleFactor, width, height, MG_BLACK); - hvGfxTextInBox(hvg, x, yOff-height+graphUpperLimit * scaleFactor, width - 1, dataValue * scaleFactor, + hvGfxTextInBox(hvg, x, yOff-height+graphUpperLimit * scaleFactor, width - 1, height, color, font, string); } } if (((boxTop+boxHeight) == 0) && !isnan(dataValue)) boxHeight += 1; } double stackValue = dataValue; if ((yOffsets != NULL) && (numTrack > 0)) stackValue += yOffsets[(numTrack-1) * width + x1]; if (stackValue > graphUpperLimit) { doLine(image, x, yOff, 2, clipColor); } else if (stackValue < graphLowerLimit)