bio-bigwig 0.1.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 972d5cd642441b8881267966c288fec25708aba244c7aa8ca2618d0888ca769e
4
- data.tar.gz: 328fd1c1d6f0705a8eef2144c1f4894b9f27bc58d35c5e3e20ea15fd58e4e776
3
+ metadata.gz: 95e1d69741807991fdf8d393e063690c1df359641277c61ade57183b4ec275e1
4
+ data.tar.gz: daa00c09d52d963d4a8ff32c45005c24577ccc82c5f41d5aca014f3e9dd08f66
5
5
  SHA512:
6
- metadata.gz: 40ede32f219724178e4076ede669ab89f2d68065ff5becf16f84b7e8d6c2b0636d3a3c51bf1d0d3f3a29b37dbacf232a167bccf838882e6d946c35779fa8c075
7
- data.tar.gz: 608f3bf25e5b549ad6c31d7bf41f6a8d7b55f735721ccf19a33843390e6038bd1b0fbdc28693c9321101de9aa54495952e2565700fe38bc30097e8e7d979f6e3
6
+ metadata.gz: 4654fa6ed84c7bcd4ca09e2cb70a9498f5a0591644db7562b88a0c73ab8721ae2ba42ca38180ab2caf85b2717bda33760ab950644c19163dc19e37714e3fb34f
7
+ data.tar.gz: ad73abfb58f31059059aaa415c9a39e305fe1e25cba82d621576fd7a1080db451ca728f2a913ad0224c94e2662560c8e48c7716e46b7366b67fb3a38f11c8aae
@@ -81,6 +81,29 @@ static bigWigFile_t *get_bigWigFile(VALUE obj)
81
81
  return data;
82
82
  }
83
83
 
84
+ static uint32_t
85
+ coordinate_arg(VALUE value)
86
+ {
87
+ long long coordinate = NUM2LL(value);
88
+ if (coordinate < 0 || coordinate > UINT32_MAX)
89
+ rb_raise(rb_eRangeError, "coordinate must be in 0..4294967295");
90
+ return (uint32_t)coordinate;
91
+ }
92
+
93
+ static void
94
+ parse_region(bigWigFile_t *bw, uint32_t tid, VALUE rb_start, VALUE rb_end,
95
+ uint32_t *start, uint32_t *end)
96
+ {
97
+ if (tid == UINT32_MAX)
98
+ rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
99
+
100
+ *start = NIL_P(rb_start) ? 0 : coordinate_arg(rb_start);
101
+ *end = NIL_P(rb_end) || rb_end == INT2FIX(-1) ? bw->cl->len[tid] : coordinate_arg(rb_end);
102
+
103
+ if (*end <= *start || *end > bw->cl->len[tid])
104
+ rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
105
+ }
106
+
84
107
  static VALUE
85
108
  bigwig_allocate(VALUE klass)
