taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
98 lines (97 loc) • 2.96 kB
JavaScript
import { s as p, be as o } from "./JBrowsePanel-BNE3gNW1.js";
import { B as l } from "./index-CpJXUZUB.js";
import { c as f } from "./crc32-CxoSWZf_.js";
import { B as w } from "./index-CoM8QAjP.js";
const i = (c, t) => w.from(c, t);
function x(c, t) {
const a = (s, e) => t(i(s), e) >>> 0;
return a.signed = (s, e) => t(i(s), e), a.unsigned = a, a.model = c, a;
}
const g = x("crc-32", f);
class b {
constructor(t) {
this.url = t.url.endsWith("/") ? t.url : `${t.url}/`;
}
async readMeta() {
const t = await this.loadFile("meta.json"), { compress: a, track_names: s } = t;
return { hashHexCharacters: Math.ceil(t.hash_bits / 4), compress: a, tracks: s };
}
async getHashHexCharacters() {
return (await this.readMeta()).hashHexCharacters;
}
async getCompress() {
return (await this.readMeta()).compress;
}
async getTrackNames() {
return (await this.readMeta()).tracks;
}
async get(t) {
return (await this.getBucket(t))[t];
}
async getBucket(t) {
const a = this.hash(t), s = await this.hexToDirPath(a);
return this.loadFile(s);
}
async loadFile(t) {
const a = await fetch(`${this.url}${t}`);
if (!a.ok)
throw new Error(`HTTP ${a.status} ${a.statusText}`);
return a.json();
}
async hexToDirPath(t) {
const a = await this.getHashHexCharacters();
if (a) {
const s = await this.getCompress();
for (; t.length < 8; )
t = `0${t}`;
t = t.slice(8 - a);
const e = [];
for (let r = 0; r < t.length; r += 3)
e.push(t.slice(r, r + 3));
return `${e.join("/")}.json${s ? "z" : ""}`;
}
return "";
}
hash(t) {
return g(t).toString(16).toLowerCase().replace("-", "n");
}
}
class B extends l.BaseAdapter {
constructor(t, a, s) {
super(t, a, s);
const e = p.readConfObject(t, "namesIndexLocation"), { baseUri: r, uri: n } = e;
this.httpMap = new b({
url: r ? new URL(n, r).href : n
});
}
async loadIndexFile(t) {
return this.httpMap.getBucket(t);
}
async searchIndex(t) {
const { searchType: a, queryString: s } = t, e = this.tracksNames || await this.httpMap.getTrackNames(), r = s.toLowerCase(), n = await this.loadIndexFile(r);
return n[r] ? this.formatResults(n[r], e, a) : [];
}
formatResults(t, a, s) {
return [
...s === "exact" ? [] : t.prefix.map((e) => new o({
label: typeof e == "object" ? e.name : e,
matchedAttribute: "name",
matchedObject: { result: e }
})),
...t.exact.map((e) => {
const r = e[0], n = e[1], h = e[3], m = e[4], u = e[5], d = `${h || r}:${m}-${u}`;
return new o({
locString: d,
label: r,
matchedAttribute: "name",
matchedObject: e,
trackId: a[n]
});
})
].filter((e) => e.getLabel() !== "too many matches");
}
}
export {
B as default
};
//# sourceMappingURL=JBrowse1TextSearchAdapter-D51GTsh9.js.map