jbrowse-plugin-protein3d 1.20.0 → 1.22.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.
@@ -1,8 +1,8 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import { observer } from 'mobx-react';
3
- import { placeLabels } from '../labelLayout';
3
+ import { nearestInFront, placeLabels } from '../labelLayout';
4
4
  import loadMolstar from '../loadMolstar';
5
- import { labelAnchors } from '../sessionHighlights';
5
+ import { copyCenters, labelAnchors, pickHitsCopy } from '../sessionHighlights';
6
6
  const FONT_SIZE = 13;
7
7
  const FONT = `${FONT_SIZE}px Roboto, Helvetica, Arial, sans-serif`;
8
8
  const PAD_X = 5;
@@ -18,10 +18,10 @@ function textWidth(text) {
18
18
  }
19
19
  /**
20
20
  * The session highlights' labels over the Mol* canvas, in screen pixels: a dot
21
- * on each labelled residue, a leader, and the label in a box of the
22
- * highlight's color, placed apart by placeLabels. Mol*'s own text is
23
- * depth-tested, sized in Å and never moves off another label. The residues
24
- * are projected again on every frame Mol* draws.
21
+ * on the nearest visible copy of each labelled residue, a leader, and the
22
+ * label in a box of the highlight's color, placed apart by placeLabels. Mol*'s
23
+ * own text is depth-tested, sized in Å and never moves off another label. The
24
+ * residues are projected again on every frame Mol* draws.
25
25
  */
