libBigWig
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Pages
bigWig.h
Go to the documentation of this file.
1 #include "io.h"
2 #include "bwValues.h"
3 #include <inttypes.h>
4 #include <zlib.h>
5 
44 #define LIBBIGWIG_VERSION 0.1
45 
49 #define BIGWIG_MAGIC 0x888FFC26
50 
53 #define CIRTREE_MAGIC 0x78ca8c91
54 
57 #define IDX_MAGIC 0x2468ace0
58 
61 #define DEFAULT_nCHILDREN 64
62 
65 #define DEFAULT_BLOCKSIZE 32768
66 
71  doesNotExist = -1,
72  mean = 0,
73  average = 0,
74  std = 1,
75  stdev = 1,
76  dev = 1,
77  max = 2,
78  min = 3,
79  cov = 4,
80  coverage = 4
81 };
82 
83 //Should hide this from end users
89 typedef struct {
90  uint32_t *level;
91  //There's 4 bytes of padding between these
92  uint64_t *dataOffset;
93  uint64_t *indexOffset;
95 } bwZoomHdr_t;
96 
102 typedef struct {
103  uint16_t version;
104  uint16_t nLevels;
105  uint64_t ctOffset;
106  uint64_t dataOffset;
107  uint64_t indexOffset;
108  uint64_t sqlOffset;
109  uint64_t summaryOffset;
110  uint32_t bufSize;
111  uint64_t extensionOffset;
113  //total Summary
114  uint64_t nBasesCovered;
115  double minVal;
116  double maxVal;
117  double sumData;
118  double sumSquared;
119 } bigWigHdr_t;
120 
121 //Should probably replace this with a hash
125 typedef struct {
126  int64_t nKeys;
127  char **chrom;
128  uint32_t *len;
129 } chromList_t;
130 
131 //TODO remove from bigWig.h
133 typedef struct bwLL bwLL;
134 struct bwLL {
135  bwRTreeNode_t *node;
136  struct bwLL *next;
137 };
138 typedef struct bwZoomBuffer_t bwZoomBuffer_t;
139 struct bwZoomBuffer_t { //each individual entry takes 32 bytes
140  void *p;
141  uint32_t l, m;
142  struct bwZoomBuffer_t *next;
143 };
145 
150 typedef struct {
151  uint64_t nBlocks;
152  uint32_t blockSize;
153  uint64_t nEntries;
154  uint64_t runningWidthSum;
155  uint32_t tid;
156  uint32_t start;
157  uint32_t end;
158  uint32_t span;
159  uint32_t step;
160  uint8_t ltype;
161  uint32_t l;
162  void *p;
165  bwZoomBuffer_t **firstZoomBuffer;
166  bwZoomBuffer_t **lastZoomBuffer;
167  uint64_t *nNodes;
168  uLongf compressPsz;
169  void *compressP;
171 
175 typedef struct {
181  int isWrite;
182 } bigWigFile_t;
183 
187 typedef struct {
188  uint32_t l;
189  uint32_t m;
190  uint32_t *start;
191  uint32_t *end;
192  float *value;
194 
202 int bwInit(size_t bufSize);
203 
208 void bwCleanup(void);
209 
218 bigWigFile_t *bwOpen(char *fname, CURLcode (*callBack)(CURL*), const char* mode);
219 
224 void bwClose(bigWigFile_t *fp);
225 
226 /*******************************************************************************
227 *
228 * The following are in bwStats.c
229 *
230 *******************************************************************************/
231 
239 uint32_t bwGetTid(bigWigFile_t *fp, char *chrom);
240 
247 
260 bwOverlappingIntervals_t *bwGetOverlappingIntervals(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end);
261 
275 bwOverlappingIntervals_t *bwGetValues(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, int includeNA);
276 
289 double *bwStats(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type);
290 
291 //Writer functions
292 
300 int bwCreateHdr(bigWigFile_t *fp, int32_t maxZooms);
301 
310 chromList_t *bwCreateChromList(char **chroms, uint32_t *lengths, int64_t n);
311 
319 int bwWriteHdr(bigWigFile_t *bw);
320 
337 int bwAddIntervals(bigWigFile_t *fp, char **chrom, uint32_t *start, uint32_t *end, float *values, uint32_t n);
338 
351 int bwAppendIntervals(bigWigFile_t *fp, uint32_t *start, uint32_t *end, float *values, uint32_t n);
352 
369 int bwAddIntervalSpans(bigWigFile_t *fp, char *chrom, uint32_t *start, uint32_t span, float *values, uint32_t n);
370 
382 int bwAppendIntervalSpans(bigWigFile_t *fp, uint32_t *start, float *values, uint32_t n);
383 
401 int bwAddIntervalSpanSteps(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t span, uint32_t step, float *values, uint32_t n);
402 
413 int bwAppendIntervalSpanSteps(bigWigFile_t *fp, float *values, uint32_t n);
uint64_t summaryOffset
Definition: bigWig.h:109
This structure holds the file pointers and buffers needed for raw access to local and remote files...
Definition: io.h:24
uint64_t nBlocks
Definition: bigWig.h:151
bwZoomHdr_t * zoomHdrs
Definition: bigWig.h:112
double maxVal
Definition: bigWig.h:116
int bwAppendIntervalSpans(bigWigFile_t *fp, uint32_t *start, float *values, uint32_t n)
Append to a previous block of variable-step entries. If you previously used bwAddIntervalSpans(), this will continue appending more values to the block(s) it created.
Definition: bwWrite.c:463
int bwAddIntervals(bigWigFile_t *fp, char **chrom, uint32_t *start, uint32_t *end, 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:346
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
uint32_t span
Definition: bigWig.h:158
bwWriteBuffer_t * writeBuffer
Definition: bigWig.h:180
uint32_t m
Definition: bigWig.h:189
uint32_t * start
Definition: bigWig.h:190
uint32_t start
Definition: bigWig.h:156
uint32_t l
Definition: bigWig.h:188
uint32_t l
Definition: bigWig.h:161
uint32_t * len
Definition: bigWig.h:128
uint32_t end
Definition: bigWig.h:157
bigWigFile_t * bwOpen(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:294
bwZoomBuffer_t ** lastZoomBuffer
Definition: bigWig.h:166
double sumData
Definition: bigWig.h:117
bwLL * currentIndexNode
Definition: bigWig.h:164
uint16_t version
Definition: bigWig.h:103
uint8_t ltype
Definition: bigWig.h:160
uint32_t bwGetTid(bigWigFile_t *fp, char *chrom)
Converts between chromosome name and ID.
Definition: bwValues.c:279
bwZoomBuffer_t ** firstZoomBuffer
Definition: bigWig.h:165
int bwWriteHdr(bigWigFile_t *bw)
Write a the header to a bigWig file. You must have already opened the output file, created a header and a chromosome list.
Definition: bwWrite.c:159
uint64_t nEntries
Definition: bigWig.h:153
The header section of a bigWig file.
Definition: bigWig.h:102
uint64_t sqlOffset
Definition: bigWig.h:108
bwOverlappingIntervals_t * bwGetValues(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, int includeNA)
Return all per-base values in a given interval. Given an interval (e.g., chr1:0-100), return the value at each position. Positions without associated values are suppressed by default, but may be returned if includeNA is not 0.
Definition: bwValues.c:462
uint32_t blockSize
Definition: bigWig.h:152
int bwAppendIntervalSpanSteps(bigWigFile_t *fp, float *values, uint32_t n)
Append to a previous block of fixed-step entries. If you previously used bwAddIntervalSpanSteps(), this will continue appending more values to the block(s) it created.
Definition: bwWrite.c:515
int bwAddIntervalSpanSteps(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t span, uint32_t step, 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:486
uint32_t bufSize
Definition: bigWig.h:110
uint64_t ctOffset
Definition: bigWig.h:105
This is only needed for writing bigWig files (and won't be created otherwise) This should be removed ...
Definition: bigWig.h:150
uint32_t tid
Definition: bigWig.h:155
bwRTree_t ** idx
Definition: bigWig.h:94
uint64_t nBasesCovered
Definition: bigWig.h:114
BigWig files have multiple "zoom" levels, each of which has its own header. This hold those headers...
Definition: bigWig.h:89
uint64_t dataOffset
Definition: bigWig.h:106
bwOverlappingIntervals_t * bwGetOverlappingIntervals(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end)
Return entries overlapping an interval. Find all entries overlapping a range and returns them...
Definition: bwValues.c:447
void * p
Definition: bigWig.h:162
URL_t * URL
Definition: bigWig.h:176
double sumSquared
Definition: bigWig.h:118
chromList_t * bwCreateChromList(char **chroms, 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
int bwAddIntervalSpans(bigWigFile_t *fp, char *chrom, uint32_t *start, uint32_t span, 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:433
uint32_t step
Definition: bigWig.h:159
uint16_t nLevels
Definition: bigWig.h:104
bwLL * firstIndexNode
Definition: bigWig.h:163
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
bigWigHdr_t * hdr
Definition: bigWig.h:177
void bwDestroyOverlappingIntervals(bwOverlappingIntervals_t *o)
Frees space allocated by bwGetOverlappingIntervals
Definition: bwValues.c:320
int isWrite
Definition: bigWig.h:181
float * value
Definition: bigWig.h:192
char ** chrom
Definition: bigWig.h:127
Holds interval:value associations.
Definition: bigWig.h:187
uint64_t runningWidthSum
Definition: bigWig.h:154
A structure that holds everything needed to access a bigWig file.
Definition: bigWig.h:175
double * bwStats(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type)
Determines per-interval statistics Can determine mean/min/max/coverage/standard deviation of values i...
Definition: bwStats.c:476
bwStatsType
Definition: bigWig.h:70
bwRTree_t * idx
Definition: bigWig.h:179
uint64_t * nNodes
Definition: bigWig.h:167
double minVal
Definition: bigWig.h:115
void bwCleanup(void)
The counterpart to bwInit, this cleans up curl.
Definition: bwRead.c:50
uint32_t * end
Definition: bigWig.h:191
Holds the chromosomes and their lengths.
Definition: bigWig.h:125
Definition: bwValues.h:36
uLongf compressPsz
Definition: bigWig.h:168
uint64_t * indexOffset
Definition: bigWig.h:93
uint64_t indexOffset
Definition: bigWig.h:107
int bwAppendIntervals(bigWigFile_t *fp, uint32_t *start, uint32_t *end, float *values, uint32_t n)
Append bedGraph-like intervals to a previous block of bedGraph-like intervals in a bigWig file...
Definition: bwWrite.c:406
uint64_t extensionOffset
Definition: bigWig.h:111
uint64_t * dataOffset
Definition: bigWig.h:92
chromList_t * cl
Definition: bigWig.h:178
uint32_t * level
Definition: bigWig.h:90
A node within an R-tree holding the index for data.
Definition: bwValues.h:17
void bwClose(bigWigFile_t *fp)
Closes a bigWigFile_t and frees up allocated memory.
Definition: bwRead.c:281
int64_t nKeys
Definition: bigWig.h:126
void * compressP
Definition: bigWig.h:169