예제 #1
0
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;
    }

    if(bwInit(1<<17) != 0) {
        fprintf(stderr, "Received an error in bwInit\n");
        return 1;
    }

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

    bwPrintHdr(fp);
    bwPrintIndexTree(fp);

    //Try to get some blocks
    printf("1:0-99\n");
    intervals = bwGetValues(fp, "1", 0, 99, 0);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

    printf("1:99-1000\n");
    intervals = bwGetValues(fp, "1", 99, 1000, 0);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

    printf("1:99-150\n");
    intervals = bwGetValues(fp, "1", 99, 150, 1);
    printIntervals(intervals,99);
    bwDestroyOverlappingIntervals(intervals);

    printf("1:99-100\n");
    intervals = bwGetValues(fp, "1", 99, 100, 0);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

    printf("1:151-1000\n");
    intervals = bwGetValues(fp, "1", 151, 1000, 0);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

    printf("chr1:0-100\n");
    intervals = bwGetValues(fp, "chr1", 0, 100, 0);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

    stats = bwStats(fp, "1", 0, 200, 1, mean);
    assert(stats);
    printf("1:0-1000 mean: %f\n", *stats);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 2, mean);
    assert(stats);
    printf("1:0-1000 mean: %f %f\n", stats[0], stats[1]);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 1, dev);
    assert(stats);
    printf("1:0-1000 std. dev.: %f\n", *stats);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 2, dev);
    assert(stats);
    printf("1:0-1000 std. dev.: %f %f\n", stats[0], stats[1]);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 1, min);
    assert(stats);
    printf("1:0-1000 min: %f\n", *stats);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 2, min);
    assert(stats);
    printf("1:0-1000 min: %f %f\n", stats[0], stats[1]);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 1, max);
    assert(stats);
    printf("1:0-1000 max: %f\n", *stats);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 2, max);
    assert(stats);
    printf("1:0-1000 max: %f %f\n", stats[0], stats[1]);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 1, cov);
    assert(stats);
    printf("1:0-1000 coverage: %f\n", *stats);
    free(stats);

    stats = bwStats(fp, "1", 0, 200, 2, cov);
    assert(stats);
    printf("1:0-1000 coverage: %f %f\n", stats[0], stats[1]);
    free(stats);

    printf("1:0-200000000 intervals\n");
    intervals = bwGetOverlappingIntervals(fp, "1", 0, 200000000);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

    printf("10:0-200000000 intervals\n");
    intervals = bwGetOverlappingIntervals(fp, "10", 0, 200000000);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

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

    if(bwInit(1<<17) != 0) {
        fprintf(stderr, "Received an error in bwInit\n");
        return 1;
    }

    fp = bwOpen(argv[1], callBack, "r");
    if(!fp) {
        fprintf(stderr, "An error occured while opening %s\n", argv[1]);
        return 1;
    }

    bwPrintHdr(fp);
    bwPrintIndexTree(fp);

    //Try to get some blocks
    printf("%s:10000000-10000100 Intervals\n", chrom);
    intervals = bwGetOverlappingIntervals(fp, chrom, 10000000, 10000100);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

    printf("%s:10000000-10000100 Values\n", chrom);
    intervals = bwGetValues(fp, chrom, 10000000, 10000100, 0);
    printIntervals(intervals,0);
    bwDestroyOverlappingIntervals(intervals);

    stats = bwStats(fp, chrom, 10000000, 10000100, 1, mean);
    if(stats) {
        printf("%s:10000000-10000100 mean: %f\n", chrom, stats[0]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 2, mean);
    if(stats) {
        printf("%s:10000000-10000100 mean: %f %f\n", chrom, stats[0], stats[1]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 1, dev);
    if(stats) {
        printf("%s:10000000-10000100 std. dev.: %f\n", chrom, stats[0]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 2, dev);
    if(stats) {
        printf("%s:10000000-10000100 std. dev.: %f %f\n", chrom, stats[0], stats[1]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 1, min);
    if(stats) {
        printf("%s:10000000-10000100 min: %f\n", chrom, stats[0]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 2, min);
    if(stats) {
        printf("%s:10000000-10000100 min: %f %f\n", chrom, stats[0], stats[1]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 1, max);
    if(stats) {
        printf("%s:10000000-10000100 max: %f\n", chrom, stats[0]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 2, max);
    if(stats) {
        printf("%s:10000000-10000100 max: %f %f\n", chrom, stats[0], stats[1]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 1, cov);
    if(stats) {
        printf("%s:10000000-10000100 coverage: %f\n", chrom, stats[0]);
        free(stats);
    }

    stats = bwStats(fp, chrom, 10000000, 10000100, 2, cov);
    if(stats) {
        printf("%s:10000000-10000100 coverage: %f %f\n", chrom, stats[0], stats[1]);
        free(stats);
    }

    bwClose(fp);
    bwCleanup();
    return 0;
}