bio-bigwig 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16a4f8614b5681336c4cb6f2e94318e70b1319b67ac30a01e4f60e36b66646cb
4
- data.tar.gz: 1bdc56ff64d8a4c96e2a6be92375b432562476f456b7c3541c1a3f932603f77d
3
+ metadata.gz: '0585eab5aa345929c023943bafc6e27955be406f79379f056a9c45ec5d0b1933'
4
+ data.tar.gz: 7ffd6b9bcce8e12382fad0fcfe26914f69da45a3db66b022c82007e9820abd9f
5
5
  SHA512:
6
- metadata.gz: 3aafa8e3e0c69abdf2f07152997fc4b8162e05e9e0a10521a0780c3ce2cb237e4bc84367d771d7394f74568faa5f5ef542a19cb2cc2b0bc2a28a2d1125b8a1c7
7
- data.tar.gz: d639dab381fd5613c527dc6b7c0abd4d66c89f0df36fce15903b827e7e22ceba4d86c391f9197577082b9ab44534341569020149eaebfd9c345bb9ad5768cf63
6
+ metadata.gz: 776424b2382940cc1b31242d527b3e468bc5abbfa7a98009fb662389cc79cd2693e49d365423263435db06ab09811d66e5634ca8c07b546ebd46ef1bfb243141
7
+ data.tar.gz: d245494b5f68359d66fdb80250ab1de08dd9fc21db17f28436e90997b94ca6a5c90f72e9048bcbcf0a4906a274a2785074e57b896def130ab6ebccaa62943881
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # bio-bigwig
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/bio-bigwig?color=brightgreen)](https://rubygems.org/gems/bio-bigwig)
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
+ [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://rubydoc.info/gems/bio-bigwig)
6
+
3
7
  Ruby wrapper to [libBigWig](https://github.com/dpryan79/libBigWig) compatible with [pyBigWig](https://github.com/deeptools/pyBigWig).
4
8
 
5
9
  * Currently, curl does not seem to work well ((Pull requests welcome)).
@@ -7,18 +11,6 @@ Ruby wrapper to [libBigWig](https://github.com/dpryan79/libBigWig) compatible wi
7
11
 
8
12
  ## Installation
9
13
 
10
- Installation from source.
11
-
12
- ```
13
- git clone --recursive https://github.com/kojix2/bio-bigwig
14
- cd bio-bigwig
15
- bundle install
16
- bundle exec rake compile
17
- bundle exec rake install
18
- ```
19
-
20
- Not yet uploaded to the Gem server.
21
-
22
14
  ```
23
15
  gem install bio-bigwig
24
16
  ```
@@ -119,12 +111,17 @@ bb.sql
119
111
  # )
120
112
  ```
121
113
 
114
+ ## Contributing
115
+
116
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/kojix2/bio-bigwig>.
117
+
122
118
  ## Development
123
119
 
124
120
  Pull requests are welcome!
125
- ## Contributing
126
121
 
127
- Bug reports and pull requests are welcome on GitHub at https://github.com/kojix2/bio-bigwig.
122
+ Do you need commit rights to my repository?
123
+ Do you want to get admin rights and take over the project?
124
+ If so, please feel free to contact us @kojix2.
128
125
 
129
126
  ## License
130
127
 
@@ -32,7 +32,7 @@
32
32
  #define NUM2INT64 NUM2LONG
33
33
  #define UINT64_2NUM ULONG2NUM
34
34
  #define INT64_2NUM LONG2NUM
35
- #elif SIZEOF_LONGLONG == SIZEOF_INT64
35
+ #elif SIZEOF_LONG_LONG == SIZEOF_INT64
36
36
  #define NUM2UINT64 NUM2ULL
37
37
  #define NUM2INT64 NUM2LL
38
38
  #define UINT64_2NUM ULL2NUM
@@ -1,30 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "mkmf"
4
2
 
5
- # https://github.com/taf2/curb/blob/master/ext/extconf.rb
6
- dir_config("curl")
7
- if find_executable("curl-config")
8
- $CFLAGS << " #{`curl-config --cflags`.strip} -g"
9
- $LIBS << if ENV["STATIC_BUILD"]
10
- " #{`curl-config --static-libs`.strip}"
11
- else
12
- " #{`curl-config --libs`.strip}"
13
- end
14
- ca_bundle_path = `curl-config --ca`.strip
15
- if !ca_bundle_path.nil? && (ca_bundle_path != "")
16
- $defs.push(%(-D HAVE_CURL_CONFIG_CA))
17
- $defs.push(%(-D CURL_CONFIG_CA='#{ca_bundle_path.inspect}'))
18
- end
19
- end
3
+ # check curl
4
+ have_library("curl", "curl_easy_init")
5
+ have_header("libbigwig/bigWig.h")
20
6
 
21
- # dir_config("libbigwig")
22
- # unless find_header("bigWig.h") && have_library("bigwig")
23
- $INCFLAGS << " -I$(srcdir)/libBigWig"
24
- $VPATH << "$(srcdir)/libBigWig"
25
- $srcs = Dir.glob(["{.,libBigWig}/*.c"], base: __dir__)
26
- .map { |f| File.expand_path(f, __dir__) }
27
- $objs = $srcs.map { |f| f.sub(/\.c$/, ".o") }
28
- # end
7
+ $srcs = Dir.glob("libBigWig/*.c", base: __dir__)
8
+ .map { |src| File.expand_path(src, __dir__) }
9
+ .unshift(File.expand_path("bigwigext.c", __dir__))
10
+ $objs = $srcs.map { |src| src.gsub(/\.c\z/, ".o") }
29
11
 
30
12
  create_makefile("bio/bigwig/bigwigext")
@@ -56,7 +56,7 @@ extern "C" {
56
56
  /*!
57
57
  * The library version number
58
58
  */
59
- #define LIBBIGWIG_VERSION 0.4.6
59
+ #define LIBBIGWIG_VERSION 0.4.7
60
60
 
61
61
  /*!
62
62
  * If 1, then this library was compiled with remote file support.
@@ -279,7 +279,7 @@ void bwCleanup(void);
279
279
  * @param callBack An optional user-supplied function. This is applied to remote connections so users can specify things like proxy and password information. See `test/testRemote` for an example.
280
280
  * @return 1 if the file appears to be bigWig, otherwise 0.
281
281
  */
282
- int bwIsBigWig(char *fname, CURLcode (*callBack)(CURL*));
282
+ int bwIsBigWig(const char *fname, CURLcode (*callBack)(CURL*));
283
283
 
284
284
  /*!
285
285
  * @brief Determine is a file is a bigBed file.
@@ -288,7 +288,7 @@ int bwIsBigWig(char *fname, CURLcode (*callBack)(CURL*));
288
288
  * @param callBack An optional user-supplied function. This is applied to remote connections so users can specify things like proxy and password information. See `test/testRemote` for an example.
289
289
  * @return 1 if the file appears to be bigWig, otherwise 0.
290
290
  */
291
- int bbIsBigBed(char *fname, CURLcode (*callBack)(CURL*));
291
+ int bbIsBigBed(const char *fname, CURLcode (*callBack)(CURL*));
292
292
 
293
293
  /*!
294
294
  * @brief Opens a local or remote bigWig file.
@@ -298,7 +298,7 @@ int bbIsBigBed(char *fname, CURLcode (*callBack)(CURL*));
298
298
  * @param mode The mode, by default "r". Both local and remote files can be read, but only local files can be written. For files being written the callback function is ignored. If and only if the mode contains "w" will the file be opened for writing (in all other cases the file will be opened for reading.
299
299
  * @return A bigWigFile_t * on success and NULL on error.
300
300
  */
301
- bigWigFile_t *bwOpen(char *fname, CURLcode (*callBack)(CURL*), const char* mode);
301
+ bigWigFile_t *bwOpen(const char *fname, CURLcode (*callBack)(CURL*), const char* mode);
302
302
 
303
303
  /*!
304
304
  * @brief Opens a local or remote bigBed file.
@@ -307,7 +307,7 @@ bigWigFile_t *bwOpen(char *fname, CURLcode (*callBack)(CURL*), const char* mode)
307
307
  * @param callBack An optional user-supplied function. This is applied to remote connections so users can specify things like proxy and password information. See `test/testRemote` for an example.
308
308
  * @return A bigWigFile_t * on success and NULL on error.
309
309
  */
310
- bigWigFile_t *bbOpen(char *fname, CURLcode (*callBack)(CURL*));
310
+ bigWigFile_t *bbOpen(const char *fname, CURLcode (*callBack)(CURL*));
311
311
 
312
312
  /*!
313
313
  * @brief Returns a string containing the SQL entry (or NULL).
@@ -339,7 +339,7 @@ void bwClose(bigWigFile_t *fp);
339
339
  * @param chrom A chromosome name
340
340
  * @return An ID, -1 will be returned on error (note that this is an unsigned value, so that's ~4 billion. bigWig/bigBed files can't store that many chromosomes anyway.
341
341
  */
342
- uint32_t bwGetTid(bigWigFile_t *fp, char *chrom);
342
+ uint32_t bwGetTid(const bigWigFile_t *fp, const char *chrom);
343
343
 
344
344
  /*!
345
345
  * @brief Frees space allocated by `bwGetOverlappingIntervals`
@@ -367,7 +367,7 @@ void bbDestroyOverlappingEntries(bbOverlappingEntries_t *o);
367
367
  * @see bwDestroyOverlappingIntervals
368
368
  * @see bwGetValues
369
369
  */
370
- bwOverlappingIntervals_t *bwGetOverlappingIntervals(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end);
370
+ bwOverlappingIntervals_t *bwGetOverlappingIntervals(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end);
371
371
 
372
372
  /*!
373
373
  * @brief Return bigBed entries overlapping an interval.
@@ -381,7 +381,7 @@ bwOverlappingIntervals_t *bwGetOverlappingIntervals(bigWigFile_t *fp, char *chro
381
381
  * @see bbOverlappingEntries_t
382
382
  * @see bbDestroyOverlappingEntries
383
383
  */
384
- bbOverlappingEntries_t *bbGetOverlappingEntries(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, int withString);
384
+ bbOverlappingEntries_t *bbGetOverlappingEntries(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int withString);
385
385
 
386
386
  /*!
387
387
  * @brief Creates an iterator over intervals in a bigWig file
@@ -397,7 +397,7 @@ bbOverlappingEntries_t *bbGetOverlappingEntries(bigWigFile_t *fp, char *chrom, u
397
397
  * @see bwIteratorNext
398
398
  * @see bwIteratorDestroy
399
399
  */
400
- bwOverlapIterator_t *bwOverlappingIntervalsIterator(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uint32_t blocksPerIteration);
400
+ bwOverlapIterator_t *bwOverlappingIntervalsIterator(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t blocksPerIteration);
401
401
 
402
402
  /*!
403
403
  * @brief Creates an iterator over entries in a bigBed file
@@ -415,7 +415,7 @@ bwOverlapIterator_t *bwOverlappingIntervalsIterator(bigWigFile_t *fp, char *chro
415
415
  * @see bwIteratorNext
416
416
  * @see bwIteratorDestroy
417
417
  */
418
- bwOverlapIterator_t *bbOverlappingEntriesIterator(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, int withString, uint32_t blocksPerIteration);
418
+ bwOverlapIterator_t *bbOverlappingEntriesIterator(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int withString, uint32_t blocksPerIteration);
419
419
 
420
420
  /*!
421
421
  * @brief Traverses to the entries/intervals in the next group of blocks.
@@ -445,7 +445,7 @@ void bwIteratorDestroy(bwOverlapIterator_t *iter);
445
445
  * @see bwDestroyOverlappingIntervals
446
446
  * @see bwGetOverlappingIntervals
447
447
  */
448
- bwOverlappingIntervals_t *bwGetValues(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, int includeNA);
448
+ bwOverlappingIntervals_t *bwGetValues(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int includeNA);
449
449
 
450
450
  /*!
451
451
  * @brief Determines per-interval bigWig statistics
@@ -459,7 +459,7 @@ bwOverlappingIntervals_t *bwGetValues(bigWigFile_t *fp, char *chrom, uint32_t st
459
459
  * @see bwStatsType
460
460
  * @return A pointer to an array of double precission floating point values. Note that bigWig files only hold 32-bit values, so this is done to help prevent overflows.
461
461
  */
462
- double *bwStats(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type);
462
+ double *bwStats(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type);
463
463
 
464
464
  /*!
465
465
  * @brief Determines per-interval bigWig statistics
@@ -473,7 +473,7 @@ double *bwStats(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uin
473
473
  * @see bwStatsType
474
474
  * @return A pointer to an array of double precission floating point values. Note that bigWig files only hold 32-bit values, so this is done to help prevent overflows.
475
475
  */
476
- double *bwStatsFromFull(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type);
476
+ double *bwStatsFromFull(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type);
477
477
 
478
478
  //Writer functions
479
479
 
@@ -494,7 +494,7 @@ int bwCreateHdr(bigWigFile_t *fp, int32_t maxZooms);
494
494
  * @param n The number of chromosomes (thus, the length of `chroms` and `lengths`)
495
495
  * @return A pointer to a chromList_t or NULL on error.
496
496
  */
497
- chromList_t *bwCreateChromList(char **chroms, uint32_t *lengths, int64_t n);
497
+ chromList_t *bwCreateChromList(const char* const* chroms, const uint32_t *lengths, int64_t n);
498
498
 
499
499
  /*!
500
500
  * @brief Write a the header to a bigWig file.
@@ -521,7 +521,7 @@ int bwWriteHdr(bigWigFile_t *bw);
521
521
  * @return 0 on success and another value on error.
522
522
  * @see bwAppendIntervals
523
523
  */
524
- int bwAddIntervals(bigWigFile_t *fp, char **chrom, uint32_t *start, uint32_t *end, float *values, uint32_t n);
524
+ int bwAddIntervals(bigWigFile_t *fp, const char* const* chrom, const uint32_t *start, const uint32_t *end, const float *values, uint32_t n);
525
525
 
526
526
  /*!
527
527
  * @brief Append bedGraph-like intervals to a previous block of bedGraph-like intervals in a bigWig file.
@@ -535,7 +535,7 @@ int bwAddIntervals(bigWigFile_t *fp, char **chrom, uint32_t *start, uint32_t *en
535
535
  * @warning Do NOT use this after `bwAddIntervalSpanSteps()`, `bwAppendIntervalSpanSteps()`, `bwAddIntervalSpanSteps()`, or `bwAppendIntervalSpanSteps()`.
536
536
  * @see bwAddIntervals
537
537
  */
538
- int bwAppendIntervals(bigWigFile_t *fp, uint32_t *start, uint32_t *end, float *values, uint32_t n);
538
+ int bwAppendIntervals(bigWigFile_t *fp, const uint32_t *start, const uint32_t *end, const float *values, uint32_t n);
539
539
 
540
540
  /*!
541
541
  * @brief Add a new block of variable-step entries to a bigWig file
@@ -553,7 +553,7 @@ int bwAppendIntervals(bigWigFile_t *fp, uint32_t *start, uint32_t *end, float *v
553
553
  * @return 0 on success and another value on error.
554
554
  * @see bwAppendIntervalSpans
555
555
  */
556
- int bwAddIntervalSpans(bigWigFile_t *fp, char *chrom, uint32_t *start, uint32_t span, float *values, uint32_t n);
556
+ int bwAddIntervalSpans(bigWigFile_t *fp, const char *chrom, const uint32_t *start, uint32_t span, const float *values, uint32_t n);
557
557
 
558
558
  /*!
559
559
  * @brief Append to a previous block of variable-step entries.
@@ -566,7 +566,7 @@ int bwAddIntervalSpans(bigWigFile_t *fp, char *chrom, uint32_t *start, uint32_t
566
566
  * @warning Do NOT use this after `bwAddIntervals()`, `bwAppendIntervals()`, `bwAddIntervalSpanSteps()` or `bwAppendIntervalSpanSteps()`
567
567
  * @see bwAddIntervalSpans
568
568
  */
569
- int bwAppendIntervalSpans(bigWigFile_t *fp, uint32_t *start, float *values, uint32_t n);
569
+ int bwAppendIntervalSpans(bigWigFile_t *fp, const uint32_t *start, const float *values, uint32_t n);
570
570
 
571
571
  /*!
572
572
  * @brief Add a new block of fixed-step entries to a bigWig file
@@ -585,7 +585,7 @@ int bwAppendIntervalSpans(bigWigFile_t *fp, uint32_t *start, float *values, uint
585
585
  * @return 0 on success and another value on error.
586
586
  * @see bwAddIntervalSpanSteps
587
587
  */
588
- int bwAddIntervalSpanSteps(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t span, uint32_t step, float *values, uint32_t n);
588
+ int bwAddIntervalSpanSteps(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t span, uint32_t step, const float *values, uint32_t n);
589
589
 
590
590
  /*!
591
591
  * @brief Append to a previous block of fixed-step entries.
@@ -597,7 +597,7 @@ int bwAddIntervalSpanSteps(bigWigFile_t *fp, char *chrom, uint32_t start, uint32
597
597
  * @warning Do NOT use this after `bwAddIntervals()`, `bwAppendIntervals()`, `bwAddIntervalSpans()` or `bwAppendIntervalSpans()`
598
598
  * @see bwAddIntervalSpanSteps
599
599
  */
600
- int bwAppendIntervalSpanSteps(bigWigFile_t *fp, float *values, uint32_t n);
600
+ int bwAppendIntervalSpanSteps(bigWigFile_t *fp, const float *values, uint32_t n);
601
601
 
602
602
  #ifdef __cplusplus
603
603
  }
@@ -49,7 +49,7 @@ typedef struct {
49
49
  size_t bufLen; /**<The actual size of the buffer used.*/
50
50
  enum bigWigFile_type_enum type; /**<The connection type*/
51
51
  int isCompressed; /**<1 if the file is compressed, otherwise 0*/
52
- char *fname; /**<Only needed for remote connections. The original URL/filename requested, since we need to make multiple connections.*/
52
+ const char *fname; /**<Only needed for remote connections. The original URL/filename requested, since we need to make multiple connections.*/
53
53
  } URL_t;
54
54
 
55
55
  /*!
@@ -94,7 +94,7 @@ CURLcode urlSeek(URL_t *URL, size_t pos);
94
94
  *
95
95
  * @return A URL_t * or NULL on error.
96
96
  */
97
- URL_t *urlOpen(char *fname, CURLcode (*callBack)(CURL*), const char* mode);
97
+ URL_t *urlOpen(const char *fname, CURLcode (*callBack)(CURL*), const char* mode);
98
98
 
99
99
  /*!
100
100
  * @brief Close a local/remote file
@@ -68,3 +68,7 @@ void destroyBWOverlapBlock(bwOverlapBlock_t *b);
68
68
  * @return 0 on success
69
69
  */
70
70
  int bwFinalize(bigWigFile_t *fp);
71
+
72
+ /// @cond SKIP
73
+ char *bwStrdup(const char *s);
74
+ /// @endcond
@@ -194,7 +194,7 @@ static uint64_t readChromLeaf(bigWigFile_t *bw, chromList_t *cl, uint32_t valueS
194
194
  if(bwRead((void*) chrom, sizeof(char), valueSize, bw) != valueSize) goto error;
195
195
  if(bwRead((void*) &idx, sizeof(uint32_t), 1, bw) != 1) goto error;
196
196
  if(bwRead((void*) &(cl->len[idx]), sizeof(uint32_t), 1, bw) != 1) goto error;
197
- cl->chrom[idx] = strdup(chrom);
197
+ cl->chrom[idx] = bwStrdup(chrom);
198
198
  if(!(cl->chrom[idx])) goto error;
199
199
  }
200
200
 
@@ -299,7 +299,7 @@ void bwClose(bigWigFile_t *fp) {
299
299
  free(fp);
300
300
  }
301
301
 
302
- int bwIsBigWig(char *fname, CURLcode (*callBack) (CURL*)) {
302
+ int bwIsBigWig(const char *fname, CURLcode (*callBack) (CURL*)) {
303
303
  uint32_t magic = 0;
304
304
  URL_t *URL = NULL;
305
305
 
@@ -312,15 +312,15 @@ int bwIsBigWig(char *fname, CURLcode (*callBack) (CURL*)) {
312
312
  return 0;
313
313
  }
314
314
 
315
- char *bbGetSQL(bigWigFile_t *bw) {
315
+ char *bbGetSQL(bigWigFile_t *fp) {
316
316
  char *o = NULL;
317
317
  uint64_t len;
318
- if(!bw->hdr->sqlOffset) return NULL;
319
- len = bw->hdr->summaryOffset - bw->hdr->sqlOffset; //This includes the NULL terminator
318
+ if(!fp->hdr->sqlOffset) return NULL;
319
+ len = fp->hdr->summaryOffset - fp->hdr->sqlOffset; //This includes the NULL terminator
320
320
  o = malloc(sizeof(char) * len);
321
321
  if(!o) goto error;
322
- if(bwSetPos(bw, bw->hdr->sqlOffset)) goto error;
323
- if(bwRead((void*) o, len, 1, bw) != 1) goto error;
322
+ if(bwSetPos(fp, fp->hdr->sqlOffset)) goto error;
323
+ if(bwRead((void*) o, len, 1, fp) != 1) goto error;
324
324
  return o;
325
325
 
326
326
  error:
@@ -329,7 +329,7 @@ error:
329
329
  return NULL;
330
330
  }
331
331
 
332
- int bbIsBigBed(char *fname, CURLcode (*callBack) (CURL*)) {
332
+ int bbIsBigBed(const char *fname, CURLcode (*callBack) (CURL*)) {
333
333
  uint32_t magic = 0;
334
334
  URL_t *URL = NULL;
335
335
 
@@ -342,7 +342,7 @@ int bbIsBigBed(char *fname, CURLcode (*callBack) (CURL*)) {
342
342
  return 0;
343
343
  }
344
344
 
345
- bigWigFile_t *bwOpen(char *fname, CURLcode (*callBack) (CURL*), const char *mode) {
345
+ bigWigFile_t *bwOpen(const char *fname, CURLcode (*callBack) (CURL*), const char *mode) {
346
346
  bigWigFile_t *bwg = calloc(1, sizeof(bigWigFile_t));
347
347
  if(!bwg) {
348
348
  fprintf(stderr, "[bwOpen] Couldn't allocate space to create the output object!\n");
@@ -394,7 +394,7 @@ error:
394
394
  return NULL;
395
395
  }
396
396
 
397
- bigWigFile_t *bbOpen(char *fname, CURLcode (*callBack) (CURL*)) {
397
+ bigWigFile_t *bbOpen(const char *fname, CURLcode (*callBack) (CURL*)) {
398
398
  bigWigFile_t *bb = calloc(1, sizeof(bigWigFile_t));
399
399
  if(!bb) {
400
400
  fprintf(stderr, "[bbOpen] Couldn't allocate space to create the output object!\n");
@@ -425,3 +425,14 @@ error:
425
425
  bwClose(bb);
426
426
  return NULL;
427
427
  }
428
+
429
+
430
+ //Implementation taken from musl:
431
+ //https://git.musl-libc.org/cgit/musl/tree/src/string/strdup.c
432
+ //License: https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
433
+ char* bwStrdup(const char *s) {
434
+ size_t l = strlen(s);
435
+ char *d = malloc(l+1);
436
+ if (!d) return NULL;
437
+ return memcpy(d, s, l+1);
438
+ }
@@ -8,7 +8,7 @@
8
8
 
9
9
  //Returns -1 if there are no applicable levels, otherwise an integer indicating the most appropriate level.
10
10
  //Like Kent's library, this divides the desired bin size by 2 to minimize the effect of blocks overlapping multiple bins
11
- static int32_t determineZoomLevel(bigWigFile_t *fp, int basesPerBin) {
11
+ static int32_t determineZoomLevel(const bigWigFile_t *fp, int basesPerBin) {
12
12
  int32_t out = -1;
13
13
  int64_t diff;
14
14
  uint32_t bestDiff = -1;
@@ -420,7 +420,7 @@ static double intSum(bwOverlappingIntervals_t* ints, uint32_t start, uint32_t en
420
420
  }
421
421
 
422
422
  //Returns NULL on error, otherwise a double* that needs to be free()d
423
- double *bwStatsFromZoom(bigWigFile_t *fp, int32_t level, uint32_t tid, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type) {
423
+ static double *bwStatsFromZoom(bigWigFile_t *fp, int32_t level, uint32_t tid, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type) {
424
424
  bwOverlapBlock_t *blocks = NULL;
425
425
  double *output = NULL;
426
426
  uint32_t pos = start, i, end2;
@@ -482,7 +482,7 @@ error:
482
482
  return NULL;
483
483
  }
484
484
 
485
- double *bwStatsFromFull(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type) {
485
+ double *bwStatsFromFull(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type) {
486
486
  bwOverlappingIntervals_t *ints = NULL;
487
487
  double *output = malloc(sizeof(double)*nBins);
488
488
  uint32_t i, pos = start, end2;
@@ -527,7 +527,7 @@ double *bwStatsFromFull(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t
527
527
 
528
528
  //Returns a list of floats of length nBins that must be free()d
529
529
  //On error, NULL is returned
530
- double *bwStats(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type) {
530
+ double *bwStats(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t nBins, enum bwStatsType type) {
531
531
  int32_t level = determineZoomLevel(fp, ((double)(end-start))/((int) nBins));
532
532
  uint32_t tid = bwGetTid(fp, chrom);
533
533
  if(tid == (uint32_t) -1) return NULL;
@@ -140,7 +140,7 @@ static bwOverlapBlock_t *overlapsLeaf(bwRTreeNode_t *node, uint32_t tid, uint32_
140
140
 
141
141
  /*
142
142
  The individual blocks can theoretically span multiple contigs.
143
- So if we treat the first/last contig in the range as special
143
+ So if we treat the first/last contig in the range as special
144
144
  but anything in the middle is a guaranteed match
145
145
  */
146
146
  if(node->chrIdxStart[i] != node->chrIdxEnd[i]) {
@@ -281,7 +281,7 @@ bwOverlapBlock_t *walkRTreeNodes(bigWigFile_t *bw, bwRTreeNode_t *root, uint32_t
281
281
 
282
282
  //In reality, a hash or some sort of tree structure is probably faster...
283
283
  //Return -1 (AKA 0xFFFFFFFF...) on "not there", so we can hold (2^32)-1 items.
284
- uint32_t bwGetTid(bigWigFile_t *fp, char *chrom) {
284
+ uint32_t bwGetTid(const bigWigFile_t *fp, const char *chrom) {
285
285
  uint32_t i;
286
286
  if(!chrom) return -1;
287
287
  for(i=0; i<fp->cl->nKeys; i++) {
@@ -290,7 +290,7 @@ uint32_t bwGetTid(bigWigFile_t *fp, char *chrom) {
290
290
  return -1;
291
291
  }
292
292
 
293
- static bwOverlapBlock_t *bwGetOverlappingBlocks(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end) {
293
+ static bwOverlapBlock_t *bwGetOverlappingBlocks(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end) {
294
294
  uint32_t tid = bwGetTid(fp, chrom);
295
295
 
296
296
  if(tid == (uint32_t) -1) {
@@ -379,7 +379,7 @@ static bbOverlappingEntries_t *pushBBIntervals(bbOverlappingEntries_t *o, uint32
379
379
  }
380
380
  o->start[o->l] = start;
381
381
  o->end[o->l] = end;
382
- if(withString) o->str[o->l] = strdup(str);
382
+ if(withString) o->str[o->l] = bwStrdup(str);
383
383
  o->l++;
384
384
  return o;
385
385
 
@@ -437,7 +437,7 @@ bwOverlappingIntervals_t *bwGetOverlappingIntervalsCore(bigWigFile_t *fp, bwOver
437
437
  if(hdr.tid != tid) continue;
438
438
 
439
439
  if(hdr.type == 3) start = hdr.start - hdr.step;
440
-
440
+
441
441
  //FIXME: We should ensure that sz is large enough to hold nItems of the given type
442
442
  for(j=0; j<hdr.nItems; j++) {
443
443
  switch(hdr.type) {
@@ -560,7 +560,7 @@ error:
560
560
  }
561
561
 
562
562
  //Returns NULL on error OR no intervals, which is a bad design...
563
- bwOverlappingIntervals_t *bwGetOverlappingIntervals(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end) {
563
+ bwOverlappingIntervals_t *bwGetOverlappingIntervals(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end) {
564
564
  bwOverlappingIntervals_t *output;
565
565
  uint32_t tid = bwGetTid(fp, chrom);
566
566
  if(tid == (uint32_t) -1) return NULL;
@@ -572,7 +572,7 @@ bwOverlappingIntervals_t *bwGetOverlappingIntervals(bigWigFile_t *fp, char *chro
572
572
  }
573
573
 
574
574
  //Like above, but for bigBed files
575
- bbOverlappingEntries_t *bbGetOverlappingEntries(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, int withString) {
575
+ bbOverlappingEntries_t *bbGetOverlappingEntries(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int withString) {
576
576
  bbOverlappingEntries_t *output;
577
577
  uint32_t tid = bwGetTid(fp, chrom);
578
578
  if(tid == (uint32_t) -1) return NULL;
@@ -584,16 +584,16 @@ bbOverlappingEntries_t *bbGetOverlappingEntries(bigWigFile_t *fp, char *chrom, u
584
584
  }
585
585
 
586
586
  //Returns NULL on error
587
- bwOverlapIterator_t *bwOverlappingIntervalsIterator(bigWigFile_t *bw, char *chrom, uint32_t start, uint32_t end, uint32_t blocksPerIteration) {
587
+ bwOverlapIterator_t *bwOverlappingIntervalsIterator(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, uint32_t blocksPerIteration) {
588
588
  bwOverlapIterator_t *output = NULL;
589
589
  uint64_t n;
590
- uint32_t tid = bwGetTid(bw, chrom);
590
+ uint32_t tid = bwGetTid(fp, chrom);
591
591
  if(tid == (uint32_t) -1) return output;
592
592
  output = calloc(1, sizeof(bwOverlapIterator_t));
593
593
  if(!output) return output;
594
- bwOverlapBlock_t *blocks = bwGetOverlappingBlocks(bw, chrom, start, end);
594
+ bwOverlapBlock_t *blocks = bwGetOverlappingBlocks(fp, chrom, start, end);
595
595
 
596
- output->bw = bw;
596
+ output->bw = fp;
597
597
  output->tid = tid;
598
598
  output->start = start;
599
599
  output->end = end;
@@ -603,7 +603,7 @@ bwOverlapIterator_t *bwOverlappingIntervalsIterator(bigWigFile_t *bw, char *chro
603
603
  if(blocks) {
604
604
  n = blocks->n;
605
605
  if(n>blocksPerIteration) blocks->n = blocksPerIteration;
606
- output->intervals = bwGetOverlappingIntervalsCore(bw, blocks,tid, start, end);
606
+ output->intervals = bwGetOverlappingIntervalsCore(fp, blocks,tid, start, end);
607
607
  blocks->n = n;
608
608
  output->offset = blocksPerIteration;
609
609
  }
@@ -612,16 +612,16 @@ bwOverlapIterator_t *bwOverlappingIntervalsIterator(bigWigFile_t *bw, char *chro
612
612
  }
613
613
 
614
614
  //Returns NULL on error
615
- bwOverlapIterator_t *bbOverlappingEntriesIterator(bigWigFile_t *bw, char *chrom, uint32_t start, uint32_t end, int withString, uint32_t blocksPerIteration) {
615
+ bwOverlapIterator_t *bbOverlappingEntriesIterator(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int withString, uint32_t blocksPerIteration) {
616
616
  bwOverlapIterator_t *output = NULL;
617
617
  uint64_t n;
618
- uint32_t tid = bwGetTid(bw, chrom);
618
+ uint32_t tid = bwGetTid(fp, chrom);
619
619
  if(tid == (uint32_t) -1) return output;
620
620
  output = calloc(1, sizeof(bwOverlapIterator_t));
621
621
  if(!output) return output;
622
- bwOverlapBlock_t *blocks = bwGetOverlappingBlocks(bw, chrom, start, end);
622
+ bwOverlapBlock_t *blocks = bwGetOverlappingBlocks(fp, chrom, start, end);
623
623
 
624
- output->bw = bw;
624
+ output->bw = fp;
625
625
  output->tid = tid;
626
626
  output->start = start;
627
627
  output->end = end;
@@ -632,7 +632,7 @@ bwOverlapIterator_t *bbOverlappingEntriesIterator(bigWigFile_t *bw, char *chrom,
632
632
  if(blocks) {
633
633
  n = blocks->n;
634
634
  if(n>blocksPerIteration) blocks->n = blocksPerIteration;
635
- output->entries = bbGetOverlappingEntriesCore(bw, blocks,tid, start, end, withString);
635
+ output->entries = bbGetOverlappingEntriesCore(fp, blocks,tid, start, end, withString);
636
636
  blocks->n = n;
637
637
  output->offset = blocksPerIteration;
638
638
  }
@@ -710,7 +710,7 @@ error:
710
710
  //The ->end member is NULL
711
711
  //If includeNA is not 0 then ->start is also NULL, since it's implied
712
712
  //Note that bwDestroyOverlappingIntervals() will work in either case
713
- bwOverlappingIntervals_t *bwGetValues(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t end, int includeNA) {
713
+ bwOverlappingIntervals_t *bwGetValues(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t end, int includeNA) {
714
714
  uint32_t i, j, n;
715
715
  bwOverlappingIntervals_t *output = NULL;
716
716
  bwOverlappingIntervals_t *intermediate = bwGetOverlappingIntervals(fp, chrom, start, end);
@@ -19,7 +19,7 @@ struct val_t {
19
19
 
20
20
  //Create a chromList_t and attach it to a bigWigFile_t *. Returns NULL on error
21
21
  //Note that chroms and lengths are duplicated, so you MUST free the input
22
- chromList_t *bwCreateChromList(char **chroms, uint32_t *lengths, int64_t n) {
22
+ chromList_t *bwCreateChromList(const char* const* chroms, const uint32_t *lengths, int64_t n) {
23
23
  int64_t i = 0;
24
24
  chromList_t *cl = calloc(1, sizeof(chromList_t));
25
25
  if(!cl) return NULL;
@@ -32,7 +32,7 @@ chromList_t *bwCreateChromList(char **chroms, uint32_t *lengths, int64_t n) {
32
32
 
33
33
  for(i=0; i<n; i++) {
34
34
  cl->len[i] = lengths[i];
35
- cl->chrom[i] = strdup(chroms[i]);
35
+ cl->chrom[i] = bwStrdup(chroms[i]);
36
36
  if(!cl->chrom[i]) goto error;
37
37
  }
38
38
 
@@ -188,7 +188,8 @@ int bwWriteHdr(bigWigFile_t *bw) {
188
188
  uint32_t magic = BIGWIG_MAGIC;
189
189
  uint16_t two = 4;
190
190
  FILE *fp;
191
- void *p = calloc(58, sizeof(uint8_t)); //58 bytes of nothing
191
+ const uint8_t pbuff[58] = {0}; // 58 bytes of nothing
192
+ const void *p = (const void *)&pbuff;
192
193
  if(!bw->isWrite) return 1;
193
194
 
194
195
  //The header itself, largely just reserving space...
@@ -223,7 +224,6 @@ int bwWriteHdr(bigWigFile_t *bw) {
223
224
  //Save space for the number of blocks
224
225
  if(fwrite(p, sizeof(uint8_t), 8, fp) != 8) return 13;
225
226
 
226
- free(p);
227
227
  return 0;
228
228
  }
229
229
 
@@ -371,9 +371,9 @@ static void updateStats(bigWigFile_t *fp, uint32_t span, float val) {
371
371
  }
372
372
 
373
373
  //12 bytes per entry
374
- int bwAddIntervals(bigWigFile_t *fp, char **chrom, uint32_t *start, uint32_t *end, float *values, uint32_t n) {
374
+ int bwAddIntervals(bigWigFile_t *fp, const char* const* chrom, const uint32_t *start, const uint32_t *end, const float *values, uint32_t n) {
375
375
  uint32_t tid = 0, i;
376
- char *lastChrom = NULL;
376
+ const char *lastChrom = NULL;
377
377
  bwWriteBuffer_t *wb = fp->writeBuffer;
378
378
  if(!n) return 0; //Not an error per se
379
379
  if(!fp->isWrite) return 1;
@@ -431,7 +431,7 @@ int bwAddIntervals(bigWigFile_t *fp, char **chrom, uint32_t *start, uint32_t *en
431
431
  return 0;
432
432
  }
433
433
 
434
- int bwAppendIntervals(bigWigFile_t *fp, uint32_t *start, uint32_t *end, float *values, uint32_t n) {
434
+ int bwAppendIntervals(bigWigFile_t *fp, const uint32_t *start, const uint32_t *end, const float *values, uint32_t n) {
435
435
  uint32_t i;
436
436
  bwWriteBuffer_t *wb = fp->writeBuffer;
437
437
  if(!n) return 0;
@@ -459,7 +459,7 @@ int bwAppendIntervals(bigWigFile_t *fp, uint32_t *start, uint32_t *end, float *v
459
459
  }
460
460
 
461
461
  //8 bytes per entry
462
- int bwAddIntervalSpans(bigWigFile_t *fp, char *chrom, uint32_t *start, uint32_t span, float *values, uint32_t n) {
462
+ int bwAddIntervalSpans(bigWigFile_t *fp, const char *chrom, const uint32_t *start, uint32_t span, const float *values, uint32_t n) {
463
463
  uint32_t i, tid;
464
464
  bwWriteBuffer_t *wb = fp->writeBuffer;
465
465
  if(!n) return 0;
@@ -492,7 +492,7 @@ int bwAddIntervalSpans(bigWigFile_t *fp, char *chrom, uint32_t *start, uint32_t
492
492
  return 0;
493
493
  }
494
494
 
495
- int bwAppendIntervalSpans(bigWigFile_t *fp, uint32_t *start, float *values, uint32_t n) {
495
+ int bwAppendIntervalSpans(bigWigFile_t *fp, const uint32_t *start, const float *values, uint32_t n) {
496
496
  uint32_t i;
497
497
  bwWriteBuffer_t *wb = fp->writeBuffer;
498
498
  if(!n) return 0;
@@ -517,7 +517,7 @@ int bwAppendIntervalSpans(bigWigFile_t *fp, uint32_t *start, float *values, uint
517
517
  }
518
518
 
519
519
  //4 bytes per entry
520
- int bwAddIntervalSpanSteps(bigWigFile_t *fp, char *chrom, uint32_t start, uint32_t span, uint32_t step, float *values, uint32_t n) {
520
+ int bwAddIntervalSpanSteps(bigWigFile_t *fp, const char *chrom, uint32_t start, uint32_t span, uint32_t step, const float *values, uint32_t n) {
521
521
  uint32_t i, tid;
522
522
  bwWriteBuffer_t *wb = fp->writeBuffer;
523
523
  if(!n) return 0;
@@ -549,7 +549,7 @@ int bwAddIntervalSpanSteps(bigWigFile_t *fp, char *chrom, uint32_t start, uint32
549
549
  return 0;
550
550
  }
551
551
 
552
- int bwAppendIntervalSpanSteps(bigWigFile_t *fp, float *values, uint32_t n) {
552
+ int bwAppendIntervalSpanSteps(bigWigFile_t *fp, const float *values, uint32_t n) {
553
553
  uint32_t i;
554
554
  bwWriteBuffer_t *wb = fp->writeBuffer;
555
555
  if(!n) return 0;