364d1a8cc6016b048b66e530a5c9161c4b9fa554
max
  Mon Jun 8 05:54:31 2015 -0700
fixing a bug where a wig file would open a new file for every span on gbib (thanks Angie!)

diff --git src/hg/hgTracks/wigTrack.c src/hg/hgTracks/wigTrack.c
index 19803ff..106f174 100644
--- src/hg/hgTracks/wigTrack.c
+++ src/hg/hgTracks/wigTrack.c
@@ -1292,30 +1292,31 @@
     *retGraphLowerLimit = graphLowerLimit;
 }
 
 struct preDrawContainer *wigLoadPreDraw(struct track *tg, int seqStart, int seqEnd, int width)
 /* Do bits that load the predraw buffer tg->preDrawContainer. */
 {
 /* Just need to do this once... */
 if (tg->preDrawContainer)
     return tg->preDrawContainer;
 
 struct wigItem *wi;
 double pixelsPerBase = scaleForPixels(width);
 double basesPerPixel = 1.0;
 int itemCount = 0;
 char *currentFile = NULL;
+//char *currentFileRewrite = NULL;
 struct udcFile *wibFH = NULL;	/*	file handle to binary file */
 int i;				/* an integer loop counter	*/
 int x1 = 0;			/*	screen coordinates	*/
 int x2 = 0;			/*	screen coordinates	*/
 int usingDataSpan = 1;		/* will become larger if possible */
 
 if (tg->items == NULL)
     return NULL;
 
 if (pixelsPerBase > 0.0)
     basesPerPixel = 1.0 / pixelsPerBase;
 
 /*	width - width of drawing window in pixels
  *	pixelsPerBase - pixels per base
  *	basesPerPixel - calculated as 1.0/pixelsPerBase
@@ -1342,40 +1343,40 @@
     /*	Now that we know what Span to draw, see if this item should be
      *	drawn at all.
      */
     if (usingDataSpan == wi->span)
 	{
 	/*	Check our data file, see if we need to open a new one */
 	if (differentStringNullOk(currentFile,""))
 	    {
 	    if (differentStringNullOk(currentFile,wi->file))
 		{
 		if (wibFH > 0)
 		    {
 		    udcFileClose(&wibFH);
 		    freeMem(currentFile);
 		    }
-                currentFile = hReplaceGbdb(wi->file);
-		wibFH = udcFileMayOpen(currentFile, NULL);
+                currentFile = wi->file;
+		wibFH = udcFileMayOpen(hReplaceGbdb(currentFile), NULL);
 		if (wibFH==NULL)
 		    errAbort("hgTracks/wigLoadPreDraw: failed to open wiggle %s", currentFile);
 		}
 	    }
 	else
 	    {
-            currentFile = hReplaceGbdb(wi->file);
-            wibFH = udcFileMayOpen(currentFile, NULL);
+            currentFile = wi->file;
+            wibFH = udcFileMayOpen(hReplaceGbdb(currentFile), NULL);
 	    if (wibFH==NULL)
 		errAbort("hgTracks/wigLoadPreDraw: failed to open wiggle %s", currentFile);
 	    }
 /*	Ready to draw, what do we know:
  *	the feature being processed:
  *	chrom coords:  [wi->start : wi-end)
  *
  *	The data to be drawn: to be read from file f at offset wi->Offset
  *	data points available: wi->Count, representing wi->Span bases
  *	for each data point
  *
  *	The drawing window, in pixels:
  *	xOff = left margin, yOff = top margin, h = height of drawing window
  *	drawing window in chrom coords: seqStart, seqEnd
  *      'basesPerPixel' is known, 'pixelsPerBase' is known