26
26
  const HighlightLabels = observer(function HighlightLabels({ model, }) {
27
27
  const plugin = model.molstarPluginContext;
@@ -31,52 +31,97 @@ const HighlightLabels = observer(function HighlightLabels({ model, }) {
31
31
  if (!plugin || !canvas3d) {
32
32
  return;
33
33
  }
34
- let getBoundary;
34
+ let molstar;
35
35
  let cancelled = false;
36
+ // the chains whose copy Mol* last saw unoccluded, by anchor ref
37
+ let visible = new Map();
36
38
  const projected = [0, 0, 0, 0];
39
+ const copiesOnScreen = () => {
40
+ const { camera } = canvas3d;
41
+ const pixelRatio = canvas3d.webgl.pixelRatio;
42
+ const height = camera.viewport.height / pixelRatio;
43
+ return [...labelAnchors(plugin)].map(([ref, anchor]) => {
44
+ const loci = plugin.state.data.cells.get(ref)?.obj?.data?.[0]?.loci;
45
+ const copies = (loci && molstar ? copyCenters(molstar, loci) : []).map(({ chain, center }) => {
46
+ camera.project(projected, center);
47
+ return {
48
+ chain,
49
+ x: projected[0] / pixelRatio,
50
+ y: height - projected[1] / pixelRatio,
51
+ depth: projected[2],
52
+ visible: visible.get(ref)?.has(chain),
53
+ };
54
+ });
55
+ return { ref, ...anchor, copies };
56
+ });
57
+ };
37
58
  const place = () => {
38
- if (!getBoundary) {
39
- return;
40
- }
41
59
  const { camera } = canvas3d;
42
60
  const pixelRatio = canvas3d.webgl.pixelRatio;
43
61
  const width = camera.viewport.width / pixelRatio;
44
62
  const height = camera.viewport.height / pixelRatio;
45
63
  const points = [];
46
- for (const [ref, { label, color }] of labelAnchors(plugin)) {
47
- const loci = plugin.state.data.cells.get(ref)?.obj?.data?.[0]?.loci;
48
- if (loci) {
49
- camera.project(projected, getBoundary(loci).sphere.center);
50
- const depth = projected[2];
51
- if (depth > 0 && depth < 1) {
52
- points.push({
53
- ref,
54
- label,
55
- color,
56
- x: projected[0] / pixelRatio,
57
- y: height - projected[1] / pixelRatio,
58
- width: textWidth(label) + PAD_X * 2,
59
- });
60
- }
64
+ for (const { ref, label, color, copies } of copiesOnScreen()) {
65
+ const nearest = nearestInFront(copies);
66
+ if (nearest) {
67
+ points.push({
68
+ ref,
69
+ label,
70
+ color,
71
+ x: nearest.x,
72
+ y: nearest.y,
73
+ width: textWidth(label) + PAD_X * 2,
74
+ });
61
75
  }
62
76
  }
63
77
  const placed = placeLabels(points.map(p => ({ ...p, height: BOX_HEIGHT })), { width, height });
64
78
  const next = points.map((p, i) => ({ ...p, ...placed[i] }));
65
79
  setDrawn(prev => JSON.stringify(prev) === JSON.stringify(next) ? prev : next);
66
80
  };
81
+ // Once the view settles, ask Mol*'s picking which copies show at their
82
+ // own centre: the nearest copy of haemoglobin's Val6 can sit behind
83
+ // another chain, and a label there points at cartoon
84
+ const findVisible = () => {
85
+ const next = new Map();
86
+ for (const { ref, labelSeqIds, copies } of copiesOnScreen()) {
87
+ const seen = new Set();
88
+ for (const { chain, x, y, depth } of copies) {
89
+ const pick = depth > 0 && depth < 1
90
+ ? canvas3d.identify([x, y])
91
+ : undefined;
92
+ const { loci } = pick ? canvas3d.getLoci(pick.id) : {};
93
+ if (molstar && pickHitsCopy(molstar, loci, chain, labelSeqIds)) {
94
+ seen.add(chain);
95
+ }
96
+ }
97
+ next.set(ref, seen);
98
+ }
99
+ const key = (m) => JSON.stringify([...m].map(([ref, chains]) => [ref, [...chains]]));
100
+ if (key(next) !== key(visible)) {
101
+ visible = next;
102
+ place();
103
+ }
104
+ };
105
+ let settle;
106
+ const onDraw = () => {
107
+ place();
108
+ clearTimeout(settle);
109
+ settle = setTimeout(findVisible, 250);
110
+ };
67
111
  loadMolstar()
68
- .then(molstar => {
112
+ .then(loaded => {
69
113
  if (!cancelled) {
70
- getBoundary = loci => molstar.StructureElement.Loci.getBoundary(loci);
71
- place();
114
+ molstar = loaded;
115
+ onDraw();
72
116
  }
73
117
  })
74
118
  .catch((e) => {
75
119
  console.error(e);
76
120
  });
77
- const subscription = canvas3d.didDraw.subscribe(place);
121
+ const subscription = canvas3d.didDraw.subscribe(onDraw);
78
122
  return () => {
79
123
  cancelled = true;
124
+ clearTimeout(settle);
80
125
  subscription.unsubscribe();
81
126
  };
82
127
  }, [plugin]);
@@ -86,7 +131,7 @@ const HighlightLabels = observer(function HighlightLabels({ model, }) {
86
131
  width: '100%',
87
132
  height: '100%',
88
133
  pointerEvents: 'none',
89
- } }, drawn.map(({ ref, label, color, x, y, width, boxX, boxY, leaderX, leaderY }) => (React.createElement("g", { key: ref },
134
+ } }, drawn.map(({ ref, label, color, x, y, width, boxX, boxY, leaderX, leaderY }) => (React.createElement("g", { key: ref, "data-highlight-label": label },
90
135
  React.createElement("line", { x1: x, y1: y, x2: leaderX, y2: leaderY, stroke: "#000", strokeWidth: 1.5 }),
91
136
  React.createElement("circle", { cx: x, cy: y, r: 3.5, fill: color, stroke: "#000" }),
92
137
  React.createElement("rect", { x: boxX, y: boxY, width: width, height: BOX_HEIGHT, rx: 4, fill: "#fff", fillOpacity: 0.92, stroke: color, strokeWidth: 2 }),
@@ -54,3 +54,20 @@ export function placeLabels(requests, bounds) {
54
54
  return { boxX: box.x, boxY: box.y, leaderX, leaderY };
55
55
  });
56
56
  }
57
+ /**
58
+ * Of a residue's copies projected to the screen, the one nearest the viewer
59
+ * among those Mol* last saw unoccluded, or the nearest of all when none was.
60
+ * A copy behind the camera or past the far plane (depth outside 0..1) never
61
+ * takes the label.
62
+ */
63
+ export function nearestInFront(copies) {
64
+ const front = copies.filter(c => c.depth > 0 && c.depth < 1);
65
+ const pool = front.some(c => c.visible) ? front.filter(c => c.visible) : front;
66
+ let nearest;
67
+ for (const copy of pool) {
68
+ if (copy.depth < (nearest?.depth ?? 1)) {
69
+ nearest = copy;
70
+ }
71
+ }
72
+ return nearest;
73
+ }
@@ -2,11 +2,11 @@
2
2
  * The session's highlights on a structure. `session.highlights` is one list of
3
3
  * labelled genome regions that every view draws on its own terms: a band on
4
4
  * the genome, a column on the alignment, and here the residues the region
5
- * codes for. An unlabelled highlight draws its residues as sticks on every
6
- * chain that has them. A labelled one draws them as spheres on one chain, the
7
- * cartoon around them fades, and HighlightLabels writes the label over the
8
- * canvas with a leader to the spheres, so a figure or a shared session names
9
- * the same position in each view.
5
+ * codes for, on every chain that has them: sticks for an unlabelled
6
+ * highlight, and spheres for a labelled one, with the cartoon around them
7
+ * faded and the label written over the canvas by HighlightLabels on the copy
8
+ * nearest the viewer. A figure or a shared session thus names the same
9
+ * position in each view.
10
10
  *
11
11
  * Every Mol* cell this makes is tagged `SESSION_HIGHLIGHTS_TAG`. A change
12
12
  * rebuilds all of them, since highlights change by hand and a structure holds
@@ -71,32 +71,48 @@ export function labelAnchors(plugin) {
71
71
  }
72
72
  return anchors;
73
73
  }
74
+ /**
75
+ * Each chain's copy of the residues in `loci` and its centre, in the order
76
+ * the structure holds the chains: haemoglobin's four β chains each carry
77
+ * Val6, and the label goes on the copy nearest the viewer
78
+ */
79
+ export function copyCenters(molstar, loci) {
80
+ const { StructureElement } = molstar;
81
+ const byChain = new Map();
82
+ for (const element of loci.elements) {
83
+ const chain = element.unit.chainGroupId;
84
+ byChain.set(chain, [...(byChain.get(chain) ?? []), element]);
85
+ }
86
+ return [...byChain.entries()].map(([chain, elements]) => ({
87
+ chain,
88
+ center: StructureElement.Loci.getBoundary(StructureElement.Loci(loci.structure, elements)).sphere.center,
89
+ }));
90
+ }
91
+ /**
92
+ * Whether a Mol* pick landed on `chain`'s copy of the residues: a hit on the
93
+ * same chain's cartoon in front of them does not count
94
+ */
95
+ export function pickHitsCopy(molstar, loci, chain, labelSeqIds) {
96
+ const { StructureElement, StructureProperties: SP } = molstar;
97
+ if (!loci || !StructureElement.Loci.is(loci)) {
98
+ return false;
99
+ }
100
+ const location = StructureElement.Loci.getFirstLocation(loci);
101
+ return (location?.unit.chainGroupId === chain &&
102
+ labelSeqIds.includes(SP.residue.label_seq_id(location)));
103
+ }
74
104
  // how far around a labelled residue the cartoon fades, and how much
75
105
  const FADE_RADIUS = 12;
76
106
  const FADE_TRANSPARENCY = 0.75;
77
107
  /**
78
108
  * Make each structure's highlight marks match `marks`: the old ones go, and
79
- * each mark gets its residues in its color. A labelled mark also gets an
80
- * anchor cell, the selection HighlightLabels points its label at, and fades
81
- * the cartoon around it.
109
+ * each mark gets its residues in its color on every chain that has them. A
110
+ * labelled mark also gets an anchor cell, the selection HighlightLabels
111
+ * points its label at, and fades the cartoon around it.
82
112
  */
83
113
  export async function syncSessionHighlightMarks({ plugin, structures, }) {
84
114
  const molstar = await loadMolstar();
85
- const { Color, MolScriptBuilder: MS, Script, StateSelection, StateTransforms, StructureElement, StructureProperties: SP, createStructureRepresentationParams, formatMolScript, } = molstar;
86
- // the first chain of an entity: a homo-oligomer such as haemoglobin's four
87
- // β chains carries a highlighted residue once per chain, and a label on
88
- // each copy would name four places, so the label goes on the first
89
- const firstChain = (structure, entityId) => {
90
- const l = StructureElement.Location.create(structure);
91
- for (const unit of structure.units) {
92
- l.unit = unit;
93
- l.element = unit.elements[0];
94
- if (SP.entity.id(l) === entityId) {
95
- return SP.chain.label_asym_id(l);
96
- }
97
- }
98
- return undefined;
99
- };
115
+ const { Color, MolScriptBuilder: MS, Script, StateSelection, StateTransforms, createStructureRepresentationParams, formatMolScript, } = molstar;
100
116
  const anchors = labelAnchors(plugin);
101
117
  const update = plugin.state.data.build();
102
118
  const existing = plugin.state.data.select(StateSelection.Generators.root.subtree().withTag(SESSION_HIGHLIGHTS_TAG));
@@ -111,23 +127,13 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
111
127
  }
112
128
  const labelled = [];
113
129
  for (const { entityId, labelSeqIds, label, color } of marks) {
114
- const chain = label ? firstChain(molstarStructure, entityId) : undefined;
115
- const residues = MS.core.set.has([
116
- MS.set(...labelSeqIds),
117
- MS.ammp('label_seq_id'),
118
- ]);
119
- const expression = MS.struct.generator.atomGroups(chain
120
- ? {
121
- 'chain-test': MS.core.rel.eq([MS.ammp('label_asym_id'), chain]),
122
- 'residue-test': residues,
123
- }
124
- : {
125
- 'entity-test': MS.core.rel.eq([
126
- MS.ammp('label_entity_id'),
127
- entityId,
128
- ]),
129
- 'residue-test': residues,
130
- });
130
+ const expression = MS.struct.generator.atomGroups({
131
+ 'entity-test': MS.core.rel.eq([MS.ammp('label_entity_id'), entityId]),
132
+ 'residue-test': MS.core.set.has([
133
+ MS.set(...labelSeqIds),
134
+ MS.ammp('label_seq_id'),
135
+ ]),
136
+ });
131
137
  update
132
138
  .to(root)
133
139
  .apply(StateTransforms.Model.StructureComponent, {
@@ -136,7 +142,7 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
136
142
  label: label ?? 'Session highlight',
137
143
  }, { tags: [SESSION_HIGHLIGHTS_TAG] })
138
144
  .apply(StateTransforms.Representation.StructureRepresentation3D, createStructureRepresentationParams(plugin, molstarStructure, {
139
- ...(chain
145
+ ...(label
140
146
  ? { type: 'spacefill', typeParams: { sizeFactor: 1 } }
141
147
  : {
142
148
  type: 'ball-and-stick',
@@ -145,7 +151,7 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
145
151
  color: 'uniform',
146
152
  colorParams: { value: Color.fromHexStyle(color) },
147
153
  }), { tags: [SESSION_HIGHLIGHTS_TAG] });
148
- if (label && chain) {
154
+ if (label) {
149
155
  labelled.push(expression);
150
156
  const anchor = update.toRoot().apply(StateTransforms.Model.MultiStructureSelectionFromExpression, {
151
157
  selections: [{ key: 'a', ref: root.transform.ref, expression }],
@@ -155,7 +161,7 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
155
161
  dependsOn: [root.transform.ref],
156
162
  tags: [SESSION_HIGHLIGHTS_TAG],
157
163
  });
158
- anchors.set(anchor.ref, { label, color });
164
+ anchors.set(anchor.ref, { label, color, labelSeqIds });
159
165
  }
160
166
  }
161
167
  if (labelled.length > 0) {
@@ -184,14 +190,14 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
184
190
  await update.commit();
185
191
  }
186
192
  /**
187
- * The camera that looks at the whole structure from the side its labelled
188
- * residues sit on, at the distance Mol* frames the scene from, or undefined
189
- * when nothing is labelled or the residues average out at the centre. A
190
- * residue facing away from the camera hides behind the fold, so a label
191
- * there points at nothing visible.
193
+ * The camera that looks at the whole structure from the side the first copy
194
+ * of its labelled residues sits on, at the distance Mol* frames the scene
195
+ * from, or undefined when nothing is labelled or the residues average out at
196
+ * the centre. A residue facing away from the camera hides behind the fold,
197
+ * so a label there points at nothing visible.
192
198
  */
193
199
  export function highlightCameraSnapshot(plugin, molstar) {
194
- const { StateSelection, StateTransforms, StructureElement, Vec3 } = molstar;
200
+ const { StateSelection, StateTransforms, Vec3 } = molstar;
195
201
  const anchors = plugin.state.data.select(StateSelection.Generators.root
196
202
  .subtree()
197
203
  .withTag(SESSION_HIGHLIGHTS_TAG)
@@ -201,8 +207,9 @@ export function highlightCameraSnapshot(plugin, molstar) {
201
207
  let sphere;
202
208
  for (const cell of anchors) {
203
209
  const loci = cell.obj?.data?.[0]?.loci;
204
- if (loci) {
205
- Vec3.add(mean, mean, StructureElement.Loci.getBoundary(loci).sphere.center);
210
+ const first = loci ? copyCenters(molstar, loci)[0] : undefined;
211
+ if (loci && first) {
212
+ Vec3.add(mean, mean, first.center);
206
213
  sphere ??= loci.structure.boundary.sphere;
207
214
  n++;
208
215
  }
@@ -0,0 +1,3 @@
1
+ import{A as Ht,g as wt,h as St,i as Pt,l as kt,p as Mt,q as Tt,r as Ct,s as Lt,t as Et,u as It,v as Bt,w as ge,x as he,y as Ce}from"./chunk-5BKNIN4Q.js";import{c as fe,e as yt}from"./chunk-RL54DUYZ.js";import{a as ft,b as gt,c as ht}from"./chunk-X47I2IB5.js";import{a as se}from"./chunk-6UOHQ33M.js";import{a as bt,b as vt,f as xt}from"./chunk-KXSOSKHQ.js";import{a as q}from"./chunk-HAGLAQP5.js";import{a as Mo}from"./chunk-56ZPPPNO.js";import{a as ko}from"./chunk-NZ3TO6NV.js";import{a as P}from"./chunk-SIZG3XB4.js";import{a as V}from"./chunk-533QNNGN.js";import{a as L}from"./chunk-LOG7ZCI7.js";import{a as Te}from"./chunk-HLB63AD7.js";import{a as w}from"./chunk-GVEKA5YG.js";import{a as pt}from"./chunk-MJZSVHMS.js";import{a as pe}from"./chunk-LZTO76OW.js";import{e as Ze}from"./chunk-2RFFBSIA.js";import{$ as ut,A as nt,D as it,E as st,F as lt,G as at,Ia as mt,Ka as ct,f as Re,g as et,h as tt,sa as dt,y as rt,z as ot}from"./chunk-2MXFJYQ7.js";import{a as Po}from"./chunk-B3HKXTGK.js";import"./chunk-SPXMXPSC.js";import{a as D,c as l}from"./chunk-KVMUXFPB.js";var Kt=D((On,jt)=>{jt.exports=JBrowseExports["@mui/material/Checkbox"]});var qt=D((An,Gt)=>{Gt.exports=JBrowseExports["@mui/material/Divider"]});var Ie=D((Dn,Xt)=>{Xt.exports=JBrowseExports["@mui/material/IconButton"]});var Qt=D(($n,Yt)=>{Yt.exports=JBrowseExports["@mui/material/ListItemIcon"]});var Rt=D((Jn,Zt)=>{Zt.exports=JBrowseExports["@mui/material/ListItemText"]});var tr=D((_n,er)=>{er.exports=JBrowseExports["@mui/material/Menu"]});var or=D((zn,rr)=>{rr.exports=JBrowseExports["@mui/material/MenuItem"]});var Be=D((Un,nr)=>{nr.exports=JBrowseExports["@mui/material/Tooltip"]});var He=D((Vn,ir)=>{ir.exports=JBrowseExports["@mui/material/Typography"]});var vr=D((Zn,br)=>{br.exports=JBrowseExports["@mui/material/Chip"]});var wr=D((Rn,xr)=>{xr.exports=JBrowseExports["@mui/material/Link"]});var S=l(w()),Y=l(Te());var Ft=l(V(),1),te=(0,P.createSvgIcon)((0,Ft.jsx)("path",{d:"M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"}),"Close");var wo=l(q()),me=l(L());var $=l(w()),Jt=l(L());var To=[[1,-1],[-1,-1],[1,1],[-1,1]],Co=[28,52,80],ye=5;function Ot(o,e){return o.x<e.x+e.width&&e.x<o.x+o.width&&o.y<e.y+e.height&&e.y<o.y+o.height}function At(o,e){let r=o.map(t=>({x:t.x-ye,y:t.y-ye,width:ye*2,height:ye*2})),n=[];return o.map(({x:t,y:i,width:s,height:a})=>{let f=Co.flatMap(b=>To.map(([k,z])=>{let y=t+k*b,M=i+z*b;return{leaderX:y,leaderY:M,box:{x:k>0?y:y-s,y:z>0?M:M-a,width:s,height:a}}})),d=f.find(({box:b})=>b.x>=0&&b.y>=0&&b.x+s<=e.width&&b.y+a<=e.height&&!n.some(k=>Ot(k,b))&&!r.some(k=>Ot(k,b))),{leaderX:m,leaderY:c,box:x}=d??f[0];return n.push(x),{boxX:x.x,boxY:x.y,leaderX:m,leaderY:c}})}function Dt(o){let e=o.filter(t=>t.depth>0&&t.depth<1),r=e.some(t=>t.visible)?e.filter(t=>t.visible):e,n;for(let t of r)t.depth<(n?.depth??1)&&(n=t);return n}var Ee=13,_t=`${Ee}px Roboto, Helvetica, Arial, sans-serif`,$t=5,Le=Ee+8,be;function Lo(o){return be??=document.createElement("canvas").getContext("2d"),be?(be.font=_t,be.measureText(o).width):o.length*Ee*.6}var Eo=(0,Jt.observer)(function({model:e}){let r=e.molstarPluginContext,[n,t]=(0,$.useState)([]);return(0,$.useEffect)(()=>{let i=r?.canvas3d;if(!r||!i)return;let s,a=!1,f=new Map,d=[0,0,0,0],m=()=>{let{camera:y}=i,M=i.webgl.pixelRatio,H=y.viewport.height/M;return[...wt(r)].map(([C,B])=>{let A=r.state.data.cells.get(C)?.obj?.data?.[0]?.loci,F=(A&&s?St(s,A):[]).map(({chain:v,center:E})=>(y.project(d,E),{chain:v,x:d[0]/M,y:H-d[1]/M,depth:d[2],visible:f.get(C)?.has(v)}));return{ref:C,...B,copies:F}})},c=()=>{let{camera:y}=i,M=i.webgl.pixelRatio,H=y.viewport.width/M,C=y.viewport.height/M,B=[];for(let{ref:v,label:E,color:Q,copies:K}of m()){let G=Dt(K);G&&B.push({ref:v,label:E,color:Q,x:G.x,y:G.y,width:Lo(E)+$t*2})}let A=At(B.map(v=>({...v,height:Le})),{width:H,height:C}),F=B.map((v,E)=>({...v,...A[E]}));t(v=>JSON.stringify(v)===JSON.stringify(F)?v:F)},x=()=>{let y=new Map;for(let{ref:H,labelSeqIds:C,copies:B}of m()){let A=new Set;for(let{chain:F,x:v,y:E,depth:Q}of B){let K=Q>0&&Q<1?i.identify([v,E]):void 0,{loci:G}=K?i.getLoci(K.id):{};s&&Pt(s,G,F,C)&&A.add(F)}y.set(H,A)}let M=H=>JSON.stringify([...H].map(([C,B])=>[C,[...B]]));M(y)!==M(f)&&(f=y,c())},b,k=()=>{c(),clearTimeout(b),b=setTimeout(x,250)};se().then(y=>{a||(s=y,k())}).catch(y=>{console.error(y)});let z=i.didDraw.subscribe(k);return()=>{a=!0,clearTimeout(b),z.unsubscribe()}},[r]),n.length>0?$.default.createElement("svg",{"data-testid":"protein-view-highlight-labels",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"}},n.map(({ref:i,label:s,color:a,x:f,y:d,width:m,boxX:c,boxY:x,leaderX:b,leaderY:k})=>$.default.createElement("g",{key:i,"data-highlight-label":s},$.default.createElement("line",{x1:f,y1:d,x2:b,y2:k,stroke:"#000",strokeWidth:1.5}),$.default.createElement("circle",{cx:f,cy:d,r:3.5,fill:a,stroke:"#000"}),$.default.createElement("rect",{x:c,y:x,width:m,height:Le,rx:4,fill:"#fff",fillOpacity:.92,stroke:a,strokeWidth:2}),$.default.createElement("text",{x:c+$t,y:x+Le-6,style:{font:_t},fill:"#000"},s)))):null}),zt=Eo;var g=l(w()),fo=l(Te());var Ut=l(V(),1),Vt=(0,P.createSvgIcon)((0,Ut.jsx)("path",{d:"M12 2C6.49 2 2 6.49 2 12s4.49 10 10 10c1.38 0 2.5-1.12 2.5-2.5 0-.61-.23-1.2-.64-1.67-.08-.1-.13-.21-.13-.33 0-.28.22-.5.5-.5H16c3.31 0 6-2.69 6-6 0-4.96-4.49-9-10-9m5.5 11c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5m-3-4c-.83 0-1.5-.67-1.5-1.5S13.67 6 14.5 6s1.5.67 1.5 1.5S15.33 9 14.5 9M5 11.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5S7.33 13 6.5 13 5 12.33 5 11.5m6-4c0 .83-.67 1.5-1.5 1.5S8 8.33 8 7.5 8.67 6 9.5 6s1.5.67 1.5 1.5"}),"Palette");var Nt=l(V(),1),Wt=(0,P.createSvgIcon)((0,Nt.jsx)("path",{d:"M3 17v2h6v-2zM3 5v2h10V5zm10 16v-2h8v-2h-8v-2h-2v6zM7 9v2H3v2h4v2h2V9zm14 4v-2H11v2zm-6-4h2V7h4V5h-4V3h-2z"}),"Tune");var go=l(Kt()),ho=l(qt()),Ne=l(Ie()),yo=l(Qt()),bo=l(Rt()),We=l(tr()),je=l(or()),Ke=l(Be()),Pe=l(L());var U=l(w()),sr=l(He()),lr={width:8,height:8,border:"1px solid rgba(0,0,0,0.3)"};function ar({title:o,testId:e,color:r,children:n}){return U.default.createElement(sr.default,{variant:"caption",color:r,component:"div","data-testid":e,style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,fontSize:9,paddingLeft:8}},U.default.createElement("span",null,o,":"),n)}function le({title:o,entries:e,testId:r="track-legend",color:n="textSecondary"}){return U.default.createElement(ar,{title:o,testId:r,color:n},e.map(({label:t,color:i},s)=>U.default.createElement("span",{key:`${s}-${t}`,style:{display:"inline-flex",alignItems:"center",gap:3}},U.default.createElement("span",{style:{...lr,background:i}}),t)))}function Oe({title:o,minLabel:e,maxLabel:r,colors:n,testId:t="track-legend",color:i="textSecondary"}){return U.default.createElement(ar,{title:o,testId:t,color:i},e,U.default.createElement("span",{style:{...lr,width:60,background:`linear-gradient(to right, ${n.join(", ")})`}}),r)}function Fe(o){return`#${o.toString(16).padStart(6,"0")}`}function Io(o){return o.replaceAll(/([a-z])([A-Z])(?=[a-z])/g,(e,r,n)=>`${r} ${n.toLowerCase()}`)}function ur({title:o,legend:e}){return e.kind==="table-legend"?U.default.createElement(le,{title:o,testId:"structure-legend",entries:e.table.map(([r,n])=>({label:Io(r),color:Fe(n)}))}):U.default.createElement(Oe,{title:o,testId:"structure-legend",minLabel:e.minLabel,maxLabel:e.maxLabel,colors:e.colors.map(r=>Array.isArray(r)?`${Fe(r[0])} ${100*r[1]}%`:Fe(r))})}var h=l(w());var dr=l(V(),1),mr=(0,P.createSvgIcon)((0,dr.jsx)("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}),"ChevronRight");var cr=l(V(),1),pr=(0,P.createSvgIcon)((0,cr.jsx)("path",{d:"M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"}),"ExpandMore");var fr=l(V(),1),gr=(0,P.createSvgIcon)((0,fr.jsx)("path",{d:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5M12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5m0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3"}),"Visibility");var hr=l(V(),1),yr=(0,P.createSvgIcon)((0,hr.jsx)("path",{d:"M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7M2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2m4.31-.78 3.15 3.15.02-.16c0-1.66-1.34-3-3-3z"}),"VisibilityOff");var Mr=l(vr()),xe=l(Ie()),Tr=l(wr()),R=l(Be()),ae=l(He()),we=l(L());var ve=l(w()),re=l(q()),Sr=l(L());var Bo=(0,Sr.observer)(function({model:e}){let{entities:r,mappedEntity:n,userProvidedTranscriptSequence:t}=e;return!r||r.length<2?null:ve.default.createElement(re.Tooltip,{title:t?"Mapped chain: the one the transcript maps to":"Chain: the one hovers read",placement:"left"},ve.default.createElement(re.TextField,{select:!0,size:"small",variant:"standard","data-testid":"protein-mapped-chain",value:e.pendingEntityId??n?.entityId??"",onChange:i=>{e.chooseEntity(i.target.value)},slotProps:{input:{disableUnderline:!0,sx:{fontSize:12}},htmlInput:{"aria-label":"Mapped chain"}},sx:{minWidth:60}},r.map(i=>ve.default.createElement(re.MenuItem,{key:i.entityId,value:i.entityId,dense:!0},ut(i)))))}),Pr=Bo;function kr(o){return o.aligned===0?"no residues aligned":[`${Math.round(o.identity*100)}% identity`,o.aligned===o.transcriptLength?"whole transcript":`transcript ${o.transcriptStart}\u2013${o.transcriptEnd} (${o.aligned} of ${o.transcriptLength})`,o.aligned<o.structureLength?`${o.aligned} of ${o.structureLength} structure residues`:void 0].filter(Boolean).join(" \xB7 ")}var Ho=`Under ${Math.round(rt*100)}% of the shorter sequence is identical (${Math.round(nt*100)}% for an alignment of fewer than ${ot} residues): an alignment this weak is what two unrelated proteins produce, so the positions it maps may be unrelated. Check the mapped chain, the transcript isoform, or import a curated alignment.`,Fo=(0,we.observer)(function({structure:e}){let{uniprotId:r,uniprotName:n}=e.uniProtEntry;return r?h.default.createElement(R.default,{title:`The mapped chain is UniProt ${r}${n?` (${n})`:""}, which its feature tracks annotate`},h.default.createElement(Tr.default,{variant:"caption",href:ct(r),target:"_blank",rel:"noreferrer",noWrap:!0,sx:{minWidth:40}},"UniProt ",r)):null}),Oo=(0,we.observer)(function({model:e,structure:r,readout:n}){let{label:t,alignmentQuality:i,statusMessage:s,hidden:a}=r,f=e.structures.length>1,d=e.showAlignment&&f,m=e.alignmentStructure===r,c=i?at(i):void 0;return h.default.createElement("div",{"data-testid":"structure-row","data-label":t,"data-open":d?m:void 0,"data-hidden":a||void 0,style:{opacity:a?.6:void 0,display:"flex",alignItems:"center",gap:8,minHeight:24,minWidth:0}},d?h.default.createElement(R.default,{title:m?"Alignment shown below":"Show alignment"},h.default.createElement("span",null,h.default.createElement(xe.default,{size:"small","aria-label":`Show ${t} alignment`,"aria-expanded":m,disabled:m,onClick:()=>{e.openAlignmentOf(r)},sx:{p:0}},m?h.default.createElement(pr,{fontSize:"small"}):h.default.createElement(mr,{fontSize:"small"})))):null,h.default.createElement(ae.default,{variant:"caption",sx:{fontWeight:"bold",flexShrink:0}},t),s?h.default.createElement(ae.default,{variant:"caption",color:"error","data-testid":"structure-status"},s):null,n?h.default.createElement(ae.default,{variant:"caption",noWrap:!0,title:n,"data-testid":"structure-hover"},n):i?h.default.createElement(R.default,{title:i.aligned===0?"":`${lt(i)}${c?`, ${c}`:""}; ${st(i)}`},h.default.createElement(ae.default,{variant:"caption",color:"textSecondary",noWrap:!0,"data-testid":"header-alignment-quality"},kr(i))):null,h.default.createElement(Fo,{structure:r}),h.default.createElement("div",{style:{flex:1}}),e.offersChainPicker(r)?h.default.createElement(Pr,{model:r}):null,i&&it(i)?h.default.createElement(R.default,{title:Ho},h.default.createElement(Mr.default,{size:"small",color:"warning",variant:"outlined",label:"low similarity","data-testid":"header-low-similarity"})):null,f||a?h.default.createElement(R.default,{title:a?`Show ${t}`:`Hide ${t}`},h.default.createElement(xe.default,{size:"small","aria-label":a?`Show ${t}`:`Hide ${t}`,"aria-pressed":a,onClick:()=>{r.setHidden(!a)},sx:{p:.25}},a?h.default.createElement(yr,{fontSize:"small"}):h.default.createElement(gr,{fontSize:"small"}))):null,h.default.createElement(R.default,{title:`Remove ${t}`},h.default.createElement(xe.default,{size:"small","aria-label":`Remove ${t}`,onClick:()=>{e.removeStructure(r)},sx:{p:.25}},h.default.createElement(te,{fontSize:"small"}))))}),Ao=(0,we.observer)(function({model:e}){let{structures:r}=e,n=r.some(t=>t.hoverPosition&&t.hoverPosition.source!=="structure");return h.default.createElement("div",{style:{flex:1,minWidth:0}},r.map((t,i)=>h.default.createElement(Oo,{key:i,model:e,structure:t,readout:t.hoverString||(n&&t.genomeToTranscriptSeqMapping?"not in structure":"")})))}),Cr=Ao;var p=l(w()),io=l(Te()),so=l(q()),lo=l(kt()),ao=l(L());var uo=l(ko());var Ae=l(w()),Lr=l(L());function Do(o,e,r){let n=[];if(!o)return n;for(let t=0;t<e;t++){let i=o[t];if(i===void 0)continue;let s=r(i);s%10===0?n.push({col:t,label:`${s}`}):s%5===0&&n.push({col:t})}return n}var $o=(0,Lr.observer)(function({model:e,columns:r}){let{columnWidth:n}=e,t=Do(e.pairwiseAlignmentToStructurePosition,r,i=>e.residueNumber(i));return Ae.default.createElement("div",{style:{position:"relative",height:"100%",color:"#888",fontSize:8}},t.map(({col:i,label:s})=>Ae.default.createElement("span",{key:i,style:{position:"absolute",left:i*n,top:0,bottom:0,borderLeft:"1px solid #aaa",paddingLeft:2,lineHeight:`${12}px`,whiteSpace:"nowrap"}},s)))}),Er=$o;var J=l(w()),De=l(L());function ue({start:o,end:e,columnWidth:r,background:n,border:t}){return J.default.createElement("div",{style:{position:"absolute",top:0,bottom:0,left:o*r,width:(e-o+1)*r,background:n,border:t,boxSizing:"border-box",pointerEvents:"none"}})}function Ir({zIndex:o,children:e}){return J.default.createElement("div",{style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:o}},e)}var Br=(0,De.observer)(function({model:e,matchHeight:r}){let{clickAlignmentRanges:n,columnWidth:t,showHighlight:i,alignmentMatchSet:s}=e;return J.default.createElement(Ir,{zIndex:0},i&&s?J.default.createElement("div",{style:{position:"relative",height:r}},Ht(s).map(a=>J.default.createElement(ue,{key:a.start,start:a.start,end:a.end-1,columnWidth:t,background:Et}))):null,n.map(a=>J.default.createElement(ue,{key:a.start,start:a.start,end:a.end,columnWidth:t,background:Ct})))}),Jo=(0,De.observer)(function({model:e}){let{clickAlignmentRanges:r,alignmentHoverRange:n,alignmentHoverPos:t,columnWidth:i}=e;return J.default.createElement(Ir,{zIndex:1},r.map(s=>J.default.createElement(ue,{key:s.start,start:s.start,end:s.end,columnWidth:i,background:"transparent",border:Lt})),n?J.default.createElement(ue,{start:n.start,end:n.end,columnWidth:i,background:Tt}):null,t===void 0?null:J.default.createElement(ue,{start:t,end:t,columnWidth:i,background:Mt}))}),Hr=Jo;var _=l(w()),Fr=l(q()),$e=l(L());var _o={domain:"Domain",site:"Site"},zo=(0,$e.observer)(function({row:e,bar:r,selected:n,model:t}){let[i,s]=(0,_.useState)(!1),{columnWidth:a,trackGap:f}=t,d=t.residueNumber(r.structureStart),m=t.residueNumber(r.structureEnd-1);return _.default.createElement(Fr.Tooltip,{title:_.default.createElement("div",null,_.default.createElement("div",null,_.default.createElement("strong",null,e.label)),_.default.createElement("div",null,_o[e.kind]," from the alignment, ",e.accession),_.default.createElement("div",null,"Structure residue: ",d===m?d:`${d}-${m}`)),followCursor:!0},_.default.createElement("div",{"data-testid":`alignment-domain-${e.kind}`,"data-accession":e.accession,onClick:()=>{t.toggleDomainRow(e)},onMouseEnter:()=>{s(!0),t.setAlignmentHoverRange({start:r.alignmentStart,end:r.alignmentEnd})},onMouseLeave:()=>{s(!1),t.setAlignmentHoverRange(void 0)},style:{position:"absolute",left:r.alignmentStart*a,top:0,width:(r.alignmentEnd-r.alignmentStart+1)*a,height:`calc(100% - ${f}px)`,backgroundColor:e.color,opacity:i||n?.9:.6,cursor:"pointer",borderRadius:2,border:n?ge:i?he:"none",boxSizing:"border-box"}}))}),Uo=(0,$e.observer)(function({row:e,model:r}){let n=r.selectedFeatureId===`alignment:${e.accession}`;return e.bars.map(t=>_.default.createElement(zo,{key:t.alignmentStart,row:e,bar:t,selected:n,model:r}))}),Or=Uo;var W=l(w());var Ar=l(V(),1),Dr=(0,P.createSvgIcon)((0,Ar.jsx)("path",{d:"M7.41 18.59 8.83 20 12 16.83 15.17 20l1.41-1.41L12 14zm9.18-13.18L15.17 4 12 7.17 8.83 4 7.41 5.41 12 10z"}),"UnfoldLess");var $r=l(V(),1),Jr=(0,P.createSvgIcon)((0,$r.jsx)("path",{d:"M12 5.83 15.17 9l1.41-1.41L12 3 7.41 7.59 8.83 9zm0 12.34L8.83 15l-1.41 1.41L12 21l4.59-4.59L15.17 15z"}),"UnfoldMore");var de=l(q()),_r=l(L());var No=(0,_r.observer)(function({type:e,laneCount:r,model:n}){let t=n.expandedFeatureTypes.has(e),i=Math.min(n.trackHeight,12);return W.default.createElement(de.Tooltip,{title:e,placement:"left"},W.default.createElement("div",{style:{height:"100%",whiteSpace:"nowrap",display:"flex",alignItems:t?"flex-start":"center",justifyContent:"flex-end",gap:2}},W.default.createElement(de.IconButton,{onClick:()=>{n.hideFeatureType(e)},title:`Hide ${e} track`,sx:{p:0,color:Ce}},W.default.createElement(te,{sx:{fontSize:i}})),r>1?W.default.createElement(de.IconButton,{onClick:()=>{n.toggleFeatureTypeExpanded(e)},title:t?`Collapse ${e} track`:`Expand ${e} track (${r} overlapping rows)`,sx:{p:0,color:Ce}},t?W.default.createElement(Dr,{sx:{fontSize:i}}):W.default.createElement(Jr,{sx:{fontSize:i}})):null,W.default.createElement("span",null,e)))}),zr=No;var Vr=l(w()),Nr=l(L());function Wo(o,e,r){if(!(!o||!e||o==="-"||e==="-"||o.toUpperCase()===e.toUpperCase()))return r===":"||r==="."?"similar":"different"}function Ur(o){let e=o.alns[0]?.seq??"",r=o.alns[1]?.seq??"",n=[];for(let t=0;t<e.length;t++){let i=Wo(e[t],r[t],o.consensus[t]),s=n.at(-1);i&&s?.kind===i&&s.end===t?s.end=t+1:i&&n.push({start:t,end:t+1,kind:i})}return n}var jo=(0,Nr.observer)(function({model:e}){let{alignment:r,columnWidth:n}=e;return r?Ur(r).map(t=>Vr.default.createElement("div",{key:t.start,style:{position:"absolute",top:0,bottom:0,left:t.start*n,width:(t.end-t.start)*n,background:t.kind==="similar"?It:Bt}})):null}),Wr=jo;var qr=l(w()),Xr=l(L());var O=l(w()),jr=l(q()),Kr=l(L());var Ko=fe(pt);function Go({feature:o,layout:e,model:r}){let n=r.residueNumber(e.structureStart),t=r.residueNumber(e.structureEnd-1),i=n!==o.start||t!==o.end;return O.default.createElement("div",null,O.default.createElement("div",null,O.default.createElement("strong",null,o.type)),O.default.createElement("div",null,"UniProt position: ",o.start,"-",o.end),i?O.default.createElement("div",null,"Structure residue: ",n,"-",t,e.clipped?" (the structure lacks the rest)":""):null,o.description?O.default.createElement("div",null,o.description):null)}var qo=(0,Kr.observer)(function({layout:e,top:r,height:n,selected:t,model:i}){let[s,a]=(0,O.useState)(!1),{feature:f,alignmentStart:d,alignmentEnd:m}=e,{columnWidth:c}=i;return O.default.createElement(jr.Tooltip,{title:O.default.createElement(Go,{feature:f,layout:e,model:i}),followCursor:!0},O.default.createElement("div",{"data-testid":`protein-feature-${f.type}`,"data-feature-id":f.uniqueId,"data-feature-start":f.start,"data-feature-end":f.end,onClick:()=>{t?(i.setSelectedFeatureId(void 0),i.setClickedStructureRanges([])):(i.selectResidues(e.structureStart,e.structureEnd),i.setSelectedFeatureId(f.uniqueId))},onMouseEnter:()=>{a(!0),i.setAlignmentHoverRange({start:d,end:m})},onMouseLeave:()=>{a(!1),i.setAlignmentHoverRange(void 0)},style:{position:"absolute",left:d*c,top:r,width:(m-d+1)*c,height:n,backgroundColor:Ko(f.type),opacity:s||t?.9:.6,cursor:"pointer",borderRadius:2,border:t?ge:s?he:"none",boxSizing:"border-box"}}))}),Gr=qo;var Xo=(0,Xr.observer)(function({group:e,model:r}){let{selectedFeatureId:n,trackGap:t}=r,i=r.expandedFeatureTypes.has(e.type)?e.laneCount:1,s=`calc(${100/i}% - ${t}px)`;return e.layouts.map(a=>qr.default.createElement(Gr,{key:a.feature.uniqueId,layout:a,top:`${Math.min(a.lane,i-1)/i*100}%`,height:s,selected:n===a.feature.uniqueId,model:r}))}),Yr=Xo;var X=l(w()),Qr=l(q()),Je=l(L()),Yo=(0,Je.observer)(function({cells:e,colorFor:r,model:n}){let{columnWidth:t,trackGap:i}=n;return X.default.createElement("div",{style:{position:"relative",height:`calc(100% - ${i}px)`}},e.map(s=>X.default.createElement("div",{key:s.col,style:{position:"absolute",left:s.col*t,width:t,height:"100%",backgroundColor:r(s.value)}})))}),Qo=(0,Je.observer)(function({cells:e,colorFor:r,formatValue:n,model:t}){let i=(0,X.useMemo)(()=>new Map(e.map(f=>[f.col,f.value])),[e]),{alignmentHoverPos:s}=t,a=s===void 0?void 0:i.get(s);return X.default.createElement(Qr.Tooltip,{title:a===void 0?"":n(a),followCursor:!0},X.default.createElement("div",{style:{height:"100%"}},X.default.createElement(Yo,{cells:e,colorFor:r,model:t})))}),_e=Qo;var Zr=l(w()),Rr=l(L()),Zo=(0,Rr.observer)(function({model:e,str:r}){let{columnWidth:n}=e;return r.split("").map((t,i)=>Zr.default.createElement("span",{key:i,style:{position:"absolute",left:i*n,width:n}},t===" "?"\xA0":t))}),eo=Zo;var to=l(kt());function Ro({x:o,width:e,scrollLeft:r,clientWidth:n}){return o>=r&&o+e<=r+n?void 0:o+e/2-n/2}function ro({start:o,end:e,scrollLeft:r,clientWidth:n}){let t=r+n;return e>=r&&o<=t?void 0:(o+e)/2-n/2}function oo(o,e){return(0,to.reaction)(()=>o.alignmentHoverPos,r=>{let n=e();if(r!==void 0&&n&&o.autoScrollAlignment&&!o.isMouseInAlignment){let t=Ro({x:r*o.columnWidth,width:o.columnWidth,scrollLeft:n.scrollLeft,clientWidth:n.clientWidth});t!==void 0&&(n.scrollLeft=t)}})}var no=l(w());function en(o){try{return decodeURIComponent(o)}catch{return o}}function tn(o){let e=[];for(let r of o.split(`
2
+ `)){if(r.startsWith("#")||!r.trim())continue;let n=r.split(" ");if(n.length<9)continue;let t=n[2],i=Number.parseInt(n[3]??"",10),s=Number.parseInt(n[4]??"",10),f=(n[8]??"").split(";").find(d=>d.startsWith("Note="))?.slice(5);t&&i>=1&&s>=i&&e.push({type:t,start:i,end:s,description:en(f??""),uniqueId:`${t}-${i}-${s}-${e.length}`})}return e}async function rn(o){return tn(await(await dt(o)).text())}function ze(o){let{data:e,error:r,isLoading:n}=ft(o?mt(o):null,rn,gt);return{features:e,error:r,isLoading:n}}var on=new Set(["Disulfide bond","Cross-link"]);function nn(o,e,r){let n=d=>{let m=r(d),c=m===void 0?void 0:e[m];return m===void 0||c===void 0?void 0:{structurePos:m,column:c}},t=o.start,i=n(t);for(;!i&&t<o.end;)i=n(++t);let s=o.end,a=n(s);for(;!a&&s>t;)a=n(--s);let f=t!==o.start||s!==o.end;return!i||!a||f&&on.has(o.type)?void 0:{feature:o,structureStart:i.structurePos,structureEnd:a.structurePos+1,alignmentStart:i.column,alignmentEnd:a.column,clipped:f,lane:0}}function sn(o){let e=[],r=[...o].sort((n,t)=>n.alignmentStart-t.alignmentStart);for(let n of r){let t=e.findIndex(i=>i<n.alignmentStart);t===-1?(n.lane=e.length,e.push(n.alignmentEnd)):(n.lane=t,e[t]=n.alignmentEnd)}return Math.max(e.length,1)}function ln(o){return[...o].sort((e,r)=>r.alignmentEnd-r.alignmentStart-(e.alignmentEnd-e.alignmentStart))}function Ue(o,e,r){let{features:n,isLoading:t,error:i}=ze(e),{omittedFeatureTypes:s,structurePositionToAlignmentMap:a}=o;return{groups:(0,no.useMemo)(()=>{if(!n||!a)return;let d=new Map;for(let m of n)if(!s.has(m.type)){let c=nn(m,a,r);if(c){let x=d.get(m.type);x?x.push(c):d.set(m.type,[c])}}return[...d].map(([m,c])=>({type:m,laneCount:sn(c),layouts:ln(c)}))},[n,s,a,r]),isLoading:t,error:i}}var un=fe(pe.plddt),dn=yt(pe.plddt),mn=(0,uo.makeStyles)()(o=>({scroll:{overflow:"auto",whiteSpace:"nowrap",flex:1,paddingBottom:2,backgroundColor:o.palette.background.paper},trackMessage:{position:"sticky",left:0,lineHeight:`${12}px`,color:o.palette.text.secondary},trackError:{color:o.palette.error.main}}));function oe({label:o,title:e}){return p.default.createElement(so.Tooltip,{title:e,placement:"left"},p.default.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"flex-end"}},o))}var cn=(0,ao.observer)(function({model:e}){let{alignment:r,showProteinTracks:n,showAllFeatureTracks:t,label:i,confidenceCells:s,columnWidth:a,laneHeight:f,domainRows:d}=e,m=t?e.hydrophobicityCells:[],{classes:c,cx:x}=mn(),b=(0,p.useRef)(null),k=(0,p.useRef)(void 0),{uniprotId:z,mapUniProtPosition:y,isLoading:M,error:H,isoformAccession:C}=e.uniProtEntry,{groups:B,isLoading:A,error:F}=Ue(e,C?void 0:z,y),v=M||A,E=H??F,Q=E?`${H?`Could not map ${i} to a UniProt entry through SIFTS`:`Could not load UniProt features for ${z??i}`}: ${Ze(E)}`:void 0;if((0,p.useEffect)(()=>oo(e,()=>b.current),[e]),(0,p.useEffect)(()=>(0,lo.autorun)(()=>{let u=b.current,T=e.clickAlignmentRanges,I=T[0];if(u)if(I){let ee=T.map(Z=>`${Z.start}-${Z.end}`).join(",");if(ee!==k.current){k.current=ee;let Z=ro({start:I.start*e.columnWidth,end:(I.end+1)*e.columnWidth,scrollLeft:u.scrollLeft,clientWidth:u.clientWidth});Z!==void 0&&(u.scrollLeft=Z)}}else k.current=void 0}),[e]),!r)return null;let K=tt(r),G=(u,T,I,ee,Z)=>({key:u,height:12,label:p.default.createElement(oe,{label:T,title:I}),content:p.default.createElement("div",{style:{lineHeight:`${12}px`}},Z,p.default.createElement(eo,{model:e,str:ee})),selectsResidue:!0}),ke=Q??(C?`UniProt features are numbered for ${z}; this model is isoform ${C}`:v?"Loading UniProt features...":""),Xe=[G("transcript","GENOME","The protein as the reference genome's transcript translates",Re(r)),G("structure","STRUCT","The protein as the structure file spells it. Shaded where it differs from the transcript's: amber for a similar amino acid, red for a different one.",et(r),p.default.createElement(Wr,{model:e}))],ie=[...Xe,{key:"ruler",height:12,label:p.default.createElement(oe,{label:"residue",title:"Residue numbers as the structure's authors assigned them, the numbering papers and the 3D view's hover label use"}),content:p.default.createElement(Er,{model:e,columns:K}),selectsResidue:!0}],So=Xe.length*12,Me=0,ce=(u,T,I,ee)=>{Me+=T,ie.push({key:u,height:T*f,label:I,content:ee})},Ye=(u,T)=>{ie.push({key:u,height:12,label:null,content:p.default.createElement("span",{className:c.trackMessage},T)})};if(n){if(d.length>0){Ye("alignment-section","From the alignment");for(let u of d)ce(`alignment-${u.accession}`,1,p.default.createElement(oe,{label:u.label,title:`${u.label} (${u.accession}), a ${u.kind} the connected alignment draws on its query row`}),p.default.createElement(Or,{row:u,model:e}));Ye("uniprot-section","From UniProt")}ke&&ie.push({key:"uniprot-status",height:12,label:p.default.createElement(oe,{label:"UniProt",title:ke}),content:p.default.createElement("span",{className:x(c.trackMessage,Q&&c.trackError)},ke)});for(let u of B??[])ce(`feature-${u.type}`,e.expandedFeatureTypes.has(u.type)?u.laneCount:1,p.default.createElement(zr,{type:u.type,laneCount:u.laneCount,model:e}),p.default.createElement(Yr,{group:u,model:e}));s.length>0&&ce("plddt",1,p.default.createElement(oe,{label:"pLDDT",title:p.default.createElement(le,{title:pe.plddt.title,entries:dn,color:"inherit"})}),p.default.createElement(_e,{cells:s,colorFor:un,formatValue:u=>`pLDDT ${u.toFixed(0)}`,model:e})),m.length>0&&ce("hydrophobicity",1,p.default.createElement(oe,{label:"hydro",title:p.default.createElement(Oe,{title:e.hydrophobicityScale.title,testId:"hydrophobicity-legend",...e.hydrophobicityScale.key,color:"inherit"})}),p.default.createElement(_e,{cells:m,colorFor:e.hydrophobicityScale.paint,formatValue:u=>`Kyte-Doolittle ${u.toFixed(1)}`,model:e}))}let Qe=u=>{let{left:T}=u.currentTarget.getBoundingClientRect(),I=Math.floor((u.clientX-T)/a);return I>=0&&I<K?I:void 0};return p.default.createElement("div",{"data-testid":"protein-alignment-panel","data-structure":i},p.default.createElement("div",{style:{display:"flex",fontSize:9,fontFamily:"monospace",margin:"2px 8px 4px"},onMouseEnter:()=>{e.setIsMouseInAlignment(!0)},onMouseLeave:()=>{e.leaveAlignment()}},p.default.createElement("div",{style:{flexShrink:0,minWidth:124,paddingRight:4,whiteSpace:"nowrap",lineHeight:1}},ie.map(u=>p.default.createElement("div",{key:u.key,"data-row-label":u.key,style:{height:u.height,overflow:"hidden"}},u.label))),p.default.createElement("div",{ref:b,className:c.scroll},p.default.createElement("div",{"data-testid":"alignment-rows",style:{position:"relative",width:K*a},onMouseMove:u=>{let T=Qe(u);T===void 0?e.setHoveredPosition(void 0):e.hoverAlignmentPosition(T)},onMouseLeave:()=>{e.setHoveredPosition(void 0)}},p.default.createElement(Br,{model:e,matchHeight:So}),ie.map(u=>p.default.createElement("div",{key:u.key,"data-row":u.key,style:{position:"relative",height:u.height,cursor:u.selectsResidue?"pointer":void 0},onClick:u.selectsResidue?T=>{let I=Qe(T);I!==void 0&&e.clickAlignmentPosition(I)}:void 0},u.content)),p.default.createElement(Hr,{model:e})))),Me>0?p.default.createElement(io.ResizeHandle,{bar:!0,title:"Drag to resize the feature tracks","data-testid":"feature-tracks-resize-handle",gain:Me,onDrag:u=>{e.resizeTracks(u)}}):null)}),mo=cn;var ne=l(w()),co=l(Po());var Se=l(q()),pn=(0,ne.lazy)(()=>import("./ProteinAlignmentHelpDialog-BNW2WV6D.js"));function Ve({model:o}){return ne.default.createElement(Se.Tooltip,{title:"What the alignment panel shows"},ne.default.createElement(Se.IconButton,{size:"small",onClick:()=>{(0,co.getSession)(o).queueDialog(e=>[pn,{handleClose:e}])}},ne.default.createElement(ht,{fontSize:"small"})))}var fn=[{label:vt},...Object.entries(bt).map(([o,{label:e}])=>({field:o,label:e}))],gn=(0,Pe.observer)(function({model:e}){let[r,n]=(0,g.useState)(null),t=`Color by: ${xt(e.color)}`;return g.default.createElement(g.default.Fragment,null,g.default.createElement(Ke.default,{title:t},g.default.createElement(Ne.default,{size:"small","aria-label":t,onClick:i=>{n(i.currentTarget)}},g.default.createElement(Vt,{fontSize:"small"}))),g.default.createElement(We.default,{anchorEl:r,open:!!r,onClose:()=>{n(null)}},fn.map(({field:i,label:s})=>g.default.createElement(je.default,{key:s,dense:!0,selected:i===e.color.field,onClick:()=>{i!==e.color.field&&e.setColor(i?{field:i}:{}),n(null)}},s))))});function po({checked:o,label:e,disabled:r,onToggle:n}){return g.default.createElement(je.default,{onClick:()=>{n()},disabled:r,dense:!0},g.default.createElement(yo.default,null,g.default.createElement(go.default,{checked:o,size:"small",edge:"start",disableRipple:!0})),g.default.createElement(bo.default,null,e))}var hn=(0,Pe.observer)(function({model:e}){let[r,n]=(0,g.useState)(null);return g.default.createElement(g.default.Fragment,null,g.default.createElement(Ke.default,{title:"Display settings"},g.default.createElement(Ne.default,{size:"small",onClick:t=>{n(t.currentTarget)}},g.default.createElement(Wt,{fontSize:"small"}))),g.default.createElement(We.default,{anchorEl:r,open:!!r,onClose:()=>{n(null)}},e.displayToggles.map(t=>g.default.createElement(po,{key:t.key,checked:t.checked,label:t.label,disabled:t.disabled,onToggle:t.toggle})),g.default.createElement(ho.default,null),e.behaviorToggles.map(t=>g.default.createElement(po,{key:t.label,checked:t.checked,label:t.label,onToggle:t.toggle}))))}),yn=(0,Pe.observer)(function({model:e}){let{alignmentStructure:r,showAlignment:n,colorLegend:t,domainLegend:i}=e;return g.default.createElement("div",null,g.default.createElement("div",{style:{display:"flex",alignItems:"flex-start",gap:8}},g.default.createElement(Cr,{model:e}),g.default.createElement("div",{style:{display:"flex",gap:4,alignItems:"center",flexShrink:0,minHeight:24}},g.default.createElement(gn,{model:e}),g.default.createElement(hn,{model:e}),g.default.createElement(Ve,{model:e}))),i?i.map(s=>g.default.createElement(le,{key:s.title,title:s.title,entries:s.entries,testId:"structure-legend"})):t?g.default.createElement(ur,{title:"Structure colors",legend:t}):null,n&&r?.pairwiseAlignment?g.default.createElement(mo,{model:r}):n&&r?.alignmentPending?g.default.createElement(fo.LoadingEllipses,{message:"Loading pairwise alignment"}):null)}),vo=yn;var j=l(w()),Ge=l(Mo());var xo=!1;function bn(o){if(!xo){xo=!0;let e=document.createElement("style");e.append(o),document.head.append(e)}}function qe({showControls:o,model:e}){let r=(0,j.useRef)(null),[n,t]=(0,j.useState)(),[i,s]=(0,j.useState)(),[a,f]=(0,j.useState)(!0);return(0,j.useEffect)(()=>{let d={cancelled:!1},m=()=>d.cancelled;return(async()=>{let c;try{let{Color:x,GeometryExport:b,MAQualityAssessment:k,PluginConfig:z,PluginSpec:y,DefaultPluginUISpec:M,createPluginUI:H,registerColorThemes:C,renderReact18:B,css:A}=await se(),F=r.current;if(m()||!F)return;bn(A);let v=document.createElement("div");F.append(v),d.host=v;let E=M();c=await H({target:v,render:B,spec:{...E,behaviors:[...E.behaviors,y.Behavior(b),y.Behavior(k)],layout:{initial:{controlsDisplay:"reactive",showControls:o}},config:[[z.Viewport.ShowExpand,!1]]}}),await c.initialized,C(c),c.canvas3d?.setProps({renderer:{selectColor:x(16711935),selectStrength:1},marking:{selectEdgeColor:x(16711935)}}),m()?(c.dispose(),v.remove()):(d.plugin=c,t(c),e.setMolstarPluginContext(c))}catch(x){c&&d.plugin!==c&&(c.dispose(),d.host?.remove()),console.error(x),s(x)}finally{f(!1)}})(),()=>{d.cancelled=!0,(0,Ge.isAlive)(e)&&e.setMolstarPluginContext(void 0),d.plugin?.dispose(),d.host?.remove()}},[]),(0,j.useEffect)(()=>{let d={cancelled:!1};return(async()=>{try{if(n){let{PluginCommands:m}=await se();d.cancelled||await m.Layout.Update(n,{state:{showControls:o}})}}catch(m){console.error(m),(0,Ge.isAlive)(e)&&e.setError(m)}})(),()=>{d.cancelled=!0}},[n,o,e]),{parentRef:r,error:i,loading:a}}var vn=(0,me.observer)(function({model:e}){let{showControls:r}=e,{parentRef:n,error:t,loading:i}=qe({showControls:r,model:e});return t?S.default.createElement(Y.ErrorMessage,{error:t}):S.default.createElement(Sn,{model:e,parentRef:n,loading:i})}),xn=(0,me.observer)(function({model:e}){let{error:r}=e;return r?S.default.createElement("div",{style:{display:"flex",alignItems:"flex-start"}},S.default.createElement("div",{style:{flex:1}},S.default.createElement(Y.ErrorMessage,{error:r})),S.default.createElement(wo.IconButton,{size:"small","aria-label":"Dismiss error",onClick:()=>{e.setError(void 0)}},S.default.createElement(te,{fontSize:"small"}))):null}),wn=(0,me.observer)(function({model:e}){let{loadingMessages:r}=e;return r.length>0?S.default.createElement("div",{"data-testid":"protein-view-loading-overlay",style:{position:"absolute",top:8,left:8,maxWidth:"calc(100% - 16px)",padding:"2px 8px",borderRadius:4,background:"rgba(255,255,255,0.85)",color:"#000",pointerEvents:"none"}},r.map(({id:n,message:t})=>S.default.createElement(Y.LoadingEllipses,{key:n,message:t}))):null}),Sn=(0,me.observer)(function({model:e,parentRef:r,loading:n}){let{width:t,height:i}=e,s=!n&&!e.showLoading;return S.default.createElement("div",{style:{background:"#ccc"},"data-testid":s?"protein-view-ready":"protein-view-loading"},S.default.createElement(xn,{model:e}),n?S.default.createElement(Y.LoadingEllipses,{message:"Loading protein viewer"}):S.default.createElement(vo,{model:e}),S.default.createElement("div",{style:{position:"relative",width:t,height:i}},S.default.createElement("div",{ref:r,"data-testid":"protein-view-molstar",style:{position:"relative",width:t,height:i}}),S.default.createElement(zt,{model:e}),S.default.createElement(wn,{model:e})),S.default.createElement(Y.ResizeHandle,{style:{height:4,background:"grey"},onDrag:a=>{e.setHeight(e.height+a)}}))}),Ts=vn;export{Ts as default};
3
+ //# sourceMappingURL=ProteinView-L3EKMAPI.js.map