UNPKG

taxonium-component

Version:

React component for exploring large phylogenetic trees in the browser

145 lines (144 loc) 3.79 kB
import { u as A, bq as I, br as x, bs as B } from "./JBrowsePanel-BNE3gNW1.js"; function q(s, e) { let n = 0, o = 0, t = 0; const c = []; for (let f = 0; f < s.length && t < e.length; f += 2) { const r = +s[f], i = s[f + 1]; if (i === "S" || i === "I") { for (let l = 0; l < r && t < e.length; l++) e[t] === n + l && t++; n += r; } else if (i === "D" || i === "N") o += r; else if (i === "M" || i === "X" || i === "=") { for (let l = 0; l < r && t < e.length; l++) e[t] === n + l && (c.push({ ref: o + l, idx: t }), t++); n += r, o += r; } } return c; } function R(s, e, n) { const o = n === -1 ? A.revcom(e) : e, t = s.split(";"), c = []; for (const f of t) { if (f === "") continue; const r = f.split(","), i = r[0], l = I.exec(i); if (!l) throw new Error(`bad format for MM tag: "${f}"`); const [, a, h, g] = l, m = g.split(/(\d+|.)/); h === "-" && (console.warn("unsupported negative strand modifications"), c.push({ type: "unsupported", positions: [], base: a, strand: h })); for (const p of m) { if (p === "") continue; let d = 0; const b = []; for (let u = 1, M = r.length; u < M; u++) { let y = +r[u]; do (a === "N" || a === o[d]) && y--, d++; while (y >= 0 && d < o.length); if (n === -1) { const P = o.length - d; P >= 0 && b.unshift(P); } else b.push(d - 1); } c.push({ type: p, base: a, strand: h, positions: b }); } } return c; } function w(s) { const e = x(s, "ML", "Ml") || []; if (e) { const n = []; if (typeof e == "string") { const o = e.split(","); for (let t = 0, c = o.length; t < c; t++) n.push(+o[t] / 255); } else for (let o = 0, t = e.length; o < t; o++) n.push(e[o] / 255); return n; } else { const n = x(s, "MP", "Mp"); if (n) { const o = []; for (let t = 0, c = n.length; t < c; t++) { const f = n.charCodeAt(t) - 33; o.push(Math.min(1, f / 50)); } return o; } return; } } function E(s, e) { const n = s.get("strand"), o = s.get("seq"), t = x(s, "MM", "Mm") || "", c = e || B(s.get("CIGAR")); if (o) { const f = R(t, o, n), r = w(s), i = []; let l = 0; for (const { type: a, positions: h } of f) { for (const { ref: g, idx: m } of q(c, h)) { const p = (r == null ? void 0 : r[l + (n === -1 ? h.length - 1 - m : m)]) || 0; if (!i[g]) i[g] = { type: a, prob: p, allProbs: [p] }; else { const d = i[g]; i[g] = { allProbs: [...d.allProbs, p], prob: Math.max(d.prob, p), type: d.prob > p ? d.type : a }; } } l += h.length; } return i; } } function N(s, e) { const n = s.get("start"), o = s.get("end"), t = s.get("strand"), c = o - n, f = x(s, "MM", "Mm") || "", r = [], i = [], l = [], a = [], h = s.get("seq"); if (h) { const g = w(s), m = R(f, h, t); let p = 0; for (const { type: d, positions: b } of m) { for (const { ref: u, idx: M } of q(e, b)) { if (u < 0 || u >= c) continue; const P = p + (t === -1 ? b.length - 1 - M : M), v = (g == null ? void 0 : g[P]) || 0; d === "m" ? (r[u] = 1, l[u] = v) : d === "h" && (i[u] = 1, a[u] = v); } p += b.length; } } return { methBins: r, hydroxyMethBins: i, methProbs: l, hydroxyMethProbs: a }; } export { N as a, E as g }; //# sourceMappingURL=getMethBins-CvqMYb7k.js.map