libBigWig
Loading...
Searching...
No Matches
bigWig.h
Go to the documentation of this file.
1#ifndef LIBBIGWIG_H
2#define LIBBIGWIG_H
3
4#include "bigWigIO.h"
5#include "bwValues.h"
6#include <inttypes.h>
7#include <zlib.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
59#define LIBBIGWIG_VERSION 0.4.7
60
64#ifdef NOCURL
65#define LIBBIGWIG_CURL 0
66#ifndef CURLTYPE_DEFINED
67#define CURLTYPE_DEFINED
68typedef int CURLcode;
69typedef void CURL;
70#endif
71#else
72#define LIBBIGWIG_CURL 1
73#endif
74
78#define BIGWIG_MAGIC 0x888FFC26
82#define BIGBED_MAGIC 0x8789F2EB
86#define CIRTREE_MAGIC 0x78ca8c91
90#define IDX_MAGIC 0x2468ace0
94#define DEFAULT_nCHILDREN 64
98#define DEFAULT_BLOCKSIZE 32768
99
105 mean = 0,
107 stdev = 1,
108 dev = 1,
109 max = 2,
110 min = 3,
111 cov = 4,
113 sum = 5
115
116//Should hide this from end users
122typedef struct {
123 uint32_t *level;
124 //There's 4 bytes of padding between these
125 uint64_t *dataOffset;
126 uint64_t *indexOffset;
129
135typedef struct {
136 uint16_t version;
137 uint16_t nLevels;
138 uint64_t ctOffset;
139 uint64_t dataOffset;
140 uint64_t indexOffset;
141 uint16_t fieldCount;
143 uint64_t sqlOffset;
144 uint64_t summaryOffset;
145 uint32_t bufSize;
148 //total Summary
149 uint64_t nBasesCovered;
150 double minVal;
151 double maxVal;
152 double sumData;
153 double sumSquared;
155
156//Should probably replace this with a hash
160typedef struct {
161 int64_t nKeys;
162 char **chrom;
163 uint32_t *len;
165
166//TODO remove from bigWig.h
168typedef struct bwLL bwLL;
169struct bwLL {
170 bwRTreeNode_t *node;
171 struct bwLL *next;
172};
173typedef struct bwZoomBuffer_t bwZoomBuffer_t;
174struct bwZoomBuffer_t { //each individual entry takes 32 bytes
175 void *p;
176 uint32_t l, m;
177 struct bwZoomBuffer_t *next;
178};
180
185typedef struct {
186 uint64_t nBlocks;
187 uint32_t blockSize;
188 uint64_t nEntries;
190 uint32_t tid;
191 uint32_t start;
192 uint32_t end;
193 uint32_t span;
194 uint32_t step;
195 uint8_t ltype;
196 uint32_t l;
197 void *p;
200 bwZoomBuffer_t **firstZoomBuffer;
201 bwZoomBuffer_t **lastZoomBuffer;
202 uint64_t *nNodes;
203 uLongf compressPsz;
204 void *compressP;
206
219
223typedef struct {
224 uint32_t l;
225 uint32_t m;
226 uint32_t *start;
227 uint32_t *end;
228 float *value;
230
234typedef struct {
235 uint32_t l;
236 uint32_t m;
237 uint32_t *start;
238 uint32_t *end;
239 char **str;
241
259
267int bwInit(size_t bufSize);
268
273void bwCleanup(void);
274
282int bwIsBigWig(const char *fname, CURLcode (*callBack)(CURL*));
283
291int bbIsBigBed(const char *fname, CURLcode (*callBack)(CURL*));
292
301bigWigFile_t *bwOpen(const char *fname, CURLcode (*callBack)(CURL*), const char* mode);
302
310bigWigFile_t *bbOpen(const char *fname, CURLcode (*callBack)(CURL*));
311
320char *bbGetSQL(bigWigFile_t *fp);
321
327void bwClose(bigWigFile_t *fp);
328
329/*******************************************************************************
330*
331* The following are in bwStats.c
332*
333*******************************************************************************/
334
342uint32_t bwGetTid(const bigWigFile_t *fp, const char *chrom);
343
350
357
370bwOverlappingIntervals_t *bwGetOverlappingIntervals(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end);
371
384bbOverlappingEntries_t *bbGetOverlappingEntries(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int withString);
385
400bwOverlapIterator_t *bwOverlappingIntervalsIterator(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t blocksPerIteration);
401
418bwOverlapIterator_t *bbOverlappingEntriesIterator(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int withString, uint32_t blocksPerIteration);
419
428
434
448bwOverlappingIntervals_t *bwGetValues(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int includeNA);
449
462double *bwStats(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type);
463
476double *bwStatsFromFull(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type);
477
478//Writer functions
479
487int bwCreateHdr(bigWigFile_t *fp, int32_t maxZooms);
488
497chromList_t *bwCreateChromList(const char* const* chroms, const uint32_t *lengths, int64_t n);
498
506int bwWriteHdr(bigWigFile_t *bw);
507
524int bwAddIntervals(bigWigFile_t *fp, const char* const* chrom, const uint32_t *start, const uint32_t *end, const float *values, uint32_t n);
525
538int bwAppendIntervals(bigWigFile_t *fp, const uint32_t *start, const uint32_t *end, const float *values, uint32_t n);
539
556int bwAddIntervalSpans(bigWigFile_t *fp, const char *chrom, const uint32_t *start, uint32_t span, const float *values, uint32_t n);
557
569int bwAppendIntervalSpans(bigWigFile_t *fp, const uint32_t *start, const float *values, uint32_t n);
570
588int bwAddIntervalSpanSteps(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t span, uint32_t step, const float *values, uint32_t n);
589
600int bwAppendIntervalSpanSteps(bigWigFile_t *fp, const float *values, uint32_t n);
601
602#ifdef __cplusplus
603}
604#endif
605
606#endif // LIBBIGWIG_H
int bwCreateHdr(bigWigFile_t *fp, int32_t maxZooms)
Create a largely empty bigWig header Every bigWig file has a header, this creates the template for on...
Definition bwWrite.c:56
char * bbGetSQL(bigWigFile_t *fp)
Returns a string containing the SQL entry (or NULL). The "auto SQL" field contains the names and valu...
Definition bwRead.c:315
void bbDestroyOverlappingEntries(bbOverlappingEntries_t *o)
Frees space allocated by bbGetOverlappingEntries
Definition bwValues.c:333
bwOverlappingIntervals_t * bwGetValues(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int includeNA)
Return all per-base bigWig values in a given interval. Given an interval (e.g., chr1:0-100),...
Definition bwValues.c:713
int bwAppendIntervalSpanSteps(bigWigFile_t *fp, const float *values, uint32_t n)
Append to a previous block of fixed-step entries. If you previously used bwAddIntervalSpanSteps(),...
Definition bwWrite.c:552
int bwInit(size_t bufSize)
Initializes curl and global variables. This MUST be called before other functions (at least if you wa...
Definition bwRead.c:38
bigWigFile_t * bbOpen(const char *fname, CURLcode(*callBack)(CURL *))
Opens a local or remote bigBed file. This will open a local or remote bigBed file....
Definition bwRead.c:397
bigWigFile_t * bwOpen(const char *fname, CURLcode(*callBack)(CURL *), const char *mode)
Opens a local or remote bigWig file. This will open a local or remote bigWig file....
Definition bwRead.c:345
int bbIsBigBed(const char *fname, CURLcode(*callBack)(CURL *))
Determine is a file is a bigBed file. This function will quickly check either local or remote files t...
Definition bwRead.c:332
void bwDestroyOverlappingIntervals(bwOverlappingIntervals_t *o)
Frees space allocated by bwGetOverlappingIntervals
Definition bwValues.c:325
bwOverlappingIntervals_t * bwGetOverlappingIntervals(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end)
Return bigWig entries overlapping an interval. Find all bigWig entries overlapping a range and return...
Definition bwValues.c:563
int bwAddIntervals(bigWigFile_t *fp, const char *const *chrom, const uint32_t *start, const uint32_t *end, const float *values, uint32_t n)
Write a new block of bedGraph-like intervals to a bigWig file Adds entries of the form: chromosome st...
Definition bwWrite.c:374
double * bwStats(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type)
Determines per-interval bigWig statistics Can determine mean/min/max/coverage/standard deviation of v...
Definition bwStats.c:530
uint32_t bwGetTid(const bigWigFile_t *fp, const char *chrom)
Converts between chromosome name and ID.
Definition bwValues.c:284
void bwIteratorDestroy(bwOverlapIterator_t *iter)
Destroys a bwOverlapIterator_t.
Definition bwValues.c:643
int bwAppendIntervalSpans(bigWigFile_t *fp, const uint32_t *start, const float *values, uint32_t n)
Append to a previous block of variable-step entries. If you previously used bwAddIntervalSpans(),...
Definition bwWrite.c:495
bwStatsType
Definition bigWig.h:103
@ coverage
Definition bigWig.h:112
@ min
Definition bigWig.h:110
@ sum
Definition bigWig.h:113
@ doesNotExist
Definition bigWig.h:104
@ max
Definition bigWig.h:109
@ mean
Definition bigWig.h:105
@ dev
Definition bigWig.h:108
@ stdev
Definition bigWig.h:107
@ average
Definition bigWig.h:106
@ cov
Definition bigWig.h:111
chromList_t * bwCreateChromList(const char *const *chroms, const uint32_t *lengths, int64_t n)
Take a list of chromosome names and lengths and return a pointer to a chromList_t This MUST be run be...
Definition bwWrite.c:22
double * bwStatsFromFull(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type)
Determines per-interval bigWig statistics Can determine mean/min/max/coverage/standard deviation of v...
Definition bwStats.c:485
int bwAddIntervalSpans(bigWigFile_t *fp, const char *chrom, const uint32_t *start, uint32_t span, const float *values, uint32_t n)
Add a new block of variable-step entries to a bigWig file Adds entries for the form chromosome start ...
Definition bwWrite.c:462
bbOverlappingEntries_t * bbGetOverlappingEntries(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int withString)
Return bigBed entries overlapping an interval. Find all bigBed entries overlapping a range and return...
Definition bwValues.c:575
int bwAppendIntervals(bigWigFile_t *fp, const uint32_t *start, const uint32_t *end, const float *values, uint32_t n)
Append bedGraph-like intervals to a previous block of bedGraph-like intervals in a bigWig file....
Definition bwWrite.c:434
int bwIsBigWig(const char *fname, CURLcode(*callBack)(CURL *))
Determine if a file is a bigWig file. This function will quickly check either local or remote files t...
Definition bwRead.c:302
int bwAddIntervalSpanSteps(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t span, uint32_t step, const float *values, uint32_t n)
Add a new block of fixed-step entries to a bigWig file Adds entries for the form value to the file....
Definition bwWrite.c:520
bwOverlapIterator_t * bbOverlappingEntriesIterator(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int withString, uint32_t blocksPerIteration)
Creates an iterator over entries in a bigBed file Iterators can be traversed with bwIteratorNext() an...
Definition bwValues.c:615
void bwClose(bigWigFile_t *fp)
Closes a bigWigFile_t and frees up allocated memory This closes both bigWig and bigBed files.
Definition bwRead.c:289
void bwCleanup(void)
The counterpart to bwInit, this cleans up curl.
Definition bwRead.c:52
int bwWriteHdr(bigWigFile_t *bw)
Write a the header to a bigWig file. You must have already opened the output file,...
Definition bwWrite.c:187
bwOverlapIterator_t * bwIteratorNext(bwOverlapIterator_t *iter)
Traverses to the entries/intervals in the next group of blocks.
Definition bwValues.c:652
bwOverlapIterator_t * bwOverlappingIntervalsIterator(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t blocksPerIteration)
Creates an iterator over intervals in a bigWig file Iterators can be traversed with bwIteratorNext() ...
Definition bwValues.c:587
This structure holds the file pointers and buffers needed for raw access to local and remote files.
Definition bigWigIO.h:38
Holds interval:str associations.
Definition bigWig.h:234
uint32_t m
Definition bigWig.h:236
char ** str
Definition bigWig.h:239
uint32_t * start
Definition bigWig.h:237
uint32_t * end
Definition bigWig.h:238
uint32_t l
Definition bigWig.h:235
A structure that holds everything needed to access a bigWig file.
Definition bigWig.h:210
bwRTree_t * idx
Definition bigWig.h:214
int isWrite
Definition bigWig.h:216
int type
Definition bigWig.h:217
URL_t * URL
Definition bigWig.h:211
bwWriteBuffer_t * writeBuffer
Definition bigWig.h:215
chromList_t * cl
Definition bigWig.h:213
bigWigHdr_t * hdr
Definition bigWig.h:212
The header section of a bigWig file.
Definition bigWig.h:135
bwZoomHdr_t * zoomHdrs
Definition bigWig.h:147
double sumData
Definition bigWig.h:152
uint64_t extensionOffset
Definition bigWig.h:146
uint16_t definedFieldCount
Definition bigWig.h:142
uint64_t sqlOffset
Definition bigWig.h:143
double minVal
Definition bigWig.h:150
uint16_t fieldCount
Definition bigWig.h:141
uint64_t indexOffset
Definition bigWig.h:140
uint64_t ctOffset
Definition bigWig.h:138
uint16_t version
Definition bigWig.h:136
uint64_t dataOffset
Definition bigWig.h:139
uint64_t nBasesCovered
Definition bigWig.h:149
uint16_t nLevels
Definition bigWig.h:137
uint64_t summaryOffset
Definition bigWig.h:144
double sumSquared
Definition bigWig.h:153
uint32_t bufSize
Definition bigWig.h:145
double maxVal
Definition bigWig.h:151
A structure to hold iterations One of intervals and entries should be used to access records from big...
Definition bigWig.h:246
uint64_t offset
Definition bigWig.h:251
uint32_t blocksPerIteration
Definition bigWig.h:252
bbOverlappingEntries_t * entries
Definition bigWig.h:256
int withString
Definition bigWig.h:253
bwOverlappingIntervals_t * intervals
Definition bigWig.h:255
void * data
Definition bigWig.h:257
bigWigFile_t * bw
Definition bigWig.h:247
uint32_t start
Definition bigWig.h:249
uint32_t tid
Definition bigWig.h:248
uint32_t end
Definition bigWig.h:250
void * blocks
Definition bigWig.h:254
Holds interval:value associations.
Definition bigWig.h:223
uint32_t m
Definition bigWig.h:225
float * value
Definition bigWig.h:228
uint32_t * start
Definition bigWig.h:226
uint32_t l
Definition bigWig.h:224
uint32_t * end
Definition bigWig.h:227
A node within an R-tree holding the index for data.
Definition bwValues.h:20
Definition bwValues.h:39
This is only needed for writing bigWig files (and won't be created otherwise) This should be removed ...
Definition bigWig.h:185
bwZoomBuffer_t ** lastZoomBuffer
Definition bigWig.h:201
uint64_t nEntries
Definition bigWig.h:188
uLongf compressPsz
Definition bigWig.h:203
uint32_t tid
Definition bigWig.h:190
uint8_t ltype
Definition bigWig.h:195
uint32_t span
Definition bigWig.h:193
bwZoomBuffer_t ** firstZoomBuffer
Definition bigWig.h:200
bwLL * firstIndexNode
Definition bigWig.h:198
uint64_t runningWidthSum
Definition bigWig.h:189
uint32_t blockSize
Definition bigWig.h:187
bwLL * currentIndexNode
Definition bigWig.h:199
uint64_t * nNodes
Definition bigWig.h:202
uint32_t l
Definition bigWig.h:196
uint32_t step
Definition bigWig.h:194
uint32_t start
Definition bigWig.h:191
uint32_t end
Definition bigWig.h:192
void * p
Definition bigWig.h:197
uint64_t nBlocks
Definition bigWig.h:186
void * compressP
Definition bigWig.h:204
BigWig files have multiple "zoom" levels, each of which has its own header. This hold those headers.
Definition bigWig.h:122
uint64_t * dataOffset
Definition bigWig.h:125
uint32_t * level
Definition bigWig.h:123
bwRTree_t ** idx
Definition bigWig.h:127
uint64_t * indexOffset
Definition bigWig.h:126
Holds the chromosomes and their lengths.
Definition bigWig.h:160
char ** chrom
Definition bigWig.h:162
uint32_t * len
Definition bigWig.h:163
int64_t nKeys
Definition bigWig.h:161