src/lib/bigBed.c 1.12
1.12 2009/03/16 05:07:54 kent
Adding maxItems parameter to bigBedIntervalQuery. Checking that asFile field count matches tab-file field count.
Index: src/lib/bigBed.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/bigBed.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -b -B -U 4 -r1.11 -r1.12
--- src/lib/bigBed.c 15 Mar 2009 00:17:52 -0000 1.11
+++ src/lib/bigBed.c 16 Mar 2009 05:07:54 -0000 1.12
@@ -342,8 +342,12 @@
/* Parse it and do sanity check. */
struct asObject *as = asParseFile(asFileName);
if (as->next != NULL)
errAbort("Can only handle .as files containing a single object.");
+ int colCount = slCount(as->columnList);
+ if (colCount != fieldCount)
+ errAbort("%d columns in %s, %d columns in %s. These must match!",
+ colCount, asFileName, fieldCount, inName);
asOffset = ftell(f);
FILE *asFile = mustOpen(asFileName, "r");
copyOpenFile(asFile, f);
fputc(0, f);
@@ -402,9 +406,8 @@
fseek(f, chromTreeOffsetPos, SEEK_SET);
writeOne(f, chromTreeOffset);
if (asOffset != 0)
{
- uglyf("asOffsetPos = %lld, asOffset=%lld\n", asOffsetPos, asOffset);
fseek(f, asOffsetPos, SEEK_SET);
writeOne(f, asOffset);
}
@@ -420,11 +423,13 @@
freez(&chromInfoArray);
}
struct bigBedInterval *bigBedIntervalQuery(struct bbiFile *bbi, char *chrom,
- bits32 start, bits32 end, struct lm *lm)
-/* Get data for interval. Return list allocated out of lm. */
+ bits32 start, bits32 end, int maxItems, struct lm *lm)
+/* Get data for interval. Return list allocated out of lm. Set maxItems to maximum
+ * number of items to return, or to 0 for all items. */
{
+int itemCount = 0;
bbiAttachUnzoomedCir(bbi);
struct bigBedInterval *el, *list = NULL;
bits32 chromId;
struct fileOffsetSize *blockList = bbiOverlappingBlocks(bbi, bbi->unzoomedCir,
@@ -438,8 +443,12 @@
bits64 endPos = block->offset + block->size;
udcSeek(f, block->offset);
while (udcTell(f) < endPos)
{
+ ++itemCount;
+ if (maxItems > 0 && itemCount > maxItems)
+ break;
+
/* Read next record into local variables. */
bits32 chr = udcReadBits32(f, isSwapped); // Read and discard chromId
bits32 s = udcReadBits32(f, isSwapped);
bits32 e = udcReadBits32(f, isSwapped);
@@ -462,8 +471,10 @@
el->rest = lmCloneString(lm, dy->string);
slAddHead(&list, el);
}
}
+ if (maxItems > 0 && itemCount > maxItems)
+ break;
}
slFreeList(&blockList);
slReverse(&list);
return list;
@@ -494,9 +505,9 @@
char *chrom, bits32 start, bits32 end, struct lm *lm)
/* Return intervals where the val is the depth of coverage. */
{
/* Get list of overlapping intervals */
-struct bigBedInterval *bi, *biList = bigBedIntervalQuery(bbi, chrom, start, end, lm);
+struct bigBedInterval *bi, *biList = bigBedIntervalQuery(bbi, chrom, start, end, 0, lm);
if (biList == NULL)
return NULL;
/* Make a range tree that collects coverage. */