taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
494 lines (493 loc) • 17.5 kB
JavaScript
import { u as K, a4 as H } from "./JBrowsePanel-uJIA-L6s.js";
import { g as z } from "./index-dFotuATn.js";
/*!
* isobject <https://github.com/jonschlinkert/isobject>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
var $, E;
function M() {
return E || (E = 1, $ = function(t) {
return t != null && typeof t == "object" && Array.isArray(t) === !1;
}), $;
}
/*!
* get-value <https://github.com/jonschlinkert/get-value>
*
* Copyright (c) 2014-2018, Jon Schlinkert.
* Released under the MIT License.
*/
var J, V;
function N() {
if (V) return J;
V = 1;
const e = M();
J = function(n, l, u) {
if (e(u) || (u = { default: u }), !i(n))
return typeof u.default < "u" ? u.default : n;
typeof l == "number" && (l = String(l));
const y = Array.isArray(l), d = typeof l == "string", w = u.separator || ".", p = u.joinChar || (typeof w == "string" ? w : ".");
if (!d && !y)
return n;
if (d && l in n)
return s(l, n, u) ? n[l] : u.default;
let c = y ? l : r(l, w, u), o = c.length, a = 0;
do {
let f = c[a];
for (typeof f == "number" && (f = String(f)); f && f.slice(-1) === "\\"; )
f = t([f.slice(0, -1), c[++a] || ""], p, u);
if (f in n) {
if (!s(f, n, u))
return u.default;
n = n[f];
} else {
let m = !1, h = a + 1;
for (; h < o; )
if (f = t([f, c[h++]], p, u), m = f in n) {
if (!s(f, n, u))
return u.default;
n = n[f], a = h - 1;
break;
}
if (!m)
return u.default;
}
} while (++a < o && i(n));
return a === o ? n : u.default;
};
function t(n, l, u) {
return typeof u.join == "function" ? u.join(n) : n[0] + l + n[1];
}
function r(n, l, u) {
return typeof u.split == "function" ? u.split(n) : n.split(l);
}
function s(n, l, u) {
return typeof u.isValid == "function" ? u.isValid(n, l) : !0;
}
function i(n) {
return e(n) || Array.isArray(n) || typeof n == "function";
}
return J;
}
var X = N();
const D = /* @__PURE__ */ z(X);
/*!
* is-primitive <https://github.com/jonschlinkert/is-primitive>
*
* Copyright (c) 2014-present, Jon Schlinkert.
* Released under the MIT License.
*/
var F, _;
function Y() {
return _ || (_ = 1, F = function(t) {
return typeof t == "object" ? t === null : typeof t != "function";
}), F;
}
/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
var A, L;
function Q() {
if (L) return A;
L = 1;
var e = M();
function t(r) {
return e(r) === !0 && Object.prototype.toString.call(r) === "[object Object]";
}
return A = function(s) {
var i, n;
return !(t(s) === !1 || (i = s.constructor, typeof i != "function") || (n = i.prototype, t(n) === !1) || n.hasOwnProperty("isPrototypeOf") === !1);
}, A;
}
/*!
* set-value <https://github.com/jonschlinkert/set-value>
*
* Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
* Released under the MIT License.
*/
var x, T;
function Z() {
if (T) return x;
T = 1;
const { deleteProperty: e } = Reflect, t = Y(), r = Q(), s = (o) => typeof o == "object" && o !== null || typeof o == "function", i = (o) => o === "__proto__" || o === "constructor" || o === "prototype", n = (o) => {
if (!t(o))
throw new TypeError("Object keys must be strings or symbols");
if (i(o))
throw new Error(`Cannot set unsafe key: "${o}"`);
}, l = (o) => Array.isArray(o) ? o.flat().map(String).join(",") : o, u = (o, a) => {
if (typeof o != "string" || !a) return o;
let f = o + ";";
return a.arrays !== void 0 && (f += `arrays=${a.arrays};`), a.separator !== void 0 && (f += `separator=${a.separator};`), a.split !== void 0 && (f += `split=${a.split};`), a.merge !== void 0 && (f += `merge=${a.merge};`), a.preservePaths !== void 0 && (f += `preservePaths=${a.preservePaths};`), f;
}, y = (o, a, f) => {
const m = l(a ? u(o, a) : o);
n(m);
const h = c.cache.get(m) || f();
return c.cache.set(m, h), h;
}, d = (o, a = {}) => {
const f = a.separator || ".", m = f === "/" ? !1 : a.preservePaths;
if (typeof o == "string" && m !== !1 && /\//.test(o))
return [o];
const h = [];
let b = "";
const k = (S) => {
let j;
S.trim() !== "" && Number.isInteger(j = Number(S)) ? h.push(j) : h.push(S);
};
for (let S = 0; S < o.length; S++) {
const j = o[S];
if (j === "\\") {
b += o[++S];
continue;
}
if (j === f) {
k(b), b = "";
continue;
}
b += j;
}
return b && k(b), h;
}, w = (o, a) => a && typeof a.split == "function" ? a.split(o) : typeof o == "symbol" ? [o] : Array.isArray(o) ? o : y(o, a, () => d(o, a)), p = (o, a, f, m) => {
if (n(a), f === void 0)
e(o, a);
else if (m && m.merge) {
const h = m.merge === "function" ? m.merge : Object.assign;
h && r(o[a]) && r(f) ? o[a] = h(o[a], f) : o[a] = f;
} else
o[a] = f;
return o;
}, c = (o, a, f, m) => {
if (!a || !s(o)) return o;
const h = w(a, m);
let b = o;
for (let k = 0; k < h.length; k++) {
const S = h[k], j = h[k + 1];
if (n(S), j === void 0) {
p(b, S, f, m);
break;
}
if (typeof j == "number" && !Array.isArray(b[S])) {
b = b[S] = [];
continue;
}
s(b[S]) || (b[S] = {}), b = b[S];
}
return o;
};
return c.split = w, c.cache = /* @__PURE__ */ new Map(), c.clear = () => {
c.cache = /* @__PURE__ */ new Map();
}, x = c, x;
}
var ee = Z();
const re = /* @__PURE__ */ z(ee);
function I(e) {
return (e == null ? void 0 : e.label) && typeof e.label == "string";
}
function te(e) {
return (e == null ? void 0 : e.url) && typeof e.url == "string";
}
function O(e, t) {
for (const r of Object.keys(t))
r in e && typeof t[r] == "object" && typeof e[r] == "object" ? O(e[r], t[r]) : (e[r] === void 0 || t[r] !== void 0) && (e[r] = t[r]);
return e;
}
function se(e, t) {
return e.replaceAll(/{([\s\w.]+)}/g, (r, s) => {
s = s.replaceAll(/\s+/g, "");
const i = D(t, s);
if (i !== void 0)
return typeof i == "function" ? i(s) : i;
if (t.callback) {
const n = t.callback.call(this, s);
if (n !== void 0)
return n;
}
return r;
});
}
function ne(e, t) {
if (typeof e == "string") {
let r;
try {
r = JSON.parse(e);
} catch (s) {
throw new Error(`${s} when parsing configuration.`);
}
return g(r, t);
}
return g(e, t);
}
function ie(e, t) {
let r;
try {
r = ae(e, t);
} catch (s) {
throw new Error(`${s} when parsing configuration.`);
}
return g(r, t);
}
function oe(e) {
return e === "include";
}
function ae(e, t) {
let r = [], s, i, n;
const l = { tracks: {} };
let u;
function y() {
if (n !== void 0) {
let d;
try {
const w = /^json:(.+)/i.exec(n);
if (w ? d = JSON.parse(w[1]) : /^[+-]?[\d.,]+([eE][-+]?\d+)?$/.test(n) ? d = Number.parseFloat(n.replaceAll(",", "")) : d = n, !s)
throw new Error(`Error parsing in section ${r.join(" - ")}`);
const p = [...r, ...s].join(".");
if (i === "+=") {
let c = D(l, p);
c ? Array.isArray(c) || (c = [c]) : c = [], c.push(d), d = c;
}
d === "true" && (d = !0), d === "false" && (d = !1), re(l, p, d);
} catch {
throw new Error(`syntax error${t ? ` in ${t}` : ""}${u ? ` at line ${u - 1}` : ""}`);
}
}
}
for (const [d, w] of e.split(/\n|\r\n|\r/).entries()) {
u = d + 1;
const p = w.replace(/^\s*#.+/, "");
let c;
if (c = /^\s*\[([^\]]+)/.exec(p))
y(), s = void 0, n = void 0, r = c[1].trim().split(/\s*\.\s*/), r.length === 1 && r[0].toLowerCase() === "general" && (r = []);
else if (c = p.match(n === void 0 ? /^([^+=]+)(\+?=)(.*)/ : /^(\S[^+=]+)(\+?=)(.*)/))
y(), s = c[1].trim().split(/\s*\.\s*/), [, , i] = c, oe([...r, ...s].join(".")) && (i = "+="), n = c[3].trim();
else if (s !== void 0 && (c = /^\s{0,4}\+\s*(.+)/.exec(p)))
y(), i = "+=", n = c[1].trim();
else if (n !== void 0 && (c = /^\s+(\S.*)/.exec(p))) {
const o = c[1];
n += n.length ? ` ${o.trim()}` : o.trim();
} else
y(), s = void 0, n = void 0;
}
return y(), l;
}
function g(e, t) {
if (e.tracks && !Array.isArray(e.tracks))
if (I(e.tracks))
e.tracks = [e.tracks];
else {
const s = [];
for (const i of Object.keys(e.tracks)) {
const n = e.tracks[i];
I(n) ? s.push(n) : s.push({ label: i, ...n });
}
e.tracks = s;
}
const r = e.trackMetadata;
if (r != null && r.sources) {
if (typeof r.sources == "string" && (r.sources = [r.sources]), te(r.sources) && (r.sources = [r.sources]), !Array.isArray(r.sources)) {
const s = [];
for (const i of Object.keys(r.sources)) {
const n = r.sources[i];
"name" in n || (n.name = i), s.push(n);
}
r.sources = s;
}
r.sources = r.sources.map((s) => {
if (typeof s == "string") {
const i = { url: s }, n = /\.(\w+)$/.exec(s);
return n && (i.type = n[1].toLowerCase()), i;
}
return s;
});
}
if (e.sourceUrl = e.sourceUrl || t, e.sourceUrl.startsWith("/") && (e.sourceUrl = new URL(e.sourceUrl, window.location.href).href), e.baseUrl = e.baseUrl || new URL(".", e.sourceUrl).href, e.baseUrl.length && !e.baseUrl.endsWith("/") && (e.baseUrl += "/"), e.sourceUrl) {
const s = [];
e.tracks && s.push(...e.tracks), e.stores && s.push(...Object.values(e.stores)), e.names && s.push(e.names);
for (const i of s)
i.baseUrl || (i.baseUrl = e.baseUrl || "/");
e.refSeqs && typeof e.refSeqs == "string" && (e.refSeqs = new URL(e.refSeqs, e.sourceUrl).href), e.nameUrl && (e.nameUrl = new URL(e.nameUrl, e.sourceUrl).href);
}
e.stores = e.stores || {};
for (let s of e.tracks || []) {
if (s.config) {
const n = s.config;
s.config = void 0, s = { ...n, ...s };
}
if (s.store)
continue;
let i;
s.type === "FeatureTrack" ? i = "JBrowse/View/Track/HTMLFeatures" : s.type === "ImageTrack" ? i = "JBrowse/View/Track/FixedImage" : s.type === "ImageTrack.Wiggle" ? i = "JBrowse/View/Track/FixedImage/Wiggle" : s.type === "SequenceTrack" ? i = "JBrowse/View/Track/Sequence" : i = W("JBrowse/View/Track", s.type), s.type = i, R(e, s), s.histograms && (s.histograms.baseUrl || (s.histograms.baseUrl = s.baseUrl), R(e, s.histograms));
}
return e;
}
function W(e, t) {
return t ? (t.includes("/") || (t = `${e}/${t}`), t = t.replace(/^\//, ""), t) : "";
}
function ue(e, t) {
var r, s;
return e ? !((r = e.type) === null || r === void 0) && r.includes("/FixedImage") ? `JBrowse/Store/TiledImage/Fixed${e.backendVersion === 0 ? "_v0" : ""}` : /\.jsonz?$/i.test(t) ? `JBrowse/Store/SeqFeature/NCList${e.backendVersion === 0 ? "_v0" : ""}` : /\.bam$/i.test(t) ? "JBrowse/Store/SeqFeature/BAM" : /\.cram$/i.test(t) ? "JBrowse/Store/SeqFeature/CRAM" : /\.gff3?$/i.test(t) ? "JBrowse/Store/SeqFeature/GFF3" : /\.bed$/i.test(t) ? "JBrowse/Store/SeqFeature/BED" : /\.vcf.b?gz$/i.test(t) ? "JBrowse/Store/SeqFeature/VCFTabix" : /\.gff3?.b?gz$/i.test(t) ? "JBrowse/Store/SeqFeature/GFF3Tabix" : /\.bed.b?gz$/i.test(t) ? "JBrowse/Store/SeqFeature/BEDTabix" : /\.(bw|bigwig)$/i.test(t) ? "JBrowse/Store/SeqFeature/BigWig" : /\.(bb|bigbed)$/i.test(t) ? "JBrowse/Store/SeqFeature/BigBed" : /\.(fa|fasta)$/i.test(t) ? "JBrowse/Store/SeqFeature/IndexedFasta" : /\.(fa|fasta)\.b?gz$/i.test(t) ? "JBrowse/Store/SeqFeature/BgzipIndexedFasta" : /\.2bit$/i.test(t) ? "JBrowse/Store/SeqFeature/TwoBit" : !((s = e.type) === null || s === void 0) && s.endsWith("/Sequence") ? "JBrowse/Store/Sequence/StaticChunked" : "" : "";
}
function R(e, t) {
var r;
const { urlTemplate: s = "" } = t, i = t.storeClass ? W("JBrowse/Store", t.storeClass) : ue(t, s);
if (!i) {
console.warn(`Unable to determine an appropriate data store to use with track '${t.label}', please explicitly specify a storeClass in the configuration.`);
return;
}
const n = { ...t, type: i };
n.name = (i === "JBrowse/Store/Sequence/StaticChunked" || i === "JBrowse/Store/Sequence/IndexedFasta" || i === "JBrowse/Store/SeqFeature/IndexedFasta" || i === "JBrowse/Store/SeqFeature/BgzipIndexedFasta" || i === "JBrowse/Store/SeqFeature/TwoBit" || i === "JBrowse/Store/Sequence/TwoBit" || t.useAsRefSeqStore) && !(!((r = e.stores) === null || r === void 0) && r.refseqs) ? "refseqs" : `store${K.objectHash(n)}`, e.stores || (e.stores = {}), e.stores[n.name] = n, t.store = n.name;
}
function v(e) {
return e.uri !== void 0;
}
function U(e) {
return e.localPath !== void 0;
}
async function Se(e = { uri: "", locationType: "UriLocation" }, t = {
include: ["{dataRoot}/trackList.json", "{dataRoot}/tracks.conf"]
}, r = { uri: "", locationType: "UriLocation" }) {
const s = "uri" in e ? "uri" : "localPath", i = JSON.parse(JSON.stringify(e));
let n = "";
if (v(e) && (n = e.uri), U(e) && (n = e.localPath), n.endsWith("/") && (i[s] = n.slice(0, -1)), v(r) && r.uri || U(r) && r.localPath) {
const u = "uri" in r ? "uri" : "localPath";
let y = "";
v(r) && (y = r.uri), U(r) && (y = r.localPath), y.endsWith("/") && (y = y.slice(0, -1));
let d = {};
for (const w of ["jbrowse.conf", "jbrowse_conf.json"]) {
let p = null;
try {
p = await G({
[u]: `${y}/${w}`
});
} catch {
console.error(`tried to access ${y}/${w}, but failed`);
}
d = B(d, p) || {};
}
return i[s] && (d.dataRoot = i[s]), C(d);
}
const l = g(t, window.location.href);
return i[s] && (l.dataRoot = i[s]), C(l);
}
async function C(e, t = ye) {
const r = O(structuredClone(t), e);
let s = await ce(r);
return s = B(s, e) || s, q(s, s), we(s), s;
}
async function G(e) {
const t = await H.openLocation(e).readFile("utf8");
return v(e) ? P(t, e.uri) : U(e) ? P(t, e.localPath) : P(t);
}
function P(e, t = "") {
return e.trim().startsWith("{") ? ne(e, t) : ie(e, t);
}
function B(e, t) {
if (t === null)
return null;
e === null && (e = {});
for (const r of Object.keys(t))
if (r === "tracks" && r in e) {
const s = e[r] || [], i = t[r] || [];
if (Array.isArray(s) && Array.isArray(i))
e[r] = fe(s, i);
else
throw new Error(`Track config has not been properly regularized: ${s} ${i}`);
} else !de(r) && r in e && typeof t[r] == "object" && typeof e[r] == "object" ? e[r] = O(e[r], t[r]) : r === "dataRoot" ? (e[r] === void 0 || e[r] === "data" && t[r] !== void 0) && (e[r] = t[r]) : (e[r] === void 0 || t[r] !== void 0) && (e[r] = t[r]);
return e;
}
function fe(e, t) {
if (!t.length)
return e;
const r = {};
for (const [s, i] of e.entries())
i.index = s, r[i.label] = i;
for (const s of t) {
const i = r[s.label];
i ? B(i, s) : e.push(s);
}
return e;
}
async function ce(e) {
e = structuredClone(e);
async function t(r, s) {
const i = r.sourceUrl || r.baseUrl;
if (!i)
throw new Error(`Could not determine source URL: ${JSON.stringify(r)}`);
const n = B(structuredClone(s), r);
if (!n)
throw new Error("Problem merging configs");
const l = q(le(r.include || []), n);
r.include = void 0;
const u = l.map(async (d) => {
d.cacheBuster = e.cacheBuster;
const w = await G({
uri: new URL(d.url, i).href,
locationType: "UriLocation"
});
return t(w, n);
}), y = await Promise.all(u);
for (const d of y)
r = B(r, d) || r;
return r;
}
return t(e, {});
}
function le(e) {
return e ? (Array.isArray(e) || (e = [e]), e.map((t) => (typeof t == "string" && (t = { url: t }), "format" in t || (t.format = t.url.endsWith(".conf") ? "conf" : "JB_json"), t.format === "JB_json" && !("version" in t) && (t.version = 1), t))) : [];
}
function q(e, t) {
if (!e)
return e;
if (Array.isArray(e))
for (let r = 0; r < e.length; r += 1)
e[r] = q(e[r], t);
else if (typeof e == "object") {
const r = e;
for (const s of Object.keys(r))
r[s] = q(r[s], t);
} else if (typeof e == "string")
return se(e, t);
return e;
}
function de(e) {
return e === "datasets";
}
const ye = {
tracks: [],
containerID: "GenomeBrowser",
dataRoot: "data",
show_tracklist: !0,
show_nav: !0,
show_menu: !0,
show_overview: !0,
show_fullviewlink: !0,
update_browser_title: !0,
updateBrowserURL: !0,
refSeqs: "{dataRoot}/seq/refSeqs.json",
include: ["jbrowse.conf", "jbrowse_conf.json"],
nameUrl: "{dataRoot}/names/root.json",
datasets: {
_DEFAULT_EXAMPLES: !0,
volvox: { url: "?data=sample_data/json/volvox", name: "Volvox Example" },
modencode: {
url: "?data=sample_data/json/modencode",
name: "MODEncode Example"
},
yeast: { url: "?data=sample_data/json/yeast", name: "Yeast Example" }
},
highlightSearchedRegions: !1,
highResolutionMode: "auto"
};
function we(e) {
if (e.tracks || (e.tracks = []), !e.baseUrl)
throw new Error("Must provide a `baseUrl` in configuration");
}
export {
C as createFinalConfig,
G as fetchConfigFile,
Se as fetchJb1,
P as parseJb1
};
//# sourceMappingURL=jb1ConfigLoad-DsWxhvl2.js.map