src/lib/bigBed.c 1.10
1.10 2009/02/10 22:06:09 kent
Adding fieldCount and definedFieldCount to bbiFile header for bigBeds.
Index: src/lib/bigBed.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/bigBed.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -b -B -U 4 -r1.9 -r1.10
--- src/lib/bigBed.c 9 Feb 2009 02:51:42 -0000 1.9
+++ src/lib/bigBed.c 10 Feb 2009 22:06:09 -0000 1.10
@@ -67,19 +67,22 @@
}
static struct ppBed *ppBedLoadAll(char *fileName, struct hash *chromHash, struct lm *lm,
- bits64 *retDiskSize)
+ bits64 *retDiskSize, bits16 *retFieldCount)
/* Read bed file and return it as list of ppBeds. The whole thing will
* be allocated in the passed in lm - don't ppBedFreeList or slFree
* list! */
{
struct ppBed *pbList = NULL, *pb;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *line;
bits64 diskSize = 0;
+int fieldCount = 0;
while (lineFileNextReal(lf, &line))
{
+ if (fieldCount == 0)
+ fieldCount = chopByWhite(line, NULL, 0);
int i;
char *words[3];
for (i=0; i<3; ++i)
words[i] = nextWord(&line);
@@ -102,8 +105,9 @@
slAddHead(&pbList, pb);
}
slReverse(&pbList);
*retDiskSize = diskSize;
+*retFieldCount = fieldCount;
return pbList;
}
static double ppBedAverageSize(struct ppBed *pbList)
@@ -202,8 +206,10 @@
char *inName, /* Input file in a tabular bed format <chrom><start><end> + whatever. */
char *chromSizes, /* Two column tab-separated file: <chromosome> <size>. */
int blockSize, /* Number of items to bundle in r-tree. 1024 is good. */
int itemsPerSlot, /* Number of items in lowest level of tree. 64 is good. */
+ bits16 definedFieldCount, /* Number of defined bed fields - 3-16 or so. 0 means all fields
+ * are the defined bed ones. */
char *outName) /* BigBed output file name. */
/* Convert tab-separated bed file to binary indexed, zoomed bigBed version. */
{
/* This code needs to agree with code in two other places currently - bigWigFileCreate,
@@ -225,16 +231,19 @@
bits32 reductionAmounts[10];
bits64 reductionDataOffsetPos[10];
bits64 reductionDataOffsets[10];
bits64 reductionIndexOffsets[10];
+bits16 fieldCount;
/* Load in chromosome sizes. */
struct hash *chromHash = bbiChromSizesFromFile(chromSizes);
verbose(1, "Read %d chromosomes and sizes from %s\n", chromHash->elCount, chromSizes);
/* Load and sort input file. */
bits64 fullSize;
-struct ppBed *pb, *pbList = ppBedLoadAll(inName, chromHash, chromHash->lm, &fullSize);
+struct ppBed *pb, *pbList = ppBedLoadAll(inName, chromHash, chromHash->lm, &fullSize, &fieldCount);
+if (definedFieldCount == 0)
+ definedFieldCount = fieldCount;
bits64 pbCount = slCount(pbList);
verbose(1, "Read %llu items from %s\n", pbCount, inName);
slSort(&pbList, ppBedCmp);
@@ -306,9 +315,11 @@
dataOffsetPos = ftell(f);
writeOne(f, dataOffset);
indexOffsetPos = ftell(f);
writeOne(f, indexOffset);
-for (i=0; i<8; ++i)
+writeOne(f, fieldCount);
+writeOne(f, definedFieldCount);
+for (i=0; i<7; ++i)
writeOne(f, reserved32);
/* Write summary headers */
for (i=0; i<summaryCount; ++i)