bio-bigwig 0.0.6 → 0.1.0

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: 87a8791f8697b0b4cff130d28f370e67770688d6da475f7caf956556c8431332
4
- data.tar.gz: 8faebc66db077059394015892d69c3dde78e4eee4eb614f36b2b3377bd88450f
3
+ metadata.gz: 972d5cd642441b8881267966c288fec25708aba244c7aa8ca2618d0888ca769e
4
+ data.tar.gz: 328fd1c1d6f0705a8eef2144c1f4894b9f27bc58d35c5e3e20ea15fd58e4e776
5
5
  SHA512:
6
- metadata.gz: 017d2fa8b7b03646961344fad93a97d71e9a3d3620e0ced75002d64fa44f5175a8434249ed668924b67b72df2d43a05986dca836018c8e5c144a03ee4a5fa29a
7
- data.tar.gz: 9ca76c76d3803689d7e94cd5d9acbd5bd5e939d94bab7a8a2d3c1f0a13ebd5bd3ee97ea617a16877f8a4673ac2fc3291c9b01d56acfa15e70dd05204ec50f398
6
+ metadata.gz: 40ede32f219724178e4076ede669ab89f2d68065ff5becf16f84b7e8d6c2b0636d3a3c51bf1d0d3f3a29b37dbacf232a167bccf838882e6d946c35779fa8c075
7
+ data.tar.gz: 608f3bf25e5b549ad6c31d7bf41f6a8d7b55f735721ccf19a33843390e6038bd1b0fbdc28693c9321101de9aa54495952e2565700fe38bc30097e8e7d979f6e3
data/README.md CHANGED
@@ -3,11 +3,13 @@
3
3
  [![Gem Version](https://img.shields.io/gem/v/bio-bigwig?color=brightgreen)](https://rubygems.org/gems/bio-bigwig)
4
4
  [![test](https://github.com/kojix2/bio-bigwig/actions/workflows/ci.yml/badge.svg)](https://github.com/kojix2/bio-bigwig/actions/workflows/ci.yml)
5
5
  [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://rubydoc.info/gems/bio-bigwig)
6
+ [![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Fbio-bigwig%2Flines)](https://tokei.kojix2.net/github/kojix2/bio-bigwig)
7
+ [![DOI](https://zenodo.org/badge/438516085.svg)](https://doi.org/10.5281/zenodo.13860901)
6
8
 
7
9
  Ruby wrapper to [libBigWig](https://github.com/dpryan79/libBigWig) compatible with [pyBigWig](https://github.com/deeptools/pyBigWig).
8
10
 
9
- * Currently, curl does not seem to work well ((Pull requests welcome)).
10
- * File writing is not implemented.
11
+ - Supports both local and remote file access via HTTP/HTTPS.
12
+ - File writing is not implemented.
11
13
 
12
14
  ## Installation
13
15
 
@@ -33,13 +35,13 @@ bw.chroms("1")
33
35
 
34
36
  bw.header
35
37
  # {
36
- # :version => 4, the version number
37
- # :levels => 1, the number of zoom levels
38
- # :bases_covered => 154, the number of bases described
39
- # :min_val => 0, the minimum value
40
- # :max_val => 2, the maximum value
41
- # :sum_data => 272, the sum of all values
42
- # :sum_squared => 500 the sum of all squared values
38
+ # :version => 4, the version number
39
+ # :levels => 1, the number of zoom levels
40
+ # :bases_covered => 154, the number of bases described
41
+ # :min_val => 0, the minimum value
42
+ # :max_val => 2, the maximum value
43
+ # :sum_data => 272, the sum of all values
44
+ # :sum_squared => 500 the sum of all squared values
43
45
  # }
44
46
 
45
47
  bw.stats("1", 0, 3)
@@ -54,8 +56,8 @@ bw.stats("1", 0, 3, type: :max)
54
56
  # max - the maximum value
55
57
  # cov/coverage - the fraction of bases covered
56
58
  # std - the standard deviation of the values
57
- # dev -
58
- # sum -
59
+ # dev -
60
+ # sum -
59
61
 
60
62
  bw.stats("1",99, 200, type: :max, nbins: 2)
61
63
  # [1.399999976158142, 1.5]
@@ -84,25 +86,25 @@ require "bio/bigwig"
84
86
 
85
87
  bb = Bio::BigWig.open("test/fixtures/test.bigBed")
86
88
 
87
- bb.entries("chr1", 10000000, 10020000)
88
- # [[10009333, 10009640, "61035\t130\t-\t0.026\t0.42\t404"],
89
- # [10014007, 10014289, "61047\t136\t-\t0.029\t0.42\t404"],
90
- # [10014373, 10024307, "61048\t630\t-\t5.420\t0.00\t2672399"]]
89
+ bb.entries("chr1", 10000000, 10020000)
90
+ # [[10009333, 10009640, "61035\t130\t-\t0.026\t0.42\t404"],
91
+ # [10014007, 10014289, "61047\t136\t-\t0.029\t0.42\t404"],
92
+ # [10014373, 10024307, "61048\t630\t-\t5.420\t0.00\t2672399"]]
91
93
 
92
94
  bb = Bio::BigWig.open("test/fixtures/test.bigBed")
93
- bb.entries("chr1", 10000000, 10020000, text: false)
94
- # [[10009333, 10009640],
95
- # [10014007, 10014289],
96
- # [10014373, 10024307]]
95
+ bb.entries("chr1", 10000000, 10020000, with_string: false)
96
+ # [[10009333, 10009640],
97
+ # [10014007, 10014289],
98
+ # [10014373, 10024307]]
97
99
 
98
100
  bb.sql
99
- # table RnaElements
100
- # "BED6 + 3 scores for RNA Elements data "
101
- # (
102
- # string chrom; "Reference sequence chromosome or scaffold"
103
- # uint chromStart; "Start position in chromosome"
104
- # uint chromEnd; "End position in chromosome"
105
- # string name; "Name of item"
101
+ # table RnaElements
102
+ # "BED6 + 3 scores for RNA Elements data "
103
+ # (
104
+ # string chrom; "Reference sequence chromosome or scaffold"
105
+ # uint chromStart; "Start position in chromosome"
106
+ # uint chromEnd; "End position in chromosome"
107
+ # string name; "Name of item"
106
108
  # uint score; "Normalized score from 0-1000"
107
109
  # char[1] strand; "+ or - or . for unknown"
108
110
  # float level; "Expression level such as RPKM or FPKM. Set to -1 for no data."
@@ -102,7 +102,7 @@ static VALUE
102
102
  bigwig_init(VALUE self, VALUE rb_fname, VALUE rb_mode)
103
103
  {
104
104
  char *fname = NULL;
105
- char *mode = "r";
105
+ const char *mode = "r";
106
106
  bigWigFile_t *bw = NULL;
107
107
 
108
108
  fname = StringValueCStr(rb_fname);
@@ -207,10 +207,6 @@ bw_get_header(VALUE self)
207
207
  rb_hash_aset(rb_header, ID2SYM(rb_intern("sum_squared")), INT2NUM((int)bw->hdr->sumSquared));
208
208
 
209
209
  return rb_header;
210
-
211
- error:
212
- rb_raise(rb_eRuntimeError, "Received an error while getting the bigWig header!");
213
- return Qnil;
214
210
  }
215
211
 
216
212
  static VALUE
@@ -262,7 +258,7 @@ bw_get_chroms(int argc, VALUE *argv, VALUE self)
262
258
  return ret;
263
259
  }
264
260
 
265
- enum bwStatsType char2enum(char *s)
261
+ enum bwStatsType char2enum(const char *s)
266
262
  {
267
263
  if (strcmp(s, "mean") == 0)
268
264
  return mean;
@@ -280,7 +276,7 @@ enum bwStatsType char2enum(char *s)
280
276
  return cov;
281
277
  if (strcmp(s, "sum") == 0)
282
278
  return sum;
283
- return -1;
279
+ return doesNotExist;
284
280
  };
285
281
 
286
282
  // double *bwStats (bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type);
@@ -294,7 +290,8 @@ bw_get_stats(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE rb_
294
290
  unsigned long startl = 0, endl = -1;
295
291
  uint32_t start, end = -1, tid;
296
292
  int nBins = 1, i;
297
- char *chrom = NULL, *type = "mean";
293
+ char *chrom = NULL;
294
+ const char *type = "mean";
298
295
  VALUE ret;
299
296
 
300
297
  if (!bw)
@@ -473,7 +470,7 @@ bw_get_intervals(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end)
473
470
  uint32_t start, end = -1, tid, i;
474
471
  unsigned long startl = 0, endl = -1;
475
472
  bwOverlappingIntervals_t *intervals = NULL;
476
- char *chrom;
473
+ char *chrom = NULL;
477
474
  VALUE ret;
478
475
 
479
476
  if (!bw)
@@ -559,8 +556,8 @@ bb_get_entries(VALUE self, VALUE rb_chrom, VALUE rb_start, VALUE rb_end, VALUE r
559
556
  {
560
557
  bigWigFile_t *bw = get_bigWigFile(self);
561
558
  uint32_t start, end = -1, tid, i;
562
- unsigned long startl, endl;
563
- char *chrom;
559
+ unsigned long startl = 0, endl = -1;
560
+ char *chrom = NULL;
564
561
  VALUE ret, t;
565
562
  int withString = 1;
566
563
  bbOverlappingEntries_t *o;
@@ -744,8 +741,33 @@ bw_is_bigbed_q(VALUE self)
744
741
  return bw_is_file_type(self, 1); // 1 = BigBed
745
742
  }
746
743
 
747
- void Init_bigwigext()
744
+ static int bigwig_initialized = 0;
745
+
746
+ static void bigwig_cleanup_handler(void)
748
747
  {
748
+ if (bigwig_initialized)
749
+ {
750
+ bwCleanup();
751
+ bigwig_initialized = 0;
752
+ }
753
+ }
754
+
755
+ void Init_bigwigext(void)
756
+ {
757
+ // Initialize libBigWig only once with proper error handling
758
+ if (!bigwig_initialized)
759
+ {
760
+ if (bwInit(1 << 17) != 0)
761
+ {
762
+ rb_raise(rb_eRuntimeError, "Failed to initialize libBigWig for remote access");
763
+ return;
764
+ }
765
+ bigwig_initialized = 1;
766
+
767
+ // Register cleanup handler to be called at process exit
768
+ atexit(bigwig_cleanup_handler);
769
+ }
770
+
749
771
  rb_Bio = rb_define_module("Bio");
750
772
  rb_BigWig = rb_define_class_under(rb_Bio, "BigWig", rb_cObject);
751
773
 
@@ -56,7 +56,7 @@ extern "C" {
56
56
  /*!
57
57
  * The library version number
58
58
  */
59
- #define LIBBIGWIG_VERSION 0.4.7
59
+ #define LIBBIGWIG_VERSION 0.4.8
60
60
 
61
61
  /*!
62
62
  * If 1, then this library was compiled with remote file support.
@@ -70,7 +70,7 @@ static struct vals_t *getVals(bigWigFile_t *fp, bwOverlapBlock_t *o, int i, uint
70
70
 
71
71
  if(sz) {
72
72
  compressed = 1;
73
- buf = malloc(sz);
73
+ buf = malloc(sz);
74
74
  }
75
75
  sz = 0; //This is now the size of the compressed buffer
76
76
 
@@ -96,7 +96,7 @@ static struct vals_t *getVals(bigWigFile_t *fp, bwOverlapBlock_t *o, int i, uint
96
96
  }
97
97
 
98
98
  p = buf;
99
- while(((uLongf) ((void*)p-buf)) < sz) {
99
+ while(((uLongf) ((char*)p - (char*)buf)) < sz) {
100
100
  vtid = p[0];
101
101
  vstart = p[1];
102
102
  vend = p[2];
@@ -135,8 +135,7 @@ static bwOverlapBlock_t *overlapsLeaf(bwRTreeNode_t *node, uint32_t tid, uint32_
135
135
  if(!o) return NULL;
136
136
 
137
137
  for(i=0; i<node->nChildren; i++) {
138
- if(tid < node->chrIdxStart[i]) break;
139
- if(tid > node->chrIdxEnd[i]) continue;
138
+ if(tid < node->chrIdxStart[i] || tid > node->chrIdxEnd[i]) continue;
140
139
 
141
140
  /*
142
141
  The individual blocks can theoretically span multiple contigs.
@@ -162,7 +161,6 @@ static bwOverlapBlock_t *overlapsLeaf(bwRTreeNode_t *node, uint32_t tid, uint32_
162
161
  if(!o->size) goto error;
163
162
 
164
163
  for(i=0; i<node->nChildren; i++) {
165
- if(tid < node->chrIdxStart[i]) break;
166
164
  if(tid < node->chrIdxStart[i] || tid > node->chrIdxEnd[i]) continue;
167
165
  if(node->chrIdxStart[i] != node->chrIdxEnd[i]) {
168
166
  if(tid == node->chrIdxStart[i]) {
@@ -524,15 +522,15 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
524
522
  tmp = o->size[i]; //TODO: Is this correct? Do non-gzipped bigBeds exist?
525
523
  }
526
524
 
527
- bufEnd = buf + tmp;
525
+ bufEnd = (char*)buf + tmp;
528
526
  while(buf < bufEnd) {
529
527
  entryTid = ((uint32_t*)buf)[0];
530
528
  start = ((uint32_t*)buf)[1];
531
529
  end = ((uint32_t*)buf)[2];
532
- buf += 12;
530
+ buf = (char*)buf + 12;
533
531
  str = (char*)buf;
534
532
  slen = strlen(str) + 1;
535
- buf += slen;
533
+ buf = (char*)buf + slen;
536
534
 
537
535
  if(entryTid < tid) continue;
538
536
  if(entryTid > tid) break;
@@ -543,7 +541,7 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
543
541
  if(!pushBBIntervals(output, start, end, str, withString)) goto error;
544
542
  }
545
543
 
546
- buf = bufEnd - tmp; //reset the buffer pointer
544
+ buf = (char*)bufEnd - tmp; //reset the buffer pointer
547
545
  }
548
546
 
549
547
  if(compressed && buf) free(buf);
@@ -552,7 +550,7 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
552
550
 
553
551
  error:
554
552
  fprintf(stderr, "[bbGetOverlappingEntriesCore] Got an error\n");
555
- buf = bufEnd - tmp;
553
+ buf = (char*)bufEnd - tmp;
556
554
  if(output) bbDestroyOverlappingEntries(output);
557
555
  if(compressed && buf) free(buf);
558
556
  if(compBuf) free(compBuf);
@@ -317,12 +317,12 @@ static int flushBuffer(bigWigFile_t *fp) {
317
317
  if(!wb->ltype) return 0;
318
318
 
319
319
  //Fill in the header
320
- if(!memcpy(wb->p, &(wb->tid), sizeof(uint32_t))) return 1;
321
- if(!memcpy(wb->p+4, &(wb->start), sizeof(uint32_t))) return 2;
322
- if(!memcpy(wb->p+8, &(wb->end), sizeof(uint32_t))) return 3;
323
- if(!memcpy(wb->p+12, &(wb->step), sizeof(uint32_t))) return 4;
324
- if(!memcpy(wb->p+16, &(wb->span), sizeof(uint32_t))) return 5;
325
- if(!memcpy(wb->p+20, &(wb->ltype), sizeof(uint8_t))) return 6;
320
+ if(!memcpy((char*)wb->p, &(wb->tid), sizeof(uint32_t))) return 1;
321
+ if(!memcpy((char*)wb->p+4, &(wb->start), sizeof(uint32_t))) return 2;
322
+ if(!memcpy((char*)wb->p+8, &(wb->end), sizeof(uint32_t))) return 3;
323
+ if(!memcpy((char*)wb->p+12, &(wb->step), sizeof(uint32_t))) return 4;
324
+ if(!memcpy((char*)wb->p+16, &(wb->span), sizeof(uint32_t))) return 5;
325
+ if(!memcpy((char*)wb->p+20, &(wb->ltype), sizeof(uint8_t))) return 6;
326
326
  //1 byte padding
327
327
  //Determine the number of items
328
328
  switch(wb->ltype) {
@@ -338,7 +338,7 @@ static int flushBuffer(bigWigFile_t *fp) {
338
338
  default:
339
339
  return 7;
340
340
  }
341
- if(!memcpy(wb->p+22, &nItems, sizeof(uint16_t))) return 8;
341
+ if(!memcpy((char*)wb->p+22, &nItems, sizeof(uint16_t))) return 8;
342
342
 
343
343
  if(sz) {
344
344
  //compress
@@ -399,9 +399,9 @@ int bwAddIntervals(bigWigFile_t *fp, const char* const* chrom, const uint32_t *s
399
399
  wb->span = 0;
400
400
  wb->step = 0;
401
401
  }
402
- if(!memcpy(wb->p+wb->l, start, sizeof(uint32_t))) return 7;
403
- if(!memcpy(wb->p+wb->l+4, end, sizeof(uint32_t))) return 8;
404
- if(!memcpy(wb->p+wb->l+8, values, sizeof(float))) return 9;
402
+ if(!memcpy((char*)wb->p+wb->l, start, sizeof(uint32_t))) return 7;
403
+ if(!memcpy((char*)wb->p+wb->l+4, end, sizeof(uint32_t))) return 8;
404
+ if(!memcpy((char*)wb->p+wb->l+8, values, sizeof(float))) return 9;
405
405
  updateStats(fp, end[0]-start[0], values[0]);
406
406
  wb->l += 12;
407
407
 
@@ -420,9 +420,9 @@ int bwAddIntervals(bigWigFile_t *fp, const char* const* chrom, const uint32_t *s
420
420
  flushBuffer(fp);
421
421
  wb->start = start[i];
422
422
  }
423
- if(!memcpy(wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 11;
424
- if(!memcpy(wb->p+wb->l+4, &(end[i]), sizeof(uint32_t))) return 12;
425
- if(!memcpy(wb->p+wb->l+8, &(values[i]), sizeof(float))) return 13;
423
+ if(!memcpy((char*)wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 11;
424
+ if(!memcpy((char*)wb->p+wb->l+4, &(end[i]), sizeof(uint32_t))) return 12;
425
+ if(!memcpy((char*)wb->p+wb->l+8, &(values[i]), sizeof(float))) return 13;
426
426
  updateStats(fp, end[i]-start[i], values[i]);
427
427
  wb->l += 12;
428
428
  }
@@ -447,9 +447,9 @@ int bwAppendIntervals(bigWigFile_t *fp, const uint32_t *start, const uint32_t *e
447
447
  flushBuffer(fp);
448
448
  wb->start = start[i];
449
449
  }
450
- if(!memcpy(wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 4;
451
- if(!memcpy(wb->p+wb->l+4, &(end[i]), sizeof(uint32_t))) return 5;
452
- if(!memcpy(wb->p+wb->l+8, &(values[i]), sizeof(float))) return 6;
450
+ if(!memcpy((char*)wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 4;
451
+ if(!memcpy((char*)wb->p+wb->l+4, &(end[i]), sizeof(uint32_t))) return 5;
452
+ if(!memcpy((char*)wb->p+wb->l+8, &(values[i]), sizeof(float))) return 6;
453
453
  updateStats(fp, end[i]-start[i], values[i]);
454
454
  wb->l += 12;
455
455
  }
@@ -482,8 +482,8 @@ int bwAddIntervalSpans(bigWigFile_t *fp, const char *chrom, const uint32_t *star
482
482
  flushBuffer(fp);
483
483
  wb->start = start[i];
484
484
  }
485
- if(!memcpy(wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 5;
486
- if(!memcpy(wb->p+wb->l+4, &(values[i]), sizeof(float))) return 6;
485
+ if(!memcpy((char*)wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 5;
486
+ if(!memcpy((char*)wb->p+wb->l+4, &(values[i]), sizeof(float))) return 6;
487
487
  updateStats(fp, span, values[i]);
488
488
  wb->l += 8;
489
489
  }
@@ -506,8 +506,8 @@ int bwAppendIntervalSpans(bigWigFile_t *fp, const uint32_t *start, const float *
506
506
  flushBuffer(fp);
507
507
  wb->start = start[i];
508
508
  }
509
- if(!memcpy(wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 4;
510
- if(!memcpy(wb->p+wb->l+4, &(values[i]), sizeof(float))) return 5;
509
+ if(!memcpy((char*)wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 4;
510
+ if(!memcpy((char*)wb->p+wb->l+4, &(values[i]), sizeof(float))) return 5;
511
511
  updateStats(fp, wb->span, values[i]);
512
512
  wb->l += 8;
513
513
  }
@@ -540,7 +540,7 @@ int bwAddIntervalSpanSteps(bigWigFile_t *fp, const char *chrom, uint32_t start,
540
540
  flushBuffer(fp);
541
541
  wb->start = wb->end;
542
542
  }
543
- if(!memcpy(wb->p+wb->l, &(values[i]), sizeof(float))) return 5;
543
+ if(!memcpy((char*)wb->p+wb->l, &(values[i]), sizeof(float))) return 5;
544
544
  updateStats(fp, wb->span, values[i]);
545
545
  wb->l += 4;
546
546
  }
@@ -563,7 +563,7 @@ int bwAppendIntervalSpanSteps(bigWigFile_t *fp, const float *values, uint32_t n)
563
563
  flushBuffer(fp);
564
564
  wb->start = wb->end;
565
565
  }
566
- if(!memcpy(wb->p+wb->l, &(values[i]), sizeof(float))) return 4;
566
+ if(!memcpy((char*)wb->p+wb->l, &(values[i]), sizeof(float))) return 4;
567
567
  updateStats(fp, wb->span, values[i]);
568
568
  wb->l += 4;
569
569
  }
@@ -754,7 +754,7 @@ int writeIndex(bigWigFile_t *fp) {
754
754
  }
755
755
  if(!root) return 4;
756
756
  fp->idx->root = root;
757
-
757
+
758
758
  ll = fp->writeBuffer->firstIndexNode;
759
759
  while(ll) {
760
760
  p = ll->next;
@@ -994,8 +994,8 @@ int addIntervalValue(bigWigFile_t *fp, uint64_t *nEntries, double *sum, double *
994
994
  newBuffer->p = calloc(itemsPerSlot, 32);
995
995
  if(!newBuffer->p) goto error;
996
996
  newBuffer->m = itemsPerSlot*32;
997
- memcpy(newBuffer->p, buffer->p+buffer->l-32, 4);
998
- memcpy(newBuffer->p+4, buffer->p+buffer->l-28, 4);
997
+ memcpy(newBuffer->p, (unsigned char*)buffer->p+buffer->l-32, 4);
998
+ memcpy((unsigned char*)newBuffer->p+4, (unsigned char*)buffer->p + buffer->l-28, 4);
999
999
  ((uint32_t*) newBuffer->p)[2] = ((uint32_t*) newBuffer->p)[1] + zoom;
1000
1000
  *sum = *sumsq = 0.0;
1001
1001
  rv = updateInterval(fp, newBuffer, sum, sumsq, zoom, tid, start, end, value);
@@ -1122,7 +1122,7 @@ int writeZoomLevels(bigWigFile_t *fp) {
1122
1122
  while(ll) {
1123
1123
  p = ll->next;
1124
1124
  free(ll);
1125
- ll=p;
1125
+ ll=p;
1126
1126
  }
1127
1127
 
1128
1128
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bio
4
4
  class BigWig
5
- VERSION = "0.0.6"
5
+ VERSION = "0.1.0"
6
6
  end
7
7
  end
data/lib/bio/bigwig.rb CHANGED
@@ -4,7 +4,25 @@ require_relative "bigwig/version"
4
4
  require_relative "bigwig/bigwigext"
5
5
 
6
6
  module Bio
7
+ # BigWig/BigBed file reader for Ruby
8
+ #
9
+ # @example Reading a local BigWig file
10
+ # Bio::BigWig.open("file.bw") do |bw|
11
+ # puts bw.header
12
+ # puts bw.chroms
13
+ # end
14
+ #
15
+ # @example Reading a remote BigWig file
16
+ # Bio::BigWig.open("https://example.com/file.bw") do |bw|
17
+ # values = bw.values("chr1", 0, 1000)
18
+ # end
7
19
  class BigWig
20
+ # Open a BigWig/BigBed file
21
+ #
22
+ # @param args [Array] file path or URL
23
+ # @param kwargs [Hash] options
24
+ # @return [BigWig] file handle
25
+ # @yield [BigWig] file handle for block usage
8
26
  def self.open(*args, **kwargs)
9
27
  file = new(*args, **kwargs)
10
28
  return file unless block_given?
@@ -17,6 +35,10 @@ module Bio
17
35
  file
18
36
  end
19
37
 
38
+ # Initialize a BigWig/BigBed file handle
39
+ #
40
+ # @param fname [String] file path or URL
41
+ # @param mode [String] file mode (default: "r")
20
42
  def initialize(fname, mode = "r")
21
43
  raise "BigWig::new() does not take block; use BigWig::open() instead" if block_given?
22
44
 
@@ -24,24 +46,88 @@ module Bio
24
46
  initialize_raw(fname, mode)
25
47
  end
26
48
 
49
+ # Get the file path
50
+ #
51
+ # @return [String] file path or URL
27
52
  def path
28
53
  @fname
29
54
  end
30
55
 
56
+ # Get statistics for a genomic region
57
+ #
58
+ # @param chrom [String] chromosome name
59
+ # @param start [Integer, nil] start position (0-based)
60
+ # @param stop [Integer, nil] stop position (0-based)
61
+ # @param nbins [Integer, nil] number of bins
62
+ # @param type [String, Symbol, nil] statistic type ("mean", "max", "min", "sum", "coverage", "std")
63
+ # @param exact [Boolean, nil] use exact calculation
64
+ # @return [Array<Float>] statistics values
31
65
  def stats(chrom, start = nil, stop = nil, nbins: nil, type: nil, exact: nil)
32
66
  stats_raw(chrom, start, stop, nbins, type&.to_s, exact)
33
67
  end
34
68
 
69
+ # Get values for a genomic region
70
+ #
71
+ # @param chrom [String] chromosome name
72
+ # @param start [Integer] start position (0-based)
73
+ # @param stop [Integer] stop position (0-based)
74
+ # @return [Array<Float>] values
35
75
  def values(chrom, start, stop)
36
76
  values_raw(chrom, start, stop)
37
77
  end
38
78
 
79
+ # Get intervals for a genomic region
80
+ #
81
+ # @param chrom [String] chromosome name
82
+ # @param start [Integer] start position (0-based, default: 0)
83
+ # @param stop [Integer] stop position (0-based, default: -1 for end of chromosome)
84
+ # @return [Array<Array>] intervals as [start, end, value]
39
85
  def intervals(chrom, start = 0, stop = -1)
40
86
  intervals_raw(chrom, start, stop)
41
87
  end
42
88
 
89
+ # Get entries for a genomic region (BigBed files only)
90
+ #
91
+ # @param chrom [String] chromosome name
92
+ # @param start [Integer] start position (0-based, default: 0)
93
+ # @param stop [Integer] stop position (0-based, default: -1 for end of chromosome)
94
+ # @param with_string [Boolean] include string data (default: true)
95
+ # @return [Array<Array>] entries as [start, end, string] or [start, end]
43
96
  def entries(chrom, start = 0, stop = -1, with_string: true)
44
97
  entries_raw(chrom, start, stop, with_string)
45
98
  end
99
+
100
+ # @!method close
101
+ # Close the file handle
102
+ # @return [nil]
103
+
104
+ # @!method closed?
105
+ # Check if the file is closed
106
+ # @return [Boolean] true if closed, false if open
107
+
108
+ # @!method chroms(chrom = nil)
109
+ # Get chromosome information
110
+ # @param chrom [String, nil] specific chromosome name (optional)
111
+ # @return [Hash, Integer, nil] all chromosomes as Hash, or length of specific chromosome, or nil if not found
112
+
113
+ # @!method header
114
+ # Get file header information
115
+ # @return [Hash] header information including version, levels, bases_covered, min_val, max_val, sum_data, sum_squared
116
+
117
+ # @!method file_type
118
+ # Get file type
119
+ # @return [String] "BigWig" or "BigBed"
120
+
121
+ # @!method is_bigwig?
122
+ # Check if file is BigWig format
123
+ # @return [Boolean] true if BigWig, false otherwise
124
+
125
+ # @!method is_bigbed?
126
+ # Check if file is BigBed format
127
+ # @return [Boolean] true if BigBed, false otherwise
128
+
129
+ # @!method sql
130
+ # Get SQL schema (BigBed files only)
131
+ # @return [String, nil] SQL schema string, or nil if not available
46
132
  end
47
133
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-bigwig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-09-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: This is a Ruby binding for libBigWig (https://github.com/dpryan79/libBigWig),
14
13
  which provides high-speed access to bigWig or bigBed files.
@@ -40,7 +39,6 @@ homepage: https://github.com/kojix2/bio-bigwig
40
39
  licenses:
41
40
  - MIT
42
41
  metadata: {}
43
- post_install_message:
44
42
  rdoc_options: []
45
43
  require_paths:
46
44
  - lib
@@ -55,8 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
53
  - !ruby/object:Gem::Version
56
54
  version: '0'
57
55
  requirements: []
58
- rubygems_version: 3.4.19
59
- signing_key:
56
+ rubygems_version: 3.6.9
60
57
  specification_version: 4
61
58
  summary: A ruby library for accessing bigWig / bigBed files
62
59
  test_files: []