@genome-spy/app 0.51.0 → 0.53.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.
@@ -18,12 +18,12 @@ function Sr(c, f) {
18
18
  var V = {}, j = {};
19
19
  j.byteLength = Nr;
20
20
  j.toByteArray = kr;
21
- j.fromByteArray = Pr;
21
+ j.fromByteArray = $r;
22
22
  var _ = [], R = [], Lr = typeof Uint8Array < "u" ? Uint8Array : Array, H = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
23
23
  for (var k = 0, br = H.length; k < br; ++k)
24
24
  _[k] = H[k], R[H.charCodeAt(k)] = k;
25
- R["-".charCodeAt(0)] = 62;
26
- R["_".charCodeAt(0)] = 63;
25
+ R[45] = 62;
26
+ R[95] = 63;
27
27
  function hr(c) {
28
28
  var f = c.length;
29
29
  if (f % 4 > 0)
@@ -49,14 +49,14 @@ function kr(c) {
49
49
  function Dr(c) {
50
50
  return _[c >> 18 & 63] + _[c >> 12 & 63] + _[c >> 6 & 63] + _[c & 63];
51
51
  }
52
- function $r(c, f, s) {
52
+ function Pr(c, f, s) {
53
53
  for (var w, y = [], l = f; l < s; l += 3)
54
54
  w = (c[l] << 16 & 16711680) + (c[l + 1] << 8 & 65280) + (c[l + 2] & 255), y.push(Dr(w));
55
55
  return y.join("");
56
56
  }
57
- function Pr(c) {
57
+ function $r(c) {
58
58
  for (var f, s = c.length, w = s % 3, y = [], l = 16383, p = 0, o = s - w; p < o; p += l)
59
- y.push($r(c, p, p + l > o ? o : p + l));
59
+ y.push(Pr(c, p, p + l > o ? o : p + l));
60
60
  return w === 1 ? (f = c[s - 1], y.push(
61
61
  _[f >> 2] + _[f << 4 & 63] + "=="
62
62
  )) : w === 2 && (f = (c[s - 2] << 8) + c[s - 1], y.push(
@@ -81,12 +81,12 @@ X.read = function(c, f, s, w, y) {
81
81
  return (A ? -1 : 1) * p * Math.pow(2, l - w);
82
82
  };
83
83
  X.write = function(c, f, s, w, y, l) {
84
- var p, o, B, T = l * 8 - y - 1, I = (1 << T) - 1, F = I >> 1, S = y === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, A = w ? 0 : l - 1, D = w ? 1 : -1, $ = f < 0 || f === 0 && 1 / f < 0 ? 1 : 0;
84
+ var p, o, B, T = l * 8 - y - 1, I = (1 << T) - 1, F = I >> 1, S = y === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, A = w ? 0 : l - 1, D = w ? 1 : -1, P = f < 0 || f === 0 && 1 / f < 0 ? 1 : 0;
85
85
  for (f = Math.abs(f), isNaN(f) || f === 1 / 0 ? (o = isNaN(f) ? 1 : 0, p = I) : (p = Math.floor(Math.log(f) / Math.LN2), f * (B = Math.pow(2, -p)) < 1 && (p--, B *= 2), p + F >= 1 ? f += S / B : f += S * Math.pow(2, 1 - F), f * B >= 2 && (p++, B /= 2), p + F >= I ? (o = 0, p = I) : p + F >= 1 ? (o = (f * B - 1) * Math.pow(2, y), p = p + F) : (o = f * Math.pow(2, F - 1) * Math.pow(2, y), p = 0)); y >= 8; c[s + A] = o & 255, A += D, o /= 256, y -= 8)
86
86
  ;
87
87
  for (p = p << y | o, T += y; T > 0; c[s + A] = p & 255, A += D, p /= 256, T -= 8)
88
88
  ;
89
- c[s + A - D] |= $ * 128;
89
+ c[s + A - D] |= P * 128;
90
90
  };
91
91
  /*!
92
92
  * The buffer module from node.js, for the browser.
@@ -151,7 +151,7 @@ X.write = function(c, f, s, w, y, l) {
151
151
  "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof i
152
152
  );
153
153
  if (C(i, ArrayBuffer) || i && C(i.buffer, ArrayBuffer) || typeof SharedArrayBuffer < "u" && (C(i, SharedArrayBuffer) || i && C(i.buffer, SharedArrayBuffer)))
154
- return $(i, r, t);
154
+ return P(i, r, t);
155
155
  if (typeof i == "number")
156
156
  throw new TypeError(
157
157
  'The "value" argument must not be of type number. Received type number'
@@ -208,11 +208,11 @@ X.write = function(c, f, s, w, y, l) {
208
208
  function D(i) {
209
209
  if (C(i, Uint8Array)) {
210
210
  const r = new Uint8Array(i);
211
- return $(r.buffer, r.byteOffset, r.byteLength);
211
+ return P(r.buffer, r.byteOffset, r.byteLength);
212
212
  }
213
213
  return A(i);
214
214
  }
215
- function $(i, r, t) {
215
+ function P(i, r, t) {
216
216
  if (r < 0 || i.byteLength < r)
217
217
  throw new RangeError('"offset" is outside of buffer bounds');
218
218
  if (i.byteLength < r + (t || 0))
@@ -664,13 +664,13 @@ X.write = function(c, f, s, w, y, l) {
664
664
  }, o.prototype.readBigUInt64LE = L(function(r) {
665
665
  r = r >>> 0, M(r, "offset");
666
666
  const t = this[r], n = this[r + 7];
667
- (t === void 0 || n === void 0) && P(r, this.length - 8);
667
+ (t === void 0 || n === void 0) && $(r, this.length - 8);
668
668
  const e = t + this[++r] * 2 ** 8 + this[++r] * 2 ** 16 + this[++r] * 2 ** 24, u = this[++r] + this[++r] * 2 ** 8 + this[++r] * 2 ** 16 + n * 2 ** 24;
669
669
  return BigInt(e) + (BigInt(u) << BigInt(32));
670
670
  }), o.prototype.readBigUInt64BE = L(function(r) {
671
671
  r = r >>> 0, M(r, "offset");
672
672
  const t = this[r], n = this[r + 7];
673
- (t === void 0 || n === void 0) && P(r, this.length - 8);
673
+ (t === void 0 || n === void 0) && $(r, this.length - 8);
674
674
  const e = t * 2 ** 24 + this[++r] * 2 ** 16 + this[++r] * 2 ** 8 + this[++r], u = this[++r] * 2 ** 24 + this[++r] * 2 ** 16 + this[++r] * 2 ** 8 + n;
675
675
  return (BigInt(e) << BigInt(32)) + BigInt(u);
676
676
  }), o.prototype.readIntLE = function(r, t, n) {
@@ -702,13 +702,13 @@ X.write = function(c, f, s, w, y, l) {
702
702
  }, o.prototype.readBigInt64LE = L(function(r) {
703
703
  r = r >>> 0, M(r, "offset");
704
704
  const t = this[r], n = this[r + 7];
705
- (t === void 0 || n === void 0) && P(r, this.length - 8);
705
+ (t === void 0 || n === void 0) && $(r, this.length - 8);
706
706
  const e = this[r + 4] + this[r + 5] * 2 ** 8 + this[r + 6] * 2 ** 16 + (n << 24);
707
707
  return (BigInt(e) << BigInt(32)) + BigInt(t + this[++r] * 2 ** 8 + this[++r] * 2 ** 16 + this[++r] * 2 ** 24);
708
708
  }), o.prototype.readBigInt64BE = L(function(r) {
709
709
  r = r >>> 0, M(r, "offset");
710
710
  const t = this[r], n = this[r + 7];
711
- (t === void 0 || n === void 0) && P(r, this.length - 8);
711
+ (t === void 0 || n === void 0) && $(r, this.length - 8);
712
712
  const e = (t << 24) + // Overflow
713
713
  this[++r] * 2 ** 16 + this[++r] * 2 ** 8 + this[++r];
714
714
  return (BigInt(e) << BigInt(32)) + BigInt(this[++r] * 2 ** 24 + this[++r] * 2 ** 16 + this[++r] * 2 ** 8 + n);
@@ -932,13 +932,13 @@ X.write = function(c, f, s, w, y, l) {
932
932
  return `${i.slice(0, t)}${r}`;
933
933
  }
934
934
  function Ir(i, r, t) {
935
- M(r, "offset"), (i[r] === void 0 || i[r + t] === void 0) && P(r, i.length - (t + 1));
935
+ M(r, "offset"), (i[r] === void 0 || i[r + t] === void 0) && $(r, i.length - (t + 1));
936
936
  }
937
937
  function or(i, r, t, n, e, u) {
938
938
  if (i > t || i < r) {
939
939
  const h = typeof r == "bigint" ? "n" : "";
940
940
  let a;
941
- throw u > 3 ? r === 0 || r === BigInt(0) ? a = `>= 0${h} and < 2${h} ** ${(u + 1) * 8}${h}` : a = `>= -(2${h} ** ${(u + 1) * 8 - 1}${h}) and < 2 ** ${(u + 1) * 8 - 1}${h}` : a = `>= ${r}${h} and <= ${t}${h}`, new N.ERR_OUT_OF_RANGE("value", a, i);
941
+ throw r === 0 || r === BigInt(0) ? a = `>= 0${h} and < 2${h} ** ${(u + 1) * 8}${h}` : a = `>= -(2${h} ** ${(u + 1) * 8 - 1}${h}) and < 2 ** ${(u + 1) * 8 - 1}${h}`, new N.ERR_OUT_OF_RANGE("value", a, i);
942
942
  }
943
943
  Ir(n, e, u);
944
944
  }
@@ -946,10 +946,10 @@ X.write = function(c, f, s, w, y, l) {
946
946
  if (typeof i != "number")
947
947
  throw new N.ERR_INVALID_ARG_TYPE(r, "number", i);
948
948
  }
949
- function P(i, r, t) {
950
- throw Math.floor(i) !== i ? (M(i, t), new N.ERR_OUT_OF_RANGE(t || "offset", "an integer", i)) : r < 0 ? new N.ERR_BUFFER_OUT_OF_BOUNDS() : new N.ERR_OUT_OF_RANGE(
951
- t || "offset",
952
- `>= ${t ? 1 : 0} and <= ${r}`,
949
+ function $(i, r, t) {
950
+ throw Math.floor(i) !== i ? (M(i, t), new N.ERR_OUT_OF_RANGE("offset", "an integer", i)) : r < 0 ? new N.ERR_BUFFER_OUT_OF_BOUNDS() : new N.ERR_OUT_OF_RANGE(
951
+ "offset",
952
+ `>= 0 and <= ${r}`,
953
953
  i
954
954
  );
955
955
  }
@@ -0,0 +1,274 @@
1
+ import { L as g } from "./__vite-browser-external-C--ziKoh.js";
2
+ import { b as m } from "./index-B5cesONJ.js";
3
+ import { L as E, u as _ } from "./long-D4tVjLLz.js";
4
+ const w = 1;
5
+ class I {
6
+ constructor({ filehandle: e, path: t }) {
7
+ if (e)
8
+ this.filehandle = e;
9
+ else if (t)
10
+ this.filehandle = new g(t);
11
+ else
12
+ throw new TypeError("either filehandle or path must be defined");
13
+ }
14
+ _readLongWithOverflow(e, t = 0, s = !0) {
15
+ const n = E.fromBytesLE(e.slice(t, t + 8), s);
16
+ if (n.greaterThan(Number.MAX_SAFE_INTEGER) || n.lessThan(Number.MIN_SAFE_INTEGER))
17
+ throw new TypeError("integer overflow");
18
+ return n.toNumber();
19
+ }
20
+ _getIndex() {
21
+ return this.index || (this.index = this._readIndex()), this.index;
22
+ }
23
+ async _readIndex() {
24
+ let e = m.Buffer.allocUnsafe(8);
25
+ await this.filehandle.read(e, 0, 8, 0);
26
+ const t = this._readLongWithOverflow(e, 0, !0);
27
+ if (!t)
28
+ return [[0, 0]];
29
+ const s = new Array(t + 1);
30
+ s[0] = [0, 0];
31
+ const n = 8 * 2 * t;
32
+ if (n > Number.MAX_SAFE_INTEGER)
33
+ throw new TypeError("integer overflow");
34
+ e = m.Buffer.allocUnsafe(n), await this.filehandle.read(e, 0, n, 8);
35
+ for (let r = 0; r < t; r += 1) {
36
+ const i = this._readLongWithOverflow(e, r * 16), l = this._readLongWithOverflow(e, r * 16 + 8);
37
+ s[r + 1] = [i, l];
38
+ }
39
+ return s;
40
+ }
41
+ async getLastBlock() {
42
+ const e = await this._getIndex();
43
+ if (e.length)
44
+ return e[e.length - 1];
45
+ }
46
+ async getRelevantBlocksForRead(e, t) {
47
+ const s = t + e;
48
+ if (e === 0)
49
+ return [];
50
+ const n = await this._getIndex(), r = [], i = (h, u) => {
51
+ const p = h[w], x = u ? u[w] : 1 / 0;
52
+ return p <= t && x > t ? 0 : p < t ? -1 : 1;
53
+ };
54
+ let l = 0, f = n.length - 1, a = Math.floor(n.length / 2), d = i(n[a], n[a + 1]);
55
+ for (; d !== 0; )
56
+ d > 0 ? f = a - 1 : d < 0 && (l = a + 1), a = Math.ceil((f - l) / 2) + l, d = i(n[a], n[a + 1]);
57
+ r.push(n[a]);
58
+ let c = a + 1;
59
+ for (; c < n.length && (r.push(n[c]), !(n[c][w] >= s)); c += 1)
60
+ ;
61
+ return r[r.length - 1][w] < s && r.push([]), r;
62
+ }
63
+ }
64
+ class y {
65
+ constructor({ filehandle: e, path: t, gziFilehandle: s, gziPath: n }) {
66
+ if (e)
67
+ this.filehandle = e;
68
+ else if (t)
69
+ this.filehandle = new g(t);
70
+ else
71
+ throw new TypeError("either filehandle or path must be defined");
72
+ if (!s && !n && !t)
73
+ throw new TypeError("either gziFilehandle or gziPath must be defined");
74
+ this.gzi = new I({
75
+ filehandle: s,
76
+ path: !s && !n && t ? n : `${t}.gzi`
77
+ });
78
+ }
79
+ async stat() {
80
+ const e = await this.filehandle.stat();
81
+ return Object.assign(e, {
82
+ size: await this.getUncompressedFileSize(),
83
+ blocks: void 0,
84
+ blksize: void 0
85
+ });
86
+ }
87
+ async getUncompressedFileSize() {
88
+ const [, e] = await this.gzi.getLastBlock(), { size: t } = await this.filehandle.stat(), s = m.Buffer.allocUnsafe(4), { bytesRead: n } = await this.filehandle.read(s, 0, 4, t - 28 - 4);
89
+ if (n !== 4)
90
+ throw new Error("read error");
91
+ const r = s.readUInt32LE(0);
92
+ return e + r;
93
+ }
94
+ async _readAndUncompressBlock(e, [t], [s]) {
95
+ let n = s;
96
+ n || (n = (await this.filehandle.stat()).size);
97
+ const r = n - t;
98
+ return await this.filehandle.read(e, 0, r, t), await _(e.slice(0, r));
99
+ }
100
+ async read(e, t, s, n) {
101
+ const r = await this.gzi.getRelevantBlocksForRead(s, n), i = m.Buffer.allocUnsafe(32768 * 2);
102
+ let l = t, f = 0;
103
+ for (let a = 0; a < r.length - 1; a += 1) {
104
+ const d = await this._readAndUncompressBlock(i, r[a], r[a + 1]), [, c] = r[a], h = c >= n ? 0 : n - c, u = Math.min(n + s, c + d.length) - c;
105
+ h >= 0 && h < d.length && (d.copy(e, l, h, u), l += u - h, f += u - h);
106
+ }
107
+ return { bytesRead: f, buffer: e };
108
+ }
109
+ }
110
+ function b(o, e) {
111
+ return o.offset + o.lineBytes * Math.floor(e / o.lineLength) + e % o.lineLength;
112
+ }
113
+ async function S(o, e) {
114
+ const t = await o.readFile(e);
115
+ if (!(t && t.length))
116
+ throw new Error("No data read from FASTA index (FAI) file");
117
+ let s = 0, n;
118
+ const r = t.toString("utf8").split(/\r?\n/).filter((i) => /\S/.test(i)).map((i) => i.split(" ")).filter((i) => i[0] !== "").map((i) => ((!n || n.name !== i[0]) && (n = { name: i[0], id: s }, s += 1), {
119
+ id: n.id,
120
+ name: i[0],
121
+ length: +i[1],
122
+ start: 0,
123
+ end: +i[1],
124
+ offset: +i[2],
125
+ lineLength: +i[3],
126
+ lineBytes: +i[4]
127
+ }));
128
+ return {
129
+ name: Object.fromEntries(r.map((i) => [i.name, i])),
130
+ id: Object.fromEntries(r.map((i) => [i.id, i]))
131
+ };
132
+ }
133
+ class B {
134
+ constructor({ fasta: e, fai: t, path: s, faiPath: n }) {
135
+ if (e)
136
+ this.fasta = e;
137
+ else if (s)
138
+ this.fasta = new g(s);
139
+ else
140
+ throw new Error("Need to pass filehandle for fasta or path to localfile");
141
+ if (t)
142
+ this.fai = t;
143
+ else if (n)
144
+ this.fai = new g(n);
145
+ else if (s)
146
+ this.fai = new g(`${s}.fai`);
147
+ else
148
+ throw new Error("Need to pass filehandle for or path to localfile");
149
+ }
150
+ async _getIndexes(e) {
151
+ return this.indexes || (this.indexes = S(this.fai, e)), this.indexes;
152
+ }
153
+ /**
154
+ * @returns {array[string]} array of string sequence
155
+ * names that are present in the index, in which the
156
+ * array index indicates the sequence ID, and the value
157
+ * is the sequence name
158
+ */
159
+ async getSequenceNames(e) {
160
+ return Object.keys((await this._getIndexes(e)).name);
161
+ }
162
+ /**
163
+ * @returns {array[string]} array of string sequence
164
+ * names that are present in the index, in which the
165
+ * array index indicates the sequence ID, and the value
166
+ * is the sequence name
167
+ */
168
+ async getSequenceSizes(e) {
169
+ const t = {}, s = await this._getIndexes(e), n = Object.values(s.id);
170
+ for (let r = 0; r < n.length; r += 1)
171
+ t[n[r].name] = n[r].length;
172
+ return t;
173
+ }
174
+ /**
175
+ * @returns {array[string]} array of string sequence
176
+ * names that are present in the index, in which the
177
+ * array index indicates the sequence ID, and the value
178
+ * is the sequence name
179
+ */
180
+ async getSequenceSize(e, t) {
181
+ var s;
182
+ return (s = (await this._getIndexes(t)).name[e]) === null || s === void 0 ? void 0 : s.length;
183
+ }
184
+ /**
185
+ *
186
+ * @param {string} name
187
+ * @returns {Promise[boolean]} true if the file contains the given reference sequence name
188
+ */
189
+ async hasReferenceSequence(e, t) {
190
+ return !!(await this._getIndexes(t)).name[e];
191
+ }
192
+ /**
193
+ *
194
+ * @param {number} seqId
195
+ * @param {number} min
196
+ * @param {number} max
197
+ */
198
+ async getResiduesById(e, t, s, n) {
199
+ const r = (await this._getIndexes(n)).id[e];
200
+ if (r)
201
+ return this._fetchFromIndexEntry(r, t, s, n);
202
+ }
203
+ /**
204
+ * @param {string} seqName
205
+ * @param {number} min
206
+ * @param {number} max
207
+ */
208
+ async getResiduesByName(e, t, s, n) {
209
+ const r = (await this._getIndexes(n)).name[e];
210
+ if (r)
211
+ return this._fetchFromIndexEntry(r, t, s, n);
212
+ }
213
+ //alias for getResiduesByName
214
+ async getSequence(e, t, s, n) {
215
+ return this.getResiduesByName(e, t, s, n);
216
+ }
217
+ async _fetchFromIndexEntry(e, t = 0, s, n) {
218
+ let r = s;
219
+ if (t < 0)
220
+ throw new TypeError("regionStart cannot be less than 0");
221
+ if ((r === void 0 || r > e.length) && (r = e.length), t >= r)
222
+ return "";
223
+ const i = b(e, t), l = b(e, r) - i, f = Buffer.allocUnsafe(l);
224
+ return await this.fasta.read(f, 0, l, i, n), f.toString("utf8").replace(/\s+/g, "");
225
+ }
226
+ }
227
+ class O extends B {
228
+ constructor({ fasta: e, path: t, fai: s, faiPath: n, gzi: r, gziPath: i }) {
229
+ super({ fasta: e, path: t, fai: s, faiPath: n }), e && r ? this.fasta = new y({
230
+ filehandle: e,
231
+ gziFilehandle: r
232
+ }) : t && i && (this.fasta = new y({ path: t, gziPath: i }));
233
+ }
234
+ }
235
+ function F(o) {
236
+ return o.split(">").filter((e) => /\S/.test(e)).map((e) => {
237
+ const [t, ...s] = e.split(`
238
+ `), [n, ...r] = t.split(" "), i = s.join("").replace(/\s/g, "");
239
+ return {
240
+ id: n,
241
+ description: r.join(" "),
242
+ sequence: i
243
+ };
244
+ });
245
+ }
246
+ class k {
247
+ constructor({ fasta: e, path: t }) {
248
+ if (e)
249
+ this.fasta = e;
250
+ else if (t)
251
+ this.fasta = new g(t);
252
+ else
253
+ throw new Error("Need to pass fasta or path");
254
+ this.data = this.fasta.readFile().then((s) => {
255
+ const n = s.toString("utf8");
256
+ return F(n);
257
+ });
258
+ }
259
+ async fetch(e, t, s) {
260
+ const r = (await this.data).find((l) => l.id === e), i = s - t;
261
+ if (!r)
262
+ throw new Error(`no sequence with id ${e} exists`);
263
+ return r.sequence.substr(t, i);
264
+ }
265
+ async getSequenceNames() {
266
+ return (await this.data).map((t) => t.id);
267
+ }
268
+ }
269
+ export {
270
+ O as BgzipIndexedFasta,
271
+ k as FetchableSmallFasta,
272
+ B as IndexedFasta,
273
+ F as parseSmallFasta
274
+ };