A C library for reading/parsing local and remote bigWig and bigBed files. While Kent's source code is free to use for these purposes, it's really inappropriate as library code since it has the unfortunate habit of calling `exit()` whenever there's an error. If that's then used inside of something like python then the python interpreter gets killed. This library is aimed at resolving these sorts of issues and should also use more standard things like curl and has a friendlier license to boot.
Documentation is automatically generated by doxygen and can be found under `docs/html` or online [here](https://cdn.rawgit.com/dpryan79/libBigWig/master/docs/html/index.html).
Documentation is automatically generated by doxygen and can be found under [`docs/html`](/docs/html) or online [here](https://cdn.rawgit.com/dpryan79/libBigWig/master/docs/html/index.html).
# Example
The only functions and structures that end users need to care about are in "bigWig.h". Below is a commented example. You can see the files under `test/` for further examples.
The only functions and structures that end users need to care about are in "bigWig.h". Below is a commented example. You can see the files under [`test/`](./test/) for further examples.
```c
#include"bigWig.h"
intmain(intargc,char*argv[]){
bigWigFile_t*fp=NULL;
...
...
@@ -55,13 +56,15 @@ The only functions and structures that end users need to care about are in "bigW
bwCleanup();
return0;
}
```
## Writing example
N.B., creation of bigBed files is not supported (there are no plans to change this).
Below is an example of how to write bigWig files. You can also find this file under `test/exampleWrite.c`. Unlike with Kent's tools, you can create bigWig files entry by entry without needing an intermediate wiggle or bedGraph file. Entries in bigWig files are stored in blocks with each entry in a block referring to the same chromosome and having the same type, of which there are three (see the [wiggle specification](http://genome.ucsc.edu/goldenpath/help/wiggle.html) for more information on this).
Below is an example of how to write bigWig files. You can also find this file under [`test/exampleWrite.c`](test/exampleWrite.c). Unlike with Kent's tools, you can create bigWig files entry by entry without needing an intermediate wiggle or bedGraph file. Entries in bigWig files are stored in blocks with each entry in a block referring to the same chromosome and having the same type, of which there are three (see the [wiggle specification](http://genome.ucsc.edu/goldenpath/help/wiggle.html) for more information on this).
```c
#include"bigWig.h"
intmain(intargc,char*argv[]){
...
...
@@ -137,11 +140,13 @@ Below is an example of how to write bigWig files. You can also find this file un
bwCleanup();
return1;
}
```
# Testing file types
As of version 0.3.0, this library supports accessing bigBed files, which are related to bigWig files. Applications that need to support both bigWig and bigBed input can use the `bwIsBigWig` and `bbIsBigBed` functions to determine if their inputs are bigWig/bigBed files:
```c
...code...
if(bwIsBigWig(input_file_name,NULL)){
//do something
...
...
@@ -150,6 +155,7 @@ As of version 0.3.0, this library supports accessing bigBed files, which are rel
}else{
//handle unknown input
}
```
Note that these two functions rely on the "magic number" at the beginning of each file, which differs between bigWig and bigBed files.
...
...
@@ -220,12 +226,14 @@ Regardless of whether a bigWig or bigBed file is being used, the `bwIteratorNext
A full example is provided in `tests/testIterator.c`, but a small example of iterating over all bigWig intervals in `chr1:0-10000000` in chunks of 5 blocks follows: