3b48412a1e8b3124093c30330c3730e4e4522ca0
braney
  Sun Sep 2 13:01:35 2018 -0700
libify custom bigbed labels so they can be used in hgFind reports #21963

diff --git src/hg/hgTracks/bigBedTrack.c src/hg/hgTracks/bigBedTrack.c
index c4a434b..2f97d8d 100644
--- src/hg/hgTracks/bigBedTrack.c
+++ src/hg/hgTracks/bigBedTrack.c
@@ -13,30 +13,31 @@
 #include "bedCart.h"
 #include "hgTracks.h"
 #include "hmmstats.h"
 #include "localmem.h"
 #include "wigCommon.h"
 #include "bbiFile.h"
 #include "obscure.h"
 #include "bigWig.h"
 #include "bigBed.h"
 #include "bigWarn.h"
 #include "errCatch.h"
 #include "trackHub.h"
 #include "net.h"
 #include "bigPsl.h"
 #include "bigBedFilter.h"
+#include "bigBedLabel.h"
 
 struct bigBedFilter *bigBedMakeNumberFilter(struct cart *cart, struct bbiFile *bbi, struct trackDb *tdb, char *filter, char *defaultLimits,  char *field)
 /* Make a filter on this column if the trackDb or cart wants us to. */
 {
 struct bigBedFilter *ret = NULL;
 char *setting = trackDbSettingClosestToHome(tdb, filter);
 int fieldNum =  bbExtraFieldIndex(bbi, field) + 3;
 if (setting)
     {
     struct asObject *as = bigBedAsOrDefault(bbi);
     // All this isFloat conditional code is here because the cart
     // variables used for floats are different than those used for ints
     // in ../lib/hui.c so we have to use the correct getScore*() routine
     // to access them..    We're doomed.
     boolean isFloat = FALSE;
@@ -353,68 +354,30 @@
 /* return a given field from the bb->rest field, NULL on error */
 {
 if (fieldIdx==0) // we don't return the first(=name) field of bigBed
     return NULL;
 char *rest = cloneString(bb->rest);
 char *restFields[1024];
 int restCount = chopTabs(rest, restFields);
 char *field = NULL;
 if (fieldIdx < restCount)
     field = cloneString(restFields[fieldIdx]);
 freeMem(rest);
 return field;
 }
 
 
-char *makeLabel(struct track *track,  struct bigBedInterval *bb)
-// Build a label for a bigBedTrack from the requested label fields.
-{
-char *labelSeparator = stripEnclosingDoubleQuotes(trackDbSettingClosestToHome(track->tdb, "labelSeparator"));
-if (labelSeparator == NULL)
-    labelSeparator = "/";
-char *restFields[256];
-if (bb->rest != NULL)
-    chopTabs(cloneString(bb->rest), restFields);
-struct dyString *dy = newDyString(128);
-boolean firstTime = TRUE;
-struct slInt *labelInt = track->labelColumns;
-for(; labelInt; labelInt = labelInt->next)
-    {
-    if (!firstTime)
-        dyStringAppend(dy, labelSeparator);
-
-    switch(labelInt->val)
-        {
-        case 0:
-            dyStringAppend(dy, chromName);
-            break;
-        case 1:
-            dyStringPrintf(dy, "%d", bb->start);
-            break;
-        case 2:
-            dyStringPrintf(dy, "%d", bb->end);
-            break;
-        default:
-            assert(bb->rest != NULL);
-            dyStringPrintf(dy, "%s", restFields[labelInt->val - 3]);
-            break;
-        }
-    firstTime = FALSE;
-    }
-return dyStringCannibalize(&dy);
-}
-
 void bigBedAddLinkedFeaturesFromExt(struct track *track,
 	char *chrom, int start, int end, int scoreMin, int scoreMax, boolean useItemRgb,
 	int fieldCount, struct linkedFeatures **pLfList, int maxItems)
 /* Read in items in chrom:start-end from bigBed file named in track->bbiFileName, convert
  * them to linkedFeatures, and add to head of list. */
 {
 struct lm *lm = lmInit(0);
 struct trackDb *tdb = track->tdb;
 struct bigBedInterval *bb, *bbList = bigBedSelectRangeExt(track, chrom, start, end, lm, maxItems);
 char *scoreFilter = cartOrTdbString(cart, track->tdb, "scoreFilter", NULL);
 char *mouseOverField = cartOrTdbString(cart, track->tdb, "mouseOverField", NULL);
 int minScore = 0;
 if (scoreFilter)
     minScore = atoi(scoreFilter);
 
@@ -453,31 +416,31 @@
         char startBuf[16], endBuf[16];
         char *bedRow[32];
 
         bigBedIntervalToRow(bb, chromName, startBuf, endBuf, bedRow, ArraySize(bedRow));
         if (bigBedFilterInterval(bedRow, filters))
             {
             struct bed *bed = bedLoadN(bedRow, fieldCount);
             lf = bedMungToLinkedFeatures(&bed, tdb, fieldCount,
                 scoreMin, scoreMax, useItemRgb);
             }
 	}
 
     if (lf == NULL)
         continue;
 
-    lf->label = makeLabel(track,  bb);
+    lf->label = bigBedMakeLabel(track->tdb, track->labelColumns,  bb, chromName);
     if (sameString(track->tdb->type, "bigGenePred") || startsWith("genePred", track->tdb->type))
         {
         lf->original = genePredFromBigGenePred(chromName, bb); 
         }
 
     char* mouseOver = restField(bb, mouseOverIdx);
     lf->mouseOver   = mouseOver; // leaks some memory, cloneString handles NULL ifself 
 
     if (scoreFilter == NULL || lf->score >= minScore)
 	slAddHead(pLfList, lf);
     }
 lmCleanup(&lm);
 
 if (!trackDbSettingClosestToHomeOn(track->tdb, "linkIdInName"))
     track->itemName = bigLfItemName;