-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtestBigBed.c
132 lines (117 loc) · 4.41 KB
/
testBigBed.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "bigWig.h"
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <assert.h>
void bwPrintHdr(bigWigFile_t *bb) {
uint64_t i;
int64_t i64;
printf("Version: %"PRIu16"\n", bb->hdr->version);
printf("Levels: %"PRIu16"\n", bb->hdr->nLevels);
printf("ctOffset: 0x%"PRIx64"\n", bb->hdr->ctOffset);
printf("dataOffset: 0x%"PRIx64"\n", bb->hdr->dataOffset);
printf("indexOffset: 0x%"PRIx64"\n", bb->hdr->indexOffset);
printf("fieldCount: %"PRIu32"\n", bb->hdr->fieldCount);
printf("definedFieldCount: %"PRIu32"\n", bb->hdr->definedFieldCount);
printf("sqlOffset: 0x%"PRIx64"\n", bb->hdr->sqlOffset);
printf("summaryOffset: 0x%"PRIx64"\n", bb->hdr->summaryOffset);
printf("bufSize: %"PRIu32"\n", bb->hdr->bufSize);
if(bb->hdr->nLevels) {
printf(" i level data index\n");
}
for(i=0; i<bb->hdr->nLevels; i++) {
printf("\t%"PRIu64"\t%"PRIu32"\t%"PRIx64"\t%"PRIx64"\n", i, bb->hdr->zoomHdrs->level[i], bb->hdr->zoomHdrs->dataOffset[i], bb->hdr->zoomHdrs->indexOffset[i]);
}
printf("nBasesCovered: %"PRIu64"\n", bb->hdr->nBasesCovered);
printf("minVal: %f\n", bb->hdr->minVal);
printf("maxVal: %f\n", bb->hdr->maxVal);
printf("sumData: %f\n", bb->hdr->sumData);
printf("sumSquared: %f\n", bb->hdr->sumSquared);
//Chromosome idx/name/length
if(bb->cl) {
printf("Chromosome List\n");
printf(" idx\tChrom\tLength (bases)\n");
for(i64=0; i64<bb->cl->nKeys; i64++) {
printf(" %"PRIu64"\t%s\t%"PRIu32"\n", i64, bb->cl->chrom[i64], bb->cl->len[i64]);
}
}
}
void bwPrintIndexNode(bwRTreeNode_t *node, int level) {
uint16_t i;
if(!node) return;
for(i=0; i<node->nChildren; i++) {
if(node->isLeaf) {
printf(" %i\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t0x%"PRIx64"\t%"PRIu64"\n", level,\
node->chrIdxStart[i], \
node->baseStart[i], \
node->chrIdxEnd[i], \
node->baseEnd[i], \
node->dataOffset[i], \
node->x.size[i]);
} else {
printf(" %i\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t0x%"PRIx64"\tNA\n", level,\
node->chrIdxStart[i], \
node->baseStart[i], \
node->chrIdxEnd[i], \
node->baseEnd[i], \
node->dataOffset[i]);
bwPrintIndexNode(node->x.child[i], level+1);
}
}
}
void bwPrintIndexTree(bigWigFile_t *fp) {
printf("\nIndex tree:\n");
printf("nItems:\t%"PRIu64"\n", fp->idx->nItems);
printf("chrIdxStart:\t%"PRIu32"\n", fp->idx->chrIdxStart);
printf("baseStart:\t%"PRIu32"\n", fp->idx->baseStart);
printf("chrIdxEnd:\t%"PRIu32"\n", fp->idx->chrIdxEnd);
printf("baseEnd:\t%"PRIu32"\n", fp->idx->baseEnd);
printf("idxSize:\t%"PRIu64"\n", fp->idx->idxSize);
printf(" level\tchrIdxStart\tbaseStart\tchrIdxEnd\tbaseEnd\tchild\tsize\n");
bwPrintIndexNode(fp->idx->root, 0);
}
int main(int argc, char *argv[]) {
bigWigFile_t *fp = NULL;
bbOverlappingEntries_t *o;
uint32_t i;
char *sql;
if(argc != 2) {
fprintf(stderr, "Usage: %s {file.bb|URL://path/file.bb}\n", argv[0]);
return 1;
}
if(bwInit(1<<17) != 0) {
fprintf(stderr, "Received an error in bwInit\n");
return 1;
}
assert(bwIsBigWig(argv[1], NULL) == 0);
assert(bbIsBigBed(argv[1], NULL) == 1);
fp = bbOpen(argv[1], NULL);
if(!fp) {
fprintf(stderr, "An error occured while opening %s\n", argv[1]);
return 1;
}
bwPrintHdr(fp);
bwPrintIndexTree(fp);
sql = bbGetSQL(fp);
if(sql) {
printf("SQL is: %s\n", sql);
free(sql);
}
//Presumably this is the sort of interface that's needed...
o = bbGetOverlappingEntries(fp, "chr1", 4450000, 4500000, 1);
printf("%"PRIu32" entries overlap\n", o->l);
for(i=0; i<o->l; i++) {
printf("%"PRIu32"-%"PRIu32"\t %s\n", o->start[i], o->end[i], o->str[i]);
}
if(o) bbDestroyOverlappingEntries(o);
//Ensure that we can fetch entries with no strings
o = bbGetOverlappingEntries(fp, "chr1", 4450000, 4500000, 0);
printf("%"PRIu32" entries overlap\n", o->l);
for(i=0; i<o->l; i++) {
printf("%"PRIu32"-%"PRIu32"\n", o->start[i], o->end[i]);
}
if(o) bbDestroyOverlappingEntries(o);
bwClose(fp);
bwCleanup();
return 0;
}