cb217f20b4a701edfa88f4db623266a9bf25202e
kent
  Mon Mar 4 22:58:07 2013 -0800
Some more steps towards supporting multiple extra indexes in bigBed files.
diff --git src/lib/bigBed.c src/lib/bigBed.c
index 07f225c..a663195 100644
--- src/lib/bigBed.c
+++ src/lib/bigBed.c
@@ -193,37 +193,40 @@
 boolean bigBedSummaryArray(struct bbiFile *bbi, char *chrom, bits32 start, bits32 end,
 	enum bbiSummaryType summaryType, int summarySize, double *summaryValues)
 /* Fill in summaryValues with  data from indicated chromosome range in bigBed file.
  * Be sure to initialize summaryValues to a default value, which will not be touched
  * for regions without data in file.  (Generally you want the default value to either
  * be 0.0 or nan("") depending on the application.)  Returns FALSE if no data
  * at that position. */
 {
 return bbiSummaryArray(bbi, chrom, start, end, bigBedCoverageIntervals,
 	summaryType, summarySize, summaryValues);
 }
 
 void bigBedAttachNameIndex(struct bbiFile *bbi)
 /* Attach name index part of bbiFile to bbi */
 {
+#ifdef OLD
 if (bbi->nameBpt == NULL)
     {
     if (bbi->nameIndexOffset == 0)
 	errAbort("%s has no name index", bbi->fileName);
     udcSeek(bbi->udc, bbi->nameIndexOffset);
     bbi->nameBpt = bptFileAttach(bbi->fileName, bbi->udc);
     }
+#endif /* OLD */
+uglyAbort("bigBedAttachNameIndex() - no can do");
 }
 
 struct offsetSize 
 /* Simple file offset and file size. */
     {
     bits64 offset; 
     bits64 size;
     };
 
 static int cmpOffsetSizeRef(const void *va, const void *vb)
 /* Compare to sort slRef pointing to offsetSize.  Sort is kind of hokey,
  * but guarantees all items that are the same will be next to each other
  * at least, which is all we care about. */
 {
 const struct slRef *a = *((struct slRef **)va);
@@ -506,15 +509,81 @@
 if (bbi)
     {
     struct asObject *as = bigBedAsOrDefault(bbi);
     bbiFileClose(&bbi);
     return as;
     }
 return NULL;
 }
 
 bits64 bigBedItemCount(struct bbiFile *bbi)
 /* Return total items in file. */
 {
 udcSeek(bbi->udc, bbi->unzoomedDataOffset);
 return udcReadBits64(bbi->udc, bbi->isSwapped);
 }
+
+struct slName *bigBedListExtraIndexes(struct bbiFile *bbi)
+/* Return list of names of extra indexes beyond primary chrom:start-end one" */
+{
+struct udcFile *udc = bbi->udc;
+boolean isSwapped = bbi->isSwapped;
+
+/* See if we have any extra indexes, and if so seek to there. */
+bits64 offset = bbi->extraIndexListOffset;
+if (offset == 0)
+   return NULL;
+udcSeek(udc, offset);
+
+/* Construct list of field that are being indexed.  List is list of 
+ * field numbers within asObj. */
+int i;
+struct slInt *intList = NULL, *intEl;
+for (i=0; i<bbi->extraIndexCount; ++i)
+    {
+    bits16 type,fieldCount;
+    type = udcReadBits16(udc, isSwapped);
+    fieldCount = udcReadBits16(udc, isSwapped);
+    udcSeekCur(udc, 12);    // skip over reserved bits
+    if (fieldCount == 1)
+        {
+	bits16 fieldId = udcReadBits16(udc, isSwapped);
+	udcSeekCur(udc, 2);    // skip over reserved bits
+	intEl = slIntNew(fieldId);
+	slAddHead(&intList, intEl);
+	}
+    else
+        {
+	warn("Not yet understanding indexes on multiple fields at once.");
+	internalErr();
+	}
+    }
+
+/* Now have to make an asObject to find out name that corresponds to this field. */
+struct asObject *as = bigBedAsOrDefault(bbi);
+
+/* Make list of field names out of list of field numbers */
+struct slName *nameList = NULL;
+for (intEl = intList; intEl != NULL; intEl = intEl->next)
+    {
+    struct asColumn *col = slElementFromIx(as->columnList, intEl->val);
+    if (col == NULL)
+	{
+        warn("Inconsistent bigBed file %s", bbi->fileName);
+	internalErr();
+	}
+    slNameAddHead(&nameList, col->name);
+    }
+
+asObjectFree(&as);
+return nameList;
+}
+
+struct bptFile *bigBedOpenExtraIndex(struct bbiFile *bbi, char *fieldName)
+/* Return index associated with fieldName.  Aborts if no such index. */
+{
+uglyAbort("Coming soon.");
+return NULL;
+}
+
+
+