c8834b5b67c2b983e3c7736a2ce2342448b536f2
kate
  Tue May 2 16:13:27 2017 -0700
A little more robust to bad trackDb. refs #18736

diff --git src/hg/hgTracks/barChartTrack.c src/hg/hgTracks/barChartTrack.c
index c475ad4..1a44e76 100644
--- src/hg/hgTracks/barChartTrack.c
+++ src/hg/hgTracks/barChartTrack.c
@@ -63,31 +63,32 @@
 
 char *getCategoryName(struct track *tg, int id)
 /* Get category name from id, cacheing */
 {
 struct barChartCategory *categ;
 int count = getCategoryCount(tg);
 struct barChartTrack *info = (struct barChartTrack *)tg->extraUiData;
 if (!info->categNames)
     {
     struct barChartCategory *categs = getCategories(tg);
     AllocArray(info->categNames, count);
     for (categ = categs; categ != NULL; categ = categ->next)
         info->categNames[categ->id] = cloneString(categ->name);
     }
 if (id >= count)
-    errAbort("Bar chart track: can't find id %d\n", id);
+    //errAbort("Bar chart track: can't find id %d\n", id);
+    return NULL;        // Exclude this category
 return info->categNames[id];
 }
 
 char *getCategoryLabel(struct track *tg, int id)
 /* Get category descriptive label from id, cacheing */
 {
 struct barChartTrack *info = (struct barChartTrack *)tg->extraUiData;
 struct barChartCategory *categ;
 int count = getCategoryCount(tg);
 if (!info->categLabels)
     {
     struct barChartCategory *categs = getCategories(tg);
     AllocArray(info->categLabels, count);
     for (categ = categs; categ != NULL; categ = categ->next)
         info->categLabels[categ->id] = cloneString(categ->label);
@@ -170,30 +171,32 @@
 /* no filter */
 for (categ = extras->categories; categ != NULL; categ = categ->next)
     hashAdd(extras->categoryFilter, categ->name, categ->name);
 }
 
 static int filteredCategoryCount(struct track *tg)
 /* Count of categories to display */
 {
 struct barChartTrack *extras = (struct barChartTrack *)tg->extraUiData;
 return hashNumEntries(extras->categoryFilter);
 }
 
 static boolean filterCategory(struct track *tg, char *name)
 /* Does category pass filter */
 {
+if (name == NULL)
+    return FALSE;
 struct barChartTrack *extras = (struct barChartTrack *)tg->extraUiData;
 return (hashLookup(extras->categoryFilter, name) != NULL);
 }
 
 static int maxCategoryForItem(struct bed *bed, int threshold)
 /* Return id of highest valued category for an item, if significantly higher than median.
  * If none are over threshold, return -1 */
 {
 double maxScore = 0.0, expScore;
 double totalScore = 0.0;
 int maxNum = 0, i;
 int expCount = bed->expCount;
 for (i=0; i<expCount; i++)
     {
     expScore = bed->expScores[i];
@@ -487,31 +490,31 @@
 struct rgbColor lineColor = {.r=0};
 int lineColorIx = hvGfxFindColorIx(hvg, lineColor.r, lineColor.g, lineColor.b);
 int barWidth = barChartBarWidth(tg);
 int graphPadding = barChartPadding();
 char *colorScheme = cartUsualStringClosestToHome(cart, tg->tdb, FALSE, BAR_CHART_COLORS, 
                         BAR_CHART_COLORS_DEFAULT);
 Color clipColor = MG_MAGENTA;
 
 // draw bar graph
 double viewMax = (double)cartUsualIntClosestToHome(cart, tg->tdb, FALSE, 
                                 BAR_CHART_MAX_VIEW_LIMIT, BAR_CHART_MAX_VIEW_LIMIT_DEFAULT);
 double maxMedian = ((struct barChartTrack *)tg->extraUiData)->maxMedian;
 int i;
 int expCount = bed->expCount;
 struct barChartCategory *categ;
-for (i=0, categ=extras->categories; i<expCount; i++, categ=categ->next)
+for (i=0, categ=extras->categories; i<expCount && categ != NULL; i++, categ=categ->next)
     {
     if (!filterCategory(tg, categ->name))
         continue;
     struct rgbColor fillColor = extras->colors[i];
     int fillColorIx = hvGfxFindColorIx(hvg, fillColor.r, fillColor.g, fillColor.b);
     double expScore = bed->expScores[i];
     int height = valToClippedHeight(expScore, maxMedian, viewMax, 
                                         barChartMaxHeight(), extras->doLogTransform);
     if (graphPadding == 0 || sameString(colorScheme, BAR_CHART_COLORS_USER))
         hvGfxBox(hvg, x1, yZero-height+1, barWidth, height, fillColorIx);
     else
         hvGfxOutlinedBox(hvg, x1, yZero-height+1, barWidth, height, fillColorIx, lineColorIx);
     // mark clipped bar with magenta tip
     if (!extras->doLogTransform && expScore > viewMax)
         hvGfxBox(hvg, x1, yZero-height+1, barWidth, 2, clipColor);