be4311c07e14feb728abc6425ee606ffaa611a58
markd
  Fri Jan 22 06:46:58 2021 -0800
merge with master

diff --git src/hg/lib/wiggleCart.c src/hg/lib/wiggleCart.c
index 7e2530d..1861b30 100644
--- src/hg/lib/wiggleCart.c
+++ src/hg/lib/wiggleCart.c
@@ -1,29 +1,30 @@
 /*	wiggleCart - take care of parsing and combining values from the
  *	wiggle trackDb optional settings and the same values that may be
  *	in the cart.
  */
 
 /* Copyright (C) 2014 The Regents of the University of California 
  * See README in this or parent directory for licensing information. */
 #include "common.h"
 #include "jksql.h"
 #include "trackDb.h"
 #include "cart.h"
 #include "dystring.h"
 #include "hui.h"
 #include "wiggle.h"
+#include "bigWig.h"
 
 
 #define correctOrder(min,max) if (max < min) \
         { double d; d = max; max = min; min = d; }
 /* check a min,max pair (doubles) and keep them properly in order */
 
 #if defined(DEBUG)      /*      dbg     */
 
 #include "portable.h"
 
 static long wigProfileEnterTime = 0;
 
 void wigProfileEnter()
 {
 wigProfileEnterTime = clock1000();
@@ -156,30 +157,48 @@
 double absMax = 0.0, absMin = 0.0;
 boolean missingAbsMin = FALSE, missingAbsMax = FALSE;
 if (isBedGraph)
     {
     char *tdbMin = trackDbSettingClosestToHomeOrDefault(tdb, MIN_LIMIT, NULL);
     char *tdbMax = trackDbSettingClosestToHomeOrDefault(tdb, MAX_LIMIT, NULL);
     if (tdbMin == NULL)
 	missingAbsMin = TRUE;
     else
 	absMin = sqlDouble(tdbMin);
     if (tdbMax == NULL)
 	missingAbsMax = TRUE;
     else
 	absMax = sqlDouble(tdbMax);
     }
+else if (sameString(tdb->type, "bigWig"))
+    {
+    // bigWig: get default absMin and absMax from data
+    char *fileName = trackDbSetting(tdb, "bigDataUrl");
+    if (fileName)
+        {
+        struct bbiFile *bwf = bigWigFileOpen(hReplaceGbdb(fileName));
+        struct bbiSummaryElement sum = bbiTotalSummary(bwf);
+        absMin = sum.minVal;
+        absMax = sum.maxVal;
+        bigWigFileClose(&bwf);
+        }
+    else
+        {
+        missingAbsMin = TRUE;
+        missingAbsMax = TRUE;
+        }
+    }
 else
     {
     // Wiggle: get min and max from type setting, which has been chopped into words and wordCount:
     // type wig <min> <max>
     if (wordCount >= 3)
 	absMax = atof(words[2]);
     else
 	missingAbsMax = TRUE;
     if (wordCount >= 2)
 	absMin = atof(words[1]);
     else
 	missingAbsMin = TRUE;
     }
 correctOrder(absMin, absMax);