<commit_before>![Master build status](https://travis-ci.org/dpryan79/libBigWig.svg?branch=master) [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.45278.svg)](http://dx.doi.org/10.5281/zenodo.45278)

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).

# 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.

    #include "bigWig.h"
    int main(int argc, char *argv[]) {
        bigWigFile_t *fp = NULL;
        bwOverlappingIntervals_t *intervals = NULL;
        double *stats = NULL;
        if(argc != 2) {
            fprintf(stderr, "Usage: %s {file.bw|URL://path/file.bw}\n", argv[0]);
            return 1;
        }

        //Initialize enough space to hold 128KiB (1<<17) of data at a time
        if(bwInit(1<<17) != 0) {
            fprintf(stderr, "Received an error in bwInit\n");
            return 1;
        }

        //Open the local/remote file
        fp = bwOpen(argv[1], NULL, "r");
        if(!fp) {
            fprintf(stderr, "An error occured while opening %s\n", argv[1]);
            return 1;
        }

        //Get values in a range (0-based, half open) without NAs
        intervals = bwGetValues(fp, "chr1", 10000000, 10000100, 0);
        bwDestroyOverlappingIntervals(intervals); //Free allocated memory

        //Get values in a range (0-based, half open) with NAs
        intervals = bwGetValues(fp, "chr1", 10000000, 10000100, 1);
        bwDestroyOverlappingIntervals(intervals); //Free allocated memory

        //Get the full intervals that overlap
        intervals = bwGetOverlappingIntervals(fp, "chr1", 10000000, 10000100);
        bwDestroyOverlappingIntervals(intervals);

        //Get an example statistic - standard deviation
        //We want ~4 bins in the range
        stats = bwStats(fp, "chr1", 10000000, 10000100, 4, dev);
        if(stats) {
            printf("chr1:10000000-10000100 std. dev.: %f %f %f %f\n", stats[0], stats[1], stats[2], stats[3]);
            free(stats);
        }

        bwClose(fp);
        bwCleanup();
        return 0;
    }<commit_msg>syntax highlighting<commit_after>![Master build status](https://travis-ci.org/dpryan79/libBigWig.svg?branch=master) [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.45278.svg)](http://dx.doi.org/10.5281/zenodo.45278)

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).

# 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.

```c
#include "bigWig.h"
int main(int argc, char *argv[]) {
    bigWigFile_t *fp = NULL;
    bwOverlappingIntervals_t *intervals = NULL;
    double *stats = NULL;
    if(argc != 2) {
        fprintf(stderr, "Usage: %s {file.bw|URL://path/file.bw}\n", argv[0]);
        return 1;
    }

    //Initialize enough space to hold 128KiB (1<<17) of data at a time
    if(bwInit(1<<17) != 0) {
        fprintf(stderr, "Received an error in bwInit\n");
        return 1;
    }

    //Open the local/remote file
    fp = bwOpen(argv[1], NULL, "r");
    if(!fp) {
        fprintf(stderr, "An error occured while opening %s\n", argv[1]);
        return 1;
    }

    //Get values in a range (0-based, half open) without NAs
    intervals = bwGetValues(fp, "chr1", 10000000, 10000100, 0);
    bwDestroyOverlappingIntervals(intervals); //Free allocated memory

    //Get values in a range (0-based, half open) with NAs
    intervals = bwGetValues(fp, "chr1", 10000000, 10000100, 1);
    bwDestroyOverlappingIntervals(intervals); //Free allocated memory

    //Get the full intervals that overlap
    intervals = bwGetOverlappingIntervals(fp, "chr1", 10000000, 10000100);
    bwDestroyOverlappingIntervals(intervals);

    //Get an example statistic - standard deviation
    //We want ~4 bins in the range
    stats = bwStats(fp, "chr1", 10000000, 10000100, 4, dev);
    if(stats) {
        printf("chr1:10000000-10000100 std. dev.: %f %f %f %f\n", stats[0], stats[1], stats[2], stats[3]);
        free(stats);
    }

    bwClose(fp);
    bwCleanup();
    return 0;
}
```
{'fraction_non_alphanumeric': 0.11469666236400516, 'fraction_numerical': 0.05126313848423382, 'mean_word_length': 3.0720720720720722, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 10, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2288783', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1643, 'n_words': 578}