f236f0e852855ee84cd7e996a0345b2da65b67df
angie
  Wed Jan 23 11:32:50 2013 -0800
Bug #9860 (TB paste IDs button not working for bigBed) - Steve foundthat while one can now get to the paste IDs page for bigBed, one can't
get out of it -- clicking submit caused another illegal mysql query.
Added the rest of the missing implementation for pasted/uploaded IDs
for bigBed.

diff --git src/hg/hgTables/bigBed.c src/hg/hgTables/bigBed.c
index 54b2271..0579576 100644
--- src/hg/hgTables/bigBed.c
+++ src/hg/hgTables/bigBed.c
@@ -172,30 +172,35 @@
 
 /* Convert comma separated list of fields to array. */
 int fieldCount = chopByChar(fields, ',', NULL, 0);
 char **fieldArray;
 AllocArray(fieldArray, fieldCount);
 chopByChar(fields, ',', fieldArray, fieldCount);
 
 /* Get list of all fields in big bed and turn it into a hash of column indexes keyed by
  * column name. */
 struct hash *fieldHash = hashNew(0);
 struct slName *bb, *bbList = bigBedGetFields(table, conn);
 int i;
 for (bb = bbList, i=0; bb != NULL; bb = bb->next, ++i)
     hashAddInt(fieldHash, bb->name, i);
 
+// If bigBed has name column, look up pasted/uploaded identifiers if any:
+struct hash *idHash = NULL;
+if (slCount(bbList) >= 4)
+    idHash = identifierHash(db, table);
+
 /* Create an array of column indexes corresponding to the selected field list. */
 int *columnArray;
 AllocArray(columnArray, fieldCount);
 for (i=0; i<fieldCount; ++i)
     {
     columnArray[i] = hashIntVal(fieldHash, fieldArray[i]);
     }
 
 /* Output row of labels */
 fprintf(f, "#%s", fieldArray[0]);
 for (i=1; i<fieldCount; ++i)
     fprintf(f, "\t%s", fieldArray[i]);
 fprintf(f, "\n");
 
 /* Open up bigBed file. */
@@ -215,30 +220,32 @@
 
 /* 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 *row[bbi->fieldCount];
     char startBuf[16], endBuf[16];
     for (iv = ivList; iv != NULL; iv = iv->next)
         {
 	bigBedIntervalToRow(iv, region->chrom, startBuf, endBuf, row, bbi->fieldCount);
 	if (asFilterOnRow(filter, row))
 	    {
+	    if ((idHash != NULL) && (hashLookup(idHash, row[3]) == NULL))
+		continue;
 	    int i;
 	    fprintf(f, "%s", row[columnArray[0]]);
 	    for (i=1; i<fieldCount; ++i)
 		fprintf(f, "\t%s", row[columnArray[i]]);
 	    fprintf(f, "\n");
 	    }
 	}
     lmCleanup(&lm);
     }
 
 /* Clean up and exit. */
 bbiFileClose(&bbi);
 hashFree(&fieldHash);
 freeMem(fieldArray);
 freeMem(columnArray);