bio-bigwig 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,223 @@
1
+ #include "bigWig.h"
2
+ #include <stdio.h>
3
+ #include <inttypes.h>
4
+ #include <stdlib.h>
5
+ #include <assert.h>
6
+
7
+ void bwPrintHdr(bigWigFile_t *bw) {
8
+ uint64_t i;
9
+ int64_t i64;
10
+ printf("Version: %"PRIu16"\n", bw->hdr->version);
11
+ printf("Levels: %"PRIu16"\n", bw->hdr->nLevels);
12
+ printf("ctOffset: 0x%"PRIx64"\n", bw->hdr->ctOffset);
13
+ printf("dataOffset: 0x%"PRIx64"\n", bw->hdr->dataOffset);
14
+ printf("indexOffset: 0x%"PRIx64"\n", bw->hdr->indexOffset);
15
+ printf("sqlOffset: 0x%"PRIx64"\n", bw->hdr->sqlOffset);
16
+ printf("summaryOffset: 0x%"PRIx64"\n", bw->hdr->summaryOffset);
17
+ printf("bufSize: %"PRIu32"\n", bw->hdr->bufSize);
18
+ printf("extensionOffset: 0x%"PRIx64"\n", bw->hdr->extensionOffset);
19
+
20
+ if(bw->hdr->nLevels) {
21
+ printf(" i level data index\n");
22
+ }
23
+ for(i=0; i<bw->hdr->nLevels; i++) {
24
+ printf("\t%"PRIu64"\t%"PRIu32"\t%"PRIx64"\t%"PRIx64"\n", i, bw->hdr->zoomHdrs->level[i], bw->hdr->zoomHdrs->dataOffset[i], bw->hdr->zoomHdrs->indexOffset[i]);
25
+ }
26
+
27
+ printf("nBasesCovered: %"PRIu64"\n", bw->hdr->nBasesCovered);
28
+ printf("minVal: %f\n", bw->hdr->minVal);
29
+ printf("maxVal: %f\n", bw->hdr->maxVal);
30
+ printf("sumData: %f\n", bw->hdr->sumData);
31
+ printf("sumSquared: %f\n", bw->hdr->sumSquared);
32
+
33
+ //Chromosome idx/name/length
34
+ if(bw->cl) {
35
+ printf("Chromosome List\n");
36
+ printf(" idx\tChrom\tLength (bases)\n");
37
+ for(i64=0; i64<bw->cl->nKeys; i64++) {
38
+ printf(" %"PRIu64"\t%s\t%"PRIu32"\n", i64, bw->cl->chrom[i64], bw->cl->len[i64]);
39
+ }
40
+ }
41
+ }
42
+
43
+ void bwPrintIndexNode(bwRTreeNode_t *node, int level) {
44
+ uint16_t i;
45
+ if(!node) return;
46
+ for(i=0; i<node->nChildren; i++) {
47
+ if(node->isLeaf) {
48
+ printf(" %i\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t0x%"PRIx64"\t%"PRIu64"\n", level,\
49
+ node->chrIdxStart[i], \
50
+ node->baseStart[i], \
51
+ node->chrIdxEnd[i], \
52
+ node->baseEnd[i], \
53
+ node->dataOffset[i], \
54
+ node->x.size[i]);
55
+ } else {
56
+ printf(" %i\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t0x%"PRIx64"\tNA\n", level,\
57
+ node->chrIdxStart[i], \
58
+ node->baseStart[i], \
59
+ node->chrIdxEnd[i], \
60
+ node->baseEnd[i], \
61
+ node->dataOffset[i]);
62
+ bwPrintIndexNode(node->x.child[i], level+1);
63
+ }
64
+ }
65
+ }
66
+
67
+ void bwPrintIndexTree(bigWigFile_t *fp) {
68
+ printf("\nIndex tree:\n");
69
+ printf("nItems:\t%"PRIu64"\n", fp->idx->nItems);
70
+ printf("chrIdxStart:\t%"PRIu32"\n", fp->idx->chrIdxStart);
71
+ printf("baseStart:\t%"PRIu32"\n", fp->idx->baseStart);
72
+ printf("chrIdxEnd:\t%"PRIu32"\n", fp->idx->chrIdxEnd);
73
+ printf("baseEnd:\t%"PRIu32"\n", fp->idx->baseEnd);
74
+ printf("idxSize:\t%"PRIu64"\n", fp->idx->idxSize);
75
+ printf(" level\tchrIdxStart\tbaseStart\tchrIdxEnd\tbaseEnd\tchild\tsize\n");
76
+ bwPrintIndexNode(fp->idx->root, 0);
77
+ }
78
+
79
+ void printIntervals(bwOverlappingIntervals_t *ints, uint32_t start) {
80
+ uint32_t i;
81
+ if(!ints) return;
82
+ for(i=0; i<ints->l; i++) {
83
+ if(ints->start && ints->end) {
84
+ printf("Interval %"PRIu32"\t%"PRIu32"-%"PRIu32": %f\n",i, ints->start[i], ints->end[i], ints->value[i]);
85
+ } else if(ints->start) {
86
+ printf("Interval %"PRIu32"\t%"PRIu32"-%"PRIu32": %f\n",i, ints->start[i], ints->start[i]+1, ints->value[i]);
87
+ } else {
88
+ printf("Interval %"PRIu32"\t%"PRIu32"-%"PRIu32": %f\n",i, start+i, start+i+1, ints->value[i]);
89
+ }
90
+ }
91
+ }
92
+
93
+ int main(int argc, char *argv[]) {
94
+ bigWigFile_t *fp = NULL;
95
+ bwOverlappingIntervals_t *intervals = NULL;
96
+ double *stats = NULL;
97
+ if(argc != 2) {
98
+ fprintf(stderr, "Usage: %s {file.bw|URL://path/file.bw}\n", argv[0]);
99
+ return 1;
100
+ }
101
+
102
+ if(bwInit(1<<17) != 0) {
103
+ fprintf(stderr, "Received an error in bwInit\n");
104
+ return 1;
105
+ }
106
+
107
+ assert(bwIsBigWig(argv[1], NULL) == 1);
108
+ assert(bbIsBigBed(argv[1], NULL) == 0);
109
+
110
+ fp = bwOpen(argv[1], NULL, "r");
111
+ if(!fp) {
112
+ fprintf(stderr, "An error occured while opening %s\n", argv[1]);
113
+ return 1;
114
+ }
115
+
116
+ bwPrintHdr(fp);
117
+ bwPrintIndexTree(fp);
118
+
119
+ //Try to get some blocks
120
+ printf("1:0-99\n");
121
+ intervals = bwGetValues(fp, "1", 0, 99, 0);
122
+ printIntervals(intervals,0);
123
+ bwDestroyOverlappingIntervals(intervals);
124
+
125
+ printf("1:99-1000\n");
126
+ intervals = bwGetValues(fp, "1", 99, 1000, 0);
127
+ printIntervals(intervals,0);
128
+ bwDestroyOverlappingIntervals(intervals);
129
+
130
+ printf("1:99-150\n");
131
+ intervals = bwGetValues(fp, "1", 99, 150, 1);
132
+ printIntervals(intervals,99);
133
+ bwDestroyOverlappingIntervals(intervals);
134
+
135
+ printf("1:99-100\n");
136
+ intervals = bwGetValues(fp, "1", 99, 100, 0);
137
+ printIntervals(intervals,0);
138
+ bwDestroyOverlappingIntervals(intervals);
139
+
140
+ printf("1:151-1000\n");
141
+ intervals = bwGetValues(fp, "1", 151, 1000, 0);
142
+ printIntervals(intervals,0);
143
+ bwDestroyOverlappingIntervals(intervals);
144
+
145
+ printf("chr1:0-100\n");
146
+ intervals = bwGetValues(fp, "chr1", 0, 100, 0);
147
+ printIntervals(intervals,0);
148
+ bwDestroyOverlappingIntervals(intervals);
149
+
150
+ stats = bwStats(fp, "1", 0, 200, 1, mean);
151
+ assert(stats);
152
+ printf("1:0-1000 mean: %f\n", *stats);
153
+ free(stats);
154
+
155
+ stats = bwStats(fp, "1", 0, 200, 2, mean);
156
+ assert(stats);
157
+ printf("1:0-1000 mean: %f %f\n", stats[0], stats[1]);
158
+ free(stats);
159
+
160
+ stats = bwStats(fp, "1", 0, 200, 1, dev);
161
+ assert(stats);
162
+ printf("1:0-1000 std. dev.: %f\n", *stats);
163
+ free(stats);
164
+
165
+ stats = bwStats(fp, "1", 0, 200, 2, dev);
166
+ assert(stats);
167
+ printf("1:0-1000 std. dev.: %f %f\n", stats[0], stats[1]);
168
+ free(stats);
169
+
170
+ stats = bwStats(fp, "1", 0, 200, 1, min);
171
+ assert(stats);
172
+ printf("1:0-1000 min: %f\n", *stats);
173
+ free(stats);
174
+
175
+ stats = bwStats(fp, "1", 0, 200, 2, min);
176
+ assert(stats);
177
+ printf("1:0-1000 min: %f %f\n", stats[0], stats[1]);
178
+ free(stats);
179
+
180
+ stats = bwStats(fp, "1", 0, 200, 1, max);
181
+ assert(stats);
182
+ printf("1:0-1000 max: %f\n", *stats);
183
+ free(stats);
184
+
185
+ stats = bwStats(fp, "1", 0, 200, 2, max);
186
+ assert(stats);
187
+ printf("1:0-1000 max: %f %f\n", stats[0], stats[1]);
188
+ free(stats);
189
+
190
+ stats = bwStats(fp, "1", 0, 200, 1, cov);
191
+ assert(stats);
192
+ printf("1:0-1000 coverage: %f\n", *stats);
193
+ free(stats);
194
+
195
+ stats = bwStats(fp, "1", 0, 200, 2, cov);
196
+ assert(stats);
197
+ printf("1:0-1000 coverage: %f %f\n", stats[0], stats[1]);
198
+ free(stats);
199
+
200
+ stats = bwStats(fp, "1", 0, 200, 1, sum);
201
+ assert(stats);
202
+ printf("1:0-200 sum: %f\n", *stats); //72.1
203
+ free(stats);
204
+
205
+ stats = bwStats(fp, "1", 100, 151, 2, sum);
206
+ assert(stats);
207
+ printf("1:0-200 sum: %f %f\n", stats[0], stats[1]); //35.0, 36.5
208
+ free(stats);
209
+
210
+ printf("1:0-200000000 intervals\n");
211
+ intervals = bwGetOverlappingIntervals(fp, "1", 0, 200000000);
212
+ printIntervals(intervals,0);
213
+ bwDestroyOverlappingIntervals(intervals);
214
+
215
+ printf("10:0-200000000 intervals\n");
216
+ intervals = bwGetOverlappingIntervals(fp, "10", 0, 200000000);
217
+ printIntervals(intervals,0);
218
+ bwDestroyOverlappingIntervals(intervals);
219
+
220
+ bwClose(fp);
221
+ bwCleanup();
222
+ return 0;
223
+ }
@@ -0,0 +1,203 @@
1
+ #include "bigWig.h"
2
+ #include <stdio.h>
3
+ #include <inttypes.h>
4
+ #include <stdlib.h>
5
+ #include <assert.h>
6
+
7
+ //Print overly verbose header information
8
+ void bwPrintHdr(bigWigFile_t *bw) {
9
+ uint64_t i;
10
+ int64_t i64;
11
+ printf("Version: %"PRIu16"\n", bw->hdr->version);
12
+ printf("Levels: %"PRIu16"\n", bw->hdr->nLevels);
13
+ printf("ctOffset: 0x%"PRIx64"\n", bw->hdr->ctOffset);
14
+ printf("dataOffset: 0x%"PRIx64"\n", bw->hdr->dataOffset);
15
+ printf("indexOffset: 0x%"PRIx64"\n", bw->hdr->indexOffset);
16
+ printf("sqlOffset: 0x%"PRIx64"\n", bw->hdr->sqlOffset);
17
+ printf("summaryOffset: 0x%"PRIx64"\n", bw->hdr->summaryOffset);
18
+ printf("bufSize: %"PRIu32"\n", bw->hdr->bufSize);
19
+ printf("extensionOffset: 0x%"PRIx64"\n", bw->hdr->extensionOffset);
20
+
21
+ if(bw->hdr->nLevels) {
22
+ printf(" i level data index\n");
23
+ }
24
+ for(i=0; i<bw->hdr->nLevels; i++) {
25
+ printf("\t%"PRIu64"\t%"PRIu32"\t%"PRIx64"\t%"PRIx64"\n", i, bw->hdr->zoomHdrs->level[i], bw->hdr->zoomHdrs->dataOffset[i], bw->hdr->zoomHdrs->indexOffset[i]);
26
+ }
27
+
28
+ printf("nBasesCovered: %"PRIu64"\n", bw->hdr->nBasesCovered);
29
+ printf("minVal: %f\n", bw->hdr->minVal);
30
+ printf("maxVal: %f\n", bw->hdr->maxVal);
31
+ printf("sumData: %f\n", bw->hdr->sumData);
32
+ printf("sumSquared: %f\n", bw->hdr->sumSquared);
33
+
34
+ //Chromosome idx/name/length
35
+ if(bw->cl) {
36
+ printf("Chromosome List\n");
37
+ printf(" idx\tChrom\tLength (bases)\n");
38
+ for(i64=0; i64<bw->cl->nKeys; i64++) {
39
+ printf(" %"PRIu64"\t%s\t%"PRIu32"\n", i64, bw->cl->chrom[i64], bw->cl->len[i64]);
40
+ }
41
+ }
42
+ }
43
+
44
+ void bwPrintIndexNode(bwRTreeNode_t *node, int level) {
45
+ uint16_t i;
46
+ if(!node) return;
47
+ for(i=0; i<node->nChildren; i++) {
48
+ if(node->isLeaf) {
49
+ printf(" %i\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t0x%"PRIx64"\t%"PRIu64"\n", level,\
50
+ node->chrIdxStart[i], \
51
+ node->baseStart[i], \
52
+ node->chrIdxEnd[i], \
53
+ node->baseEnd[i], \
54
+ node->dataOffset[i], \
55
+ node->x.size[i]);
56
+ } else {
57
+ printf(" %i\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t0x%"PRIx64"\tNA\n", level,\
58
+ node->chrIdxStart[i], \
59
+ node->baseStart[i], \
60
+ node->chrIdxEnd[i], \
61
+ node->baseEnd[i], \
62
+ node->dataOffset[i]);
63
+ bwPrintIndexNode(node->x.child[i], level+1);
64
+ }
65
+ }
66
+ }
67
+
68
+ void bwPrintIndexTree(bigWigFile_t *fp) {
69
+ printf("\nIndex tree:\n");
70
+ printf("nItems:\t%"PRIu64"\n", fp->idx->nItems);
71
+ printf("chrIdxStart:\t%"PRIu32"\n", fp->idx->chrIdxStart);
72
+ printf("baseStart:\t%"PRIu32"\n", fp->idx->baseStart);
73
+ printf("chrIdxEnd:\t%"PRIu32"\n", fp->idx->chrIdxEnd);
74
+ printf("baseEnd:\t%"PRIu32"\n", fp->idx->baseEnd);
75
+ printf("idxSize:\t%"PRIu64"\n", fp->idx->idxSize);
76
+ printf(" level\tchrIdxStart\tbaseStart\tchrIdxEnd\tbaseEnd\tchild\tsize\n");
77
+ bwPrintIndexNode(fp->idx->root, 0);
78
+ }
79
+
80
+ void printIntervals(bwOverlappingIntervals_t *ints, uint32_t start) {
81
+ uint32_t i;
82
+ if(!ints) return;
83
+ for(i=0; i<ints->l; i++) {
84
+ if(ints->start && ints->end) {
85
+ printf("Interval %"PRIu32"\t%"PRIu32"-%"PRIu32": %f\n",i, ints->start[i], ints->end[i], ints->value[i]);
86
+ } else if(ints->start) {
87
+ printf("Interval %"PRIu32"\t%"PRIu32"-%"PRIu32": %f\n",i, ints->start[i], ints->start[i]+1, ints->value[i]);
88
+ } else {
89
+ printf("Interval %"PRIu32"\t%"PRIu32"-%"PRIu32": %f\n",i, start+i, start+i+1, ints->value[i]);
90
+ }
91
+ }
92
+ }
93
+
94
+ //This is an example call back function
95
+ CURLcode callBack(CURL *curl) {
96
+ CURLcode rv;
97
+
98
+ rv = curl_easy_setopt(curl, CURLOPT_USERNAME, "anonymous");
99
+ if(rv != CURLE_OK) return rv;
100
+
101
+ rv = curl_easy_setopt(curl, CURLOPT_PASSWORD, "libBigWig@github.com");
102
+ return rv;
103
+ }
104
+
105
+ int main(int argc, char *argv[]) {
106
+ bigWigFile_t *fp = NULL;
107
+ bwOverlappingIntervals_t *intervals = NULL;
108
+ double *stats = NULL;
109
+ char chrom[] = "chr1";
110
+ if(argc != 2) {
111
+ fprintf(stderr, "Usage: %s {file.bw|URL://path/file.bw}\n", argv[0]);
112
+ return 1;
113
+ }
114
+
115
+ if(bwInit(1<<17) != 0) {
116
+ fprintf(stderr, "Received an error in bwInit\n");
117
+ return 1;
118
+ }
119
+
120
+ fp = bwOpen(argv[1], callBack, "r");
121
+ if(!fp) {
122
+ fprintf(stderr, "An error occured while opening %s\n", argv[1]);
123
+ return 1;
124
+ }
125
+
126
+ bwPrintHdr(fp);
127
+ bwPrintIndexTree(fp);
128
+
129
+ //Try to get some blocks
130
+ printf("%s:10000000-10000100 Intervals\n", chrom);
131
+ intervals = bwGetOverlappingIntervals(fp, chrom, 10000000, 10000100);
132
+ printIntervals(intervals,0);
133
+ bwDestroyOverlappingIntervals(intervals);
134
+
135
+ printf("%s:10000000-10000100 Values\n", chrom);
136
+ intervals = bwGetValues(fp, chrom, 10000000, 10000100, 0);
137
+ printIntervals(intervals,0);
138
+ bwDestroyOverlappingIntervals(intervals);
139
+
140
+ stats = bwStats(fp, chrom, 10000000, 10000100, 1, mean);
141
+ if(stats) {
142
+ printf("%s:10000000-10000100 mean: %f\n", chrom, stats[0]);
143
+ free(stats);
144
+ }
145
+
146
+ stats = bwStats(fp, chrom, 10000000, 10000100, 2, mean);
147
+ if(stats) {
148
+ printf("%s:10000000-10000100 mean: %f %f\n", chrom, stats[0], stats[1]);
149
+ free(stats);
150
+ }
151
+
152
+ stats = bwStats(fp, chrom, 10000000, 10000100, 1, dev);
153
+ if(stats) {
154
+ printf("%s:10000000-10000100 std. dev.: %f\n", chrom, stats[0]);
155
+ free(stats);
156
+ }
157
+
158
+ stats = bwStats(fp, chrom, 10000000, 10000100, 2, dev);
159
+ if(stats) {
160
+ printf("%s:10000000-10000100 std. dev.: %f %f\n", chrom, stats[0], stats[1]);
161
+ free(stats);
162
+ }
163
+
164
+ stats = bwStats(fp, chrom, 10000000, 10000100, 1, min);
165
+ if(stats) {
166
+ printf("%s:10000000-10000100 min: %f\n", chrom, stats[0]);
167
+ free(stats);
168
+ }
169
+
170
+ stats = bwStats(fp, chrom, 10000000, 10000100, 2, min);
171
+ if(stats) {
172
+ printf("%s:10000000-10000100 min: %f %f\n", chrom, stats[0], stats[1]);
173
+ free(stats);
174
+ }
175
+
176
+ stats = bwStats(fp, chrom, 10000000, 10000100, 1, max);
177
+ if(stats) {
178
+ printf("%s:10000000-10000100 max: %f\n", chrom, stats[0]);
179
+ free(stats);
180
+ }
181
+
182
+ stats = bwStats(fp, chrom, 10000000, 10000100, 2, max);
183
+ if(stats) {
184
+ printf("%s:10000000-10000100 max: %f %f\n", chrom, stats[0], stats[1]);
185
+ free(stats);
186
+ }
187
+
188
+ stats = bwStats(fp, chrom, 10000000, 10000100, 1, cov);
189
+ if(stats) {
190
+ printf("%s:10000000-10000100 coverage: %f\n", chrom, stats[0]);
191
+ free(stats);
192
+ }
193
+
194
+ stats = bwStats(fp, chrom, 10000000, 10000100, 2, cov);
195
+ if(stats) {
196
+ printf("%s:10000000-10000100 coverage: %f %f\n", chrom, stats[0], stats[1]);
197
+ free(stats);
198
+ }
199
+
200
+ bwClose(fp);
201
+ bwCleanup();
202
+ return 0;
203
+ }
@@ -0,0 +1,46 @@
1
+ #include "bigWig.h"
2
+ #include <stdio.h>
3
+ #include <inttypes.h>
4
+ #include <stdlib.h>
5
+ #include <assert.h>
6
+
7
+ //This is an example call back function
8
+ CURLcode callBack(CURL *curl) {
9
+ CURLcode rv;
10
+
11
+ rv = curl_easy_setopt(curl, CURLOPT_USERNAME, "anonymous");
12
+ if(rv != CURLE_OK) return rv;
13
+
14
+ rv = curl_easy_setopt(curl, CURLOPT_PASSWORD, "libBigWig@github.com");
15
+ return rv;
16
+ }
17
+
18
+ int main(int argc, char *argv[]) {
19
+ bigWigFile_t *fp = NULL;
20
+ int64_t i;
21
+
22
+ if(argc != 2) {
23
+ fprintf(stderr, "Usage: %s {file.bw|URL://path/file.bw}\n", argv[0]);
24
+ return 1;
25
+ }
26
+
27
+ if(bwInit(1<<17) != 0) {
28
+ fprintf(stderr, "Received an error in bwInit\n");
29
+ return 1;
30
+ }
31
+
32
+ fp = bwOpen(argv[1], callBack, "r");
33
+ if(!fp) {
34
+ fprintf(stderr, "An error occured while opening %s\n", argv[1]);
35
+ return 1;
36
+ }
37
+
38
+ //Return the number of chromosomes/contigs
39
+ for(i=0; i<fp->cl->nKeys; i++) {
40
+ printf("%s\t%"PRIu32"\n", fp->cl->chrom[i], fp->cl->len[i]);
41
+ }
42
+
43
+ bwClose(fp);
44
+ bwCleanup();
45
+ return 0;
46
+ }
@@ -0,0 +1,68 @@
1
+ #include "bigWig.h"
2
+ #include <stdio.h>
3
+ #include <inttypes.h>
4
+ #include <stdlib.h>
5
+ #include <assert.h>
6
+
7
+ int main(int argc, char *argv[]) {
8
+ bigWigFile_t *ifp = NULL;
9
+ bigWigFile_t *ofp = NULL;
10
+ uint32_t tid, i;
11
+ char **chroms;
12
+ bwOverlappingIntervals_t *o;
13
+ if(argc != 3) {
14
+ fprintf(stderr, "Usage: %s {inputfile.bw|URL://path/inputfile.bw} outputfile.bw\n", argv[0]);
15
+ return 1;
16
+ }
17
+
18
+ if(bwInit(1<<17) != 0) {
19
+ fprintf(stderr, "Received an error in bwInit\n");
20
+ return 1;
21
+ }
22
+
23
+ ifp = bwOpen(argv[1], NULL, "r");
24
+ if(!ifp) {
25
+ fprintf(stderr, "An error occured while opening %s\n", argv[1]);
26
+ return 1;
27
+ }
28
+
29
+ ofp = bwOpen(argv[2], NULL, "w");
30
+ if(!ofp) {
31
+ bwClose(ifp);
32
+ fprintf(stderr, "An error occured while opening %s\n", argv[2]);
33
+ return 1;
34
+ }
35
+
36
+ if(bwCreateHdr(ofp, 10)) goto error; //ten zoom levels
37
+ ofp->cl = bwCreateChromList(ifp->cl->chrom, ifp->cl->len, ifp->cl->nKeys);
38
+ if(!ofp->cl) goto error;
39
+
40
+ if(bwWriteHdr(ofp)) goto error;
41
+
42
+ //Copy all of the intervals
43
+ for(tid = 0; tid < ofp->cl->nKeys; tid++) {
44
+ o = bwGetOverlappingIntervals(ifp, ofp->cl->chrom[tid], 0, ofp->cl->len[tid]);
45
+ if(!o) goto error;
46
+ if(o->l) {
47
+ chroms = malloc(o->l * sizeof(char*));
48
+ if(!chroms) goto error;
49
+ for(i=0; i<o->l; i++) chroms[i] = ofp->cl->chrom[tid];
50
+ bwAddIntervals(ofp, chroms, o->start, o->end, o->value, o->l);
51
+ free(chroms);
52
+ }
53
+ bwDestroyOverlappingIntervals(o);
54
+ }
55
+
56
+ bwClose(ifp);
57
+ bwClose(ofp);
58
+ bwCleanup();
59
+
60
+ return 0;
61
+
62
+ error:
63
+ fprintf(stderr, "Got an error somewhere!\n");
64
+ bwClose(ifp);
65
+ bwClose(ofp);
66
+ bwCleanup();
67
+ return 1;
68
+ }
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bio
4
+ class BigWig
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
data/lib/bio/bigwig.rb ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "bigwig/version"
4
+ require_relative "bigwig/bigwigext"
5
+
6
+ module Bio
7
+ class BigWig
8
+ def self.open(*args, **kwargs)
9
+ file = new(*args, **kwargs)
10
+ return file unless block_given?
11
+
12
+ begin
13
+ yield file
14
+ ensure
15
+ file.close
16
+ end
17
+ file
18
+ end
19
+
20
+ def initialize(fname, mode = "r")
21
+ raise "BigWig::new() does not take block; use BigWig::open() instead" if block_given?
22
+
23
+ @fname = fname
24
+ initialize_raw(fname, mode)
25
+ end
26
+
27
+ def path
28
+ @fname
29
+ end
30
+
31
+ def stats(chrom, start = nil, stop = nil, nbins: nil, type: nil, exact: nil)
32
+ stats_raw(chrom, start, stop, nbins, type&.to_s, exact)
33
+ end
34
+
35
+ def values(chrom, start, stop)
36
+ values_raw(chrom, start, stop)
37
+ end
38
+
39
+ def intervals(chrom, start = 0, stop = -1)
40
+ intervals_raw(chrom, start, stop)
41
+ end
42
+
43
+ def entries(chrom, start = 0, stop = -1, text: true)
44
+ entries_raw(chrom, start, stop, text)
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bio-bigwig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kojix2
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This is a Ruby binding for libBigWig (https://github.com/dpryan79/libBigWig),
14
+ which provides high-speed access to bigWig or bigBed files.
15
+ email:
16
+ - 2xijok@gmail.com
17
+ executables: []
18
+ extensions:
19
+ - ext/bio/bigwig/extconf.rb
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE.txt
23
+ - README.md
24
+ - ext/bio/bigwig/bigwigext.c
25
+ - ext/bio/bigwig/bigwigext.h
26
+ - ext/bio/bigwig/extconf.rb
27
+ - ext/bio/bigwig/libBigWig/LICENSE
28
+ - ext/bio/bigwig/libBigWig/bigWig.h
29
+ - ext/bio/bigwig/libBigWig/bigWigIO.h
30
+ - ext/bio/bigwig/libBigWig/bwCommon.h
31
+ - ext/bio/bigwig/libBigWig/bwRead.c
32
+ - ext/bio/bigwig/libBigWig/bwStats.c
33
+ - ext/bio/bigwig/libBigWig/bwValues.c
34
+ - ext/bio/bigwig/libBigWig/bwValues.h
35
+ - ext/bio/bigwig/libBigWig/bwWrite.c
36
+ - ext/bio/bigwig/libBigWig/io.c
37
+ - ext/bio/bigwig/libBigWig/test/exampleWrite.c
38
+ - ext/bio/bigwig/libBigWig/test/testBigBed.c
39
+ - ext/bio/bigwig/libBigWig/test/testIterator.c
40
+ - ext/bio/bigwig/libBigWig/test/testLocal.c
41
+ - ext/bio/bigwig/libBigWig/test/testRemote.c
42
+ - ext/bio/bigwig/libBigWig/test/testRemoteManyContigs.c
43
+ - ext/bio/bigwig/libBigWig/test/testWrite.c
44
+ - lib/bio/bigwig.rb
45
+ - lib/bio/bigwig/version.rb
46
+ homepage: https://github.com/kojix2/bw-ruby
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.7.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.3.3
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: A ruby library for accessing bigWig / bigBed files
69
+ test_files: []