fbcf701e793eabd40136074b4b7f9d5901a2e6b1
braney
  Wed Jun 8 13:20:50 2022 -0700
make hgTables bigBed output recognize chromAuthority

diff --git src/hg/hgTables/bigBed.c src/hg/hgTables/bigBed.c
index fb8d153..3706c78 100644
--- src/hg/hgTables/bigBed.c
+++ src/hg/hgTables/bigBed.c
@@ -14,30 +14,31 @@
 #include "web.h"
 #include "bed.h"
 #include "hdb.h"
 #include "trackDb.h"
 #include "obscure.h"
 #include "hmmstats.h"
 #include "correlate.h"
 #include "asParse.h"
 #include "bbiFile.h"
 #include "bigBed.h"
 #include "hubConnect.h"
 #include "asFilter.h"
 #include "hgTables.h"
 #include "trackHub.h"
 #include "chromAlias.h"
+#include "bPlusTree.h"
 
 
 boolean isBigBed(char *database, char *table, struct trackDb *parent,
 	struct customTrack *(*ctLookupName)(char *table))
 /* Local test to see if something is big bed.  Handles hub tracks unlike hIsBigBed. */
 {
 struct trackDb *tdb = hashFindVal(fullTableToTdbHash, table);
 
 // if "table" is explicitly listed, we're going to use that instead of any bigDataUrl
 if (tdb && hashLookup(tdb->settingsHash, "table"))
     return FALSE;
 if (tdb)
     return tdbIsBigBed(tdb);
 else
     return hIsBigBed(database, table, parent, ctLookupName);
@@ -253,62 +254,70 @@
     {
     struct slName *nameList = hashSlNameFromHash(idHash);
     int count = slCount(nameList);
     char *names[count];
     int ii;
     for (ii=0; ii < count; ii++)
     {
         names[ii] = nameList->name;
         nameList = nameList->next;
     }
 
     struct lm *lm = lmInit(0);
     struct bigBedInterval *ivList = bigBedMultiNameQuery(bbi, bpt, fieldIx, names, count, lm);
     char chromBuf[4096];
     struct bigBedInterval *interval, *prevInterval = NULL;
+    char * displayChromName = NULL;
     for (interval = ivList; interval != NULL; prevInterval = interval, interval = interval->next)
         {       
-        bigBedIntervalToRowLookupChrom(interval, prevInterval, bbi, chromBuf, sizeof chromBuf, startBuf, endBuf, row, bbi->fieldCount);
+        int lastChromId = (prevInterval == NULL ? -1 : prevInterval->chromId);
+        if (interval->chromId != lastChromId)
+            {
+            bptStringKeyAtPos(bbi->chromBpt, interval->chromId, chromBuf, sizeof chromBuf);
+            displayChromName = chromAliasGetDisplayChrom(database, cart, hgOfficialChromName(database, chromBuf));
+            }
+        bigBedIntervalToRow(interval, displayChromName, startBuf, endBuf, row, bbi->fieldCount);
         if (asFilterOnRow(filter, row))
             {
             int i;
             if (outSep == ',') fputc('"', f);
             fprintf(f, "%s", row[columnArray[0]]);
             if (outSep == ',') fputc('"', f);
             for (i=1; i<fieldCount; ++i)
                 {
                 fputc(outSep, f);
                 if (outSep == ',') fputc('"', f);
                 fprintf(f, "%s", row[columnArray[i]]);
                 if (outSep == ',') fputc('"', f);
                 }
             fprintf(f, "\n");
             }
         }
     }
 else 
     {
     /* Loop through outputting each region */
     struct region *region, *regionList = getRegions();
     for (region = regionList; region != NULL; region = region->next)
         {
         struct lm *lm = lmInit(0);
         struct bigBedInterval *iv, *ivList = bigBedIntervalQuery(bbi, region->chrom,
             region->start, region->end, 0, lm);
+        char * displayChromName = chromAliasGetDisplayChrom(database, cart, region->chrom);
         for (iv = ivList; iv != NULL; iv = iv->next)
             {
-            bigBedIntervalToRow(iv, region->chrom, startBuf, endBuf, row, bbi->fieldCount);
+            bigBedIntervalToRow(iv, displayChromName, startBuf, endBuf, row, bbi->fieldCount);
             if (asFilterOnRow(filter, row))
                 {
                 if ((idHash != NULL) && (hashLookup(idHash, row[3]) == NULL))
                     continue;
                 int i;
                 if (outSep == ',') fputc('"', f);
                 fprintf(f, "%s", row[columnArray[0]]);
                 if (outSep == ',') fputc('"', f);
                 for (i=1; i<fieldCount; ++i)
                     {
                     fputc(outSep, f);
                     if (outSep == ',') fputc('"', f);
                     fprintf(f, "%s", row[columnArray[i]]);
                     if (outSep == ',') fputc('"', f);
                     }