a1a2113c2f18ce0aa25041a00f114092624d9a94
braney
  Thu Oct 24 17:44:28 2024 -0700
letting users specify a bigBed to color their wiggle

diff --git src/hg/hgTracks/wigTrack.c src/hg/hgTracks/wigTrack.c
index e52cb13..d2814cf 100644
--- src/hg/hgTracks/wigTrack.c
+++ src/hg/hgTracks/wigTrack.c
@@ -16,30 +16,31 @@
 #include "hmmstats.h"
 #include "scoredRef.h"
 #ifndef GBROWSE
 #include "customTrack.h"
 #endif /* GBROWSE */
 #include "wigCommon.h"
 #include "imageV2.h"
 #include "memgfx.h"
 #include "udc.h"
 #include "trashDir.h"
 #include "jsonWrite.h"
 #include "dnaMotif.h"
 #include "maf.h"
 #include "hgMaf.h"
 #include "chromAlias.h"
+#include "hubConnect.h"
 
 struct wigItem
 /* A wig track item. */
     {
     struct wigItem *next;
     int start, end;	/* Start/end in chrom (aka browser) coordinates. */
     char *db;		/* Database */
     int ix;		/* Position in list. */
     int height;		/* Pixel height of item. */
     unsigned span;      /* each value spans this many bases */
     unsigned count;     /* number of values to use */
     unsigned offset;    /* offset in File to fetch data */
     char *file; /* path name to data file, one byte per value */
     double lowerLimit;  /* lowest data value in this block */
     double dataRange;   /* lowerLimit + dataRange = upperLimit */
@@ -756,30 +757,61 @@
         *graphUpperLimit = overallUpperLimit;
         *graphLowerLimit = overallLowerLimit;
         }
     }
 else
     {
     *graphUpperLimit = maxY;
     *graphLowerLimit = minY;
     }
 
 double graphRange = *graphUpperLimit - *graphLowerLimit;
 *epsilon = graphRange / lineHeight;
 return(graphRange);
 }
         
+static struct trackDb *makeFakeColorTrackTdb(char *bb)
+{
+struct trackDb *tdb;
+
+AllocVar(tdb);
+//tdb->loadItems = loadBed9;
+//tdb->isBigBed = isBigBed;
+tdb->grp = "other";
+tdb->track = "fakeTrackForColorBy";
+tdb->type = "bigBed 9";
+tdb->settingsHash = newHash(5);
+hashAdd(tdb->settingsHash, "bigDataUrl", hubConnectSkipHubPrefix(bb));
+//tdb->drawItemAt =  linkedFeaturesDrawAt;
+
+return tdb;
+}
+
+struct track *colorTrackIsBigBed(char *colorTrack)
+{
+//                cTrack = trackFromTrackDb(tdb);
+struct track *cTrack = NULL;
+
+if (endsWith(colorTrack, ".bb"))
+    {
+    cTrack = trackFromTrackDb(makeFakeColorTrackTdb(colorTrack));
+    printf("colorTrack is bb %s\n", colorTrack);
+    }
+
+return cTrack;
+}
+
 static Color * makeColorArray(struct preDrawElement *preDraw, int width,
     int preDrawZero, struct wigCartOptions *wigCart, struct track *tg, struct hvGfx *hvg)
 /*	allocate and fill in a coloring array based on another track */
 {
 char *colorTrack = wigCart->colorTrack;
 int x1;
 Color *colorArray = NULL;       /*      Array of pixels to be drawn.    */
 
 /*      Set up the color by array. Determine color of each pixel
  *      based initially on the sign of the data point. If a colorTrack
  *      is specified also fill in the color array with that.
  */
 AllocArray(colorArray, width);
 for(x1 = 0; x1 < width; ++x1)
     {
@@ -791,34 +823,37 @@
 	dataValue = preDraw[preDrawIndex].smooth;
 	/*	negative data is the alternate color	*/
 	if (dataValue < 0.0)
 	    colorArray[x1] = tg->ixAltColor;
 	else
 	    colorArray[x1] = tg->ixColor;
 	}
     }
 
 /* Fill in colors from alternate track if necessary. */
 if (colorTrack != NULL)
     {
     struct track *cTrack = hashFindVal(trackHash, colorTrack);
     if (cTrack == NULL) // rightClick update of wigColorBy track may not have colorTrack in hash
         {               // so create it on the fly
+        if ((cTrack = colorTrackIsBigBed(colorTrack)) == NULL)
+            {
             struct trackDb *tdb = hTrackDbForTrack(database,colorTrack);
             if (tdb != NULL)
                 cTrack = trackFromTrackDb(tdb);
             }
+        }
     if (cTrack != NULL)
         wigFillInColorArray(tg, hvg, colorArray, width, cTrack);
     }
 
 return colorArray;
 }
 
 void vLineViaHvg(void *image, int x, int y, int height, Color color)
 /* A vertical line drawer that works via hvGfx system. */
 {
 hvGfxBox(image, x, y, 1, height, color);
 }
 
 Color somewhatLighterColor32(Color color)
 /* Get a somewhat lighter shade of a color - 1/3 of the way towards white.