bio-bigwig 0.1.2 → 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: b9937e02151804bc5a6440481d7e6ec99ff411e474f04c6889b86d6a396287f5
4
- data.tar.gz: ec2cef28451cb57e4cfd3e49436f86e64e248a804032b40e8cff3f4817f9bc98
3
+ metadata.gz: 95e1d69741807991fdf8d393e063690c1df359641277c61ade57183b4ec275e1
4
+ data.tar.gz: daa00c09d52d963d4a8ff32c45005c24577ccc82c5f41d5aca014f3e9dd08f66
5
5
  SHA512:
6
- metadata.gz: c3110386fbb9c9c9b892a934abc6ac5f66b10049e4c6a69cd23727a2e7a83ac111a6801122e1c49619e5b905ef06a87c27a5c1696111a6c7121e5c5afd0b4013
7
- data.tar.gz: c77e2b59ab87c285b111f46d466f8e71272355666ac3940253675536e58f1c0a4cbc3d2ed6a971558c53b4e1201c2a0340ff75b842335f176722ff6dfe023402
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,6 @@
2
2
 
3
3
  module Bio
4
4
  class BigWig
5
- VERSION = "0.1.2"
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2