2c43bbe76a2350dfd358bbb5047237243dcb984e markd Tue Nov 8 23:09:32 2022 -0800 added a test case and improved debug and clarified code. However it was pointless, because there was not accutally a bug, just a confused user diff --git src/hg/utils/overlapSelect/chromAnn.c src/hg/utils/overlapSelect/chromAnn.c index 20da847..5be52ce 100644 --- src/hg/utils/overlapSelect/chromAnn.c +++ src/hg/utils/overlapSelect/chromAnn.c @@ -129,34 +129,32 @@ /* free chromAnn data that is represented as a vector of strings */ { freez(&ca->rec); } static void addBedBlocks(struct chromAnn* ca, unsigned opts, struct bed* bed) /* add blocks from a bed */ { int iBlk; for (iBlk = 0; iBlk < bed->blockCount; iBlk++) { int start = bed->chromStart + bed->chromStarts[iBlk]; int end = start + bed->blockSizes[iBlk]; if (opts & chromAnnCds) { - if (start < bed->thickStart) - start = bed->thickStart; - if (end > bed->thickEnd) - end = bed->thickEnd; + start = max(start, bed->thickStart); + end = min(end, bed->thickEnd); } if (start < end) chromAnnBlkNew(ca, start, end); } } static struct chromAnn* chromAnnBedReaderRead(struct chromAnnReader *car) /* read next BED and convert to a chromAnn */ { struct rowReader *rr = car->data; if (!rowReaderNext(rr)) return NULL; rowReaderExpectAtLeast(rr, 3); char **rawCols = (car->opts & chromAnnSaveLines) ? rowReaderCloneColumns(rr) : NULL; @@ -203,34 +201,35 @@ car->caRead = chromAnnBedReaderRead; car->carFree = chromAnnBedReaderFree; car->opts = opts; car->data = rowReaderOpen(fileName, maxParsedCols, FALSE); return car; } static void addGenePredBlocks(struct chromAnn* ca, unsigned opts, struct genePred* gp) /* add blocks from a genePred */ { int iExon; for (iExon = 0; iExon < gp->exonCount; iExon++) { int start = gp->exonStarts[iExon]; int end = gp->exonEnds[iExon]; - if ((opts & chromAnnCds) && (gp->cdsStart > start)) - start = gp->cdsStart; - if ((opts & chromAnnCds) && (gp->cdsEnd < end)) - end = gp->cdsEnd; + if (opts & chromAnnCds) + { + start = max(start, gp->cdsStart); + end = min(end, gp->cdsEnd); + } if (start < end) chromAnnBlkNew(ca, start, end); } } static struct chromAnn* chromAnnGenePredReaderRead(struct chromAnnReader *car) /* Read the next genePred row and create a chromAnn object row read from a * GenePred file or table. If there is no CDS, and chromAnnCds is specified, * it will return a record with zero-length range.*/ { struct rowReader *rr = car->data; if (!rowReaderNext(rr)) return NULL; rowReaderExpectAtLeast(rr, GENEPRED_NUM_COLS);