86
109
  {
@@ -287,8 +310,7 @@ bw_get_stats(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE rb_
287
310
  {
288
311
  bigWigFile_t *bw = get_bigWigFile(self);
289
312
  double *val;
290
- unsigned long startl = 0, endl = -1;
291
- uint32_t start, end = -1, tid;
313
+ uint32_t start, end, tid;
292
314
  int nBins = 1, i;
293
315
  char *chrom = NULL;
294
316
  const char *type = "mean";
@@ -317,12 +339,6 @@ bw_get_stats(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE rb_
317
339
  chrom = StringValueCStr(rb_chrom);
318
340
  }
319
341
 
320
- if (rb_start != Qnil)
321
- startl = NUM2LONG(rb_start);
322
-
323
- if (rb_end != Qnil)
324
- endl = NUM2LONG(rb_end);
325
-
326
342
  if (rb_nBins != Qnil)
327
343
  nBins = NUM2INT(rb_nBins);
328
344
 
@@ -330,24 +346,7 @@ bw_get_stats(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE rb_
330
346
  type = StringValueCStr(rb_type);
331
347
 
332
348
  tid = bwGetTid(bw, chrom);
333
-
334
- if (endl == (unsigned long)-1 && tid != (uint32_t)-1)
335
- endl = bw->cl->len[tid];
336
-
337
- if (tid == (uint32_t)-1 || startl > end || endl > end)
338
- {
339
- rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
340
- return Qnil;
341
- }
342
-
343
- start = (uint32_t)startl;
344
- end = (uint32_t)endl;
345
-
346
- if (end <= start || end > bw->cl->len[tid] || start >= end)
347
- {
348
- rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
349
- return Qnil;
350
- }
349
+ parse_region(bw, tid, rb_start, rb_end, &start, &end);
351
350
 
352
351
  if (char2enum(type) == doesNotExist)
353
352
  {
@@ -395,8 +394,7 @@ bw_get_values(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end)
395
394
  {
396
395
  bigWigFile_t *bw = get_bigWigFile(self);
397
396
  int i;
398
- uint32_t start, end = -1, tid;
399
- unsigned long startl = 0, endl = -1;
397
+ uint32_t start, end, tid;
400
398
  char *chrom = NULL;
401
399
  VALUE ret;
402
400
  bwOverlappingIntervals_t *o;
@@ -418,30 +416,8 @@ bw_get_values(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end)
418
416
  chrom = StringValueCStr(rb_chrom);
419
417
  }
420
418
 
421
- if (rb_start != Qnil)
422
- startl = NUM2LONG(rb_start);
423
-
424
- if (rb_end != Qnil)
425
- endl = NUM2LONG(rb_end);
426
-
427
419
  tid = bwGetTid(bw, chrom);
428
-
429
- if (endl == (unsigned long)-1 && tid != (uint32_t)-1)
430
- endl = bw->cl->len[tid];
431
- if (tid == (uint32_t)-1 || startl > end || endl > end)
432
- {
433
- rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
434
- return Qnil;
435
- }
436
-
437
- start = (uint32_t)startl;
438
- end = (uint32_t)endl;
439
-
440
- if (end <= start || end > bw->cl->len[tid] || start >= end)
441
- {
442
- rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
443
- return Qnil;
444
- }
420
+ parse_region(bw, tid, rb_start, rb_end, &start, &end);
445
421
 
446
422
  if (!hasEntries(bw))
447
423
  {
@@ -467,8 +443,7 @@ static VALUE
467
443
  bw_get_intervals(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end)
468
444
  {
469
445
  bigWigFile_t *bw = get_bigWigFile(self);
470
- uint32_t start, end = -1, tid, i;
471
- unsigned long startl = 0, endl = -1;
446
+ uint32_t start, end, tid, i;
472
447
  bwOverlappingIntervals_t *intervals = NULL;
473
448
  char *chrom = NULL;
474
449
  VALUE ret;
@@ -496,32 +471,8 @@ bw_get_intervals(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end)
496
471
  chrom = StringValueCStr(rb_chrom);
497
472
  }
498
473
 
499
- if (rb_start != Qnil)
500
- startl = NUM2LONG(rb_start);
501
-
502
- if (rb_end != Qnil)
503
- endl = NUM2LONG(rb_end);
504
-
505
474
  tid = bwGetTid(bw, chrom);
506
-
507
- // Sanity check
508
- if (endl == (unsigned long)-1 && tid != (uint32_t)-1)
509
- endl = bw->cl->len[tid];
510
-
511
- if (tid == (uint32_t)-1 || startl > end || endl > end)
512
- {
513
- rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
514
- return Qnil;
515
- }
516
-
517
- start = (uint32_t)startl;
518
- end = (uint32_t)endl;
519
-
520
- if (end <= start || end > bw->cl->len[tid] || start >= end)
521
- {
522
- rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
523
- return Qnil;
524
- }
475
+ parse_region(bw, tid, rb_start, rb_end, &start, &end);
525
476
 
526
477
  if (!hasEntries(bw))
527
478
  {
@@ -555,8 +506,7 @@ static VALUE
555
506
  bb_get_entries(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE rb_with_string)
556
507
  {
557
508
  bigWigFile_t *bw = get_bigWigFile(self);
558
- uint32_t start, end = -1, tid, i;
559
- unsigned long startl = 0, endl = -1;
509
+ uint32_t start, end, tid, i;
560
510
  char *chrom = NULL;
561
511
  VALUE ret, t;
562
512
  int withString = 1;
@@ -579,12 +529,6 @@ bb_get_entries(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE r
579
529
  chrom = StringValueCStr(rb_chrom);
580
530
  }
581
531
 
582
- if (rb_start != Qnil)
583
- startl = NUM2LONG(rb_start);
584
-
585
- if (rb_end != Qnil)
586
- endl = NUM2LONG(rb_end);
587
-
588
532
  if (rb_with_string != Qnil)
589
533
  {
590
534
  if (RTEST(rb_with_string))
@@ -594,24 +538,7 @@ bb_get_entries(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE r
594
538
  }
595
539
 
596
540
  tid = bwGetTid(bw, chrom);
597
-
598
- // Sanity check
599
- if (endl == (unsigned long)-1 && tid != (uint32_t)-1)
600
- endl = bw->cl->len[tid];
601
- if (tid == (uint32_t)-1 || startl > end || endl > end)
602
- {
603
- rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
604
- return Qnil;
605
- }
606
-
607
- start = (uint32_t)startl;
608
- end = (uint32_t)endl;
609
-
610
- if (end <= start || end > bw->cl->len[tid] || start >= end)
611
- {
612
- rb_raise(rb_eRuntimeError, "Invalid interval bounds!");
613
- return Qnil;
614
- }
541
+ parse_region(bw, tid, rb_start, rb_end, &start, &end);
615
542
 
616
543
  o = bbGetOverlappingEntries(bw, chrom, start, end, withString);
617
544
  if (!o)
@@ -2,6 +2,7 @@ require "mkmf"
2
2
 
3
3
  # check curl
4
4
  have_library("curl", "curl_easy_init")
5
+ have_library("z", "uncompress", "zlib.h")
5
6
  have_header("libbigwig/bigWig.h")
6
7
 
7
8
  $srcs = Dir.glob("libBigWig/*.c", base: __dir__)
@@ -56,7 +56,7 @@ extern "C" {
56
56
  /*!
57
57
  * The library version number
58
58
  */
59
- #define LIBBIGWIG_VERSION 0.4.8
59
+ #define LIBBIGWIG_VERSION 0.4.10
60
60
 
61
61
  /*!
62
62
  * If 1, then this library was compiled with remote file support.
@@ -487,7 +487,7 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
487
487
  uint64_t i;
488
488
  int compressed = 0, rv, slen;
489
489
  uLongf sz = fp->hdr->bufSize, tmp = 0;
490
- void *buf = NULL, *bufEnd = NULL, *compBuf = NULL;
490
+ void *buf = NULL, *bufBase = NULL, *bufEnd = NULL, *compBuf = NULL;
491
491
  uint32_t entryTid = 0, start = 0, end;
492
492
  char *str;
493
493
  bbOverlappingEntries_t *output = calloc(1, sizeof(bbOverlappingEntries_t));
@@ -499,7 +499,7 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
499
499
 
500
500
  if(sz) {
501
501
  compressed = 1;
502
- buf = malloc(sz);
502
+ bufBase = buf = malloc(sz);
503
503
  }
504
504
  sz = 0; //This is now the size of the compressed buffer
505
505
 
@@ -544,15 +544,14 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
544
544
  buf = (char*)bufEnd - tmp; //reset the buffer pointer
545
545
  }
546
546
 
547
- if(compressed && buf) free(buf);
547
+ if(compressed && bufBase) free(bufBase);
548
548
  if(compBuf) free(compBuf);
549
549
  return output;
550
550
 
551
551
  error:
552
552
  fprintf(stderr, "[bbGetOverlappingEntriesCore] Got an error\n");
553
- buf = (char*)bufEnd - tmp;
554
553
  if(output) bbDestroyOverlappingEntries(output);
555
- if(compressed && buf) free(buf);
554
+ if(compressed && bufBase) free(bufBase);
556
555
  if(compBuf) free(compBuf);
557
556
  return NULL;
558
557
  }
@@ -544,7 +544,7 @@ int bwAddIntervalSpanSteps(bigWigFile_t *fp, const char *chrom, uint32_t start,
544
544
  updateStats(fp, wb->span, values[i]);
545
545
  wb->l += 4;
546
546
  }
547
- wb->end = wb->start + (wb->l>>2) * step;
547
+ wb->end = wb->start + ((wb->l-24)>>2) * step;
548
548
 
549
549
  return 0;
550
550
  }
@@ -567,7 +567,7 @@ int bwAppendIntervalSpanSteps(bigWigFile_t *fp, const float *values, uint32_t n)
567
567
  updateStats(fp, wb->span, values[i]);
568
568
  wb->l += 4;
569
569
  }
570
- wb->end = wb->start + (wb->l>>2) * wb->step;
570
+ wb->end = wb->start + ((wb->l-24)>>2) * wb->step;
571
571
 
572
572
  return 0;
573
573
  }
@@ -209,6 +209,11 @@ URL_t *urlOpen(const char *fname, CURLcode (*callBack)(CURL*), const char *mode)
209
209
  fprintf(stderr, "[urlOpen] Failed instructing curl to use any HTTP authentication it finds to be suitable!\n");
210
210
  goto error;
211
211
  }
212
+ // set user-agent
213
+ if(curl_easy_setopt(URL->x.curl, CURLOPT_USERAGENT, "libBigWig") != CURLE_OK) {
214
+ fprintf(stderr, "[urlOpen] Failed instructing curl to use libBigWig as a user-agent!\n");
215
+ goto error;
216
+ }
212
217
  //Follow redirects
213
218
  if(curl_easy_setopt(URL->x.curl, CURLOPT_FOLLOWLOCATION, 1L) != CURLE_OK) {
214
219
  fprintf(stderr, "[urlOpen] Failed instructing curl to follow redirects!\n");
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bio
4
4
  class BigWig
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-bigwig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubygems_version: 3.6.9
56
+ rubygems_version: 4.0.20
57
57
  specification_version: 4
58
58
  summary: A ruby library for accessing bigWig / bigBed files
59
59
  test_files: []