jbrowse-plugin-protein3d 1.16.0 → 1.17.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.
@@ -96,7 +96,8 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
96
96
  if (!root) {
97
97
  continue;
98
98
  }
99
- const textSize = labelTextSize(molstarStructure.boundary.sphere.radius);
99
+ const { radius } = molstarStructure.boundary.sphere;
100
+ const textSize = labelTextSize(radius);
100
101
  for (const [i, { entityId, labelSeqIds, label, color },] of marks.entries()) {
101
102
  const expression = MS.struct.generator.atomGroups({
102
103
  'entity-test': MS.core.rel.eq([MS.ammp('label_entity_id'), entityId]),
@@ -151,7 +152,12 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
151
152
  background: true,
152
153
  backgroundColor: Color(0xffffff),
153
154
  backgroundOpacity: 0.85,
154
- offsetZ: 10,
155
+ // toward the camera by the structure's radius, past
156
+ // everything the structure draws: Mol* depth-tests text, so
157
+ // a label behind a helix or a DNA strand would hide. The
158
+ // parameter's 10 Å bound is the UI's; the shader takes any
159
+ // distance, and the camera sits outside the bounding sphere
160
+ offsetZ: radius,
155
161
  }, { tags: [SESSION_HIGHLIGHTS_TAG] });
156
162
  }
157
163
  }
