@genome-spy/app 0.64.0 → 0.66.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.
package/README.md CHANGED
@@ -6,4 +6,4 @@
6
6
 
7
7
  This package provides a user interface for interactive analysis of multiple
8
8
  samples, which can be filtered, sorted, and grouped flexibly. A session handling
9
- with provenance, url hashes, and bookmarks is included.
9
+ with provenance, URL hashes, and bookmarks is included.
@@ -1,7 +1,6 @@
1
- import { g as u } from "./_commonjsHelpers-DjF3Plf2.js";
2
- class f {
1
+ class h {
3
2
  }
4
- class b {
3
+ class d {
5
4
  constructor() {
6
5
  this.signals = /* @__PURE__ */ new Set(), this.abortController = new AbortController();
7
6
  }
@@ -11,7 +10,7 @@ class b {
11
10
  * longer be abortable.
12
11
  */
13
12
  //@ts-ignore
14
- addSignal(t = new f()) {
13
+ addSignal(t = new h()) {
15
14
  if (this.signal.aborted)
16
15
  throw new Error("cannot add a signal, already aborted!");
17
16
  this.signals.add(t), t.aborted ? this.handleAborted(t) : typeof t.addEventListener == "function" && t.addEventListener("abort", () => {
@@ -28,13 +27,13 @@ class b {
28
27
  this.abortController.abort();
29
28
  }
30
29
  }
31
- class g {
30
+ class b {
32
31
  constructor() {
33
32
  this.callbacks = /* @__PURE__ */ new Set();
34
33
  }
35
34
  addCallback(t = () => {
36
35
  }) {
37
- this.callbacks.add(t), t(this.currentMessage);
36
+ this.callbacks.add(t), this.currentMessage && t(this.currentMessage);
38
37
  }
39
38
  callback(t) {
40
39
  this.currentMessage = t;
@@ -42,7 +41,7 @@ class g {
42
41
  e(t);
43
42
  }
44
43
  }
45
- class l {
44
+ class c {
46
45
  constructor({ fill: t, cache: e }) {
47
46
  if (typeof t != "function")
48
47
  throw new TypeError("must pass a fill function");
@@ -65,16 +64,16 @@ class l {
65
64
  evict(t, e) {
66
65
  this.cache.get(t) === e && this.cache.delete(t);
67
66
  }
68
- fill(t, e, r, i) {
69
- const s = new b(), c = new g();
70
- c.addCallback(i);
67
+ fill(t, e, r, s) {
68
+ const o = new d(), i = new b();
69
+ i.addCallback(s);
71
70
  const a = {
72
- aborter: s,
73
- promise: this.fillCallback(e, s.signal, (h) => {
74
- c.callback(h);
71
+ aborter: o,
72
+ promise: this.fillCallback(e, o.signal, (n) => {
73
+ i.callback(n);
75
74
  }),
76
75
  settled: !1,
77
- statusReporter: c,
76
+ statusReporter: i,
78
77
  get aborted() {
79
78
  return this.aborter.signal.aborted;
80
79
  }
@@ -85,8 +84,8 @@ class l {
85
84
  a.settled = !0;
86
85
  }, () => {
87
86
  a.settled = !0, this.evict(t, a);
88
- }).catch((h) => {
89
- throw console.error(h), h;
87
+ }).catch((n) => {
88
+ throw console.error(n), n;
90
89
  }), this.cache.set(t, a);
91
90
  }
92
91
  static checkSinglePromise(t, e) {
@@ -94,8 +93,8 @@ class l {
94
93
  if (e != null && e.aborted)
95
94
  throw Object.assign(new Error("aborted"), { code: "ERR_ABORTED" });
96
95
  }
97
- return t.then((i) => (r(), i), (i) => {
98
- throw r(), i;
96
+ return t.then((s) => (r(), s), (s) => {
97
+ throw r(), s;
99
98
  });
100
99
  }
101
100
  has(t) {
@@ -113,12 +112,12 @@ class l {
113
112
  * @param {AbortSignal} [signal] optional AbortSignal object that aborts the request
114
113
  * @param {statusCallback} a callback to get the current status of a pending async operation
115
114
  */
116
- get(t, e, r, i) {
115
+ get(t, e, r, s) {
117
116
  if (!r && e instanceof AbortSignal)
118
117
  throw new TypeError("second get argument appears to be an AbortSignal, perhaps you meant to pass `null` for the fill data?");
119
- const s = this.cache.get(t);
120
- return s ? s.aborted && !s.settled ? (this.evict(t, s), this.get(t, e, r, i)) : s.settled ? s.promise : (s.aborter.addSignal(r), s.statusReporter.addCallback(i), l.checkSinglePromise(s.promise, r)) : (this.fill(t, e, r, i), l.checkSinglePromise(
121
- //see https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#non-null-assertion-operator-postfix-
118
+ const o = this.cache.get(t);
119
+ return o ? o.aborted && !o.settled ? (this.evict(t, o), this.get(t, e, r, s)) : o.settled ? o.promise : (o.aborter.addSignal(r), o.statusReporter.addCallback(s), c.checkSinglePromise(o.promise, r)) : (this.fill(t, e, r, s), c.checkSinglePromise(
120
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
122
121
  this.cache.get(t).promise,
123
122
  r
124
123
  ));
@@ -145,74 +144,6 @@ class l {
145
144
  return e;
146
145
  }
147
146
  }
148
- var n, d;
149
- function p() {
150
- if (d) return n;
151
- d = 1;
152
- class o {
153
- constructor(e = {}) {
154
- if (!(e.maxSize && e.maxSize > 0))
155
- throw new TypeError("`maxSize` must be a number greater than 0");
156
- this.maxSize = e.maxSize, this.cache = /* @__PURE__ */ new Map(), this.oldCache = /* @__PURE__ */ new Map(), this._size = 0;
157
- }
158
- _set(e, r) {
159
- this.cache.set(e, r), this._size++, this._size >= this.maxSize && (this._size = 0, this.oldCache = this.cache, this.cache = /* @__PURE__ */ new Map());
160
- }
161
- get(e) {
162
- if (this.cache.has(e))
163
- return this.cache.get(e);
164
- if (this.oldCache.has(e)) {
165
- const r = this.oldCache.get(e);
166
- return this.oldCache.delete(e), this._set(e, r), r;
167
- }
168
- }
169
- set(e, r) {
170
- return this.cache.has(e) ? this.cache.set(e, r) : this._set(e, r), this;
171
- }
172
- has(e) {
173
- return this.cache.has(e) || this.oldCache.has(e);
174
- }
175
- peek(e) {
176
- if (this.cache.has(e))
177
- return this.cache.get(e);
178
- if (this.oldCache.has(e))
179
- return this.oldCache.get(e);
180
- }
181
- delete(e) {
182
- const r = this.cache.delete(e);
183
- return r && this._size--, this.oldCache.delete(e) || r;
184
- }
185
- clear() {
186
- this.cache.clear(), this.oldCache.clear(), this._size = 0;
187
- }
188
- *keys() {
189
- for (const [e] of this)
190
- yield e;
191
- }
192
- *values() {
193
- for (const [, e] of this)
194
- yield e;
195
- }
196
- *[Symbol.iterator]() {
197
- for (const e of this.cache)
198
- yield e;
199
- for (const e of this.oldCache) {
200
- const [r] = e;
201
- this.cache.has(r) || (yield e);
202
- }
203
- }
204
- get size() {
205
- let e = 0;
206
- for (const r of this.oldCache.keys())
207
- this.cache.has(r) || e++;
208
- return this._size + e;
209
- }
210
- }
211
- return n = o, n;
212
- }
213
- var m = p();
214
- const C = /* @__PURE__ */ u(m);
215
147
  export {
216
- l as A,
217
- C as L
148
+ c as A
218
149
  };
@@ -0,0 +1,138 @@
1
+ class f {
2
+ constructor(e) {
3
+ this.blob = e;
4
+ }
5
+ async read(e, r = 0) {
6
+ if (!e)
7
+ return new Uint8Array(0);
8
+ const s = r, n = s + e, a = this.blob.slice(s, n);
9
+ return a.bytes ? a.bytes() : new Uint8Array(await a.arrayBuffer());
10
+ }
11
+ async readFile(e) {
12
+ const r = typeof e == "string" ? e : e == null ? void 0 : e.encoding;
13
+ if (r === "utf8")
14
+ return this.blob.text();
15
+ if (r)
16
+ throw new Error(`unsupported encoding: ${r}`);
17
+ return this.blob.bytes ? this.blob.bytes() : new Uint8Array(await this.blob.arrayBuffer());
18
+ }
19
+ async stat() {
20
+ return { size: this.blob.size };
21
+ }
22
+ async close() {
23
+ }
24
+ }
25
+ function d(i) {
26
+ return (typeof i == "object" && i !== null && "message" in i ? i.message : `${i}`).replace(/\.$/, "");
27
+ }
28
+ class u {
29
+ constructor(e, r = {}) {
30
+ this.baseOverrides = {}, this.url = e;
31
+ const s = r.fetch || globalThis.fetch.bind(globalThis);
32
+ r.overrides && (this.baseOverrides = r.overrides), this.fetchImplementation = s;
33
+ }
34
+ async fetch(e, r) {
35
+ const s = (a) => new Error(`${d(a)} fetching ${e}`, { cause: a });
36
+ let n;
37
+ try {
38
+ n = await this.fetchImplementation(e, r);
39
+ } catch (a) {
40
+ if (`${a}`.includes("Failed to fetch")) {
41
+ console.warn(`generic-filehandle: refetching ${e} to attempt to work around chrome CORS header caching bug`);
42
+ try {
43
+ n = await this.fetchImplementation(e, {
44
+ ...r,
45
+ cache: "reload"
46
+ });
47
+ } catch (c) {
48
+ throw s(c);
49
+ }
50
+ } else
51
+ throw s(a);
52
+ }
53
+ return n;
54
+ }
55
+ async read(e, r, s = {}) {
56
+ if (e === 0)
57
+ return new Uint8Array(0);
58
+ const { headers: n = {}, signal: a, overrides: c = {} } = s;
59
+ e < 1 / 0 ? n.range = `bytes=${r}-${r + e - 1}` : e === 1 / 0 && r !== 0 && (n.range = `bytes=${r}-`);
60
+ const t = await this.fetch(this.url, {
61
+ ...this.baseOverrides,
62
+ ...c,
63
+ headers: {
64
+ ...this.baseOverrides.headers,
65
+ ...c.headers,
66
+ ...n
67
+ },
68
+ method: "GET",
69
+ redirect: "follow",
70
+ mode: "cors",
71
+ signal: a
72
+ });
73
+ if (!t.ok)
74
+ throw new Error(`HTTP ${t.status} fetching ${this.url}`);
75
+ if (t.status === 200 && r === 0 || t.status === 206) {
76
+ const l = t.headers.get("content-range"), o = /\/(\d+)$/.exec(l || "");
77
+ o != null && o[1] && (this._stat = {
78
+ size: parseInt(o[1], 10)
79
+ });
80
+ const h = t.bytes ? await t.bytes() : new Uint8Array(await t.arrayBuffer());
81
+ return h.byteLength <= e ? h : h.subarray(0, e);
82
+ }
83
+ throw new Error(t.status === 200 ? `${this.url} fetch returned status 200, expected 206` : `HTTP ${t.status} fetching ${this.url}`);
84
+ }
85
+ async readFile(e = {}) {
86
+ let r, s;
87
+ if (typeof e == "string")
88
+ r = e, s = {};
89
+ else {
90
+ r = e.encoding;
91
+ const { encoding: l, ...o } = e;
92
+ s = o;
93
+ }
94
+ const { headers: n = {}, signal: a, overrides: c = {} } = s, t = await this.fetch(this.url, {
95
+ ...this.baseOverrides,
96
+ ...c,
97
+ headers: {
98
+ ...this.baseOverrides.headers,
99
+ ...c.headers,
100
+ ...n
101
+ },
102
+ method: "GET",
103
+ redirect: "follow",
104
+ mode: "cors",
105
+ signal: a
106
+ });
107
+ if (!t.ok)
108
+ throw new Error(`HTTP ${t.status} fetching ${this.url}`);
109
+ if (r === "utf8")
110
+ return t.text();
111
+ if (r)
112
+ throw new Error(`unsupported encoding: ${r}`);
113
+ return t.bytes ? t.bytes() : new Uint8Array(await t.arrayBuffer());
114
+ }
115
+ async stat() {
116
+ if (!this._stat && (await this.read(10, 0), !this._stat))
117
+ throw new Error(`unable to determine size of file at ${this.url}`);
118
+ return this._stat;
119
+ }
120
+ async close() {
121
+ }
122
+ }
123
+ class w {
124
+ readFile() {
125
+ throw new Error("unimplemented");
126
+ }
127
+ read() {
128
+ throw new Error("unimplemented");
129
+ }
130
+ close() {
131
+ throw new Error("unimplemented");
132
+ }
133
+ }
134
+ export {
135
+ f as BlobFile,
136
+ w as LocalFile,
137
+ u as RemoteFile
138
+ };
@@ -0,0 +1,271 @@
1
+ var _ = Object.defineProperty;
2
+ var I = (r, e, t) => e in r ? _(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var h = (r, e, t) => I(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { LocalFile as d } from "./browser-BRemItdO.js";
5
+ import { I as b, Z as F } from "./inflate-GtwLkvSP.js";
6
+ const w = 65536, S = w * w;
7
+ function g(r, e = 0) {
8
+ const t = r[e] | r[e + 1] << 8 | r[e + 2] << 16 | r[e + 3] << 24;
9
+ return ((r[e + 4] | r[e + 5] << 8 | r[e + 6] << 16 | r[e + 7] << 24) >>> 0) * S + (t >>> 0);
10
+ }
11
+ const u = 1;
12
+ function m(r, e, t) {
13
+ const n = e[u], s = t ? t[u] : 1 / 0;
14
+ return n <= r && s > r ? 0 : n < r ? -1 : 1;
15
+ }
16
+ class B {
17
+ constructor({ filehandle: e }) {
18
+ h(this, "filehandle");
19
+ h(this, "index");
20
+ this.filehandle = e;
21
+ }
22
+ _getIndex() {
23
+ return this.index || (this.index = this._readIndex().catch((e) => {
24
+ throw this.index = void 0, e;
25
+ })), this.index;
26
+ }
27
+ async _readIndex() {
28
+ const e = await this.filehandle.read(8, 0), t = g(e);
29
+ if (!t)
30
+ return [[0, 0]];
31
+ const n = new Array(t + 1);
32
+ n[0] = [0, 0];
33
+ const s = 16 * t;
34
+ if (s > Number.MAX_SAFE_INTEGER)
35
+ throw new TypeError("integer overflow");
36
+ const i = await this.filehandle.read(s, 8);
37
+ for (let a = 0; a < t; a += 1) {
38
+ const o = g(i, a * 16), c = g(i, a * 16 + 8);
39
+ n[a + 1] = [o, c];
40
+ }
41
+ return n;
42
+ }
43
+ async getLastBlock() {
44
+ return (await this._getIndex()).at(-1);
45
+ }
46
+ async getRelevantBlocksForRead(e, t) {
47
+ const n = t + e;
48
+ if (e === 0)
49
+ return [];
50
+ const s = await this._getIndex(), i = [];
51
+ let a = 0, o = s.length - 1, c = Math.floor(s.length / 2), l = m(t, s[c], s[c + 1]);
52
+ for (; l !== 0; )
53
+ l > 0 ? o = c - 1 : l < 0 && (a = c + 1), c = Math.ceil((o - a) / 2) + a, l = m(t, s[c], s[c + 1]);
54
+ i.push(s[c]);
55
+ let f = c + 1;
56
+ for (; f < s.length && (i.push(s[f]), !(s[f][u] >= n)); f += 1)
57
+ ;
58
+ return i[i.length - 1][u] < n && i.push([]), i;
59
+ }
60
+ }
61
+ function E(r) {
62
+ let e = 0;
63
+ for (const t of r)
64
+ e += t.length;
65
+ return e;
66
+ }
67
+ function y(r, e) {
68
+ const t = new Uint8Array(e ?? E(r));
69
+ let n = 0;
70
+ for (const s of r)
71
+ t.set(s, n), n += s.length;
72
+ return t;
73
+ }
74
+ async function k(r) {
75
+ try {
76
+ let e, t = 0, n;
77
+ const s = [];
78
+ let i = 0;
79
+ do {
80
+ const a = r.subarray(t);
81
+ if (n = new b(void 0), { strm: e } = n, n.push(a, F), n.err)
82
+ throw new Error(n.msg);
83
+ t += e.next_in;
84
+ const o = n.result;
85
+ s.push(o), i += o.length;
86
+ } while (e.avail_in);
87
+ return y(s, i);
88
+ } catch (e) {
89
+ throw /incorrect header check/.exec(`${e}`) ? new Error("problem decompressing block: incorrect gzip header check") : e;
90
+ }
91
+ }
92
+ class p {
93
+ constructor({ filehandle: e, gziFilehandle: t }) {
94
+ h(this, "filehandle");
95
+ h(this, "gzi");
96
+ this.filehandle = e, this.gzi = new B({
97
+ filehandle: t
98
+ });
99
+ }
100
+ async _readAndUncompressBlock(e, t) {
101
+ let n = t;
102
+ n || (n = (await this.filehandle.stat()).size);
103
+ const s = n - e, i = await this.filehandle.read(s, e);
104
+ return k(i);
105
+ }
106
+ async read(e, t) {
107
+ const n = await this.gzi.getRelevantBlocksForRead(e, t), s = [];
108
+ for (let i = 0; i < n.length - 1; i += 1) {
109
+ const a = await this._readAndUncompressBlock(n[i][0], n[i + 1][0]), [, o] = n[i], c = o >= t ? 0 : t - o, l = Math.min(t + e, o + a.length) - o;
110
+ c >= 0 && c < a.length && s.push(a.subarray(c, l));
111
+ }
112
+ return y(s);
113
+ }
114
+ }
115
+ function x(r, e) {
116
+ return r.offset + r.lineBytes * Math.floor(e / r.lineLength) + e % r.lineLength;
117
+ }
118
+ async function z(r, e = {}) {
119
+ const t = new TextDecoder("utf8");
120
+ return Object.fromEntries(t.decode(await r.readFile(e)).split(/\r?\n/).map((n) => n.trim()).filter((n) => !!n).map((n) => n.split(" ")).map((n) => {
121
+ var s;
122
+ if ((s = n[0]) != null && s.startsWith(">"))
123
+ throw new Error("found > in sequence name, might have supplied FASTA file for the FASTA index");
124
+ return [
125
+ n[0],
126
+ {
127
+ name: n[0],
128
+ length: +n[1],
129
+ start: 0,
130
+ end: +n[1],
131
+ offset: +n[2],
132
+ lineLength: +n[3],
133
+ lineBytes: +n[4]
134
+ }
135
+ ];
136
+ }));
137
+ }
138
+ class N {
139
+ constructor({ fasta: e, fai: t, path: n, faiPath: s }) {
140
+ if (e)
141
+ this.fasta = e;
142
+ else if (n)
143
+ this.fasta = new d(n);
144
+ else
145
+ throw new Error("Need to pass filehandle for fasta or path to localfile");
146
+ if (t)
147
+ this.fai = t;
148
+ else if (s)
149
+ this.fai = new d(s);
150
+ else if (n)
151
+ this.fai = new d(`${n}.fai`);
152
+ else
153
+ throw new Error("Need to pass filehandle for or path to localfile");
154
+ }
155
+ async _getIndexes(e) {
156
+ return this.indexes || (this.indexes = z(this.fai, e).catch((t) => {
157
+ throw this.indexes = void 0, t;
158
+ })), this.indexes;
159
+ }
160
+ /**
161
+ * @returns array of string sequence names that are present in the index, in
162
+ * which the array index indicates the sequence ID, and the value is the
163
+ * sequence name
164
+ */
165
+ async getSequenceNames(e) {
166
+ return Object.keys(await this._getIndexes(e));
167
+ }
168
+ /**
169
+ * @returns array of string sequence names that are present in the index, in
170
+ * which the array index indicates the sequence ID, and the value is the
171
+ * sequence name
172
+ */
173
+ async getSequenceSizes(e) {
174
+ const t = {}, n = await this._getIndexes(e);
175
+ for (const s of Object.values(n))
176
+ t[s.name] = s.length;
177
+ return t;
178
+ }
179
+ /**
180
+ * @returns array of string sequence names that are present in the index, in
181
+ * which the array index indicates the sequence ID, and the value is the
182
+ * sequence name
183
+ */
184
+ async getSequenceSize(e, t) {
185
+ var s;
186
+ return (s = (await this._getIndexes(t))[e]) == null ? void 0 : s.length;
187
+ }
188
+ /**
189
+ * @param name
190
+ *
191
+ * @returns true if the file contains the given reference sequence name
192
+ */
193
+ async hasReferenceSequence(e, t) {
194
+ return !!(await this._getIndexes(t))[e];
195
+ }
196
+ /**
197
+ * @param seqName
198
+ * @param min
199
+ * @param max
200
+ */
201
+ async getResiduesByName(e, t, n, s) {
202
+ const i = (await this._getIndexes(s))[e];
203
+ return i ? this._fetchFromIndexEntry(i, t, n, s) : void 0;
204
+ }
205
+ //alias for getResiduesByName
206
+ async getSequence(e, t, n, s) {
207
+ return this.getResiduesByName(e, t, n, s);
208
+ }
209
+ async _fetchFromIndexEntry(e, t = 0, n, s) {
210
+ let i = n;
211
+ if (t < 0)
212
+ throw new TypeError("regionStart cannot be less than 0");
213
+ if ((i === void 0 || i > e.length) && (i = e.length), t >= i)
214
+ return "";
215
+ const a = x(e, t), o = x(e, i) - a, l = new TextDecoder("utf8").decode(await this.fasta.read(o, a, s)).replace(/\s+/g, "");
216
+ if (/[^\x20-\x7e]/.test(l.slice(0, 1e3)))
217
+ throw new Error("Non-ASCII characters detected in sequence. The file may be gzip compressed. Use BgzipIndexedFasta for bgzip files, or decompress the file.");
218
+ return l;
219
+ }
220
+ }
221
+ class O extends N {
222
+ constructor({ fasta: e, path: t, fai: n, faiPath: s, gzi: i, gziPath: a }) {
223
+ super({ fasta: e, path: t, fai: n, faiPath: s }), e && i ? this.fasta = new p({
224
+ filehandle: e,
225
+ gziFilehandle: i
226
+ }) : t && a && (this.fasta = new p({
227
+ filehandle: new d(t),
228
+ gziFilehandle: new d(a)
229
+ }));
230
+ }
231
+ }
232
+ function A(r) {
233
+ return r.split(">").filter((e) => /\S/.test(e)).map((e) => {
234
+ const [t, ...n] = e.split(`
235
+ `), [s, ...i] = t.split(" "), a = n.join("").replace(/\s/g, "");
236
+ return {
237
+ id: s,
238
+ description: i.join(" "),
239
+ sequence: a
240
+ };
241
+ });
242
+ }
243
+ class R {
244
+ constructor({ fasta: e, path: t }) {
245
+ if (e)
246
+ this.fasta = e;
247
+ else if (t)
248
+ this.fasta = new d(t);
249
+ else
250
+ throw new Error("Need to pass fasta or path");
251
+ this.data = this.fasta.readFile().then((n) => {
252
+ const i = new TextDecoder("utf8").decode(n);
253
+ return A(i);
254
+ });
255
+ }
256
+ async fetch(e, t, n) {
257
+ const i = (await this.data).find((o) => o.id === e), a = n - t;
258
+ if (!i)
259
+ throw new Error(`no sequence with id ${e} exists`);
260
+ return i.sequence.slice(t, a);
261
+ }
262
+ async getSequenceNames() {
263
+ return (await this.data).map((t) => t.id);
264
+ }
265
+ }
266
+ export {
267
+ O as BgzipIndexedFasta,
268
+ R as FetchableSmallFasta,
269
+ N as IndexedFasta,
270
+ A as parseSmallFasta
271
+ };