@genome-spy/app 0.37.3 → 0.38.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.
@@ -0,0 +1,279 @@
1
+ import { L as g } from "./__vite-browser-external-ENoMJThg.js";
2
+ import { b as w } from "./index-2VmK8MLN.js";
3
+ import { L as x, u as E } from "./long-WDeGicRf.js";
4
+ import "./index-UyB03NDZ.js";
5
+ const m = 1;
6
+ class _ {
7
+ constructor({ filehandle: e, path: t }) {
8
+ if (e)
9
+ this.filehandle = e;
10
+ else if (t)
11
+ this.filehandle = new g(t);
12
+ else
13
+ throw new TypeError("either filehandle or path must be defined");
14
+ }
15
+ _readLongWithOverflow(e, t = 0, i = !0) {
16
+ const n = x.fromBytesLE(e.slice(t, t + 8), i);
17
+ if (n.greaterThan(Number.MAX_SAFE_INTEGER) || n.lessThan(Number.MIN_SAFE_INTEGER))
18
+ throw new TypeError("integer overflow");
19
+ return n.toNumber();
20
+ }
21
+ _getIndex() {
22
+ return this.index || (this.index = this._readIndex()), this.index;
23
+ }
24
+ async _readIndex() {
25
+ let e = w.Buffer.allocUnsafe(8);
26
+ await this.filehandle.read(e, 0, 8, 0);
27
+ const t = this._readLongWithOverflow(e, 0, !0);
28
+ if (!t)
29
+ return [[0, 0]];
30
+ const i = new Array(t + 1);
31
+ i[0] = [0, 0];
32
+ const n = 8 * 2 * t;
33
+ if (n > Number.MAX_SAFE_INTEGER)
34
+ throw new TypeError("integer overflow");
35
+ e = w.Buffer.allocUnsafe(n), await this.filehandle.read(e, 0, n, 8);
36
+ for (let s = 0; s < t; s += 1) {
37
+ const r = this._readLongWithOverflow(e, s * 16), a = this._readLongWithOverflow(e, s * 16 + 8);
38
+ i[s + 1] = [r, a];
39
+ }
40
+ return i;
41
+ }
42
+ async getLastBlock() {
43
+ const e = await this._getIndex();
44
+ if (e.length)
45
+ return e[e.length - 1];
46
+ }
47
+ async getRelevantBlocksForRead(e, t) {
48
+ const i = t + e;
49
+ if (e === 0)
50
+ return [];
51
+ const n = await this._getIndex(), s = [], r = (h, u) => {
52
+ const p = h[m], b = u ? u[m] : 1 / 0;
53
+ return p <= t && b > t ? 0 : p < t ? -1 : 1;
54
+ };
55
+ let a = 0, f = n.length - 1, o = Math.floor(n.length / 2), d = r(n[o], n[o + 1]);
56
+ for (; d !== 0; )
57
+ d > 0 ? f = o - 1 : d < 0 && (a = o + 1), o = Math.ceil((f - a) / 2) + a, d = r(n[o], n[o + 1]);
58
+ s.push(n[o]);
59
+ let c = o + 1;
60
+ for (; c < n.length && (s.push(n[c]), !(n[c][m] >= i)); c += 1)
61
+ ;
62
+ return s[s.length - 1][m] < i && s.push([]), s;
63
+ }
64
+ }
65
+ class y {
66
+ constructor({ filehandle: e, path: t, gziFilehandle: i, gziPath: n }) {
67
+ if (e)
68
+ this.filehandle = e;
69
+ else if (t)
70
+ this.filehandle = new g(t);
71
+ else
72
+ throw new TypeError("either filehandle or path must be defined");
73
+ if (!i && !n && !t)
74
+ throw new TypeError("either gziFilehandle or gziPath must be defined");
75
+ this.gzi = new _({
76
+ filehandle: i,
77
+ path: !i && !n && t ? n : `${t}.gzi`
78
+ });
79
+ }
80
+ async stat() {
81
+ const e = await this.filehandle.stat();
82
+ return Object.assign(e, {
83
+ size: await this.getUncompressedFileSize(),
84
+ blocks: void 0,
85
+ blksize: void 0
86
+ });
87
+ }
88
+ async getUncompressedFileSize() {
89
+ const [, e] = await this.gzi.getLastBlock(), { size: t } = await this.filehandle.stat(), i = w.Buffer.allocUnsafe(4), { bytesRead: n } = await this.filehandle.read(i, 0, 4, t - 28 - 4);
90
+ if (n !== 4)
91
+ throw new Error("read error");
92
+ const s = i.readUInt32LE(0);
93
+ return e + s;
94
+ }
95
+ async _readAndUncompressBlock(e, [t], [i]) {
96
+ let n = i;
97
+ n || (n = (await this.filehandle.stat()).size);
98
+ const s = n - t;
99
+ return await this.filehandle.read(e, 0, s, t), await E(e.slice(0, s));
100
+ }
101
+ async read(e, t, i, n) {
102
+ const s = await this.gzi.getRelevantBlocksForRead(i, n), r = w.Buffer.allocUnsafe(32768 * 2);
103
+ let a = t, f = 0;
104
+ for (let o = 0; o < s.length - 1; o += 1) {
105
+ const d = await this._readAndUncompressBlock(r, s[o], s[o + 1]), [, c] = s[o], h = c >= n ? 0 : n - c, u = Math.min(n + i, c + d.length) - c;
106
+ h >= 0 && h < d.length && (d.copy(e, a, h, u), a += u - h, f += u - h);
107
+ }
108
+ return { bytesRead: f, buffer: e };
109
+ }
110
+ }
111
+ function S(l, e) {
112
+ return l.offset + l.lineBytes * Math.floor(e / l.lineLength) + e % l.lineLength;
113
+ }
114
+ async function I(l, e) {
115
+ const t = await l.readFile(e);
116
+ if (!(t && t.length))
117
+ throw new Error("No data read from FASTA index (FAI) file");
118
+ let i = 0, n;
119
+ const s = t.toString("utf8").split(/\r?\n/).filter((r) => /\S/.test(r)).map((r) => r.split(" ")).filter((r) => r[0] !== "").map((r) => ((!n || n.name !== r[0]) && (n = { name: r[0], id: i }, i += 1), {
120
+ id: n.id,
121
+ name: r[0],
122
+ length: +r[1],
123
+ start: 0,
124
+ end: +r[1],
125
+ offset: +r[2],
126
+ lineLength: +r[3],
127
+ lineBytes: +r[4]
128
+ }));
129
+ return {
130
+ name: Object.fromEntries(s.map((r) => [r.name, r])),
131
+ id: Object.fromEntries(s.map((r) => [r.id, r]))
132
+ };
133
+ }
134
+ class B {
135
+ constructor({ fasta: e, fai: t, path: i, faiPath: n, chunkSizeLimit: s = 1e6 }) {
136
+ if (e)
137
+ this.fasta = e;
138
+ else if (i)
139
+ this.fasta = new g(i);
140
+ else
141
+ throw new Error("Need to pass filehandle for fasta or path to localfile");
142
+ if (t)
143
+ this.fai = t;
144
+ else if (n)
145
+ this.fai = new g(n);
146
+ else if (i)
147
+ this.fai = new g(`${i}.fai`);
148
+ else
149
+ throw new Error("Need to pass filehandle for or path to localfile");
150
+ this.chunkSizeLimit = s;
151
+ }
152
+ async _getIndexes(e) {
153
+ return this.indexes || (this.indexes = I(this.fai, e)), this.indexes;
154
+ }
155
+ /**
156
+ * @returns {array[string]} array of string sequence
157
+ * names that are present in the index, in which the
158
+ * array index indicates the sequence ID, and the value
159
+ * is the sequence name
160
+ */
161
+ async getSequenceNames(e) {
162
+ return Object.keys((await this._getIndexes(e)).name);
163
+ }
164
+ /**
165
+ * @returns {array[string]} array of string sequence
166
+ * names that are present in the index, in which the
167
+ * array index indicates the sequence ID, and the value
168
+ * is the sequence name
169
+ */
170
+ async getSequenceSizes(e) {
171
+ const t = {}, i = await this._getIndexes(e), n = Object.values(i.id);
172
+ for (let s = 0; s < n.length; s += 1)
173
+ t[n[s].name] = n[s].length;
174
+ return t;
175
+ }
176
+ /**
177
+ * @returns {array[string]} array of string sequence
178
+ * names that are present in the index, in which the
179
+ * array index indicates the sequence ID, and the value
180
+ * is the sequence name
181
+ */
182
+ async getSequenceSize(e, t) {
183
+ var i;
184
+ return (i = (await this._getIndexes(t)).name[e]) === null || i === void 0 ? void 0 : i.length;
185
+ }
186
+ /**
187
+ *
188
+ * @param {string} name
189
+ * @returns {Promise[boolean]} true if the file contains the given reference sequence name
190
+ */
191
+ async hasReferenceSequence(e, t) {
192
+ return !!(await this._getIndexes(t)).name[e];
193
+ }
194
+ /**
195
+ *
196
+ * @param {number} seqId
197
+ * @param {number} min
198
+ * @param {number} max
199
+ */
200
+ async getResiduesById(e, t, i, n) {
201
+ const s = (await this._getIndexes(n)).id[e];
202
+ if (s)
203
+ return this._fetchFromIndexEntry(s, t, i, n);
204
+ }
205
+ /**
206
+ * @param {string} seqName
207
+ * @param {number} min
208
+ * @param {number} max
209
+ */
210
+ async getResiduesByName(e, t, i, n) {
211
+ const s = (await this._getIndexes(n)).name[e];
212
+ if (s)
213
+ return this._fetchFromIndexEntry(s, t, i, n);
214
+ }
215
+ //alias for getResiduesByName
216
+ async getSequence(e, t, i, n) {
217
+ return this.getResiduesByName(e, t, i, n);
218
+ }
219
+ async _fetchFromIndexEntry(e, t = 0, i, n) {
220
+ let s = i;
221
+ if (t < 0)
222
+ throw new TypeError("regionStart cannot be less than 0");
223
+ if ((s === void 0 || s > e.length) && (s = e.length), t >= s)
224
+ return "";
225
+ const r = S(e, t), a = S(e, s) - r;
226
+ if (a > this.chunkSizeLimit)
227
+ throw new Error(`data size of ${a.toLocaleString()} bytes exceeded chunk size limit of ${this.chunkSizeLimit.toLocaleString()} bytes`);
228
+ const f = Buffer.allocUnsafe(a);
229
+ return await this.fasta.read(f, 0, a, r, n), f.toString("utf8").replace(/\s+/g, "");
230
+ }
231
+ }
232
+ class O extends B {
233
+ constructor({ fasta: e, path: t, fai: i, faiPath: n, gzi: s, gziPath: r, chunkSizeLimit: a }) {
234
+ super({ fasta: e, path: t, fai: i, faiPath: n, chunkSizeLimit: a }), e && s ? this.fasta = new y({
235
+ filehandle: e,
236
+ gziFilehandle: s
237
+ }) : t && r && (this.fasta = new y({ path: t, gziPath: r }));
238
+ }
239
+ }
240
+ function L(l) {
241
+ return l.split(">").filter((e) => /\S/.test(e)).map((e) => {
242
+ const [t, ...i] = e.split(`
243
+ `), [n, ...s] = t.split(" "), r = i.join("").replace(/\s/g, "");
244
+ return {
245
+ id: n,
246
+ description: s.join(" "),
247
+ sequence: r
248
+ };
249
+ });
250
+ }
251
+ class v {
252
+ constructor({ fasta: e, path: t }) {
253
+ if (e)
254
+ this.fasta = e;
255
+ else if (t)
256
+ this.fasta = new g(t);
257
+ else
258
+ throw new Error("Need to pass fasta or path");
259
+ this.data = this.fasta.readFile().then((i) => {
260
+ const n = i.toString("utf8");
261
+ return L(n);
262
+ });
263
+ }
264
+ async fetch(e, t, i) {
265
+ const s = (await this.data).find((a) => a.id === e), r = i - t;
266
+ if (!s)
267
+ throw new Error(`no sequence with id ${e} exists`);
268
+ return s.sequence.substr(t, r);
269
+ }
270
+ async getSequenceNames() {
271
+ return (await this.data).map((t) => t.id);
272
+ }
273
+ }
274
+ export {
275
+ O as BgzipIndexedFasta,
276
+ v as FetchableSmallFasta,
277
+ B as IndexedFasta,
278
+ L as parseSmallFasta
279
+ };
@@ -0,0 +1,72 @@
1
+ import { L as d } from "./__vite-browser-external-ENoMJThg.js";
2
+ import { R as b } from "./remoteFile-1ad_qGwi.js";
3
+ import { b as i } from "./index-2VmK8MLN.js";
4
+ import "./index-UyB03NDZ.js";
5
+ function a(o) {
6
+ const r = new FileReader();
7
+ return new Promise((n, e) => {
8
+ r.onerror = () => {
9
+ r.abort(), e(new Error("problem reading blob"));
10
+ }, r.onabort = () => {
11
+ e(new Error("blob reading was aborted"));
12
+ }, r.onload = () => {
13
+ r.result && typeof r.result != "string" ? n(r.result) : e(new Error("unknown error reading blob"));
14
+ }, r.readAsArrayBuffer(o);
15
+ });
16
+ }
17
+ function c(o) {
18
+ const r = new FileReader();
19
+ return new Promise((n, e) => {
20
+ r.onerror = () => {
21
+ r.abort(), e(new Error("problem reading blob"));
22
+ }, r.onabort = () => {
23
+ e(new Error("blob reading was aborted"));
24
+ }, r.onload = () => {
25
+ r.result && typeof r.result == "string" ? n(r.result) : e(new Error("unknown error reading blob"));
26
+ }, r.readAsText(o);
27
+ });
28
+ }
29
+ class E {
30
+ constructor(r) {
31
+ this.blob = r, this.size = r.size;
32
+ }
33
+ async read(r, n = 0, e, f = 0) {
34
+ if (!e)
35
+ return { bytesRead: 0, buffer: r };
36
+ const t = f, u = t + e, l = await a(this.blob.slice(t, u)), s = i.Buffer.from(l);
37
+ return { bytesRead: s.copy(r, n), buffer: s };
38
+ }
39
+ async readFile(r) {
40
+ let n;
41
+ if (typeof r == "string" ? n = r : n = r && r.encoding, n === "utf8")
42
+ return c(this.blob);
43
+ if (n)
44
+ throw new Error(`unsupported encoding: ${n}`);
45
+ const e = await a(this.blob);
46
+ return i.Buffer.from(e);
47
+ }
48
+ async stat() {
49
+ return { size: this.size };
50
+ }
51
+ async close() {
52
+ }
53
+ }
54
+ function w(o, r = {}) {
55
+ return new b(o, r);
56
+ }
57
+ function R(o, r, n, e = {}) {
58
+ if (n !== void 0)
59
+ return n;
60
+ if (o !== void 0)
61
+ return w(o, e);
62
+ if (r !== void 0)
63
+ return new d(r, e);
64
+ throw new Error("no url, path, or filehandle provided, cannot open");
65
+ }
66
+ export {
67
+ E as BlobFile,
68
+ d as LocalFile,
69
+ b as RemoteFile,
70
+ w as fromUrl,
71
+ R as open
72
+ };
@@ -0,0 +1,9 @@
1
+ import { G as o, A as p, e as s, x as m, b as l, l as n } from "./index-UyB03NDZ.js";
2
+ export {
3
+ o as GenomeSpy,
4
+ p as GenomeSpyApp,
5
+ s as embed,
6
+ m as html,
7
+ l as icon,
8
+ n as loadSpec
9
+ };