da428ce41d785aa306e4a32e2523fb9288c505d3
chmalee
  Wed Jan 18 16:18:41 2023 -0800
Fix negative strand intron numbering in table browser bed output, refs #30512

diff --git src/hg/lib/featureBits.c src/hg/lib/featureBits.c
index 4630a73..670ef64 100644
--- src/hg/lib/featureBits.c
+++ src/hg/lib/featureBits.c
@@ -464,34 +464,36 @@
 		}
 	    safef(nameBuf, sizeof(nameBuf), "%s_end_%d_%s_%d_%c", 
 		    bed->name, endSize, bed->chrom, s+1,
 		    frForStrand(bed->strand[0]));
 	    fbAddFeature(db, &fbList, nameBuf, bed->chrom, s, e - s,
 			 bed->strand[0], chromStart, chromEnd);
 	    }
 	}
     else if (doIntron)
         {
 	count  = bed->blockCount;
 	starts = bed->chromStarts;
 	sizes  = bed->blockSizes;
 	for (i=1; i<count; ++i)
 	    {
+            // the -1 is because we output intron numbers starting at 0
+            int intronNum = bed->strand[0] == '+' ? i - 1 : count - 1 - i;
 	    s = bed->chromStart + starts[i-1] + sizes[i-1];
 	    e = bed->chromStart + starts[i];
 	    safef(nameBuf, sizeof(nameBuf), "%s_intron_%d_%d_%s_%d_%c", 
-		    bed->name, i-1, extraSize, bed->chrom, s+1,
+		    bed->name, intronNum, extraSize, bed->chrom, s+1,
 		    frForStrand(bed->strand[0]));
 	    setRangePlusExtra(db, &fbList, nameBuf, bed->chrom, s, e,
 			      bed->strand[0], extraSize, extraSize,
 			      chromStart, chromEnd);
 	    }
 	}
     else
         {
 	if (canDoIntrons)
 	    {
 	    // doExon is the default action.
 	    count  = bed->blockCount;
 	    starts = bed->chromStarts;
 	    sizes  = bed->blockSizes;
 	    for (i=0; i<count; ++i)