@gmod/bbi 1.0.34 → 2.0.1

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +17 -8
  2. package/dist/bbi.d.ts +2 -2
  3. package/dist/bbi.js +56 -59
  4. package/dist/bbi.js.map +1 -0
  5. package/dist/bigbed.d.ts +1 -2
  6. package/dist/bigbed.js +23 -20
  7. package/dist/bigbed.js.map +1 -0
  8. package/dist/bigwig.d.ts +1 -3
  9. package/dist/bigwig.js +5 -8
  10. package/dist/bigwig.js.map +1 -0
  11. package/dist/blockView.d.ts +8 -9
  12. package/dist/blockView.js +156 -95
  13. package/dist/blockView.js.map +1 -0
  14. package/dist/index.js +1 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/range.js +2 -0
  17. package/dist/range.js.map +1 -0
  18. package/dist/unzip-pako.d.ts +1 -1
  19. package/dist/unzip-pako.js +2 -1
  20. package/dist/unzip-pako.js.map +1 -0
  21. package/dist/unzip.js +1 -0
  22. package/dist/unzip.js.map +1 -0
  23. package/dist/util.d.ts +11 -1
  24. package/dist/util.js +10 -4
  25. package/dist/util.js.map +1 -0
  26. package/esm/bbi.d.ts +2 -2
  27. package/esm/bbi.js +62 -67
  28. package/esm/bbi.js.map +1 -0
  29. package/esm/bigbed.d.ts +1 -2
  30. package/esm/bigbed.js +42 -46
  31. package/esm/bigbed.js.map +1 -0
  32. package/esm/bigwig.d.ts +1 -3
  33. package/esm/bigwig.js +7 -14
  34. package/esm/bigwig.js.map +1 -0
  35. package/esm/blockView.d.ts +8 -9
  36. package/esm/blockView.js +168 -118
  37. package/esm/blockView.js.map +1 -0
  38. package/esm/index.js +3 -7
  39. package/esm/index.js.map +1 -0
  40. package/esm/range.js +3 -4
  41. package/esm/range.js.map +1 -0
  42. package/esm/unzip-pako.d.ts +1 -1
  43. package/esm/unzip-pako.js +4 -7
  44. package/esm/unzip-pako.js.map +1 -0
  45. package/esm/unzip.js +3 -5
  46. package/esm/unzip.js.map +1 -0
  47. package/esm/util.d.ts +11 -1
  48. package/esm/util.js +14 -15
  49. package/esm/util.js.map +1 -0
  50. package/package.json +14 -14
  51. package/src/bbi.ts +375 -0
  52. package/src/bigbed.ts +244 -0
  53. package/src/bigwig.ts +38 -0
  54. package/src/blockView.ts +496 -0
  55. package/src/declare.d.ts +2 -0
  56. package/src/index.ts +3 -0
  57. package/src/range.ts +142 -0
  58. package/src/unzip-pako.ts +5 -0
  59. package/src/unzip.ts +2 -0
  60. package/src/util.ts +83 -0
package/src/util.ts ADDED
@@ -0,0 +1,83 @@
1
+ /* eslint no-bitwise: ["error", { "allow": ["|"] }] */
2
+ export class AbortError extends Error {
3
+ public code: string
4
+
5
+ public constructor(message: string) {
6
+ super(message)
7
+ this.code = 'ERR_ABORTED'
8
+ }
9
+ }
10
+ // sort blocks by file offset and
11
+ // group blocks that are within 2KB of eachother
12
+ export function groupBlocks(blocks: { offset: bigint; length: bigint }[]) {
13
+ blocks.sort((b0, b1) => Number(b0.offset) - Number(b1.offset))
14
+
15
+ const blockGroups = []
16
+ let lastBlock
17
+ let lastBlockEnd
18
+ for (let i = 0; i < blocks.length; i += 1) {
19
+ if (
20
+ lastBlock &&
21
+ lastBlockEnd &&
22
+ Number(blocks[i].offset) - lastBlockEnd <= 2000
23
+ ) {
24
+ lastBlock.length = BigInt(
25
+ Number(lastBlock.length) +
26
+ Number(blocks[i].length) -
27
+ lastBlockEnd +
28
+ Number(blocks[i].offset),
29
+ )
30
+ lastBlock.blocks.push(blocks[i])
31
+ } else {
32
+ blockGroups.push(
33
+ (lastBlock = {
34
+ blocks: [blocks[i]],
35
+ length: blocks[i].length,
36
+ offset: blocks[i].offset,
37
+ }),
38
+ )
39
+ }
40
+ lastBlockEnd = Number(lastBlock.offset) + Number(lastBlock.length)
41
+ }
42
+
43
+ return blockGroups
44
+ }
45
+
46
+ /**
47
+ * Properly check if the given AbortSignal is aborted.
48
+ * Per the standard, if the signal reads as aborted,
49
+ * this function throws either a DOMException AbortError, or a regular error
50
+ * with a `code` attribute set to `ERR_ABORTED`.
51
+ *
52
+ * For convenience, passing `undefined` is a no-op
53
+ *
54
+ * @param {AbortSignal} [signal] an AbortSignal, or anything with an `aborted` attribute
55
+ * @returns nothing
56
+ */
57
+ export function checkAbortSignal(signal?: AbortSignal): void {
58
+ if (!signal) {
59
+ return
60
+ }
61
+
62
+ if (signal.aborted) {
63
+ // console.log('bam aborted!')
64
+ if (typeof DOMException !== 'undefined') {
65
+ throw new DOMException('aborted', 'AbortError')
66
+ } else {
67
+ const e = new AbortError('aborted')
68
+ e.code = 'ERR_ABORTED'
69
+ throw e
70
+ }
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Skips to the next tick, then runs `checkAbortSignal`.
76
+ * Await this to inside an otherwise synchronous loop to
77
+ * provide a place to break when an abort signal is received.
78
+ * @param {AbortSignal} signal
79
+ */
80
+ export async function abortBreakPoint(signal?: AbortSignal): Promise<void> {
81
+ await Promise.resolve()
82
+ checkAbortSignal(signal)
83
+ }