7584b9d77bf4ca1bb60af851d70f12dd6bb4e670
braney
  Thu Apr 21 12:35:05 2022 -0700
pay attention to block structure in bigBed 12+ when generating
featureBit structure

diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index b884faf..2a6ea59 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -5546,53 +5546,88 @@
 
 safef(buf, sizeof buf, "%s_%s", track, type);
 if (cgiBoolean(buf))
     {
     for (fb = fbList; fb != NULL; fb = fb->next)
 	{
 	s = fb->start - winStart;
 	e = fb->end - winStart;
 	if (isRc)
 	    reverseIntRange(&s, &e, winSize);
 	bitSetRange(bits, s, e - s);
 	}
     }
 }
 
+static boolean clipFbToWindow( struct featureBits *fb, int winStart, int winEnd)
+{
+if ((fb->start > winEnd) || (fb->end < winStart))
+    return FALSE;
+
+if (fb->start < winStart)
+    fb->start = winStart;
+if (fb->end > winEnd)
+    fb->end = winEnd;
+
+return TRUE;
+}
+
 static struct featureBits *getBigBedFbList(struct trackDb *tdb, char *seqName, int winStart, int winEnd)
 /* Get a list of featureBits structures from a bigBed file. */
 {
 struct lm *lm = lmInit(0);
 char *fileName = bbiNameFromSettingOrTable(tdb, NULL, tdb->table);
 struct bbiFile *bbi =  bigBedFileOpenAlias(fileName, chromAliasFindAliases);
 struct bigBedInterval *bb, *bbList = bigBedIntervalQuery(bbi, seqName, winStart, winEnd, 0, lm);
 char *bedRow[32];
 char startBuf[16], endBuf[16];
 struct featureBits *fbList = NULL, *fb;
+//struct bed *bedList = NULL;
 for (bb = bbList; bb != NULL; bb = bb->next)
     {
     bigBedIntervalToRow(bb, seqName, startBuf, endBuf, bedRow, ArraySize(bedRow));
     struct bed *bed = bedLoadN(bedRow, bbi->definedFieldCount);
+    if (bbi->definedFieldCount >= 12)
+        {
+        int ii;
+        for (ii = 0; ii < bed->blockCount; ii++)
+            {
+            AllocVar(fb);
+            fb->name = bed->name;
+            fb->start = bed->chromStart + bed->chromStarts[ii];
+            fb->end = bed->chromStart + bed->chromStarts[ii] + bed->blockSizes[ii];
+            fb->strand = '+';
+            if (bed->strand[0])
+                fb->strand = bed->strand[0];
+            if (!clipFbToWindow(fb, winStart,winEnd))
+                break;
+            slAddHead(&fbList, fb);
+            }
+        }
+    else
+        {
         AllocVar(fb);
         fb->name = bed->name;
         fb->start = bed->chromStart;
         fb->end = bed->chromEnd;
         fb->strand = '+';
         if (bed->strand[0])
             fb->strand = bed->strand[0];
+        if (clipFbToWindow(fb, winStart,winEnd))
             slAddHead(&fbList, fb);
         }
+    }
 return fbList;
 }
 
 void doGetDna3()
 /* Fetch DNA in extended color format */
 {
 struct dnaSeq *seq;
 struct cfm *cfm;
 int i;
 boolean isRc = cartUsualBoolean(cart, "hgSeq.revComp", FALSE);
 boolean defaultUpper = sameString(cartString(cart, "hgSeq.casing"), "upper");
 int winSize;
 int lineWidth = cartInt(cart, "lineWidth");
 struct rgbColor *colors;
 struct trackDb *tdbList = hTrackDb(database), *tdb;