-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtestWrite.c
68 lines (58 loc) · 1.78 KB
/
testWrite.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
#include "bigWig.h"
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <assert.h>
int main(int argc, char *argv[]) {
bigWigFile_t *ifp = NULL;
bigWigFile_t *ofp = NULL;
uint32_t tid, i;
char **chroms;
bwOverlappingIntervals_t *o;
if(argc != 3) {
fprintf(stderr, "Usage: %s {inputfile.bw|URL://path/inputfile.bw} outputfile.bw\n", argv[0]);
return 1;
}
if(bwInit(1<<17) != 0) {
fprintf(stderr, "Received an error in bwInit\n");
return 1;
}
ifp = bwOpen(argv[1], NULL, "r");
if(!ifp) {
fprintf(stderr, "An error occured while opening %s\n", argv[1]);
return 1;
}
ofp = bwOpen(argv[2], NULL, "w");
if(!ofp) {
bwClose(ifp);
fprintf(stderr, "An error occured while opening %s\n", argv[2]);
return 1;
}
if(bwCreateHdr(ofp, 10)) goto error; //ten zoom levels
ofp->cl = bwCreateChromList((const char* const*)ifp->cl->chrom, ifp->cl->len, ifp->cl->nKeys);
if(!ofp->cl) goto error;
if(bwWriteHdr(ofp)) goto error;
//Copy all of the intervals
for(tid = 0; tid < ofp->cl->nKeys; tid++) {
o = bwGetOverlappingIntervals(ifp, ofp->cl->chrom[tid], 0, ofp->cl->len[tid]);
if(!o) goto error;
if(o->l) {
chroms = malloc(o->l * sizeof(char*));
if(!chroms) goto error;
for(i=0; i<o->l; i++) chroms[i] = ofp->cl->chrom[tid];
bwAddIntervals(ofp, (const char* const*)chroms, o->start, o->end, o->value, o->l);
free(chroms);
}
bwDestroyOverlappingIntervals(o);
}
bwClose(ifp);
bwClose(ofp);
bwCleanup();
return 0;
error:
fprintf(stderr, "Got an error somewhere!\n");
bwClose(ifp);
bwClose(ofp);
bwCleanup();
return 1;
}