-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtestIterator.c
67 lines (59 loc) · 1.95 KB
/
testIterator.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
#include "bigWig.h"
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <assert.h>
int main(int argc, char *argv[]) {
bigWigFile_t *fp = NULL;
uint32_t i, chunk = 0, tid, blocksPerIteration;
char *sql, *chrom;
bwOverlapIterator_t *iter;
if(argc != 4) {
fprintf(stderr, "Usage: %s {file.bb|URL://path/file.bb} chromosome blocksPerIteration\n", argv[0]);
return 1;
}
chrom = argv[2];
blocksPerIteration = strtoul(argv[3], NULL, 10);
if(bwInit(1<<17) != 0) {
fprintf(stderr, "Received an error in bwInit\n");
return 1;
}
if(bwIsBigWig(argv[1], NULL)) {
fp = bwOpen(argv[1], NULL, "r");
} else if(bbIsBigBed(argv[1], NULL)) {
fp = bbOpen(argv[1], NULL);
}
if(!fp) {
fprintf(stderr, "An error occured while opening %s\n", argv[1]);
return 1;
}
sql = bbGetSQL(fp);
if(sql) {
printf("SQL is: %s\n", sql);
free(sql);
}
//So we can get the bounds
tid = bwGetTid(fp, chrom);
if(fp->type == 0) {
iter = bwOverlappingIntervalsIterator(fp, chrom, 0, fp->cl->len[tid], blocksPerIteration);
} else {
iter = bbOverlappingEntriesIterator(fp, chrom, 0, fp->cl->len[tid], 1, blocksPerIteration);
}
while(iter->data) {
if(fp->type == 0) {
for(i=0; i<iter->intervals->l; i++) {
printf("chunk %"PRIu32" entry %"PRIu32" %s:%"PRIu32"-%"PRIu32" %f\n", chunk, i, chrom, iter->intervals->start[i], iter->intervals->end[i], iter->intervals->value[i]);
}
} else {
for(i=0; i<iter->entries->l; i++) {
printf("chunk %"PRIu32" entry %"PRIu32" %s:%"PRIu32"-%"PRIu32" %s\n", chunk, i, chrom, iter->entries->start[i], iter->entries->end[i], iter->entries->str[i]);
}
}
chunk++;
iter = bwIteratorNext(iter);
}
bwIteratorDestroy(iter);
bwClose(fp);
bwCleanup();
return 0;
}