@@ -0,0 +1,2 @@
1
+ import{b as j}from"./chunk-5M4LVDLT.js";import{a as ot,b as it,c as at,d as st,e as ut,f as ct,h as mt,i as ee}from"./chunk-7SEZTF5X.js";import{b as pt}from"./chunk-NOFPQXHZ.js";import{a as ne,b as F,c as ft,d as St,o as re,q as yt,r as ht,s as oe}from"./chunk-5YLRYIUR.js";import{c as dt,f as lt}from"./chunk-RL54DUYZ.js";import{a as h}from"./chunk-UTDQGJCS.js";import{c as te,d as $,e as B,g as gt}from"./chunk-KXSOSKHQ.js";import{a as dn}from"./chunk-YCRC6WEC.js";import{a as q}from"./chunk-56ZPPPNO.js";import{a as cn}from"./chunk-GVEKA5YG.js";import{b as Je,c as We,d as Ke,f as et,g as tt,i as nt}from"./chunk-R64WXKZQ.js";import{a as rt}from"./chunk-LZTO76OW.js";import{b as ye,d as he,e as D}from"./chunk-2RFFBSIA.js";import"./chunk-INWFM3CY.js";import"./chunk-5NBLSM7W.js";import{a as Ye,b as Xe,c as Qe,e as Ze}from"./chunk-ISVQX4IH.js";import{a as je,b as ze}from"./chunk-UVDYWAS6.js";import{a as Be,b as H}from"./chunk-7UQOTULP.js";import{$ as xe,C as Ie,Da as Ne,Ga as _e,Ha as Ge,L as Ee,La as De,N as Y,O as Ce,Pa as Oe,Q as V,Qa as Ue,Ra as U,U as X,Ua as $e,V as Ae,X as O,_ as ke,b as be,ba as ve,c as Pe,ca as Q,da as Re,ea as qe,fa as Le,ja as Ve,ka as He,l as Te,la as Z,m as we,ma as Fe,p as Me}from"./chunk-WZCSPP5F.js";import{a as K}from"./chunk-B3HKXTGK.js";import"./chunk-SPXMXPSC.js";import{a as un,c as T}from"./chunk-KVMUXFPB.js";var Pt=un((Hn,bt)=>{bt.exports=JBrowseExports["@jbrowse/core/util/types/mst"]});var fe=T(cn()),on=T(dn()),ge=T(K()),an=T(Pt()),f=T(q()),v=T(ne());function E(e,t,n){let r=e.helpers.substructureParent.get(n);return r?e.state.data.selectQ(o=>o.byValue(r).rootOfType(t.PluginStateObject.Molecule.Structure))[0]:void 0}var N="jbrowse-alignment-sites",ln={sizeFactor:.35,sizeAspectRatio:.6},Tt=0;async function wt({plugin:e,structures:t}){let n=await h(),{MolScriptBuilder:r,ProteinBackboneAtoms:o,StateSelection:i,StateTransforms:a,createStructureColorThemeParams:s,createStructureRepresentationParams:d,registerPlacedValues:u}=n;Tt++;let c=e.state.data.build(),l=!1;for(let{molstarStructure:m,sites:g,color:b}of t){let S=E(e,n,m);if(!S)continue;let y=e.state.data.select(i.Generators.ofTransformer(a.Model.StructureComponent,S.transform.ref).withTag(N)),I=[...g?.byLabelSeqId.keys()??[]];if(u("alignment-sites",m,g),!g||!b||I.length===0){for(let k of y)c.delete(k.transform.ref),l=!0;continue}let A=k=>r.core.rel.eq([r.ammp("label_atom_id"),k]),P={type:{name:"expression",params:r.struct.generator.atomGroups({"entity-test":r.core.rel.eq([r.ammp("label_entity_id"),g.entityId]),"residue-test":r.core.set.has([r.set(...I),r.ammp("label_seq_id")]),"atom-test":r.core.logic.or([r.core.logic.not([r.core.set.has([r.set(...o),r.ammp("label_atom_id")])]),A("CA"),r.core.logic.and([r.core.rel.eq([r.ammp("auth_comp_id"),"PRO"]),A("N")])])})},nullIfEmpty:!0,label:"Sites from the alignment"},w={...d(e,m,{type:"ball-and-stick",typeParams:ln}),colorTheme:s(e,m,"ball-and-stick","alignment-domains",{revision:Tt,color:b,mark:"atoms"})},[M]=y;if(M){c.to(M).update(P);for(let k of e.state.data.select(i.Generators.ofTransformer(a.Representation.StructureRepresentation3D,M.transform.ref)))c.to(k).update(w)}else c.to(S).apply(a.Model.StructureComponent,P,{tags:[N]}).apply(a.Representation.StructureRepresentation3D,w,{tags:[N]});l=!0}l&&await c.commit()}var mn=[...Ye,"alignment-domains"];function It(e){return mn.some(t=>t===e)}function Et(e,{entityId:t,domainColor:n,revision:r,representationType:o=""}){let i=$(e);return e.field==="mappedChain"?{entityId:t??""}:e.field==="domain"?{revision:r,color:n??it,mark:ot(o)}:i&&It(B(e))?{revision:r,color:i}:i&&{color:i}}var Mt=0;async function Ct({plugin:e,color:t,structures:n}){let r=await h(),{StateSelection:o,StateTransforms:i,createStructureColorThemeParams:a,registerPlacedValues:s}=r,d=B(t),u=It(d);u&&Mt++;let c=e.state.data.build(),l=0;for(let{molstarStructure:m,entityId:g,placedValues:b,placedSites:S,domainColor:y}of n){u&&s(d,m,b),t.field==="domain"&&s("alignment-sites",m,S);let I=E(e,r,m),A=I?e.state.data.select(o.Generators.ofTransformer(i.Representation.StructureRepresentation3D,I.transform.ref)):[];for(let P of A)!P.state.isGhost&&!P.transform.tags?.includes(N)&&(c.to(P).update(w=>{w.colorTheme=a(e,m,w.type.name,d,Et(t,{entityId:g,domainColor:y,revision:Mt,representationType:w.type.name}))}),l++)}l>0&&await c.commit()}function At({plugin:e,color:t,structure:n,entityId:r,domainColor:o}){let i=B(t);return i===void 0?void 0:e.representation.structure.themes.colorThemeRegistry.create(i,{structure:n},Et(t,{entityId:r,domainColor:o})??{}).legend}function ie(e,{structure:t,entityId:n,labelSeqIds:r}){let o=e.Script.getStructureSelection(i=>i.struct.generator.atomGroups({...n?{"chain-test":i.core.rel.eq([i.struct.atomProperty.macromolecular.label_entity_id(),n])}:{},"residue-test":i.core.set.has([i.core.type.set([...new Set(r)]),i.struct.atomProperty.macromolecular.label_seq_id()]),"group-by":i.struct.atomProperty.macromolecular.residueKey()}),t);return e.StructureSelection.toLociWithSourceUnits(o)}async function kt({interactivity:e,channel:t,targets:n}){let r=await h(),o=n.filter(s=>s.labelSeqIds.length>0).map(s=>ie(r,s)),{lociHighlights:i,lociSelects:a}=e;if(t==="highlight"){i.clearHighlights();for(let s of o)i.highlight({loci:s},!1)}else{a.deselectAll();for(let s of o)a.select({loci:s},!1)}}function ae(e){let{structures:t,superposedCount:n}=e,r=t.filter(o=>o.loadedToMolstar).length;return t.length>0&&t.every(o=>!o.loading)&&(r<2||n===r)}async function se(e,t,n=()=>!0){let r=await h();if(n()){let o=t.map(i=>ie(r,i));e.managers.camera.focusLoci(o),o[0]&&t[0]?.labelSeqIds.length===1&&e.managers.structure.focus.setFromLoci(o[0])}}function xt(e){let t;return function(){let{molstarPluginContext:r,structures:o}=e;if(!r||r===t||!ae(e))return;let i=o.flatMap(a=>a.seedLit&&!a.hidden&&a.molstarStructure&&a.clickedLabelSeqIds.length?[{structure:a.molstarStructure,entityId:a.mappedEntity?.entityId,labelSeqIds:a.clickedLabelSeqIds}]:[]);i.length!==0&&(t=r,se(r,i,()=>e.molstarPluginContext===r).catch(a=>{console.error(a)}))}}function ue(e,t){return function(){let r=e.molstarPluginContext,o=e.structures.flatMap(i=>i.molstarStructures.map(a=>({structure:a,entityId:i.mappedEntity?.entityId,labelSeqIds:t==="select"?i.selectLabelSeqIds:i.hoverLabelSeqIds})));r&&kt({interactivity:r.managers.interactivity,channel:t,targets:o}).catch(i=>{console.error(i)})}}async function z({plugin:e,molstarStructure:t}){if(!t)return;let n=await h(),{PluginCommands:r,PluginStateObject:o}=n,i=E(e,n,t),s=(i&&e.state.data.selectQ(d=>d.byValue(i).ancestorOfType(o.Molecule.Trajectory))[0])??i;s&&await r.State.RemoveObject(e,{state:e.state.data,ref:s.transform.ref,removeParentGhosts:!0})}var vt=T(q());function x(e,t){return n=>{console.error(n),(0,vt.isAlive)(e)&&e.molstarPluginContext===t&&e.setError(n)}}var _="jbrowse-session-highlights",Rt=["bottom-left","top-right","top-left","bottom-right"];function pn(e){return Math.min(8,Math.max(3,e/10))}var gn="#FFB11D";function qt({highlights:e,mapping:t,naming:n,entity:r,transcriptToStructure:o,labels:i}){let a=n.canonicalRefName(t.refName);return e.flatMap(s=>{if(!n.isAssembly(s.assemblyName)||n.canonicalRefName(s.refName)!==a)return[];let d=new Set;for(let u=s.start;u<s.end;u++){let c=t.g2p[u],l=c===void 0?void 0:o[c],m=l===void 0?void 0:r.seqIds[l];m!==void 0&&d.add(m)}return d.size>0?[{entityId:r.entityId,labelSeqIds:[...d].sort((u,c)=>u-c),label:i&&s.label?s.label:void 0,color:s.color??gn}]:[]})}async function Lt({plugin:e,structures:t}){let n=await h(),{Color:r,MolScriptBuilder:o,StateSelection:i,StateTransforms:a,StructureElement:s,StructureProperties:d,createStructureRepresentationParams:u}=n,c=(g,b)=>{let S=s.Location.create(g);for(let y of g.units)if(S.unit=y,S.element=y.elements[0],d.entity.id(S)===b)return d.chain.label_asym_id(S)},l=e.state.data.build(),m=e.state.data.select(i.Generators.root.subtree().withTag(_));for(let g of m)l.delete(g.transform.ref);for(let{molstarStructure:g,marks:b}of t){let S=E(e,n,g);if(!S)continue;let{radius:y}=g.boundary.sphere,I=pn(y);for(let[A,{entityId:P,labelSeqIds:w,label:M,color:k}]of b.entries()){let W=o.struct.generator.atomGroups({"entity-test":o.core.rel.eq([o.ammp("label_entity_id"),P]),"residue-test":o.core.set.has([o.set(...w),o.ammp("label_seq_id")])});l.to(S).apply(a.Model.StructureComponent,{type:{name:"expression",params:W},nullIfEmpty:!0,label:M??"Session highlight"},{tags:[_]}).apply(a.Representation.StructureRepresentation3D,u(e,g,{type:"ball-and-stick",typeParams:{sizeFactor:.3,sizeAspectRatio:.6},color:"uniform",colorParams:{value:r.fromHexStyle(k)}}),{tags:[_]});let Se=M?c(g,P):void 0;if(M&&Se){let sn=o.struct.generator.atomGroups({"chain-test":o.core.rel.eq([o.ammp("label_asym_id"),Se]),"residue-test":o.core.set.has([o.set(...w),o.ammp("label_seq_id")])});l.toRoot().apply(a.Model.MultiStructureSelectionFromExpression,{selections:[{key:"a",ref:S.transform.ref,expression:sn}],isTransitive:!0,label:M},{dependsOn:[S.transform.ref],tags:[_]}).apply(a.Representation.StructureSelectionsLabel3D,{customText:M,textSize:I,attachment:Rt[A%Rt.length],tether:!0,tetherLength:3,scaleByRadius:!1,textColor:r(0),borderWidth:0,background:!0,backgroundColor:r(16777215),backgroundOpacity:.85,offsetZ:y},{tags:[_]})}}}await l.commit()}function Vt(e){return!e.minimized&&!e.error&&e.structures.some(t=>t.loading)}var Ht="proteinView-settings",Ft=["showAlignment","showProteinTracks","showControls","autoScrollAlignment","compactTracks","showAllFeatureTracks"];function Nt(e,t){if(!t)return e;let n={...e};for(let r of Ft)n[r]===void 0&&t[r]!==void 0&&(n[r]=t[r]);return n}function ce(){let e=We(Ht);if(typeof e!="object"||e===null)return;let t={};for(let n of Ft){let r=Reflect.get(e,n);typeof r=="boolean"&&(t[n]=r)}return t}function _t(e,t){Je(Ht,JSON.stringify({...ce(),[e]:t}))}var L=T(q());function fn(e,{PdbFormat:t}){if(!t.is(e))return[];let{data:n,indices:r,count:o}=e.data.lines,i=[];for(let a=0;a<o;a++){let s=n.substring(r[2*a],r[2*a+1]);if(s.startsWith("EXPDTA"))i.push(...s.slice(10).split(";"));else if(s.startsWith("ATOM")||s.startsWith("HETATM"))break}return i.map(a=>a.trim()).filter(a=>a!=="")}function Sn(e,t){if(!e||!t.MmcifFormat.is(e))return[];let{db:n,source:r}=e.data;return[...Array.from(n.exptl.method.toArray()),...r?fn(r,t):[]]}async function de({structure:e,plugin:t}){let{data:n,url:r}=e,{model:o,structures:i,modelIds:a}=await pt({plugin:t,data:n||void 0,url:r}),s=Sn(o?.obj?.data.sourceData,await h()).some(d=>d!=="THEORETICAL MODEL");return{entities:o?ke(o):void 0,confidence:o&&!s?qe(o):void 0,molstarStructures:i,modelIds:a}}function Gt(e,t=_e){let n=new Map,r=new WeakMap;function o(u){let{url:c,data:l,uniprotId:m}=u;return c===void 0&&l===void 0?m:void 0}async function i(u,c){let l=await t(c).catch(()=>{});if(!(0,L.isAlive)(u))return;if(l===void 0){u.setUrl(De(c));return}let m=Ge(l,{transcript:{seq:u.userProvidedTranscriptSequence}});if(!m)throw new Error(`AlphaFold DB has no model for ${c}`);u.setUrl(m.url)}function a(u,c){n.get(u)===c&&n.delete(u)}function s(u,c){n.get(u)!==c&&d(u,c)}function d(u,c){n.set(u,c),u.setError(void 0);let l=o(u);(l===void 0?de({structure:u,plugin:c}):i(u,l).then(()=>(0,L.isAlive)(u)?de({structure:u,plugin:c}):void 0)).then(g=>{if(!g){a(u,c);return}if(!(0,L.isAlive)(u)){a(u,c),z({plugin:c,molstarStructure:g.molstarStructures?.[0]}).catch(S=>{console.error(S)});return}let b=e.molstarPluginContext;b===c&&(u.setStructureData(g),u.setLoadedToMolstar(!0)),a(u,c),b&&b!==c&&!u.loadedToMolstar&&s(u,b)}).catch(g=>{if(a(u,c),!(0,L.isAlive)(e)||!(0,L.isAlive)(u))return;let b=e.molstarPluginContext;b&&b!==c?s(u,b):(r.set(u,c),u.setError(g),console.error(g))})}return function(){let{structures:c,molstarPluginContext:l}=e;if(l)for(let m of c)!m.loadedToMolstar&&n.get(m)!==l&&r.get(m)!==l&&d(m,l)}}var C=T(K()),p=T(q()),R=T(ne());function Dt(e){let{userProvidedTranscriptSequence:t,entities:n,pairwiseAlignment:r}=e;if(!t||!n?.length)return{kind:"nothingToAlign"};if(r){if(!e.alignmentImported)return{kind:"keep"};let{mappedEntityId:o}=e,i=j(r,t,n,o);if("entityId"in i)return{kind:"adopt",entityId:i.entityId};let a=n.find(s=>s.entityId===o&&!s.nucleicAcid);return a?{kind:"realign",problem:i.problem,transcript:t,entity:a,identical:H(t,a.seq)}:{kind:"discard",problem:i.problem}}return{kind:"choose",transcript:t,entities:n,identical:n.some(o=>!o.nucleicAcid&&H(t,o.seq))}}function Ot({hovered:e,views:t,mapping:n,connectedViewId:r,genomeViewReady:o,naming:i}){let a=o?he(e,n,i):void 0;if(a!==void 0)return{transcriptPos:a,source:"genome"};let s=r?t.find(c=>c.type==="MsaView"&&c.connectedViewId===r&&!!c.connectedHoverHighlights?.length)?.connectedHoverHighlights?.[0]:void 0,{canonicalRefName:d}=i,u=n&&s&&d(s.refName)===d(n.refName)?n.g2p[s.start]:void 0;return u===void 0?void 0:{transcriptPos:u,source:"msa"}}function Ut(e,t){if(!e||t===void 0)return;let n=Me(e.p2gCodon,t);return n?`${e.refName}:${n[0]+1}-${n[1]}`:void 0}function $t({hover:e,entity:t,structureToTranscript:n,transcript:r,locus:o}){let i=e.structureSeqPos,a=i===void 0?void 0:n?.[i],s=i===void 0?void 0:t?.seq[i],d=a===void 0?void 0:r[a],u=[];if(i!==void 0){let c=O(t,i);u.push(`${c}`),a!==void 0&&a+1!==c&&u.push(`Transcript residue: ${a+1}`)}return s&&u.push(`Structure: ${s}`),d&&s&&d!==s&&u.push(`Genome: ${d}`),e.chain&&u.push(`Chain: ${e.chain}`),o&&u.push(o),u.join(", ")}var Bt=T(K());function jt(e,t){let n=e.genomeToTranscriptSeqMapping;if(!n)return[];let r=[];for(let o of t)for(let i=o.start;i<o.end;i++){let a=e.structureSeqToTranscriptSeqPosition?.[i];a!==void 0&&r.push(a)}return ze(n.p2gCodon,r)}function zt({ranges:e,assemblyName:t,model:n}){let r=n.genomeToTranscriptSeqMapping?.refName;return t&&r?jt(n,e).map(([o,i])=>({assemblyName:t,refName:r,start:o,end:i})):[]}async function le({model:e,structureSeqPos:t,structureSeqEndPos:n,zoomToBaseLevel:r}){let o=(0,Bt.getSession)(e),{connectedView:i,genomeToTranscriptSeqMapping:a}=e;if(!a||!i)return;let{strand:s,refName:d}=a,u=i.assemblyNames[0];if(!u)return;let c=jt(e,[{start:t,end:n??t+1}]),l=c[0]?.[0],m=c.at(-1)?.[1];if(!(l===void 0||m===void 0))if(r)await i.navToLocString(`${d}:${l+1}-${m}${s===-1?"[rev]":""}`,void 0,.2);else{let{assemblyManager:g}=o,S=g.get(u)?.getCanonicalRefName(d)??d;i.centerAt((l+m)/2,S)}}async function J({model:e,structureSeqPos:t,structureSeqEndPos:n}){e.setClickedStructureRanges([{start:t,end:n??t+1}]),await le({model:e,structureSeqPos:t,structureSeqEndPos:n,zoomToBaseLevel:e.zoomToBaseLevel})}var Jt=/-\d+$/;function Wt({uniprotId:e,pdbId:t,modelAccession:n,uniProtMappings:r,uniProtMappingsError:o,mappedEntity:i}){if(e&&!t){let s=[n,e].find(d=>d!==void 0&&Jt.test(d));return{uniprotId:e.replace(Jt,""),uniprotName:void 0,mapUniProtPosition:s?()=>{}:Z,isLoading:!1,error:void 0,isoformAccession:s}}let a=r?Ve(r,i):void 0;return{uniprotId:a?.accession,uniprotName:a?.name,mapUniProtPosition:a?Fe(a.segments):Z,isLoading:!!t&&!r&&!o,error:o}}function Kt(e,t,n){return function(){let o=e.variantEffectAsk,i=e.variantEffects;if(!o){i&&e.setVariantEffects(void 0);return}if(o.status!=="ready"||i?.key===o.request.key)return;let{request:a}=o,{key:s}=a;e.setVariantEffects({key:s});let d=u=>{t()&&e.variantEffects?.key===s&&e.setVariantEffects({key:s,...u})};n(a).then(u=>{d({values:u})},u=>{d({error:u})})}}function Yt({ask:e,state:t,entity:n,pdbId:r,mapUniProtPosition:o,transcriptToStructure:i}){if(e?.status!=="ready")return{pending:e?.status==="waiting",message:e?.status==="unavailable"?e.reason:void 0};let{request:a}=e,s=t?.key===a.key?t:void 0,d=Xe[a.scheme],{error:u}=s??{};if(u!==void 0)return{pending:!1,message:u instanceof Qe?u.message:`Could not fetch ${d} for ${a.label}: ${D(u)}`};let c=s?.values;if(!c)return{pending:!0};if(c.numbering==="uniprot"&&!r&&n&&c.sequence!==n.seq)return{pending:!1,message:`${d} for ${a.label} number a sequence that differs from this model's`};let l=c.numbering==="uniprot"?o:i&&(m=>i[m]);return{pending:!1,placed:n&&l?Ze(c.byPosition,l,n):void 0}}function hn(e){return"assemblyNames"in e}var bn=[],Pn=p.types.model({url:p.types.maybe(p.types.string),data:p.types.maybe(p.types.string),uniprotId:p.types.maybe(p.types.string),connectedViewId:p.types.maybe(p.types.string),pairwiseAlignment:p.types.frozen(),feature:p.types.frozen(),userProvidedTranscriptSequence:p.types.optional(p.types.string,""),initialSelection:p.types.frozen(),initialResidues:p.types.frozen(),initialTranscriptResidues:p.types.frozen(),mappedEntityId:p.types.maybe(p.types.string),alignmentImported:p.types.optional(p.types.boolean,!1),hidden:p.types.optional(p.types.boolean,!1)}).volatile(()=>({clickedStructureRanges:[],seedLit:!1,selectionTouched:!1,hoverPosition:void 0,entities:void 0,structureConfidence:void 0,isMouseInAlignment:!1,alignmentSkipped:void 0,entityChosen:!1,aligning:!1,pendingEntityId:void 0,alignmentRedecisions:0,loadedToMolstar:!1,molstarStructures:new Array,molstarModelIds:new Array,alignmentHoverRange:void 0,selectedFeatureId:void 0,hiddenFeatureTypes:new Set,expandedFeatureTypes:new Set,uniProtMappings:void 0,uniProtMappingsError:void 0,variantEffects:void 0,error:void 0})).actions(e=>({setUrl(t){e.url=t},setError(t){e.error=t},setUniProtMappings(t,n){e.uniProtMappings=t,e.uniProtMappingsError=n},setVariantEffects(t){e.variantEffects=t},setStructureData(t){e.entities=t.entities,e.structureConfidence=t.confidence,e.molstarStructures=t.molstarStructures??[],e.molstarModelIds=t.modelIds??new Array},hideFeatureType(t){e.hiddenFeatureTypes=new Set([...e.hiddenFeatureTypes,t])},showAllFeatureTypes(){e.hiddenFeatureTypes=new Set},toggleFeatureTypeExpanded(t){let n=new Set(e.expandedFeatureTypes);n.has(t)?n.delete(t):n.add(t),e.expandedFeatureTypes=n},setLoadedToMolstar(t){e.loadedToMolstar=t,t||(e.molstarStructures=[],e.molstarModelIds=new Array)}})).views(e=>({get molstarStructure(){return e.molstarStructures[0]},get connectedView(){let{views:t}=(0,C.getSession)(e);return t.filter(hn).find(n=>n.id===e.connectedViewId)}})).actions(e=>({setClickedStructureRanges(t){e.clickedStructureRanges=t,e.selectionTouched=!0,e.seedLit=!1},applySeed(t){e.selectionTouched||(e.clickedStructureRanges=t,e.seedLit=t.length>0)},setAlignmentHoverRange(t){e.alignmentHoverRange=t},setSelectedFeatureId(t){e.selectedFeatureId=t},setHoveredPosition(t){let n=e.hoverPosition;(t===void 0?n!==void 0:n?.source!=="structure"||n.structureSeqPos!==t.structureSeqPos||n.chain!==t.chain)&&(e.hoverPosition=t?{...t,source:"structure"}:void 0)},setConnectedHoveredPosition(t,n="genome"){let r=t===void 0?void 0:{structureSeqPos:t,source:n},o=e.hoverPosition;(r?.structureSeqPos!==o?.structureSeqPos||r?.source!==o?.source)&&(e.hoverPosition=r)},setAlignment(t,n=!1){e.pairwiseAlignment=t,e.alignmentImported=n,e.alignmentSkipped=void 0},setAlignmentSkipped(t){e.alignmentSkipped=t},setEntityChosen(){e.entityChosen=!0},setAligning(t,n){e.aligning=t,e.pendingEntityId=n},settleAlignment(t){e.aligning=!1,e.pendingEntityId=void 0,t()},setHidden(t){e.hidden=t},setMappedEntityId(t){e.mappedEntityId=t},setIsMouseInAlignment(t){e.isMouseInAlignment=t},leaveAlignment(){e.hoverPosition=void 0,e.isMouseInAlignment=!1}})).views(e=>({get mappedEntity(){let{entities:t,mappedEntityId:n}=e;return t?.find(r=>r.entityId===n)??t?.find(r=>!r.nucleicAcid)??t?.[0]},get mappedStructureSeq(){return this.mappedEntity?.seq},get label(){return $e(e)},get pdbId(){let{url:t}=e;return t&&!U(t)?Ue(t):void 0},get uniProtEntry(){return Wt({uniprotId:e.uniprotId,pdbId:this.pdbId,modelAccession:e.url?U(e.url):void 0,uniProtMappings:e.uniProtMappings,uniProtMappingsError:e.uniProtMappingsError,mappedEntity:this.mappedEntity})},get alignment(){let t=e.pairwiseAlignment;return!t||!e.uniProtMappings||e.alignmentImported?t:we(t,He(e.uniProtMappings,this.mappedEntity,Te(t)))},get coordinateMapper(){let{alignment:t}=this;return t?Ce(t):void 0},get structureSeqToTranscriptSeqPosition(){return this.coordinateMapper?.maps.structureSeqToTranscriptSeqPosition},get transcriptSeqToStructureSeqPosition(){return this.coordinateMapper?.maps.transcriptSeqToStructureSeqPosition},get structurePositionToAlignmentMap(){return this.coordinateMapper?.maps.structurePositionToAlignmentMap},get confidenceCells(){let t=this.mappedEntity,n=e.structureConfidence?.find(o=>o.entityId===t?.entityId);if(!t||!n)return[];let r=t.seqIds.map(o=>n.byLabelSeqId.get(o));return Le(r.filter(o=>o!==void 0))?ee(r,this.structurePositionToAlignmentMap):[]},get hydrophobicityCells(){let t=this.mappedStructureSeq;return t&&!this.mappedEntity?.nucleicAcid?ee(mt(V(t)),this.structurePositionToAlignmentMap):[]},get pairwiseAlignmentToStructurePosition(){return this.coordinateMapper?.maps.alignmentToStructurePosition},get hoverString(){let t=e.hoverPosition;return t?$t({hover:t,entity:this.mappedEntity,structureToTranscript:this.structureSeqToTranscriptSeqPosition,transcript:e.userProvidedTranscriptSequence,locus:this.hoverGenomeLocus}):""},get hoverGenomeLocus(){let t=this.structureSeqHoverPos;return Ut(this.genomeToTranscriptSeqMapping,t===void 0?void 0:this.structureSeqToTranscriptSeqPosition?.[t])},get genomeToTranscriptSeqMapping(){return e.feature?je(new C.SimpleFeature(e.feature)):void 0},get structureSeqHoverPos(){return e.hoverPosition?.structureSeqPos},get alignmentHoverPos(){let t=this.structureSeqHoverPos;return t===void 0?void 0:this.coordinateMapper?.structureToAlignment(Ee(t))},get hoverStructureRange(){let{alignmentHoverRange:t}=e,n=this.pairwiseAlignmentToStructurePosition;if(!t||!n)return;let r=n[t.start],o=n[t.end];return r===void 0||o===void 0?void 0:{start:r,end:o+1}},get hoverHighlightRange(){let t=this.structureSeqHoverPos;return this.hoverStructureRange??(t===void 0?void 0:{start:t,end:t+1})},get labelSeqIdIndex(){return Re(this.mappedEntity)},get selectLabelSeqIds(){let t=this.mappedEntity;if(e.clickedStructureRanges.length)return this.clickedLabelSeqIds;let n=this.structureSeqToTranscriptSeqPosition;return this.showHighlight&&n?ve(t,Object.keys(n).map(Number)):[]},get clickedLabelSeqIds(){let t=this.mappedEntity;return e.clickedStructureRanges.flatMap(n=>Q(t,n))},get seededSelection(){return[e.initialSelection,e.initialResidues,e.initialTranscriptResidues].some(t=>re(t).length>0)},get hoverLabelSeqIds(){return Q(this.mappedEntity,this.hoverHighlightRange)},get clickAlignmentRanges(){let t=this.structurePositionToAlignmentMap;return t?e.clickedStructureRanges.flatMap(n=>{let r=t[n.start],o=t[n.end-1];return r===void 0||o===void 0?[]:[{start:r,end:o}]}):[]},get alignmentMatchSet(){let t=this.alignment?.consensus;if(!t)return;let n=new Set;for(let r=0;r<t.length;r++)(t[r]==="|"||t[r]===":")&&n.add(r);return n},get alignmentPending(){return e.aligning||!e.pairwiseAlignment&&!e.alignmentSkipped&&!!e.userProvidedTranscriptSequence&&!!e.entities?.length},get loading(){return e.error!==void 0?!1:!e.loadedToMolstar||this.alignmentPending||!!this.pdbId&&e.uniProtMappings===void 0&&e.uniProtMappingsError===void 0},get loadingMessage(){if(this.loading){if(!e.loadedToMolstar)return e.url===void 0&&e.data===void 0&&e.uniprotId?`Resolving AlphaFold model for ${e.uniprotId}`:`Loading ${this.label}`;if(this.alignmentPending){let t=e.feature?.name;return typeof t=="string"?`Aligning ${this.label} to ${t}`:`Aligning ${this.label}`}return`Mapping ${this.label} to UniProt`}},get alignmentQuality(){let{alignment:t}=this;return t?Ie(t):void 0},get exactMatch(){let t=V(e.userProvidedTranscriptSequence),n=this.mappedStructureSeq?V(this.mappedStructureSeq):void 0;return t===n},get parentView(){return(0,p.getParent)(e,2)},get zoomToBaseLevel(){return this.parentView.zoomToBaseLevel},get autoScrollAlignment(){return this.parentView.autoScrollAlignment},get showHighlight(){return this.parentView.showHighlight},get showProteinTracks(){return this.parentView.showProteinTracks},get showAllFeatureTracks(){return this.parentView.showAllFeatureTracks},get omittedFeatureTypes(){return this.showAllFeatureTracks?e.hiddenFeatureTypes:new Set([...St,...e.hiddenFeatureTypes])},get columnWidth(){return 6},get trackHeight(){return F(this.parentView)},get trackGap(){return ft(this.trackHeight)},get laneHeight(){return this.trackHeight+this.trackGap},get alignmentAlgorithm(){return this.parentView.alignmentAlgorithm},get molstarPluginContext(){return this.parentView.molstarPluginContext}})).views(e=>({residueNumber(t){return O(e.mappedEntity,t)},interactionPosition(t){return e.molstarModelIds.includes(t.modelId)&&t.entityId===e.mappedEntity?.entityId?e.labelSeqIdIndex.get(t.labelSeqId):void 0},structureRangesToGenomeHighlight(t){return zt({ranges:t,assemblyName:e.connectedView?.assemblyNames[0],model:{genomeToTranscriptSeqMapping:e.genomeToTranscriptSeqMapping,structureSeqToTranscriptSeqPosition:e.structureSeqToTranscriptSeqPosition}})}})).views(e=>({get hoverGenomeHighlights(){let t=e.hoverPosition?.source;return t==="genome"||t==="msa"?bn:e.structureRangesToGenomeHighlight(re(e.hoverHighlightRange))},get clickGenomeHighlights(){return e.structureRangesToGenomeHighlight(e.clickedStructureRanges)}})).views(e=>({get hydrophobicityScale(){let{color:t}=e.parentView,n=(t.field==="hydrophobicity"?$(t):void 0)??rt.hydrophobicity;return{title:n.title??"",paint:dt(n),key:lt(n)}},get variantEffectAsk(){let{field:t}=e.parentView.color;if(t==="alphaMissense")return et(e.uniProtEntry);if(t==="clinvarPathogenicCount"){let n=e.connectedView?.assemblyNames[0],r=n?(0,C.getSession)(e).assemblyManager.get(n):void 0;return tt({feature:e.feature,assemblyName:n,assemblyNames:[...n?[n]:[],...r?[r.name,...r.aliases]:[]]})}}})).views(e=>({get variantEffectStatus(){return Yt({ask:e.variantEffectAsk,state:e.variantEffects,entity:e.mappedEntity,pdbId:e.pdbId,mapUniProtPosition:e.uniProtEntry.mapUniProtPosition,transcriptToStructure:e.transcriptSeqToStructureSeqPosition})},get genomeNaming(){return ye((0,C.getSession)(e).assemblyManager,e.connectedView?.assemblyNames[0])},get alignmentDomains(){return at((0,C.getSession)(e).views,e.connectedViewId).domains}})).views(e=>({get alignmentDomainStatus(){return e.parentView.color.field==="domain"?st({views:(0,C.getSession)(e).views,connectedViewId:e.connectedViewId,mapping:e.genomeToTranscriptSeqMapping,naming:e.genomeNaming,entity:e.mappedEntity,transcriptToStructure:e.transcriptSeqToStructureSeqPosition}):void 0},get sessionHighlightMarks(){let t=(0,C.getSession)(e),{genomeToTranscriptSeqMapping:n,mappedEntity:r,transcriptSeqToStructureSeqPosition:o}=e;return t.highlightsVisible&&n&&r&&o?qt({highlights:t.highlights,mapping:n,naming:e.genomeNaming,entity:r,transcriptToStructure:o,labels:!("highlightLabelsVisible"in t&&t.highlightLabelsVisible===!1)}):[]},get domainRows(){let{alignmentDomains:t,genomeToTranscriptSeqMapping:n,transcriptSeqToStructureSeqPosition:r,structurePositionToAlignmentMap:o}=e;return t&&n&&r&&o?ut({domains:t,mapping:n,naming:e.genomeNaming,transcriptToStructure:r,structureToAlignment:o}):[]}})).views(e=>({get placedVariantEffects(){return e.variantEffectStatus.placed},get placedValues(){return e.alignmentDomainStatus?.placed??e.variantEffectStatus.placed},get variantEffectsPending(){return e.variantEffectStatus.pending},get statusMessage(){let{error:t}=e;return t===void 0?e.alignmentSkipped??e.variantEffectStatus.message??e.alignmentDomainStatus?.message:D(t)}})).views(e=>({resolveSelection({positions:t,residues:n,transcriptResidues:r}){let o=!!e.entities&&(e.entityChosen||!e.userProvidedTranscriptSequence),i=e.coordinateMapper;if(!(n&&!o)&&!(r&&e.loading))return oe([...oe(t??[]),...n?yt(e.mappedEntity,n):[],...i&&r?ht(i,r):[]])}})).extend(e=>{let t=0;function n(){t++,e.setAligning(!1)}return{actions:{supersedeAlignment:n,redecideAlignment(){t++,e.aligning=!1,e.pendingEntityId=void 0,e.alignmentRedecisions++},runAlignment({identical:r,name:o,args:i,inPlace:a,apply:s,fail:d,pendingEntityId:u}){if(r){n();try{s(a())}catch(m){console.error(m),e.setError(m)}return}let c=++t,l=()=>c===t&&(0,p.isAlive)(e);e.setAligning(!0,u),Be({rpcManager:(0,C.getSession)(e).rpcManager,name:o,args:i,inPlace:a,current:l}).then(m=>{if(l())try{e.settleAlignment(()=>{s(m)})}catch(g){console.error(g),e.setError(g)}},m=>{l()&&(console.error(m),e.settleAlignment(()=>{d(m)}))})}}}}).actions(e=>({applyEntitySelection(t){let n=e.entities??[];if(t)e.setMappedEntityId(n[t.index]?.entityId),e.setAlignment(t.alignment);else{let r=n.filter(o=>!o.nucleicAcid&&o.seq.length>0);e.setAlignmentSkipped(r.length?`No chain could be aligned: ${r.map(o=>xe(o)).join(", ")} exceed the alignment size limit against this ${V(e.userProvidedTranscriptSequence).length} aa transcript`:"This structure has no protein chain to align the transcript to")}e.setEntityChosen()},applyRealignment(t){e.setAlignment(t?.alignment),t&&e.setEntityChosen()},switchEntity(t){e.setMappedEntityId(t),e.setClickedStructureRanges([]),e.setAlignmentHoverRange(void 0),e.setSelectedFeatureId(void 0),e.setHoveredPosition(void 0)}})).actions(e=>({applyChosenEntity(t,n){e.switchEntity(t),e.setAlignment(n)},importAlignment(t){let{entities:n,mappedEntityId:r}=e,o=n?j(t,e.userProvidedTranscriptSequence,n,r):void 0;o&&"entityId"in o&&o.entityId!==r&&e.switchEntity(o.entityId),e.supersedeAlignment(),e.setAlignment(t,!0)}})).actions(e=>({setViewError(t){e.parentView.setError(t)},resizeTracks(t){e.parentView.resizeTracks(t)},hoverAlignmentPosition(t){if(!e.alignmentHoverRange){let n=e.coordinateMapper?.alignmentToStructure(Y(t));e.setHoveredPosition(n!==void 0?{structureSeqPos:n}:void 0)}},chooseEntity(t){let n=e.entities?.find(s=>s.entityId===t),r=e.mappedEntity?.entityId;if(!n||t===(e.pendingEntityId??r))return;if(!e.userProvidedTranscriptSequence){e.switchEntity(t);return}if(e.pendingEntityId!==void 0&&t===r){e.redecideAlignment();return}let o=e.userProvidedTranscriptSequence,i=()=>X(o,n.seq,e.alignmentAlgorithm),a=s=>{s?e.applyChosenEntity(t,s.alignment):(e.parentView.setError(new Error(`${n.chains.join("/")||n.entityId} is too long to align to this transcript`)),e.redecideAlignment())};e.runAlignment({identical:H(o,n.seq),name:"ProteinAlignTranscriptToEntity",args:{transcript:o,entitySeq:n.seq,algorithm:e.alignmentAlgorithm},inPlace:i,apply:a,fail:s=>{e.parentView.setError(s),e.redecideAlignment()},pendingEntityId:t})},selectResidues(t,n){e.parentView.clearSelection(),J({model:e,structureSeqPos:t,structureSeqEndPos:n}).catch(r=>{console.error(r),e.parentView.setError(r)})}})).actions(e=>({clickAlignmentPosition(t){let n=e.coordinateMapper?.alignmentToStructure(Y(t));n===void 0?e.parentView.clearSelection():e.selectResidues(n)},toggleDomainRow(t){let n=`alignment:${t.accession}`;e.selectedFeatureId===n?(e.setSelectedFeatureId(void 0),e.setClickedStructureRanges([])):(e.parentView.clearSelection(),e.setClickedStructureRanges(t.bars.map(r=>({start:r.structureStart,end:r.structureEnd}))),e.setSelectedFeatureId(n))}})).actions(e=>({async focusResidues(t,{timeout:n=12e4}={}){let r=()=>(e.entityChosen||!e.userProvidedTranscriptSequence)&&e.parentView.settled&&e.resolveSelection(t)!==void 0;try{await(0,R.when)(()=>!(0,p.isAlive)(e)||e.error!==void 0||r(),{timeout:n})}catch{throw new Error(`${e.label} did not finish loading`)}if(!(0,p.isAlive)(e))return[];if(e.error!==void 0)throw new Error(`${e.label} failed`,{cause:e.error});let o=e.resolveSelection(t)??[];e.parentView.clearSelection(),e.setClickedStructureRanges(o),e.setHidden(!1);let i=o[0],a=o.at(-1),s=e.molstarPluginContext,d=e.molstarStructure,u=e.clickedLabelSeqIds;return s&&d&&u.length&&se(s,[{structure:d,entityId:e.mappedEntity?.entityId,labelSeqIds:u}],()=>e.molstarPluginContext===s).catch(c=>{console.error(c)}),i&&a&&le({model:e,structureSeqPos:i.start,structureSeqEndPos:a.end,zoomToBaseLevel:e.zoomToBaseLevel}).catch(c=>{console.error(c),e.parentView.setError(c)}),o}})).actions(e=>({afterAttach(){let{pdbId:t}=e;(0,p.addDisposer)(e,(0,R.autorun)(Kt(e,()=>(0,p.isAlive)(e),o=>nt(o,(0,C.getSession)(e))))),t&&Ne(t).then(o=>{(0,p.isAlive)(e)&&e.setUniProtMappings(o)},o=>{(0,p.isAlive)(e)&&e.setUniProtMappings(void 0,o)});let n={positions:e.initialSelection,residues:e.initialResidues,transcriptResidues:e.initialTranscriptResidues};e.seededSelection&&(0,p.addDisposer)(e,(0,R.when)(()=>e.selectionTouched||e.resolveSelection(n)!==void 0,()=>{e.applySeed(e.resolveSelection(n)??[])}));let r;(0,p.addDisposer)(e,(0,R.autorun)(()=>{try{let{alignmentAlgorithm:o}=e;e.alignmentRedecisions;let i=Dt(e),a=s=>{e.setViewError(new Error(`The alignment stored for ${e.label} no longer matches its chain and was recomputed: ${s}`))};switch(i.kind){case"nothingToAlign":e.supersedeAlignment();break;case"keep":e.setEntityChosen();break;case"adopt":e.setMappedEntityId(i.entityId),e.setEntityChosen();break;case"discard":a(i.problem),e.supersedeAlignment(),e.applyRealignment(void 0);break;case"realign":{let{transcript:s,entity:{seq:d}}=i,u=`${o}:${s}:${d}`;if(u===r&&e.aligning)break;r=u,a(i.problem),e.runAlignment({identical:i.identical,name:"ProteinAlignTranscriptToEntity",args:{transcript:s,entitySeq:d,algorithm:o},inPlace:()=>X(s,d,o),apply:c=>{e.applyRealignment(c)},fail:c=>{e.setError(c)}});break}case"choose":{let{transcript:s,entities:d}=i;e.runAlignment({identical:i.identical,name:"ProteinChooseMappedEntity",args:{transcript:s,entities:d.map(({seq:u,nucleicAcid:c})=>({seq:u,nucleicAcid:c})),algorithm:o},inPlace:()=>Ae(s,d,o),apply:u=>{e.applyEntitySelection(u)},fail:u=>{e.setError(u)}});break}}}catch(o){console.error(o),e.setError(o)}})),(0,p.addDisposer)(e,(0,R.autorun)(()=>{let{hovered:o,views:i}=(0,C.getSession)(e),a=Ot({hovered:o,views:i,mapping:e.genomeToTranscriptSeqMapping,connectedViewId:e.connectedViewId,genomeViewReady:!!e.connectedView?.initialized,naming:e.genomeNaming});a?e.setConnectedHoveredPosition(e.transcriptSeqToStructureSeqPosition?.[a.transcriptPos],a.source):e.hoverPosition?.source!=="structure"&&e.setConnectedHoveredPosition(void 0)}))}})),Tn=p.types.snapshotProcessor(Pn,{preProcessor({pdbId:e,uniprotId:t,...n}){let r=Oe({...n,uniprotId:t,pdbId:e});return{...n,url:r,uniprotId:t??(r?U(r):void 0),alignmentImported:n.alignmentImported??n.pairwiseAlignment!==void 0}}}),me=Tn;var Qt=T(q());var wn="SuperpositionTransform";async function Xt(e,t){let n=await h(),{QueryContext:r,StateTransforms:o,StructureElement:i,StructureSelection:a,StructureSelectionQueries:s,PluginCommands:d,tmAlign:u}=n,{query:c}=s.trace,l=t.flatMap(y=>{let[I]=y,A=y.flatMap(k=>E(e,n,k)??[]),[P]=A,w=P?.obj?.data;if(!I||!P||!w)return[];let M=a.toLociWithSourceUnits(c(new r(I)));return[{rootCell:P,cells:A,loci:i.Loci.remap(M,w)}]}),[m,...g]=l;if(!m||g.length===0)return;let S=e.state.data.selectQ(y=>y.byValue(m.rootCell).subtree().withTransformer(o.Model.TransformStructureConformation))[0]?.obj?.data.coordinateSystem;for(let{cells:y,loci:I}of g){let{bTransform:A,tmScoreA:P,tmScoreB:w,rmsd:M,alignedLength:k}=u(m.loci,I);for(let W of y)await Mn(n,e,W,A,S);e.log.info(`TM-align: TM-score=${P.toFixed(4)}/${w.toFixed(4)}, RMSD=${M.toFixed(2)} \xC5, aligned ${k} residues.`)}await new Promise(y=>{requestAnimationFrame(y),setTimeout(y,100)}),await d.Camera.Reset(e)}async function Mn({Mat4:e,StateObjectRef:t,StateTransforms:n},r,o,i,a){let s=t.resolveAndCheck(r.state.data,o);if(!s)return;let d=r.state.data.selectQ(m=>m.byRef(s.transform.ref).subtree().withTransformer(n.Model.TransformStructureConformation))[0],c={transform:{name:"matrix",params:{data:a&&!e.isIdentity(a.matrix)?e.mul(e(),a.matrix,i):i,transpose:!1}}},l=d?r.state.data.build().to(d).update(c):r.state.data.build().to(o).insert(n.Model.TransformStructureConformation,c,{tags:wn});await r.runTask(r.state.data.updateTree(l))}function Zt(e){let t=!1,n,r=[];function o(){let{molstarPluginContext:i,structures:a}=e,s=a.filter(l=>l.loadedToMolstar).map(l=>l.molstarStructures),d=s.length;i!==n&&(n=i,e.setSuperposedCount(0));let u=e.superposedCount,c=d!==u||s.some((l,m)=>l!==r[m]);i&&!t&&d>=2&&c&&(t=!0,Xt(i,s).catch(x(e,i)).finally(()=>{t=!1,(0,Qt.isAlive)(e)&&(e.molstarPluginContext===i&&e.superposedCount===u&&(r=s,e.setSuperposedCount(d)),o())}))}return o}async function en({plugin:e,structures:t,hidden:n}){let r=await h();for(let o of t){let i=E(e,r,o);i&&i.state.isHidden!==n&&r.setSubtreeVisibility(e.state.data,i.transform.ref,n)}}var G=T(q()),tn=T(ne());function In(e,t){return{labelSeqId:e.StructureProperties.residue.label_seq_id(t),code:e.StructureProperties.atom.label_comp_id(t),chain:e.StructureProperties.chain.auth_asym_id(t),entityId:e.StructureProperties.entity.id(t),modelId:t.unit.model.id}}async function pe({plugin:e,kind:t,onUpdate:n}){let r=await h(),o=!1,i=e.behaviors.interaction[t].subscribe(a=>{if(o)if(r.StructureElement.Loci.is(a.current.loci)){let s=r.StructureElement.Loci.getFirstLocation(a.current.loci);n(s?In(r,s):void 0)}else n(void 0)});return o=!0,()=>{i.unsubscribe()}}function nn(e,t){let n=t&&e.interactionPosition(t);return n===void 0?void 0:{...t,structureSeqPos:n}}function En(e,t){let n=nn(e,t);e.setSelectedFeatureId(void 0),n?(e.setHoveredPosition(n),J({model:e,structureSeqPos:n.structureSeqPos}).catch(r=>{console.error(r),e.setViewError(r)})):e.setClickedStructureRanges([])}function rn(e){let t=(n,r)=>{let o;(0,G.addDisposer)(e,()=>{o?.()}),(0,G.addDisposer)(e,(0,tn.autorun)(()=>{let{molstarPluginContext:i}=e;o?.(),o=void 0,i&&pe({plugin:i,kind:n,onUpdate:r}).then(a=>{(0,G.isAlive)(e)&&e.molstarPluginContext===i?o=a:a()},x(e,i))}))};t("click",n=>{for(let r of e.structures)En(r,n)}),t("hover",n=>{for(let r of e.structures)r.setHoveredPosition(nn(r,n))})}var xn=100,vn=(0,fe.lazy)(()=>import("./AddStructureDialog-C4AV64MD.js")),Rn=(0,fe.lazy)(()=>import("./ManualAlignmentDialog-A6M3SJGN.js")),qn=[{key:"showAlignment",label:"Show alignment"},{key:"showProteinTracks",label:"Show feature tracks",requires:["showAlignment"]},{key:"showAllFeatureTracks",label:"Show all feature tracks",requires:["showAlignment","showProteinTracks"]},{key:"compactTracks",label:"Compact tracks",requires:["showAlignment","showProteinTracks"]},{key:"autoScrollAlignment",label:"Auto-scroll alignment to hovered position",requires:["showAlignment"]},{key:"showControls",label:"Show Mol* controls"}],Ln=[["showHighlight","Highlight aligned residues"],["zoomToBaseLevel","Zoom to base level on click"]];function Vn(){return f.types.compose("ProteinView",on.BaseViewModel,f.types.model({id:an.ElementId,type:f.types.literal("ProteinView"),structures:f.types.array(me),showControls:!1,height:f.types.optional(f.types.number,650),showHighlight:!1,zoomToBaseLevel:!0,autoScrollAlignment:!1,color:f.types.optional(f.types.frozen(),{}),showAlignment:!0,showProteinTracks:!0,compactTracks:!0,trackHeight:f.types.maybe(f.types.number),showAllFeatureTracks:!1,alignmentStructureIndex:f.types.maybe(f.types.number),alignmentAlgorithm:f.types.optional(f.types.enumeration("AlignmentAlgorithm",Pe),be)})).preProcessSnapshot(({colorScheme:e,...t})=>Nt({...t,displayName:t.displayName??Ke(t.structures??[]),color:te(t.color??(e===void 0?{}:gt(e)))},ce())).volatile(()=>({error:void 0,molstarPluginContext:void 0,superposedCount:0})).actions(e=>({setHeight(t){e.height=Math.max(t,xn)},resizeTracks(t){e.trackHeight=Math.min(40,Math.max(2,F(e)+t))},setError(t){e.error=t},setColor(t){e.color=te(t)},setMolstarPluginContext(t){if(t!==e.molstarPluginContext)for(let n of e.structures)n.setLoadedToMolstar(!1);e.molstarPluginContext=t},setSuperposedCount(t){e.superposedCount=t},addStructure(t){e.structures.push(me.create(t))},clearSelection(){for(let t of e.structures)t.setClickedStructureRanges([]),t.setSelectedFeatureId(void 0)},openAlignmentOf(t){e.alignmentStructureIndex=e.structures.indexOf(t)}})).actions(e=>({removeStructure(t){let n=e.molstarPluginContext,r=t.molstarStructure,o=e.structures.indexOf(t),i=e.alignmentStructureIndex;i!==void 0&&(e.alignmentStructureIndex=o===i?void 0:o<i?i-1:i),e.structures.remove(t),e.setSuperposedCount(0),n&&z({plugin:n,molstarStructure:r}).catch(x(e,n))}})).views(e=>({get tracksCompact(){return F(e)<12}})).actions(e=>({toggleSetting(t){let n=t==="compactTracks"?!e.tracksCompact:!e[t];e[t]=n,t==="compactTracks"&&(e.trackHeight=void 0),_t(t,n)},toggleBehavior(t){e[t]=!e[t]}})).actions(e=>({afterAttach(){(0,f.addDisposer)(e,(0,v.autorun)(()=>{let{molstarPluginContext:t,color:n}=e,r=e.structures.flatMap(o=>o.entities?o.molstarStructures.map(i=>({molstarStructure:i,entityId:o.mappedEntity?.entityId,placedValues:o.placedValues,placedSites:o.alignmentDomainStatus?.placedSites,domainColor:o.alignmentDomainStatus?.domains?.color})):[]);t&&r.length>0&&Ct({plugin:t,color:n,structures:r}).catch(x(e,t))})),(0,f.addDisposer)(e,(0,v.autorun)(()=>{let t=e.molstarPluginContext,n=e.structures.flatMap(r=>r.entities?r.molstarStructures.map(o=>({molstarStructure:o,sites:r.alignmentDomainStatus?.placedSites,color:r.alignmentDomainStatus?.domains?.color})):[]);t&&n.length>0&&wt({plugin:t,structures:n}).catch(x(e,t))})),(0,f.addDisposer)(e,(0,v.autorun)(()=>{let t=e.molstarPluginContext,n=e.structures.flatMap(r=>r.entities?r.molstarStructures.map(o=>({molstarStructure:o,marks:r.sessionHighlightMarks})):[]);t&&n.length>0&&Lt({plugin:t,structures:n}).catch(x(e,t))})),(0,f.addDisposer)(e,(0,v.autorun)(()=>{let t=e.molstarPluginContext;for(let n of e.structures){let{hidden:r,molstarStructures:o}=n;t&&o.length>0&&en({plugin:t,structures:o,hidden:r}).catch(x(e,t))}})),(0,f.addDisposer)(e,(0,v.autorun)(Gt(e))),(0,f.addDisposer)(e,(0,v.autorun)(Zt(e))),(0,f.addDisposer)(e,(0,v.autorun)(xt(e))),(0,f.addDisposer)(e,(0,v.autorun)(ue(e,"select"))),(0,f.addDisposer)(e,(0,v.autorun)(ue(e,"highlight"))),rn(e)}})).views(e=>({get primaryStructure(){return e.structures[0]},get showLoading(){return Vt(e)},get settled(){return ae(e)},get loadingMessages(){return e.structures.flatMap(t=>t.loadingMessage===void 0?[]:[{id:(0,f.getPath)(t),message:t.loadingMessage}])},get alignmentStructure(){let{structures:t,alignmentStructureIndex:n}=e;return(n===void 0?void 0:t[n])??t.find(r=>r.seededSelection)??t[0]},get colorLegend(){let t=e.molstarPluginContext,n=e.structures.find(o=>o.entities),r=n?.molstarStructures[0];return t&&r?At({plugin:t,color:e.color,structure:r,entityId:n.mappedEntity?.entityId,domainColor:n.alignmentDomainStatus?.domains?.color}):void 0},get domainLegend(){let t=e.color.field==="domain"?e.structures.find(n=>n.alignmentDomains)?.alignmentDomains:void 0;return t?ct(t):void 0},get displayToggles(){return qn.map(({key:t,label:n,requires:r=[]})=>{let o=r.some(i=>!e[i]);return{key:t,label:n,checked:t==="compactTracks"?e.tracksCompact:e[t],disabled:o,toggle:()=>{o||e.toggleSetting(t)}}})},get behaviorToggles(){return Ln.map(([t,n])=>({label:n,checked:e[t],toggle:()=>{e.toggleBehavior(t)}}))}})).views(e=>({offersChainPicker(t){return!e.showAlignment||e.alignmentStructure===t||!t.userProvidedTranscriptSequence},menuItems(){return[{label:"Add structure...",onClick:()=>{(0,ge.getSession)(e).queueDialog(t=>[vn,{model:e,handleClose:t}])}},...e.structures.length>0?[{label:"Remove structure",subMenu:e.structures.map(t=>({label:t.label,onClick:()=>{e.removeStructure(t)}}))}]:[],{label:"Clear selection",onClick:()=>{e.clearSelection()}},{label:"Import manual alignment...",onClick:()=>{(0,ge.getSession)(e).queueDialog(t=>[Rn,{model:e,handleClose:t}])}},{label:"Re-align structures (TM-align)",onClick:()=>{e.setSuperposedCount(0)}},{label:"Restore hidden feature tracks",onClick:()=>{for(let t of e.structures)t.showAllFeatureTypes()}}]}}))}var No=Vn;export{No as default};
2
+ //# sourceMappingURL=model-C3TFTHNF.js.map