@datagrok/helm 2.1.16 → 2.1.18
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.
- package/.eslintrc.json +1 -2
- package/CHANGELOG.md +23 -0
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +2 -2
- package/src/cell-renderer.ts +12 -7
- package/src/helm-monomer-placer.ts +30 -7
- package/src/package.ts +24 -13
- package/src/utils.ts +1 -2
package/dist/package.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var helm;(()=>{"use strict";var t={n:e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{_package:()=>Y,editMoleculeCell:()=>X,getMolfiles:()=>nt,getMonomerLib:()=>B,helmCellRenderer:()=>K,helmWebEditor:()=>rt,initHelm:()=>V,openEditor:()=>Z,propertiesPanel:()=>tt});const n=grok,r=ui,s=DG;class o{constructor(){this.w=200,this.h=100,this.host=r.div([],{style:{width:`${this.w}px`,height:`${this.h}px`}}),this.editor=new JSDraw2.Editor(this.host,{width:this.w,height:this.h,viewonly:!0})}resizeEditor(t,e){this.editor.setSize(t,e)}createWebEditor(t){const e=r.div();org.helm.webeditor.MolViewer.molscale=.8;const n=new scil.helm.App(e,{showabout:!1,mexfontsize:"90%",mexrnapinontab:!0,topmargin:20,mexmonomerstab:!0,sequenceviewonly:!1,mexfavoritefirst:!0,mexfilter:!0}),s=n.calculateSizes();n.canvas.resize(s.rightwidth-100,s.topheight-210);let o={width:s.rightwidth-100+"px",height:s.bottomheight+"px"};return scil.apply(n.sequence.style,o),scil.apply(n.notation.style,o),o={width:s.rightwidth+"px",height:s.bottomheight+n.toolbarheight+"px"},scil.apply(n.properties.parent.style,o),n.structureview.resize(s.rightwidth,s.bottomheight+n.toolbarheight),n.mex.resize(s.topheight-80),setTimeout((function(){n.canvas.helm.setSequence(t,"HELM")}),200),{editorDiv:e,webEditor:n}}}const i=wu;var l=t.n(i);class a{constructor(t,e,n){this.name=t,this.alphabet=e,this.cutoff=n}}class h extends a{constructor(t,e,n){super(t.name,t.alphabet,t.cutoff),this.freq=e,this.similarity=n}}const c=/(\[[A-Za-z0-9-_]+\]|.)/g,u=new class{constructor(){this.fasta={peptide:new Set(["G","L","Y","S","E","Q","D","N","F","A","K","R","H","C","V","P","W","I","M","T"]),dna:new Set(["A","C","G","T"]),rna:new Set(["A","C","G","U"])}}},g=[new a("PT",u.fasta.peptide,.5),new a("DNA",u.fasta.dna,.55),new a("RNA",u.fasta.rna,.55)],m=new Uint32Array(65536),p={gapOpen:8,gapExtend:2,scoringMatrix:[[4,-1,-2,-2,0,-1,-1,0,-2,-1,-1,-1,-1,-2,-1,1,0,-3,-2,0,-2,-1,0,-4],[-1,5,0,-2,-3,1,0,-2,0,-3,-2,2,-1,-3,-2,-1,-1,-3,-2,-3,-1,0,-1,-4],[-2,0,6,1,-3,0,0,0,1,-3,-3,0,-2,-3,-2,1,0,-4,-2,-3,3,0,-1,-4],[-2,-2,1,6,-3,0,2,-1,-1,-3,-4,-1,-3,-3,-1,0,-1,-4,-3,-3,4,1,-1,-4],[0,-3,-3,-3,9,-3,-4,-3,-3,-1,-1,-3,-1,-2,-3,-1,-1,-2,-2,-1,-3,-3,-2,-4],[-1,1,0,0,-3,5,2,-2,0,-3,-2,1,0,-3,-1,0,-1,-2,-1,-2,0,3,-1,-4],[-1,0,0,2,-4,2,5,-2,0,-3,-3,1,-2,-3,-1,0,-1,-3,-2,-2,1,4,-1,-4],[0,-2,0,-1,-3,-2,-2,6,-2,-4,-4,-2,-3,-3,-2,0,-2,-2,-3,-3,-1,-2,-1,-4],[-2,0,1,-1,-3,0,0,-2,8,-3,-3,-1,-2,-1,-2,-1,-2,-2,2,-3,0,0,-1,-4],[-1,-3,-3,-3,-1,-3,-3,-4,-3,4,2,-3,1,0,-3,-2,-1,-3,-1,3,-3,-3,-1,-4],[-1,-2,-3,-4,-1,-2,-3,-4,-3,2,4,-2,2,0,-3,-2,-1,-2,-1,1,-4,-3,-1,-4],[-1,2,0,-1,-3,1,1,-2,-1,-3,-2,5,-1,-3,-1,0,-1,-3,-2,-2,0,1,-1,-4],[-1,-1,-2,-3,-1,0,-2,-3,-2,1,2,-1,5,0,-2,-1,-1,-1,-1,1,-3,-1,-1,-4],[-2,-3,-3,-3,-2,-3,-3,-3,-1,0,0,-3,0,6,-4,-2,-2,1,3,-1,-3,-3,-1,-4],[-1,-2,-2,-1,-3,-1,-1,-2,-2,-3,-3,-1,-2,-4,7,-1,-1,-4,-3,-2,-2,-1,-2,-4],[1,-1,1,0,-1,0,0,0,-1,-2,-2,0,-1,-2,-1,4,1,-3,-2,-2,0,0,0,-4],[0,-1,0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1,1,5,-2,-2,0,-1,-1,0,-4],[-3,-3,-4,-4,-2,-2,-3,-2,-2,-3,-2,-3,-1,1,-4,-3,-2,11,2,-3,-4,-3,-2,-4],[-2,-2,-2,-3,-2,-1,-2,-3,2,-1,-1,-2,-1,3,-3,-2,-2,2,7,-1,-3,-2,-1,-4],[0,-3,-3,-3,-1,-2,-2,-3,-3,3,1,-2,1,-1,-2,-2,0,-3,-1,4,-3,-2,-1,-4],[-2,-1,3,4,-3,0,1,-1,0,-3,-4,0,-3,-3,-2,0,-1,-4,-3,-3,4,1,-1,-4],[-1,0,0,1,-3,3,4,-2,0,-3,-3,1,-1,-3,-1,0,-1,-3,-2,-2,1,4,-1,-4],[0,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,0,0,-2,-1,-1,-1,-1,-1,-4],[-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,1]],alphabetIndexes:{A:0,R:1,N:2,D:3,C:4,Q:5,E:6,G:7,H:8,I:9,L:10,K:11,M:12,F:13,P:14,S:15,T:16,W:17,Y:18,V:19,B:20,Z:21,X:22,"*":23}};var f;!function(t){t.HAMMING="Hamming",t.LEVENSHTEIN="Levenshtein",t.NEEDLEMANN_WUNSCH="Needlemann-Wunsch"}(f||(f={}));const C={[f.HAMMING]:function(){return(t,e)=>{let n=0;t.length!==e.length&&(n=Math.abs(t.length-e.length));let r=0;for(let n=0;n<Math.min(t.length,e.length);n++)t[n]!==e[n]&&r++;return r+=n,r/=Math.max(t.length,e.length),r}},[f.LEVENSHTEIN]:function(){return(t,e)=>((t,e)=>{if(t.length<e.length){const n=e;e=t,t=n}return 0===e.length?t.length:t.length<=32?((t,e)=>{const n=t.length,r=e.length,s=1<<n-1;let o=-1,i=0,l=n,a=n;for(;a--;)m[t.charCodeAt(a)]|=1<<a;for(a=0;a<r;a++){let t=m[e.charCodeAt(a)];const n=t|i;t|=(t&o)+o^o,i|=~(t|o),o&=t,i&s&&l++,o&s&&l--,i=i<<1|1,o=o<<1|~(n|i),i&=n}for(a=n;a--;)m[t.charCodeAt(a)]=0;return l})(t,e):((t,e)=>{const n=e.length,r=t.length,s=[],o=[],i=Math.ceil(n/32),l=Math.ceil(r/32);for(let t=0;t<i;t++)o[t]=-1,s[t]=0;let a=0;for(;a<l-1;a++){let i=0,l=-1;const h=32*a,c=Math.min(32,r)+h;for(let e=h;e<c;e++)m[t.charCodeAt(e)]|=1<<e;for(let t=0;t<n;t++){const n=m[e.charCodeAt(t)],r=o[t/32|0]>>>t&1,a=s[t/32|0]>>>t&1,h=n|i,c=((n|a)&l)+l^l|n|a;let u=i|~(c|l),g=l&c;u>>>31^r&&(o[t/32|0]^=1<<t),g>>>31^a&&(s[t/32|0]^=1<<t),u=u<<1|r,g=g<<1|a,l=g|~(h|u),i=u&h}for(let e=h;e<c;e++)m[t.charCodeAt(e)]=0}let h=0,c=-1;const u=32*a,g=Math.min(32,r-u)+u;for(let e=u;e<g;e++)m[t.charCodeAt(e)]|=1<<e;let p=r;for(let t=0;t<n;t++){const n=m[e.charCodeAt(t)],i=o[t/32|0]>>>t&1,l=s[t/32|0]>>>t&1,a=n|h,u=((n|l)&c)+c^c|n|l;let g=h|~(u|c),f=c&u;p+=g>>>r-1&1,p-=f>>>r-1&1,g>>>31^i&&(o[t/32|0]^=1<<t),f>>>31^l&&(s[t/32|0]^=1<<t),g=g<<1|i,f=f<<1|l,c=f|~(a|g),h=g&a}for(let e=u;e<g;e++)m[t.charCodeAt(e)]=0;return p})(t,e)})(t,e)/Math.max(t.length,e.length)},[f.NEEDLEMANN_WUNSCH]:function(t){return(e,n)=>{const{gapOpen:r,gapExtend:s,scoringMatrix:o,alphabetIndexes:i}={...p,...t},l=[new Array(e.length+1).fill(0),new Array(e.length+1).fill(0)],a=new Array(e.length+1).fill(!1),h=new Array(e.length+1).fill(!1);let c=0,u=1;for(let t=1;t<e.length+1;t++)l[0][t]=-r-(t-1)*s;for(let t=1;t<n.length+1;t++){l[u][0]=-r-(t-1)*s;for(let g=1;g<e.length+1;g++){const m=l[c][g-1]+o[i[e[g-1]]][i[n[t-1]]],p=l[c][g]-(a[g]?s:r),f=l[u][g-1]-(h[g-1]?s:r);l[u][g]=Math.max(m,f,p),l[u][g]===m?(a[g]=!1,h[g]=!1):l[u][g]===f?(a[g]=!1,h[g]=!0):(a[g]=!0,h[g]=!1)}c=u,u=(u+1)%2}const g=e.split("").map((t=>o[i[t]][i[t]])).reduce(((t,e)=>t+e),0),m=n.split("").map((t=>o[i[t]][i[t]])).reduce(((t,e)=>t+e),0),f=Math.max(g,m);return(f-l[c][e.length])/f}}},d=new class{constructor(){this.uhTemp=`units-handler.${s.SEMTYPE.MACROMOLECULE}`}};class b{static setUnitsToFastaColumn(t){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE||"fasta"!==t.column.getTag(s.TAGS.UNITS))throw new Error(`The column of notation 'fasta' must be '${s.SEMTYPE.MACROMOLECULE}'.`);t.column.setTag(s.TAGS.UNITS,"fasta"),b.setTags(t)}static setUnitsToSeparatorColumn(t,e){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE||"separator"!==t.column.getTag(s.TAGS.UNITS))throw new Error(`The column of notation 'separator' must be '${s.SEMTYPE.MACROMOLECULE}'.`);if(!e)throw new Error("The column of notation 'separator' must have the separator tag.");t.column.setTag(s.TAGS.UNITS,"separator"),t.column.setTag("separator",e),b.setTags(t)}static setUnitsToHelmColumn(t){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE)throw new Error(`The column of notation 'helm' must be '${s.SEMTYPE.MACROMOLECULE}'`);t.column.setTag(s.TAGS.UNITS,"helm"),b.setTags(t)}static setTags(t){const e=t.column.getTag(s.TAGS.UNITS),n=t.stats;if(Object.keys(n.freq).some((t=>t.length>1)),["fasta","separator"].includes(e)){if(0===Object.keys(n.freq).length)throw new Error("Alphabet is empty");const e=n.sameLength?"SEQ.MSA":"SEQ";t.column.setTag("aligned",e);const r=function(t,e,n="-"){const r=e.map((e=>{const r=function(t,e,n="-"){const r=new Set([...new Set(Object.keys(t)),...e]);r.delete(n);const s=[],o=[];for(const n of r)s.push(n in t?t[n]:0),o.push(e.has(n)?1:0);const i=new T(s),l=new T(o);return function(t,e){if(t.length!=e.length)throw new Error("The dimensionality of the vectors must match");let n=0;for(let r=0;r<t.length;r++)n+=t[r]*e[r];return n}(i,l)/(w(i)*w(l))}(t,e.alphabet,n);return new h(e,t,r)}));let s;const o=Math.max(...r.map((t=>t.similarity>t.cutoff?t.similarity:-1)));s=o>0?r.find((t=>t.similarity===o)).name:"UN";return s}(n.freq,g);if(t.column.setTag("alphabet",r),"UN"===r){const e=Object.keys(n.freq).length,r=Object.keys(n.freq).some((t=>t.length>1));t.column.setTag(".alphabetSize",e.toString()),t.column.setTag(".alphabetIsMultichar",r?"true":"false")}}}get column(){return this._column}get units(){return this._units}get notation(){return this._notation}get defaultGapSymbol(){return this._defaultGapSymbol}get separator(){const t=this.column.getTag("separator")??void 0;if("separator"===this.notation&&void 0===t)throw new Error(`Separator is mandatory for column '${this.column.name}' of notation '${this.notation}'.`);return t}get aligned(){const t=this.column.getTag("aligned");if(!t&&(this.isFasta()||this.isSeparator()))throw new Error("Tag aligned not set");return t}get alphabet(){const t=this.column.getTag("alphabet");if(!t&&(this.isFasta()||this.isSeparator()))throw new Error("Tag alphabet not set");return t}get helmCompatible(){return this.column.getTag(".isHelmCompatible")}getAlphabetSize(){if("helm"==this.notation||"UN"==this.alphabet){const t=this.column.getTag(".alphabetSize");let e;if(t)e=parseInt(t);else{const t=this.stats;e=Object.keys(t.freq).length}return e}switch(this.alphabet){case"PT":return 20;case"DNA":case"RNA":return 4;case"NT":return console.warn("Unexpected alphabet 'NT'."),4;default:throw new Error(`Unexpected alphabet '${this.alphabet}'.`)}}getAlphabetIsMultichar(){return"helm"===this.notation||"UN"===this.alphabet&&"true"===this.column.getTag(".alphabetIsMultichar")}get splitted(){if(null===this._splitted){const t=this.getSplitter(),e=this._column.length;this._splitted=new Array(e);const n=this._column.getRawData(),r=this._column.categories;for(let s=0;s<e;s++){const e=r[n[s]];this._splitted[s]=t(e)}}return this._splitted}get stats(){if(null===this._stats){const t={};let e=!0,n=null;for(const r of this.splitted){null==n?n=r.length:r.length!==n&&(e=!1);for(const e of r)e in t||(t[e]=0),t[e]+=1}this._stats={freq:t,sameLength:e}}return this._stats}isFasta(){return"fasta"===this.notation}isSeparator(){return"separator"===this.notation}isHelm(){return"helm"===this.notation}isRna(){return"RNA"===this.alphabet}isDna(){return"DNA"===this.alphabet}isPeptide(){return"PT"===this.alphabet}isMsa(){return!!this.aligned&&this.aligned.toUpperCase().includes("MSA")}isHelmCompatible(){return"true"===this.helmCompatible}getNotation(){if(this.units.toLowerCase().startsWith("fasta"))return"fasta";if(this.units.toLowerCase().startsWith("separator"))return"separator";if(this.units.toLowerCase().startsWith("helm"))return"helm";throw new Error(`Column '${this.column.name}' has unexpected notation '${this.units}'.`)}getNewColumn(t,e){const n=this.column,r=n.length,o=t.toLowerCase()+"("+n.name+")",i=n.dataFrame.columns.getUnusedName(o),l=s.Column.fromList("string",i,new Array(r).fill(""));if(l.semType=s.SEMTYPE.MACROMOLECULE,l.setTag(s.TAGS.UNITS,t),"separator"===t){if(!e)throw new Error("Notation 'separator' requires separator value.");l.setTag("separator",e)}l.setTag(s.TAGS.CELL_RENDERER,"Macromolecule");const a=n.getTag("aligned");a&&l.setTag("aligned",a);const h=n.getTag("alphabet");h&&l.setTag("alphabet",h);let c=n.getTag(".alphabetSize");c&&l.setTag(".alphabetSize",c);const u=n.getTag(".alphabetIsMultichar");return void 0!==u&&l.setTag(".alphabetIsMultichar",u),"helm"==t&&(c=this.getAlphabetSize().toString(),l.setTag(".alphabetSize",c)),l}static getNewColumn(t){const e=b.getOrCreate(t),n=e.notation;return e.getNewColumn(n)}static unitsStringIsValid(t){return t=t.toLowerCase(),["fasta","separator","helm"].some((e=>t.startsWith(e.toLowerCase())))}static getNewColumnFromParams(t,e,n){if(!b.unitsStringIsValid(n))throw new Error("Invalid format of 'units' parameter");const r=s.Column.fromList("string",e,new Array(t).fill(""));return r.semType=s.SEMTYPE.MACROMOLECULE,r.setTag(s.TAGS.UNITS,n),r}getSplitter(){return L(this._column)}getDistanceFunctionName(){if(!this.isFasta())throw new Error("Only FASTA notation is supported");if(this.isMsa())return f.HAMMING;switch(this.alphabet){case"DNA":case"RNA":default:return f.LEVENSHTEIN;case"PT":return f.NEEDLEMANN_WUNSCH}}getDistanceFunction(){return C[this.getDistanceFunctionName()]()}async checkHelmCompatibility(){if(this.column.tags.has(".isHelmCompatible"))return"true"===this.column.getTag(".isHelmCompatible");const t=(await async function(){const t=s.Func.find({package:"Bio",name:"getMonomerLibHelper"});if(0===t.length)throw new Error('Package "Bio" must be installed for MonomerLibHelper.');return(await t[0].prepare().call()).getOutputParamValue()}()).getBioLib().getMonomerSymbolsByType("PEPTIDE".toString()),e=new Set(t),n=O(this.separator);for(const t of this.column.categories){const r=n(t);for(const t of r)if(!e.has(t))return this.column.setTag(".isHelmCompatible","false"),!1}return this.column.setTag(".isHelmCompatible","true"),!0}constructor(t){if(this._splitted=null,this._stats=null,t.type!=s.TYPE.STRING)throw new Error(`Unexpected column type '${t.type}', must be '${s.TYPE.STRING}'.`);this._column=t;const e=this._column.getTag(s.TAGS.UNITS);if(null==e)throw new Error("Units are not specified in column");if(this._units=e,this._notation=this.getNotation(),this._defaultGapSymbol=this.isFasta()?b._defaultGapSymbolsDict.FASTA:this.isHelm()?b._defaultGapSymbolsDict.HELM:b._defaultGapSymbolsDict.SEPARATOR,!this.column.tags.has("aligned")||!this.column.tags.has("alphabet")||!this.column.tags.has(".alphabetIsMultichar")&&!this.isHelm()&&"UN"===this.alphabet)if(this.isFasta())b.setUnitsToFastaColumn(this);else if(this.isSeparator()){const e=t.getTag("separator");b.setUnitsToSeparatorColumn(this,e)}else{if(!this.isHelm())throw new Error(`Unexpected units '${this.column.getTag(s.TAGS.UNITS)}'.`);b.setUnitsToHelmColumn(this)}if(!this.column.tags.has(".alphabetIsMultichar"))if(this.isHelm())this.column.setTag(".alphabetIsMultichar","true");else if(["UN"].includes(this.alphabet))throw new Error(`For column '${this.column.name}' of alphabet '${this.alphabet}' tag '.alphabetIsMultichar' is mandatory.`)}static getOrCreate(t){return d.uhTemp in t.temp||(t.temp[d.uhTemp]=new b(t)),t.temp[d.uhTemp]}}b._defaultGapSymbolsDict={HELM:"*",SEPARATOR:"",FASTA:"-"};class T extends Float32Array{}function w(t){let e=0;for(let n=0;n<t.length;n++)e+=t[n]*t[n];return Math.sqrt(e)}class S{static makePalette(t,e=!1,n=S){const r={};return t.forEach((t=>{const n=t[0],s=t[1];n.forEach(((t,n)=>{r[t]=this.colourPalette[s][e?0:n]}))})),new n(r)}constructor(t){this._palette=t}get(t){return this._palette[t]}}S.undefinedColor="rgb(100,100,100)",S.colourPalette={orange:["rgb(255,187,120)","rgb(245,167,100)","rgb(235,137,70)","rgb(205, 111, 71)"],all_green:["rgb(44,160,44)","rgb(74,160,74)","rgb(23,103,57)","rgb(30,110,96)","rgb(60,131,95)","rgb(24,110,79)","rgb(152,223,138)","rgb(182, 223, 138)","rgb(152, 193, 138)"],all_blue:["rgb(31,119,180)","rgb(23,190,207)","rgb(122, 102, 189)","rgb(158,218,229)","rgb(141, 124, 217)","rgb(31, 120, 150)"],magenta:["rgb(162,106,192)","rgb(197,165,224)","rgb(208,113,218)"],red:["rgb(214,39,40)","rgb(255,152,150)"],st_blue:["rgb(23,190,207)","rgb(158,218,229)","rgb(31,119,180)"],dark_blue:["rgb(31,119,180)","rgb(31, 120, 150)"],light_blue:["rgb(23,190,207)","rgb(158,218,229)","rgb(108, 218, 229)","rgb(23,190,227)"],lilac_blue:["rgb(124,102,211)","rgb(149,134,217)","rgb(97, 81, 150)"],dark_green:["rgb(23,103,57)","rgb(30,110,96)","rgb(60,131,95)","rgb(24,110,79)"],green:["rgb(44,160,44)","rgb(74,160,74)"],light_green:["rgb(152,223,138)","rgb(182, 223, 138)","rgb(152, 193, 138)"],st_green:["rgb(44,160,44)","rgb(152,223,138)","rgb(39, 174, 96)","rgb(74,160,74)"],pink:["rgb(247,182,210)"],brown:["rgb(140,86,75)","rgb(102, 62, 54)"],gray:["rgb(127,127,127)","rgb(199,199,199)","rgb(196,156,148)","rgb(222, 222, 180)"],yellow:["rgb(188,189,34)"],white:["rgb(230,230,230)"]};class A extends S{static get Lesk(){return void 0===this.lesk&&(this.lesk=this.makePalette([[["G","A","S","T"],"orange"],[["C","V","I","L","P","F","Y","M","W"],"all_green"],[["N","Q","H"],"magenta"],[["D","E"],"red"],[["K","R"],"all_blue"]],!1,A)),this.lesk}static get GrokGroups(){return void 0===this.grokGroups&&(this.grokGroups=this.makePalette([[["C","U"],"yellow"],[["G","P"],"red"],[["A","V","I","L","M","F","Y","W"],"all_green"],[["R","H","K"],"light_blue"],[["D","E"],"dark_blue"],[["S","T","N","Q"],"orange"]],!1,A)),this.grokGroups}static get RasMol(){return void 0===this.rasMol&&(this.rasMol=new A({D:"#E60A0A",E:"#E60A0A",C:"#E6E600",M:"#E6E600",K:"#145AFF",R:"#145AFF",S:"#FA9600",T:"#FA9600",F:"#3232AA",Y:"#3232AA",N:"#00DCDC",Q:"#00DCDC",G:"#EBEBEB",L:"#0F820F",V:"#0F820F",I:"#0F820F",A:"#C8C8C8",W:"#B45AB4",H:"#8282D2",P:"#DC9682",others:"#BEA06E"})),this.rasMol}get(t){const e=t in A.aaSynonyms?A.aaSynonyms[t]:t;return super.get(e)}}A.aaSynonyms={MeNle:"L",MeA:"A",MeG:"G",MeF:"F"};class y{static getPalette(t="grok"){switch(t){case"grok":return A.GrokGroups;case"lesk":return A.Lesk;default:throw new Error(`ChemPalette: scheme \`${t}\` does not exist`)}}static getInnerOuter(t){let e=0,n="",r="";for(const s of t)"("==s?e++:")"==s?e--:e?n+=s:r+=s;return isNaN(parseInt(n))?[r,n]:[r,""]}static getColorAAPivot(t="",e="grok"){const n=this.getPalette(e);let[r,s]=this.getInnerOuter(t);if(r=r.length>6?`${r.slice(0,3)}...`:r,s=s.length>6?`${s.slice(0,3)}...`:s,1==t.length||"("==t[1]){const e=t[0]?.toUpperCase();return e in n?[n.get(e),e,s,1]:[this.undefinedColor,r,s,1]}if("d"==t[0]&&t[1]in n&&(2==t.length||"("==t[2])){const e=t[1]?.toUpperCase();return e in n?[n.get(e),e,s,2]:[this.undefinedColor,r,s,2]}if(t.substring(0,3)in this.AAFullNames&&(3==t.length||"("==t[3])){const e=this.AAFullNames[t.substring(0,3)];return e in n?[n.get(e),e,s,3]:[this.undefinedColor,r,s,3]}if(t[0]?.toLowerCase()==t[0]&&t.substring(1,3)in this.AAFullNames&&(4==t.length||"("==t[4])){const e=this.AAFullNames[t.substring(1,3)];return e in n?[n.get(e),e,s,4]:[this.undefinedColor,r,s,4]}return[this.undefinedColor,r,s,0]}}y.SemType="Aminoacids",y.SemTypeMultipleAlignment="AminoacidsMultipleAlignment",y.undefinedColor="rgb(100,100,100)",y.Names={G:"Glycine",L:"Leucine",Y:"Tyrosine",S:"Serine",E:"Glutamic acid",Q:"Glutamine",D:"Aspartic acid",N:"Asparagine",F:"Phenylalanine",A:"Alanine",K:"Lysine",R:"Arginine",H:"Histidine",C:"Cysteine",V:"Valine",P:"Proline",W:"Tryptophan",I:"Isoleucine",M:"Methionine",T:"Threonine"},y.AASmiles={G:"NCC(=O)O",L:"N[C@H](CC(C)C)C(=O)O",Y:"NC(CC1=CC=C(O)C=C1)C(=O)O",S:"NC(CO)C(=O)O",E:"N[C@@H](CCC(O)=O)C(=O)O",Q:"N[C@@H](CCC(N)=O)C(=O)O",D:"N[C@@H](CC(O)=O)C(=O)O",N:"N[C@@H](CC(N)=O)C(=O)O",F:"NC(CC1=CC=CC=C1)C(=O)O",A:"N[C@H](C)C(=O)O",K:"NC(CCCCN)C(=O)O",R:"N[C@H](CCCNC(=N)C)C(=O)O",H:"NC(CC1=CN=C[N]1)C(=O)O",C:"N[C@@H](CS)C(=O)O",V:"NC(C(C)C)C(=O)O",P:"N(CCC1)C1C(=O)O",W:"N[C@@H](Cc1c2ccccc2n([H])c1)C(=O)O",I:"N[C@H]([C@H](C)CC)C(=O)O",M:"NC(CCSC)C(=O)O",T:"NC(C(O)C)C(=O)O"},y.AASmilesTruncated={G:"*C*",L:"CC(C)C[C@H](*)*",Y:"C1=CC(=CC=C1CC(*)*)O",S:"OCC(*)C*",E:"*[C@@H](CCC(O)=O)*",Q:"*N[C@@H](CCC(N)=O)*",D:"*[C@@H](CC(O)=O)*",N:"*[C@@H](CC(N)=O)*",F:"C1=CC=C(C=C1)CC(*)*",A:"C[C@H](*)*",K:"C(CCN)CC(*)*",R:"*[C@H](CCCNC(=N)C)*",H:"C1=C(NC=N1)CC(*)*",C:"C([C@@H](*)*)S",V:"CC(C)C(*)*",P:"C1CCN(*)C1*",W:"*[C@@H](Cc1c2ccccc2n([H])c1)*",I:"CC[C@H](C)[C@H](*)*",M:"CSCCC(*)*",T:"CC(O)C(*)*"},y.AAFullNames={Ala:"A",Arg:"R",Asn:"N",Asp:"D",Cys:"C",Gln:"Q",Glu:"E",Gly:"G",His:"H",Ile:"I",Leu:"L",Lys:"K",Met:"M",Phe:"F",Pro:"P",Ser:"S",Thr:"T",Trp:"W",Tyr:"Y",Val:"V"};class E{}E.SemType="Nucleotides",E.SemTypeMultipleAlignment="NucleotidesMultipleAlignment",E.Names={A:"Adenine",C:"Cytosine",G:"Guanine",T:"Thymine",U:"Uracil"};class M extends class{}{static buildPalette(){return[].concat(...Object.values(S.colourPalette))}get(t){const e=class{static hashCode(t){let e=0;if(0===t.length)return e;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n),e|=0;return e}}.hashCode(t)%M.palette.length;return function(t){if(null==t)return"rgb(100,100,100)";const e=s.Color.fromHtml(t),n=s.Color.g(e),r=s.Color.r(e),o=s.Color.b(e),i=Math.sqrt(Math.pow(0-r,2)+Math.pow(0-n,2)+Math.pow(0-o,2));return i>210?`rgb(${r/i*210},${n/i*210},${o/i*210})`:s.Color.toRgb(e)}(M.palette[e])}}function N(t){return t.toString().replace(c,".$1").slice(1).split(".").map((t=>t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):"-"===t?"":t))}function O(t,e){return n=>n.split(t,e)}M.palette=M.buildPalette();const v=/(PEPTIDE1|DNA1|RNA1)\{([^}]+)}/g,H=/\[([^\[\]]+)]/g;function x(t){v.lastIndex=0;const e=v.exec(t.toString()),n=e?e[2]:null;return(n?n.split("."):[]).map((t=>{H.lastIndex=0;const e=H.exec(t);return e&&e.length>=2?e[1]:t}))}function L(t){if(t.semType!==s.SEMTYPE.MACROMOLECULE)throw new Error(`Get splitter for semType "${s.SEMTYPE.MACROMOLECULE}" only.`);return function(t,e,n){if(t.toLowerCase().startsWith("fasta"))return N;if(t.toLowerCase().startsWith("separator"))return O(e,void 0);if(t.toLowerCase().startsWith("helm"))return x;throw new Error(`Unexpected units ${t} .`)}(t.getTag(s.TAGS.UNITS),t.getTag("separator"))}const P=/(\w+)/g;var F;function _(t,e,n,r,s,o,i="rgb(100,100,100)",l=0,a=!1,h=1,c="",u=!1,g=F.classic,m=[],p=0,f=null,C=[],d=null,b={}){s.textAlign="start";let T=o.substring(0),w=u?"":c;g===F.MSA&&(w="");let S=!0,A=!0,y="difference";null!=f&&null!=f.cell.column&&(S=f.cell.column.temp["color-code"]??!0,A=f.cell.column.temp["compare-with-current"]??!0,y=f.cell.column.temp["highlight-difference"]??"difference");const E=C[p];A&&C.length>0&&"difference"===y&&(h=T==E?.3:h),A&&C.length>0&&"equal"===y&&(h=T!=E?.3:h),null!=d&&(T=function(t,e){if(t.length<=e)return t;const n=t.match(P),r=t.length>e||(n?.length??0)>1,s=n?.[0]??" ";return r?s.substring(0,e)+"…":s}(T,d));const M=T+w;b[M]??(b[M]=s.measureText(M));let N=b[M];b[T]??(b[T]=s.measureText(T));let O=b[T].width;b[w]??(b[w]=s.measureText(w));const v=b[w].width,H=r/2-(N.fontBoundingBoxAscent+N.fontBoundingBoxDescent)/2+1;function x(n,r){const o=S?i:"rgb(0,0,0)";s.fillStyle=o,s.globalAlpha=h,g===F.classic&&(s.fillText(T,t+n,e+H),s.fillStyle="#808080",s.fillText(w,t+r,e+H)),g===F.MSA&&s.fillText(T,t+n,e+H)}N=N.width,g===F.MSA&&(O=m[p],N=m[p]);const L=(m[p]??0)-(m[0]??0);if(a||N>n)return x(L,L+O),t+L+O+v;{const e=(n-N)/2;return x(e,e+O),t+L+e+O}}function G(t){var e;return"string"==typeof t||t instanceof String?t:("object"==typeof t||t instanceof Object)&&"$thrownJsError"in t?G(t.$thrownJsError):t instanceof Error?null!==(e=t.stack)&&void 0!==e?e:t.message:t.toString()}function I(t){t=R(t,"$")[0];const e=[];if(!scil.Utils.isNullOrEmpty(t)){const n=R(t,"|");for(let r=0;r<n.length;++r){let s=(t=D(n[r]).str).indexOf("{");s=(t=t.substring(s+1)).indexOf("}");const o=R(t=t.substring(0,s),".");for(const t of o)if(t&&""!==t)if(t.startsWith("[")&&t.includes("]")){const n=t.substring(1,t.indexOf("]"));e.push(n);const r=t.substring(t.indexOf("]")+1);o.push(r)}else if(t.includes("[")&&t.endsWith("]")){const n=t.substring(t.lastIndexOf("[")+1,t.length-1);e.push(n);const r=t.substring(0,t.lastIndexOf("["));o.push(r)}else if(t.includes("(")&&t.includes(")")){const e=t.substring(0,t.indexOf("(")),n=t.substring(t.lastIndexOf(")")+1),r=[e,t.substring(e.length+1,t.length-n.length-1),n];for(const t of r)o.push(t)}else e.push(t)}}return e}function U(t){const e=Object.keys(org.helm.webeditor.monomerTypeList()),n=[],r=[];for(let t=0;t<e.length;t++)n.push(new scil.helm.Monomers.getMonomerSet(e[t])),Object.keys(n[t]).forEach((e=>{r.push(n[t][e].id)}));return new Set(t.filter((t=>!r.includes(t))))}function R(t,e){const n=[];let r="",s=0,o=0,i=0,l=0;for(let a=0;a<t.length;++a){let h=t.substring(a,a+1);if(h==e&&0==o&&0==s&&0==i&&0==l)n.push(r),r="";else{if(r+=h,l>0&&"\\"==h&&a+1<t.length){++a;const e=t.substring(a,a+1);r+=e,h+=e}'"'==h?a>0&&"\\"==t.substring(a-1,a)||(l=0==l?1:0):"["==h?++o:"]"==h?--o:"("==h?++s:")"==h?--s:"{"==h?++i:"}"==h&&--i}}return n.push(r),n}function D(t){const e=$(t,'"');if(null!=e.tag)return e;const n=$(t,"'");return{tag:e.tag,repeat:n.tag,str:n.str}}function $(t,e){let n=null;if(scil.Utils.endswith(t,e)){let r=t.length-1;for(;r>0&&(r=t.lastIndexOf(e,r-1),!(r<=0||"\\"!=t.substring(r-1,r))););r>0&&r<t.length-1&&(n=t.substring(r+1,t.length-1),t=t.substring(0,r))}return null!=n&&(n=function(t){return scil.Utils.isNullOrEmpty(t)?t:t.replace(/[\\]./g,(function(t){switch(t){case"\\r":return"\r";case"\\n":return"\n";case"\\t":return"\t";default:return t.substring(1)}}))}(n.replace(new RegExp("\\"+e,"g"),e))),{tag:n,str:t}}!function(t){t.MSA="MSA",t.classic="classic"}(F||(F={}));class k{constructor(t){this.col=t,this._allPartsList=null,this._lengthsList=null,this.monomerCharWidth=7,this.leftPadding=5,this.col.dataFrame.onDataChanged.subscribe(),this.monomerLib=B()}getCellAllPartsLengths(t){null===this._allPartsList&&(this._allPartsList=new Array(this.col.length).fill(null)),null===this._lengthsList&&(this._lengthsList=new Array(this.col.length).fill(null));const[e,n]=this.getCellMonomerLengthsForSeq(t),r=new Array(n.length+1);r[0]=this.leftPadding;for(let t=1;t<r.length;t++)r[t]=r[t-1]+n[t-1];return[e,n,r]}getCellMonomerLengthsForSeq(t){const e=this._allPartsList[t]=this.getAllParts(t),n=this._lengthsList[t]=new Array(e.length);for(const[t,r]of l().enumerate(e)){const e=t.length*this.monomerCharWidth;n[r]=e}return[e,n]}getAllParts(t){const e=this.col.get(t),n=e?I(e):[];return e?function(t,e){const n=[];for(let r=0;r<t.length;++r){const s=e.indexOf(t[r]),o=e.slice(0,s);n.push(o),n.push(t[r]),e=e.substring(s+t[r].length)}return n.push(e),n}(n,e):[]}getMonomer(t){let e=null;for(const n of this.monomerLib.getPolymerTypes())if(e=this.monomerLib.getMonomer(n,t),e)break;return e}static getOrCreate(t){return"bio-helmMonomerPlacer"in t.temp||(t.temp["bio-helmMonomerPlacer"]=new k(t)),t.temp["bio-helmMonomerPlacer"]}}class W extends s.GridCellRenderer{get name(){return"helm"}get cellType(){return"helm"}get defaultWidth(){return 400}get defaultHeight(){return 100}onMouseMove(t,e){var s,o;try{let i=null;try{i=t.tableColumn}catch(t){}if(!i)return;const a=k.getOrCreate(i),[h,c,u]=a.getCellAllPartsLengths(t.tableRowIndex),g=Object.values(c).length-1,m=e.offsetX-t.bounds.x;let p=0,f=g,C=!1,d=0,b=0;if(m>u[0])for(;!C&&d<u.length;)b=Math.floor((f+p)/2),m>=u[b]&&m<=u[b+1]?(p=b,C=!0):m<u[b]?f=b-1:m>u[b+1]&&(p=b+1),p==f&&(C=!0),d++;p=m>=u[p]?p:p-1;const T=I(t.cell.value),w=new Set(T),S=U(T),A=[];for(const[t,e]of l().enumerate(h))if(S.has(t))A[e]=r.divV([r.divText(`Monomer ${h[e]} not found.`),r.divText("Open the Context Panel, then expand Manage Libraries")]);else if(w.has(t)){const s=[r.div(t)],o=a.getMonomer(t);if(o){const t={autoCrop:!0,autoCropMargin:0,suppressChiralText:!0},e=n.chem.svgMol(o.smiles,void 0,void 0,t);s.push(e)}A[e]=r.divV(s)}(null!==(o=null===(s=A[p])||void 0===s?void 0:s.childNodes.length)&&void 0!==o?o:0)>0?r.tooltip.show(A[p],e.x+16,e.y+16):r.tooltip.hide()}catch(t){const e=G(t);console.error("Helm: HelmCellRenderer.onMouseMove() error:\n"+e)}}render(t,e,n,s,o,i,l){t.save();try{let l=null;try{l=i.tableColumn}catch(t){}if(!l)return;const a=-1!==i.gridRow?i.grid:void 0,h="red",c="#404040",u="#C0C0C0",g=I(i.cell.value),m=new Set(g),p=U(g);if(0==p.size){const t=r.div([],{style:{width:`${s}px`,height:`${o}px`}});return t.setAttribute("dataformat","helm"),t.setAttribute("data",i.cell.value),i.element=t,void new JSDraw2.Editor(t,{width:s,height:o,skin:"w8",viewonly:!0})}if(p.size>0){if(!a){const e=window.devicePixelRatio;o=28,t.canvas.height=o*e,t.canvas.style.height=`${o}px`}s=a?Math.min(a.canvas.width-e,s):t.canvas.width-e,t.save(),t.beginPath(),t.rect(e,n,s,o),t.clip(),t.transform(1,0,0,1,e,n),t.font="12px monospace",t.textBaseline="top";const r=k.getOrCreate(l),[g,f,C]=r.getCellAllPartsLengths(i.tableRowIndex);for(let e=0;e<g.length;++e){const n=g[e],r="."===n||n.endsWith("{")||n.startsWith("}")?u:p.has(n)?h:m.has(n)?c:u;t.fillStyle=r,_(C[e],0,s,o,t,g[e],r,0,!0,1)}}}finally{t.restore()}}}class j extends b{get splitter(){return null===this._splitter&&(this._splitter=L(this.column)),this._splitter}toFasta(t){return"fasta"===t}toSeparator(t){return"separator"===t}toHelm(t){return"helm"===t}convertFastaToSeparator(t,e=null){null===e&&(e=this.defaultGapSymbol);const n=this.getNewColumn("separator",t);return n.init((n=>{const r=this.column.get(n),s=this.splitter(r);for(let t=0;t<s.length;t++)s[t]===e&&(s[t]=b._defaultGapSymbolsDict.SEPARATOR);return s.join(t)})),n.setTag(s.TAGS.UNITS,"separator"),n}getHelmWrappers(){return[this.isDna()?"DNA1{":this.isRna()||this.isHelmCompatible()?"RNA1{":"PEPTIDE1{",this.isDna()?"D(":this.isRna()?"R(":"",this.isDna()||this.isRna()?")P":"","}$$$$"]}convertToHelmHelper(t,e,n,r,s,o){return`${n}${this.splitter(t).map((t=>t&&t!==e?1==t.length?`${r}${t}${s}`:`${r}[${t}]${s}`:b._defaultGapSymbolsDict.HELM)).join(".")}${o}`}convertStringToHelm(t,e=null){null===e&&(e=this.defaultGapSymbol);const[n,r,s,o]=this.getHelmWrappers();return this.convertToHelmHelper(t,e,n,r,s,o)}convertToHelm(t=null){null===t&&(t=this.defaultGapSymbol);const[e,n,r,o]=this.getHelmWrappers(),i=this.getNewColumn("helm");return i.init((s=>{const i=this.column.get(s);return this.convertToHelmHelper(i,t,e,n,r,o)})),i.setTag(s.TAGS.UNITS,"helm"),i}convertSeparatorToFasta(t=null){null===t&&(t=b._defaultGapSymbolsDict.FASTA);const e=this.getNewColumn("fasta");return e.init((e=>{const n=this.column.get(e),r=this.splitter(n),s=[];for(let e=0;e<r.length;e++){const n=r[e];if(0===n.length)s.push(t);else if(n.length>1){const t="["+n+"]";s.push(t)}else s.push(n)}return s.join("")})),e.setTag(s.TAGS.UNITS,"fasta"),e}convertHelmToFastaSeparator(t,e,n,r){r||(r=this.toFasta(e)?b._defaultGapSymbolsDict.FASTA:b._defaultGapSymbolsDict.SEPARATOR),n||(n=this.toFasta(e)?"":this.separator);const s=/(R\(|D\(|\)|P)/g,o=t.startsWith("DNA")||t.startsWith("RNA"),i=this.splitter(t),l=[];for(let t=0;t<i.length;t++){let n=i[t];if(o&&(n=n.replace(s,"")),n===b._defaultGapSymbolsDict.HELM)l.push(r);else if(this.toFasta(e)&&n.length>1){const t="["+n+"]";l.push(t)}else l.push(n)}return l.join(n)}convertHelm(t,e,n){const r=this.getNewColumn(t,e);r.init((r=>{const s=this.column.get(r);return this.convertHelmToFastaSeparator(s,t,e,n)})),L(r);const s=this.stats.sameLength?"SEQ.MSA":"SEQ";return r.setTag("aligned",s),r}convertHelmToSeparator(){return this.getNewColumn("separator")}convert(t,e=null){if(this.notation===t)throw new Error("tgt notation is invalid");if(this.toSeparator(t)&&null===e)throw new Error("tgt separator is not specified");if(this.isFasta()&&this.toSeparator(t)&&null!==e)return this.convertFastaToSeparator(e);if((this.isFasta()||this.isSeparator())&&this.toHelm(t))return this.convertToHelm();if(this.isSeparator()&&this.toFasta(t))return this.convertSeparatorToFasta();if(this.isHelm()&&this.toFasta(t))return this.convertHelm(t);if(this.isHelm()&&this.toSeparator(t))return this.convertHelm(t,e);throw new Error(`Not supported conversion from source notation '${this.notation}' to target notation '${t}'.`)}constructor(t){super(t),this._splitter=null}}var z=function(t,e,n,r){return new(n||(n=Promise))((function(s,o){function i(t){try{a(r.next(t))}catch(t){o(t)}}function l(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,l)}a((r=r.apply(t,e||[])).next())}))};const Y=new s.Package;let q=null;function V(){return z(this,void 0,void 0,(function*(){return Promise.all([new Promise(((t,e)=>{dojo.ready((function(){t(null)}))})),n.functions.call("Bio:getBioLib")]).then((([t,e])=>{q=e,Q(),q.onChanged.subscribe((t=>{try{Q();const t=q.getPolymerTypes(),e="Monomer lib updated:<br />"+(0==t.length?"empty":t.map((t=>`${t} ${q.getMonomerSymbolsByType(t).length}`)).join("<br />"));n.shell.info(e)}catch(t){const e=G(t);console.error("Helm: initHelm monomerLib.onChanged() error:\n"+e)}}))})).catch((t=>{const e=t instanceof Error?t.message:t?t.toString():"Exception 'undefined'";n.shell.error(`Package 'Helm' init initHelm() error: ${e}`);const r=new Error(e);throw r.stack=t.stack,r}))}))}function B(){return q}function Q(){org.helm.webeditor.Monomers.clear(),q.getPolymerTypes().forEach((t=>{q.getMonomerSymbolsByType(t).forEach((e=>{let n=!1;const r=q.getMonomer(t,e),s={id:e,m:r.molfile,n:r.name,na:r.naturalAnalog,rs:r.rgroups.length,type:r.polymerType,mt:r.monomerType,at:{}};if(r.rgroups.length>0){s.rs=r.rgroups.length;const t={};r.rgroups.forEach((e=>{t[e.label]=e.capGroupName})),s.at=t}else null!=r.smiles?(s.rs=Object.keys(et(r.smiles.toString())).length,s.at=et(r.smiles.toString())):n=!0;n||org.helm.webeditor.Monomers.addOneMonomer(s)}))}));const t=n.shell.tv.grid;t&&t.invalidate()}function K(){return new W}function J(t,e,s){const o=U(I(t&&void 0===s?t.value:e));0==o.size?function(t,e,s){const o=r.div(),i=n.shell.tv.grid.dataFrame,l=new j(i.columns.bySemType("Macromolecule"));org.helm.webeditor.MolViewer.molscale=.8;const a=new scil.helm.App(o,{showabout:!1,mexfontsize:"90%",mexrnapinontab:!0,topmargin:20,mexmonomerstab:!0,sequenceviewonly:!1,mexfavoritefirst:!0,mexfilter:!0}),h=a.calculateSizes();a.canvas.resize(h.rightwidth-100,h.topheight-210);let c={width:h.rightwidth-100+"px",height:h.bottomheight+"px"};scil.apply(a.sequence.style,c),scil.apply(a.notation.style,c),c={width:h.rightwidth+"px",height:h.bottomheight+a.toolbarheight+"px"},scil.apply(a.properties.parent.style,c),a.structureview.resize(h.rightwidth,h.bottomheight+a.toolbarheight),a.mex.resize(h.topheight-80),setTimeout((()=>{t&&void 0===s?a.canvas.helm.setSequence(t.value,"HELM"):a.canvas.helm.setSequence(e,"HELM")}),200),r.dialog({showHeader:!1,showFooter:!0}).add(o).onOK((()=>{const e=a.canvas.getHelm(!0).replace(/<\/span>/g,"").replace(/<span style='background:#bbf;'>/g,"");if(t)if(void 0===s)t.value=e;else{const n=l.convertHelmToFastaSeparator(e,s);t.value=n}})).show({modal:!0,fullScreen:!0})}(t,e,s):n.shell.warning(`Monomers ${Array.from(o).join(", ")} are absent! <br/>Please, upload the monomer library! <br/><a href="https://datagrok.ai/help/domains/bio/macromolecules" target="_blank">Learn more</a>`)}function X(t){J(t.cell,void 0,void 0)}function Z(t){const e=n.shell.tv.grid.dataFrame,r=e.columns.bySemType("Macromolecule");"helm"===r.getTag(s.TAGS.UNITS)&&J(e.currentCell,void 0,void 0);const o=new j(r).convertStringToHelm(t,"/");J(e.currentCell,o,r.getTag(s.TAGS.UNITS))}function tt(t){return z(this,void 0,void 0,(function*(){const e=n.shell.tv.grid.root.parentElement,o=r.div([]);e.appendChild(o);const i=new JSDraw2.Editor(o,{viewonly:!0});o.style.width="0px",o.style.height="0px",i.setHelm(t);const l=i.getFormula(!0),a=Math.round(100*i.getMolWeight())/100,h=Math.round(100*i.getExtinctionCoefficient(!0))/100;return e.lastChild.remove(),new s.Widget(r.tableFromMap({formula:l.replace(/<sub>/g,"").replace(/<\/sub>/g,""),"molecular weight":a,"extinction coefficient":h}))}))}function et(t){const e=t.match(/(?<=\[)[^\][]*(?=])/gm),n={};let r,s="";if(e)for(let t=0;t<e.length;t++)if(null!=e[t]&&/\d/.test(e[t])){r=e[t][e[t].length-1],e[t]=e[t].replace(/[0-9]/g,"");for(let n=0;n<e[t].length;n++)":"!=e[t][n]&&(s+=e[t][n]);n["R"+r]=s,s=""}return n}function nt(t){const e=n.shell.tv.grid.root.parentElement,o=s.Column.string("mols",t.length),i=r.div([]);e.appendChild(i);const l=new JSDraw2.Editor(i,{viewonly:!0});return i.style.width="0px",i.style.height="0px",o.init((e=>(l.setHelm(t.get(e)),l.getMolfile()))),e.lastChild.remove(),o}function rt(){return new o}helm=e})();
|
|
1
|
+
var helm;(()=>{"use strict";var t={n:e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{_package:()=>nt,editMoleculeCell:()=>at,getMolfiles:()=>gt,getMonomerLib:()=>st,helmCellRenderer:()=>ot,helmWebEditor:()=>mt,initHelm:()=>rt,openEditor:()=>ht,propertiesPanel:()=>ct});const n=grok,r=ui,s=DG;class i{constructor(){this.w=200,this.h=100,this.host=r.div([],{style:{width:`${this.w}px`,height:`${this.h}px`}}),this.editor=new JSDraw2.Editor(this.host,{width:this.w,height:this.h,viewonly:!0})}resizeEditor(t,e){this.editor.setSize(t,e)}createWebEditor(t){const e=r.div();org.helm.webeditor.MolViewer.molscale=.8;const n=new scil.helm.App(e,{showabout:!1,mexfontsize:"90%",mexrnapinontab:!0,topmargin:20,mexmonomerstab:!0,sequenceviewonly:!1,mexfavoritefirst:!0,mexfilter:!0}),s=n.calculateSizes();n.canvas.resize(s.rightwidth-100,s.topheight-210);let i={width:s.rightwidth-100+"px",height:s.bottomheight+"px"};return scil.apply(n.sequence.style,i),scil.apply(n.notation.style,i),i={width:s.rightwidth+"px",height:s.bottomheight+n.toolbarheight+"px"},scil.apply(n.properties.parent.style,i),n.structureview.resize(s.rightwidth,s.bottomheight+n.toolbarheight),n.mex.resize(s.topheight-80),setTimeout((function(){n.canvas.helm.setSequence(t,"HELM")}),200),{editorDiv:e,webEditor:n}}}const o=wu;var l,a,h=t.n(o);class c{constructor(t,e,n){this.name=t,this.alphabet=e,this.cutoff=n}}class u extends c{constructor(t,e,n){super(t.name,t.alphabet,t.cutoff),this.freq=e,this.similarity=n}}(a=l||(l={})).FASTA="fasta",a.SEPARATOR="separator",a.HELM="helm";const g=/(?:\[([A-Za-z0-9_\-,()]+)\])|([A-Za-z\-])/g,m=new class{constructor(){this.fasta={peptide:new Set(["G","L","Y","S","E","Q","D","N","F","A","K","R","H","C","V","P","W","I","M","T"]),dna:new Set(["A","C","G","T"]),rna:new Set(["A","C","G","U"])}}},p=[new c("PT",m.fasta.peptide,.5),new c("DNA",m.fasta.dna,.55),new c("RNA",m.fasta.rna,.55)],f=new Uint32Array(65536),C={gapOpen:8,gapExtend:2,scoringMatrix:[[4,-1,-2,-2,0,-1,-1,0,-2,-1,-1,-1,-1,-2,-1,1,0,-3,-2,0,-2,-1,0,-4],[-1,5,0,-2,-3,1,0,-2,0,-3,-2,2,-1,-3,-2,-1,-1,-3,-2,-3,-1,0,-1,-4],[-2,0,6,1,-3,0,0,0,1,-3,-3,0,-2,-3,-2,1,0,-4,-2,-3,3,0,-1,-4],[-2,-2,1,6,-3,0,2,-1,-1,-3,-4,-1,-3,-3,-1,0,-1,-4,-3,-3,4,1,-1,-4],[0,-3,-3,-3,9,-3,-4,-3,-3,-1,-1,-3,-1,-2,-3,-1,-1,-2,-2,-1,-3,-3,-2,-4],[-1,1,0,0,-3,5,2,-2,0,-3,-2,1,0,-3,-1,0,-1,-2,-1,-2,0,3,-1,-4],[-1,0,0,2,-4,2,5,-2,0,-3,-3,1,-2,-3,-1,0,-1,-3,-2,-2,1,4,-1,-4],[0,-2,0,-1,-3,-2,-2,6,-2,-4,-4,-2,-3,-3,-2,0,-2,-2,-3,-3,-1,-2,-1,-4],[-2,0,1,-1,-3,0,0,-2,8,-3,-3,-1,-2,-1,-2,-1,-2,-2,2,-3,0,0,-1,-4],[-1,-3,-3,-3,-1,-3,-3,-4,-3,4,2,-3,1,0,-3,-2,-1,-3,-1,3,-3,-3,-1,-4],[-1,-2,-3,-4,-1,-2,-3,-4,-3,2,4,-2,2,0,-3,-2,-1,-2,-1,1,-4,-3,-1,-4],[-1,2,0,-1,-3,1,1,-2,-1,-3,-2,5,-1,-3,-1,0,-1,-3,-2,-2,0,1,-1,-4],[-1,-1,-2,-3,-1,0,-2,-3,-2,1,2,-1,5,0,-2,-1,-1,-1,-1,1,-3,-1,-1,-4],[-2,-3,-3,-3,-2,-3,-3,-3,-1,0,0,-3,0,6,-4,-2,-2,1,3,-1,-3,-3,-1,-4],[-1,-2,-2,-1,-3,-1,-1,-2,-2,-3,-3,-1,-2,-4,7,-1,-1,-4,-3,-2,-2,-1,-2,-4],[1,-1,1,0,-1,0,0,0,-1,-2,-2,0,-1,-2,-1,4,1,-3,-2,-2,0,0,0,-4],[0,-1,0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1,1,5,-2,-2,0,-1,-1,0,-4],[-3,-3,-4,-4,-2,-2,-3,-2,-2,-3,-2,-3,-1,1,-4,-3,-2,11,2,-3,-4,-3,-2,-4],[-2,-2,-2,-3,-2,-1,-2,-3,2,-1,-1,-2,-1,3,-3,-2,-2,2,7,-1,-3,-2,-1,-4],[0,-3,-3,-3,-1,-2,-2,-3,-3,3,1,-2,1,-1,-2,-2,0,-3,-1,4,-3,-2,-1,-4],[-2,-1,3,4,-3,0,1,-1,0,-3,-4,0,-3,-3,-2,0,-1,-4,-3,-3,4,1,-1,-4],[-1,0,0,1,-3,3,4,-2,0,-3,-3,1,-1,-3,-1,0,-1,-3,-2,-2,1,4,-1,-4],[0,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,0,0,-2,-1,-1,-1,-1,-1,-4],[-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,1]],alphabetIndexes:{A:0,R:1,N:2,D:3,C:4,Q:5,E:6,G:7,H:8,I:9,L:10,K:11,M:12,F:13,P:14,S:15,T:16,W:17,Y:18,V:19,B:20,Z:21,X:22,"*":23}};var d;!function(t){t.HAMMING="Hamming",t.LEVENSHTEIN="Levenshtein",t.NEEDLEMANN_WUNSCH="Needlemann-Wunsch"}(d||(d={}));const b={[d.HAMMING]:function(){return(t,e)=>{let n=0;t.length!==e.length&&(n=Math.abs(t.length-e.length));let r=0;for(let n=0;n<Math.min(t.length,e.length);n++)t[n]!==e[n]&&r++;return r+=n,r/=Math.max(t.length,e.length),r}},[d.LEVENSHTEIN]:function(){return(t,e)=>((t,e)=>{if(t.length<e.length){const n=e;e=t,t=n}return 0===e.length?t.length:t.length<=32?((t,e)=>{const n=t.length,r=e.length,s=1<<n-1;let i=-1,o=0,l=n,a=n;for(;a--;)f[t.charCodeAt(a)]|=1<<a;for(a=0;a<r;a++){let t=f[e.charCodeAt(a)];const n=t|o;t|=(t&i)+i^i,o|=~(t|i),i&=t,o&s&&l++,i&s&&l--,o=o<<1|1,i=i<<1|~(n|o),o&=n}for(a=n;a--;)f[t.charCodeAt(a)]=0;return l})(t,e):((t,e)=>{const n=e.length,r=t.length,s=[],i=[],o=Math.ceil(n/32),l=Math.ceil(r/32);for(let t=0;t<o;t++)i[t]=-1,s[t]=0;let a=0;for(;a<l-1;a++){let o=0,l=-1;const h=32*a,c=Math.min(32,r)+h;for(let e=h;e<c;e++)f[t.charCodeAt(e)]|=1<<e;for(let t=0;t<n;t++){const n=f[e.charCodeAt(t)],r=i[t/32|0]>>>t&1,a=s[t/32|0]>>>t&1,h=n|o,c=((n|a)&l)+l^l|n|a;let u=o|~(c|l),g=l&c;u>>>31^r&&(i[t/32|0]^=1<<t),g>>>31^a&&(s[t/32|0]^=1<<t),u=u<<1|r,g=g<<1|a,l=g|~(h|u),o=u&h}for(let e=h;e<c;e++)f[t.charCodeAt(e)]=0}let h=0,c=-1;const u=32*a,g=Math.min(32,r-u)+u;for(let e=u;e<g;e++)f[t.charCodeAt(e)]|=1<<e;let m=r;for(let t=0;t<n;t++){const n=f[e.charCodeAt(t)],o=i[t/32|0]>>>t&1,l=s[t/32|0]>>>t&1,a=n|h,u=((n|l)&c)+c^c|n|l;let g=h|~(u|c),p=c&u;m+=g>>>r-1&1,m-=p>>>r-1&1,g>>>31^o&&(i[t/32|0]^=1<<t),p>>>31^l&&(s[t/32|0]^=1<<t),g=g<<1|o,p=p<<1|l,c=p|~(a|g),h=g&a}for(let e=u;e<g;e++)f[t.charCodeAt(e)]=0;return m})(t,e)})(t,e)/Math.max(t.length,e.length)},[d.NEEDLEMANN_WUNSCH]:function(t){return(e,n)=>{const{gapOpen:r,gapExtend:s,scoringMatrix:i,alphabetIndexes:o}={...C,...t},l=[new Array(e.length+1).fill(0),new Array(e.length+1).fill(0)],a=new Array(e.length+1).fill(!1),h=new Array(e.length+1).fill(!1);let c=0,u=1;for(let t=1;t<e.length+1;t++)l[0][t]=-r-(t-1)*s;for(let t=1;t<n.length+1;t++){l[u][0]=-r-(t-1)*s;for(let g=1;g<e.length+1;g++){const m=l[c][g-1]+i[o[e[g-1]]][o[n[t-1]]],p=l[c][g]-(a[g]?s:r),f=l[u][g-1]-(h[g-1]?s:r);l[u][g]=Math.max(m,f,p),l[u][g]===m?(a[g]=!1,h[g]=!1):l[u][g]===f?(a[g]=!1,h[g]=!0):(a[g]=!0,h[g]=!1)}c=u,u=(u+1)%2}const g=e.split("").map((t=>i[o[t]][o[t]])).reduce(((t,e)=>t+e),0),m=n.split("").map((t=>i[o[t]][o[t]])).reduce(((t,e)=>t+e),0),p=Math.max(g,m);return(p-l[c][e.length])/p}}};const A=new class{constructor(){this.uhTemp=`units-handler.${s.SEMTYPE.MACROMOLECULE}`}},T={[l.FASTA]:"-",[l.SEPARATOR]:"",[l.HELM]:"*"};class w{static setUnitsToFastaColumn(t){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE||t.column.getTag(s.TAGS.UNITS)!==l.FASTA)throw new Error(`The column of notation '${l.FASTA}' must be '${s.SEMTYPE.MACROMOLECULE}'.`);t.column.setTag(s.TAGS.UNITS,l.FASTA),w.setTags(t)}static setUnitsToSeparatorColumn(t,e){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE||t.column.getTag(s.TAGS.UNITS)!==l.SEPARATOR)throw new Error(`The column of notation '${l.SEPARATOR}' must be '${s.SEMTYPE.MACROMOLECULE}'.`);if(!e)throw new Error(`The column of notation '${l.SEPARATOR}' must have the separator tag.`);t.column.setTag(s.TAGS.UNITS,l.SEPARATOR),t.column.setTag("separator",e),w.setTags(t)}static setUnitsToHelmColumn(t){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE)throw new Error(`The column of notation '${l.HELM}' must be '${s.SEMTYPE.MACROMOLECULE}'`);t.column.setTag(s.TAGS.UNITS,l.HELM),w.setTags(t)}static setTags(t){const e=t.column.getTag(s.TAGS.UNITS),n=t.stats;if(Object.keys(n.freq).some((t=>t.length>1)),[l.FASTA,l.SEPARATOR].includes(e)){if(0===Object.keys(n.freq).length)throw new Error("Alphabet is empty");const e=n.sameLength?"SEQ.MSA":"SEQ";t.column.setTag("aligned",e);const r=function(t,e,n="-"){const r=e.map((e=>{const r=function(t,e,n="-"){const r=new Set([...new Set(Object.keys(t)),...e]);r.delete(n);const s=[],i=[];for(const n of r)s.push(n in t?t[n]:0),i.push(e.has(n)?1:0);const o=new N(s),l=new N(i);return function(t,e){if(t.length!=e.length)throw new Error("The dimensionality of the vectors must match");let n=0;for(let r=0;r<t.length;r++)n+=t[r]*e[r];return n}(o,l)/(L(o)*L(l))}(t,e.alphabet,n);return new u(e,t,r)}));let s;const i=Math.max(...r.map((t=>t.similarity>t.cutoff?t.similarity:-1)));s=i>0?r.find((t=>t.similarity===i)).name:"UN";return s}(n.freq,p);if(t.column.setTag("alphabet",r),"UN"===r){const e=Object.keys(n.freq).length,r=Object.keys(n.freq).some((t=>t.length>1));t.column.setTag(".alphabetSize",e.toString()),t.column.setTag(".alphabetIsMultichar",r?"true":"false")}}}get column(){return this._column}get units(){return this._units}get notation(){return this._notation}get defaultGapSymbol(){return this._defaultGapSymbol}get separator(){const t=this.column.getTag("separator")??void 0;if(this.notation===l.SEPARATOR&&void 0===t)throw new Error(`Separator is mandatory for column '${this.column.name}' of notation '${this.notation}'.`);return t}get aligned(){const t=this.column.getTag("aligned");if(!t&&(this.isFasta()||this.isSeparator()))throw new Error("Tag aligned not set");return t}get alphabet(){const t=this.column.getTag("alphabet");if(!t&&(this.isFasta()||this.isSeparator()))throw new Error("Tag alphabet not set");return t}get helmCompatible(){return this.column.getTag(".isHelmCompatible")}getAlphabetSize(){if(this.notation==l.HELM||"UN"==this.alphabet){const t=this.column.getTag(".alphabetSize");let e;if(t)e=parseInt(t);else{const t=this.stats;e=Object.keys(t.freq).length}return e}switch(this.alphabet){case"PT":return 20;case"DNA":case"RNA":return 4;case"NT":return console.warn("Unexpected alphabet 'NT'."),4;default:throw new Error(`Unexpected alphabet '${this.alphabet}'.`)}}getAlphabetIsMultichar(){return this.notation===l.HELM||"UN"===this.alphabet&&"true"===this.column.getTag(".alphabetIsMultichar")}get splitted(){if(null===this._splitted){const t=this.getSplitter(),e=this._column.length;this._splitted=new Array(e);const n=this._column.getRawData(),r=this._column.categories;for(let s=0;s<e;s++){const e=r[n[s]];this._splitted[s]=t(e)}}return this._splitted}get stats(){if(null===this._stats){const t={};let e=!0,n=null;for(const r of this.splitted){null==n?n=r.length:r.length!==n&&(e=!1);for(const e of r)e in t||(t[e]=0),t[e]+=1}this._stats={freq:t,sameLength:e}}return this._stats}get maxLength(){return null===this._maxLength&&(this._maxLength=Math.max(...this.splitted.map((t=>t.length)))),this._maxLength}get posList(){if(null===this._posList){const t=this.column.getTag(".positionNames");this._posList=t?t.split(", ").map((t=>t.trim())):h().count(1).take(this.maxLength).map((t=>t.toString())).toArray()}return this._posList}isFasta(){return this.notation===l.FASTA}isSeparator(){return this.notation===l.SEPARATOR}isHelm(){return this.notation===l.HELM}isRna(){return"RNA"===this.alphabet}isDna(){return"DNA"===this.alphabet}isPeptide(){return"PT"===this.alphabet}isMsa(){return!!this.aligned&&this.aligned.toUpperCase().includes("MSA")}isHelmCompatible(){return"true"===this.helmCompatible}isGap(t){return!t||this.units===l.FASTA&&t===T[l.FASTA]||this.units===l.HELM&&t===T[l.HELM]}getNotation(){if(this.units.toLowerCase().startsWith(l.FASTA))return l.FASTA;if(this.units.toLowerCase().startsWith(l.SEPARATOR))return l.SEPARATOR;if(this.units.toLowerCase().startsWith(l.HELM))return l.HELM;throw new Error(`Column '${this.column.name}' has unexpected notation '${this.units}'.`)}getHelmWrappers(){return[this.isDna()?"DNA1{":this.isRna()||this.isHelmCompatible()?"RNA1{":"PEPTIDE1{",this.isDna()?"D(":this.isRna()?"R(":"",this.isDna()||this.isRna()?")P":"","}$$$$"]}getNewColumn(t,e){const n=this.column,r=n.length,i=t.toLowerCase()+"("+n.name+")",o=n.dataFrame.columns.getUnusedName(i),a=s.Column.fromList("string",o,new Array(r).fill(""));if(a.semType=s.SEMTYPE.MACROMOLECULE,a.setTag(s.TAGS.UNITS,t),t===l.SEPARATOR){if(!e)throw new Error(`Notation '${l.SEPARATOR}' requires separator value.`);a.setTag("separator",e)}a.setTag(s.TAGS.CELL_RENDERER,"Macromolecule");const h=n.getTag("aligned");h&&a.setTag("aligned",h);const c=n.getTag("alphabet");null!=c&&a.setTag("alphabet",c);let u=n.getTag(".alphabetSize");null!=c&&u&&a.setTag(".alphabetSize",u);const g=n.getTag(".alphabetIsMultichar");return null!=c&&void 0!==g&&a.setTag(".alphabetIsMultichar",g),t==l.HELM&&(u=this.getAlphabetSize().toString(),a.setTag(".alphabetSize",u)),a}static getNewColumn(t){const e=w.getOrCreate(t),n=e.notation;return e.getNewColumn(n)}static unitsStringIsValid(t){return t=t.toLowerCase(),[l.FASTA,l.SEPARATOR,l.HELM].some((e=>t.startsWith(e.toLowerCase())))}static getNewColumnFromParams(t,e,n){if(!w.unitsStringIsValid(n))throw new Error("Invalid format of 'units' parameter");const r=s.Column.fromList("string",e,new Array(t).fill(""));return r.semType=s.SEMTYPE.MACROMOLECULE,r.setTag(s.TAGS.UNITS,n),r}getSplitter(t){if(this.units.toLowerCase().startsWith(l.FASTA))return null===this.column.getTag("alphabet")||this.getAlphabetIsMultichar()?_:F;if(this.units.toLowerCase().startsWith(l.SEPARATOR))return I(this.separator,t);if(this.units.toLowerCase().startsWith(l.HELM))return U;throw new Error(`Unexpected units ${this.units} .`)}getDistanceFunctionName(){if(!this.isFasta())throw new Error("Only FASTA notation is supported");if(this.isMsa())return d.HAMMING;switch(this.alphabet){case"DNA":case"RNA":default:return d.LEVENSHTEIN;case"PT":return d.NEEDLEMANN_WUNSCH}}getDistanceFunction(){return b[this.getDistanceFunctionName()]()}async checkHelmCompatibility(){if(this.column.tags.has(".isHelmCompatible"))return"true"===this.column.getTag(".isHelmCompatible");const t=(await async function(){const t=s.Func.find({package:"Bio",name:"getMonomerLibHelper"});if(0===t.length)throw new Error('Package "Bio" must be installed for MonomerLibHelper.');return(await t[0].prepare().call()).getOutputParamValue()}()).getBioLib().getMonomerSymbolsByType("PEPTIDE".toString()),e=new Set(t),n=I(this.separator);for(const t of this.column.categories){const r=n(t);for(const t of r)if(!e.has(t))return this.column.setTag(".isHelmCompatible","false"),!1}return this.column.setTag(".isHelmCompatible","true"),!0}get splitter(){var t;return null===this._splitter&&(this._splitter=(t=this.column,w.getOrCreate(t).getSplitter())),this._splitter}toFasta(t){return t===l.FASTA}toSeparator(t){return t===l.SEPARATOR}toHelm(t){return t===l.HELM}convertHelmToFastaSeparator(t,e,n,r){r||(r=this.toFasta(e)?T[l.FASTA]:T[l.SEPARATOR]),n||(n=this.toFasta(e)?"":this.separator);const s=/(R\(|D\(|\)|P)/g,i=t.startsWith("DNA")||t.startsWith("RNA"),o=this.splitter(t),a=[];for(let t=0;t<o.length;t++){let n=o[t];if(i&&(n=n.replace(s,"")),n===T[l.HELM])a.push(r);else if(this.toFasta(e)&&n.length>1){const t="["+n+"]";a.push(t)}else a.push(n)}return a.join(n)}convert(t,e){const n=this.getConverter(t,e),r=this.getNewColumn(t,e);return r.init((t=>n(this.column.get(t)))),r}getRegion(t,e,n){const r=this.getNewColumn(this.notation,this.separator);r.name=n,Math.max(...this.splitted.map((t=>t.length)));const s=t??0,i=e??this.maxLength-1,o=this.getJoiner(),l=i-s+1;r.init((t=>{const e=this.splitted[t],n=new Array(l);for(let t=0;t<l;++t){const r=s+t;n[t]=r<e.length?e[r]:T[this.notation]}return o(n)}));const a=t=>{const e=t.split(",").map((t=>t.trim())),n=new Array(l);for(let t=0;t<l;++t){const r=s+t;n[t]=r<e.length?e[r]:"?"}return n.join(", ")},h=this.column.getTag(".positionNames");h&&r.setTag(".positionNames",a(h));const c=this.column.getTag(".positionLabels");return c&&r.setTag(".positionLabels",a(c)),r}getJoiner(){const t=this;if(this.notation===l.FASTA)return function(e){return E(t,e)};if(this.notation===l.SEPARATOR)return function(e){return M(t,e,t.separator)};if(this.notation===l.HELM){const e="DNA"===t.alphabet||"RNA"===t.alphabet;return function(n){return y(t,n,e)}}throw new Error}getConverter(t,e){if(t===l.SEPARATOR&&!e)throw new Error(`Target separator is not specified for target units '${l.SEPARATOR}'.`);const n=this;if(t===l.FASTA)return function(t){return function(t,e){const n=t.isHelm()?O(t,e):t.getSplitter()(e);return E(t,n)}(n,t)};if(t===l.HELM)return function(t){return function(t,e){const n=e.startsWith("DNA")||e.startsWith("RNA"),r=t.getSplitter()(e);return y(t,r,n)}(n,t)};if(t===l.SEPARATOR)return function(t){return function(t,e,n){const r=t.isHelm()?O(t,e):t.getSplitter()(e);return M(t,r,n)}(n,t,e)};throw new Error}constructor(t){if(this._splitter=null,this._splitted=null,this._stats=null,this._maxLength=null,this._posList=null,t.type!=s.TYPE.STRING)throw new Error(`Unexpected column type '${t.type}', must be '${s.TYPE.STRING}'.`);this._column=t;const e=this._column.getTag(s.TAGS.UNITS);if(null==e)throw new Error("Units are not specified in column");if(this._units=e,this._notation=this.getNotation(),this._defaultGapSymbol=this.isFasta()?T[l.FASTA]:this.isHelm()?T[l.HELM]:T[l.SEPARATOR],!this.column.tags.has("aligned")||!this.column.tags.has("alphabet")||!this.column.tags.has(".alphabetIsMultichar")&&!this.isHelm()&&"UN"===this.alphabet)if(this.isFasta())w.setUnitsToFastaColumn(this);else if(this.isSeparator()){const e=t.getTag("separator");w.setUnitsToSeparatorColumn(this,e)}else{if(!this.isHelm())throw new Error(`Unexpected units '${this.column.getTag(s.TAGS.UNITS)}'.`);w.setUnitsToHelmColumn(this)}if(!this.column.tags.has(".alphabetIsMultichar"))if(this.isHelm())this.column.setTag(".alphabetIsMultichar","true");else if(["UN"].includes(this.alphabet))throw new Error(`For column '${this.column.name}' of alphabet '${this.alphabet}' tag '.alphabetIsMultichar' is mandatory.`)}static getOrCreate(t){return A.uhTemp in t.temp||(t.temp[A.uhTemp]=new w(t)),t.temp[A.uhTemp]}}const S=/[RD]\((\w)\)P?/g;function E(t,e){const n=new Array(e.length);for(const[r,s]of h().enumerate(e)){let i=r;t.isHelm()&&(i=r.replace(S,"$1")),t.isGap(i)?i=T[l.FASTA]:i.length>1&&(i="["+e[s]+"]"),n[s]=i}return n.join("")}function M(t,e,n){const r=new Array(e.length);for(const[n,s]of h().enumerate(e)){let e=n;t.isGap(e)&&(e=T[l.SEPARATOR]),r[s]=e}return r.map((t=>t??"")).join(n)}function y(t,e,n){const[r,s,i,o]=t.getHelmWrappers();return`${r}${h()(e).map((e=>{let r=e;return r=t.isGap(r)?T[l.HELM]:n?r.replace(S,"$1"):1==e.length?`${s}${e}${i}`:`${s}[${e}]${i}`,r})).toArray().join(".")}${o}`}function O(t,e){const n=t.getSplitter()(e),r=new Array(n.length),s=e.startsWith("DNA"),i=e.startsWith("RNA");for(const[t,e]of h().enumerate(n)){let n=t;(s||i)&&(n=n.replace(S,"$1"),n="P"===n?null:n),r[e]=n}return r.filter((t=>null!==t))}class N extends Float32Array{}function L(t){let e=0;for(let n=0;n<t.length;n++)e+=t[n]*t[n];return Math.sqrt(e)}class P{static makePalette(t,e=!1,n=P){const r={};return t.forEach((t=>{const n=t[0],s=t[1];n.forEach(((t,n)=>{r[t]=this.colourPalette[s][e?0:n]}))})),new n(r)}constructor(t){this._palette=t}get(t){return this._palette[t]}}P.undefinedColor="rgb(100,100,100)",P.colourPalette={orange:["rgb(255,187,120)","rgb(245,167,100)","rgb(235,137,70)","rgb(205, 111, 71)"],all_green:["rgb(44,160,44)","rgb(74,160,74)","rgb(23,103,57)","rgb(30,110,96)","rgb(60,131,95)","rgb(24,110,79)","rgb(152,223,138)","rgb(182, 223, 138)","rgb(152, 193, 138)"],all_blue:["rgb(31,119,180)","rgb(23,190,207)","rgb(122, 102, 189)","rgb(158,218,229)","rgb(141, 124, 217)","rgb(31, 120, 150)"],magenta:["rgb(162,106,192)","rgb(197,165,224)","rgb(208,113,218)"],red:["rgb(214,39,40)","rgb(255,152,150)"],st_blue:["rgb(23,190,207)","rgb(158,218,229)","rgb(31,119,180)"],dark_blue:["rgb(31,119,180)","rgb(31, 120, 150)"],light_blue:["rgb(23,190,207)","rgb(158,218,229)","rgb(108, 218, 229)","rgb(23,190,227)"],lilac_blue:["rgb(124,102,211)","rgb(149,134,217)","rgb(97, 81, 150)"],dark_green:["rgb(23,103,57)","rgb(30,110,96)","rgb(60,131,95)","rgb(24,110,79)"],green:["rgb(44,160,44)","rgb(74,160,74)"],light_green:["rgb(152,223,138)","rgb(182, 223, 138)","rgb(152, 193, 138)"],st_green:["rgb(44,160,44)","rgb(152,223,138)","rgb(39, 174, 96)","rgb(74,160,74)"],pink:["rgb(247,182,210)"],brown:["rgb(140,86,75)","rgb(102, 62, 54)"],gray:["rgb(127,127,127)","rgb(199,199,199)","rgb(196,156,148)","rgb(222, 222, 180)"],yellow:["rgb(188,189,34)"],white:["rgb(230,230,230)"]};class H extends P{static get Lesk(){return void 0===this.lesk&&(this.lesk=this.makePalette([[["G","A","S","T"],"orange"],[["C","V","I","L","P","F","Y","M","W"],"all_green"],[["N","Q","H"],"magenta"],[["D","E"],"red"],[["K","R"],"all_blue"]],!1,H)),this.lesk}static get GrokGroups(){return void 0===this.grokGroups&&(this.grokGroups=this.makePalette([[["C","U"],"yellow"],[["G","P"],"red"],[["A","V","I","L","M","F","Y","W"],"all_green"],[["R","H","K"],"light_blue"],[["D","E"],"dark_blue"],[["S","T","N","Q"],"orange"]],!1,H)),this.grokGroups}static get RasMol(){return void 0===this.rasMol&&(this.rasMol=new H({D:"#E60A0A",E:"#E60A0A",C:"#E6E600",M:"#E6E600",K:"#145AFF",R:"#145AFF",S:"#FA9600",T:"#FA9600",F:"#3232AA",Y:"#3232AA",N:"#00DCDC",Q:"#00DCDC",G:"#EBEBEB",L:"#0F820F",V:"#0F820F",I:"#0F820F",A:"#C8C8C8",W:"#B45AB4",H:"#8282D2",P:"#DC9682",others:"#BEA06E"})),this.rasMol}get(t){const e=t in H.aaSynonyms?H.aaSynonyms[t]:t;return super.get(e)}}H.aaSynonyms={MeNle:"L",MeA:"A",MeG:"G",MeF:"F"};class v{static getPalette(t="grok"){switch(t){case"grok":return H.GrokGroups;case"lesk":return H.Lesk;default:throw new Error(`ChemPalette: scheme \`${t}\` does not exist`)}}static getInnerOuter(t){let e=0,n="",r="";for(const s of t)"("==s?e++:")"==s?e--:e?n+=s:r+=s;return isNaN(parseInt(n))?[r,n]:[r,""]}static getColorAAPivot(t="",e="grok"){const n=this.getPalette(e);let[r,s]=this.getInnerOuter(t);if(r=r.length>6?`${r.slice(0,3)}...`:r,s=s.length>6?`${s.slice(0,3)}...`:s,1==t.length||"("==t[1]){const e=t[0]?.toUpperCase();return e in n?[n.get(e),e,s,1]:[this.undefinedColor,r,s,1]}if("d"==t[0]&&t[1]in n&&(2==t.length||"("==t[2])){const e=t[1]?.toUpperCase();return e in n?[n.get(e),e,s,2]:[this.undefinedColor,r,s,2]}if(t.substring(0,3)in this.AAFullNames&&(3==t.length||"("==t[3])){const e=this.AAFullNames[t.substring(0,3)];return e in n?[n.get(e),e,s,3]:[this.undefinedColor,r,s,3]}if(t[0]?.toLowerCase()==t[0]&&t.substring(1,3)in this.AAFullNames&&(4==t.length||"("==t[4])){const e=this.AAFullNames[t.substring(1,3)];return e in n?[n.get(e),e,s,4]:[this.undefinedColor,r,s,4]}return[this.undefinedColor,r,s,0]}}v.SemType="Aminoacids",v.SemTypeMultipleAlignment="AminoacidsMultipleAlignment",v.undefinedColor="rgb(100,100,100)",v.Names={G:"Glycine",L:"Leucine",Y:"Tyrosine",S:"Serine",E:"Glutamic acid",Q:"Glutamine",D:"Aspartic acid",N:"Asparagine",F:"Phenylalanine",A:"Alanine",K:"Lysine",R:"Arginine",H:"Histidine",C:"Cysteine",V:"Valine",P:"Proline",W:"Tryptophan",I:"Isoleucine",M:"Methionine",T:"Threonine"},v.AASmiles={G:"NCC(=O)O",L:"N[C@H](CC(C)C)C(=O)O",Y:"NC(CC1=CC=C(O)C=C1)C(=O)O",S:"NC(CO)C(=O)O",E:"N[C@@H](CCC(O)=O)C(=O)O",Q:"N[C@@H](CCC(N)=O)C(=O)O",D:"N[C@@H](CC(O)=O)C(=O)O",N:"N[C@@H](CC(N)=O)C(=O)O",F:"NC(CC1=CC=CC=C1)C(=O)O",A:"N[C@H](C)C(=O)O",K:"NC(CCCCN)C(=O)O",R:"N[C@H](CCCNC(=N)C)C(=O)O",H:"NC(CC1=CN=C[N]1)C(=O)O",C:"N[C@@H](CS)C(=O)O",V:"NC(C(C)C)C(=O)O",P:"N(CCC1)C1C(=O)O",W:"N[C@@H](Cc1c2ccccc2n([H])c1)C(=O)O",I:"N[C@H]([C@H](C)CC)C(=O)O",M:"NC(CCSC)C(=O)O",T:"NC(C(O)C)C(=O)O"},v.AASmilesTruncated={G:"*C*",L:"CC(C)C[C@H](*)*",Y:"C1=CC(=CC=C1CC(*)*)O",S:"OCC(*)C*",E:"*[C@@H](CCC(O)=O)*",Q:"*N[C@@H](CCC(N)=O)*",D:"*[C@@H](CC(O)=O)*",N:"*[C@@H](CC(N)=O)*",F:"C1=CC=C(C=C1)CC(*)*",A:"C[C@H](*)*",K:"C(CCN)CC(*)*",R:"*[C@H](CCCNC(=N)C)*",H:"C1=C(NC=N1)CC(*)*",C:"C([C@@H](*)*)S",V:"CC(C)C(*)*",P:"C1CCN(*)C1*",W:"*[C@@H](Cc1c2ccccc2n([H])c1)*",I:"CC[C@H](C)[C@H](*)*",M:"CSCCC(*)*",T:"CC(O)C(*)*"},v.AAFullNames={Ala:"A",Arg:"R",Asn:"N",Asp:"D",Cys:"C",Gln:"Q",Glu:"E",Gly:"G",His:"H",Ile:"I",Leu:"L",Lys:"K",Met:"M",Phe:"F",Pro:"P",Ser:"S",Thr:"T",Trp:"W",Tyr:"Y",Val:"V"};class x{}x.SemType="Nucleotides",x.SemTypeMultipleAlignment="NucleotidesMultipleAlignment",x.Names={A:"Adenine",C:"Cytosine",G:"Guanine",T:"Thymine",U:"Uracil"};class R extends class{}{static buildPalette(){return[].concat(...Object.values(P.colourPalette))}get(t){const e=class{static hashCode(t){let e=0;if(0===t.length)return e;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n),e|=0;return e}}.hashCode(t)%R.palette.length;return function(t){if(null==t)return"rgb(100,100,100)";const e=s.Color.fromHtml(t),n=s.Color.g(e),r=s.Color.r(e),i=s.Color.b(e),o=Math.sqrt(Math.pow(0-r,2)+Math.pow(0-n,2)+Math.pow(0-i,2));return o>210?`rgb(${r/o*210},${n/o*210},${i/o*210})`:s.Color.toRgb(e)}(R.palette[e])}}function _(t){return h()(t.toString().matchAll(g)).map((t=>t[2]??t[1])).toArray()}function F(t){return t||[]}function I(t,e){return n=>n.split(t,e)}R.palette=R.buildPalette();const $=/(PEPTIDE1|DNA1|RNA1)\{([^}]+)}/g,G=/\[([^\[\]]+)]/g;function U(t){$.lastIndex=0;const e=$.exec(t.toString()),n=e?e[2]:null;return(n?n.split("."):[]).map((t=>{G.lastIndex=0;const e=G.exec(t);return e&&e.length>=2?e[1]:t}))}const D=/([^\W_]+)/g;var k;function W(t,e,n,r,s,i,o="rgb(100,100,100)",l=0,a=!1,h=1,c="",u=!1,g=k.classic,m=[],p=0,f=null,C=[],d=null,b={}){s.textAlign="start";let A=i.substring(0),T=u?"":c;g===k.MSA&&(T="");let w=!0,S=!0,E="difference";null!=f&&null!=f.cell.column&&(w=f.cell.column.temp["color-code"]??!0,S=f.cell.column.temp["compare-with-current"]??!0,E=f.cell.column.temp["highlight-difference"]??"difference");const M=C[p];S&&C.length>0&&"difference"===E&&(h=A==M?.3:h),S&&C.length>0&&"equal"===E&&(h=A!=M?.3:h),null!=d&&(A=function(t,e){if(t.length<=e)return t;const n=t.match(D),r=t.length>e||(n?.length??0)>1,s=n?.[0]??" ";return r?s.substring(0,e-1)+"…":s}(A,d));const y=A+T;b[y]??(b[y]=s.measureText(y));let O=b[y];b[A]??(b[A]=s.measureText(A));let N=b[A].width;b[T]??(b[T]=s.measureText(T));const L=b[T].width,P=r/2-(O.fontBoundingBoxAscent+O.fontBoundingBoxDescent)/2+1;function H(n,r){const i=w?o:"rgb(0,0,0)";s.fillStyle=i,s.globalAlpha=h,g===k.classic&&(s.fillText(A,t+n,e+P),s.fillStyle="#808080",s.fillText(T,t+r,e+P)),g===k.MSA&&s.fillText(A,t+n,e+P)}O=O.width,g===k.MSA&&(N=m[p],O=m[p]);const v=(m[p]??0)-(m[0]??0);if(a||O>n)return H(v,v+N),t+v+N+L;{const e=(n-O)/2;return H(e,e+N),t+v+e+N}}function j(t){var e;return"string"==typeof t||t instanceof String?t:("object"==typeof t||t instanceof Object)&&"$thrownJsError"in t?j(t.$thrownJsError):t instanceof Error?null!==(e=t.stack)&&void 0!==e?e:t.message:t.toString()}function z(t){t=V(t,"$")[0];const e=[];if(!scil.Utils.isNullOrEmpty(t)){const n=V(t,"|");for(let r=0;r<n.length;++r){let s=(t=B(n[r]).str).indexOf("{");s=(t=t.substring(s+1)).indexOf("}");const i=V(t=t.substring(0,s),".");for(const t of i)if(t&&""!==t)if(t.startsWith("[")&&t.includes("]")){const n=t.substring(1,t.indexOf("]"));e.push(n);const r=t.substring(t.indexOf("]")+1);i.push(r)}else if(t.includes("[")&&t.endsWith("]")){const n=t.substring(t.lastIndexOf("[")+1,t.length-1);e.push(n);const r=t.substring(0,t.lastIndexOf("["));i.push(r)}else if(t.includes("(")&&t.includes(")")){const e=t.substring(0,t.indexOf("(")),n=t.substring(t.lastIndexOf(")")+1),r=[e,t.substring(e.length+1,t.length-n.length-1),n];for(const t of r)i.push(t)}else e.push(t)}}return e}function q(t){const e=Object.keys(org.helm.webeditor.monomerTypeList()),n=[],r=[];for(let t=0;t<e.length;t++)n.push(new scil.helm.Monomers.getMonomerSet(e[t])),Object.keys(n[t]).forEach((e=>{r.push(n[t][e].id)}));return new Set(t.filter((t=>!r.includes(t))))}function V(t,e){const n=[];let r="",s=0,i=0,o=0,l=0;for(let a=0;a<t.length;++a){let h=t.substring(a,a+1);if(h==e&&0==i&&0==s&&0==o&&0==l)n.push(r),r="";else{if(r+=h,l>0&&"\\"==h&&a+1<t.length){++a;const e=t.substring(a,a+1);r+=e,h+=e}'"'==h?a>0&&"\\"==t.substring(a-1,a)||(l=0==l?1:0):"["==h?++i:"]"==h?--i:"("==h?++s:")"==h?--s:"{"==h?++o:"}"==h&&--o}}return n.push(r),n}function B(t){const e=Y(t,'"');if(null!=e.tag)return e;const n=Y(t,"'");return{tag:e.tag,repeat:n.tag,str:n.str}}function Y(t,e){let n=null;if(scil.Utils.endswith(t,e)){let r=t.length-1;for(;r>0&&(r=t.lastIndexOf(e,r-1),!(r<=0||"\\"!=t.substring(r-1,r))););r>0&&r<t.length-1&&(n=t.substring(r+1,t.length-1),t=t.substring(0,r))}return null!=n&&(n=function(t){return scil.Utils.isNullOrEmpty(t)?t:t.replace(/[\\]./g,(function(t){switch(t){case"\\r":return"\r";case"\\n":return"\n";case"\\t":return"\t";default:return t.substring(1)}}))}(n.replace(new RegExp("\\"+e,"g"),e))),{tag:n,str:t}}!function(t){t.MSA="MSA",t.classic="classic"}(k||(k={}));class Q{constructor(t){this.col=t,this._allPartsList=null,this._lengthsList=null,this.monomerCharWidth=7,this.leftPadding=5,this.col.dataFrame.onDataChanged.subscribe(),this.monomerLib=st(),this.monomerLib.onChanged.subscribe(this.monomerLibOnChanged.bind(this))}skipCell(t){null===this._allPartsList&&(this._allPartsList=new Array(this.col.length).fill(null)),null===this._lengthsList&&(this._lengthsList=new Array(this.col.length).fill(null)),this._allPartsList[t]=[],this._lengthsList[t]=[]}getCellAllPartsLengths(t){null===this._allPartsList&&(this._allPartsList=new Array(this.col.length).fill(null)),null===this._lengthsList&&(this._lengthsList=new Array(this.col.length).fill(null));const[e,n]=this.getCellMonomerLengthsForSeq(t),r=new Array(n.length+1);r[0]=this.leftPadding;for(let t=1;t<r.length;t++)r[t]=r[t-1]+n[t-1];return[e,n,r]}getCellMonomerLengthsForSeq(t){let e=this._allPartsList[t];null===e&&(e=this._allPartsList[t]=this.getAllParts(t));let n=this._lengthsList[t];if(null===n){n=this._lengthsList[t]=new Array(e.length);for(const[t,r]of h().enumerate(e)){const e=t.length*this.monomerCharWidth;n[r]=e}}return[e,n]}getAllParts(t){const e=this.col.get(t),n=e?z(e):[];return e?function(t,e){const n=[];for(let r=0;r<t.length;++r){const s=e.indexOf(t[r]),i=e.slice(0,s);n.push(i),n.push(t[r]),e=e.substring(s+t[r].length)}return n.push(e),n}(n,e):[]}getMonomer(t){let e=null;for(const n of this.monomerLib.getPolymerTypes())if(e=this.monomerLib.getMonomer(n,t),e)break;return e}monomerLibOnChanged(t){this._lengthsList=null,this._allPartsList=null}static getOrCreate(t){return"bio-helmMonomerPlacer"in t.temp||(t.temp["bio-helmMonomerPlacer"]=new Q(t)),t.temp["bio-helmMonomerPlacer"]}}const K=/\{(\*\.)+/g,J=/\.(\*\.)+/g,Z=/(\.\*)+\}/g;class X extends s.GridCellRenderer{get name(){return"helm"}get cellType(){return"helm"}get defaultWidth(){return 400}get defaultHeight(){return 100}onMouseMove(t,e){var s,i;try{let o=null;try{o=t.tableColumn}catch(t){}if(!o)return;const l=Q.getOrCreate(o),[a,c,u]=l.getCellAllPartsLengths(t.tableRowIndex),g=Object.values(c).length-1,m=e.offsetX-t.bounds.x;let p=0,f=g,C=!1,d=0,b=0;if(m>u[0])for(;!C&&d<u.length;)b=Math.floor((f+p)/2),m>=u[b]&&m<=u[b+1]?(p=b,C=!0):m<u[b]?f=b-1:m>u[b+1]&&(p=b+1),p==f&&(C=!0),d++;p=m>=u[p]?p:p-1;const A=z(t.cell.value?t.cell.value.replaceAll(K,"{").replaceAll(J,".").replaceAll(Z,"}").replace("{*}","{}"):""),T=new Set(A),w=q(A),S=[];for(const[t,e]of h().enumerate(a))if(w.has(t))S[e]=r.divV([r.divText(`Monomer ${a[e]} not found.`),r.divText("Open the Context Panel, then expand Manage Libraries")]);else if(T.has(t)){const s=[r.div(t)],i=l.getMonomer(t);if(i){const t={autoCrop:!0,autoCropMargin:0,suppressChiralText:!0},e=n.chem.svgMol(i.smiles,void 0,void 0,t);s.push(e)}S[e]=r.divV(s)}(null!==(i=null===(s=S[p])||void 0===s?void 0:s.childNodes.length)&&void 0!==i?i:0)>0?r.tooltip.show(S[p],e.x+16,e.y+16):r.tooltip.hide()}catch(t){const e=j(t);console.error("Helm: HelmCellRenderer.onMouseMove() error:\n"+e)}}render(t,e,n,s,i,o,l){t.save();try{let l=null;try{l=o.tableColumn}catch(t){}if(!l)return;const a=-1!==o.gridRow?o.grid:void 0,h="red",c="#404040",u="#C0C0C0",g=o.cell.value?o.cell.value.replaceAll(K,"{").replaceAll(J,".").replaceAll(Z,"}").replace("{*}","{}"):"",m=z(g),p=new Set(m),f=q(m),C=Q.getOrCreate(l);if(0==f.size){C.skipCell(o.tableRowIndex);const t=r.div([],{style:{width:`${s}px`,height:`${i}px`}});return t.setAttribute("dataformat","helm"),t.setAttribute("data",g),o.element=t,void new JSDraw2.Editor(t,{width:s,height:i,skin:"w8",viewonly:!0})}if(f.size>0){if(!a){const e=window.devicePixelRatio;i=28,t.canvas.height=i*e,t.canvas.style.height=`${i}px`}s=a?Math.min(a.canvas.width-e,s):t.canvas.width-e,t.save(),t.beginPath(),t.rect(e,n,s,i),t.clip(),t.transform(1,0,0,1,e,n),t.font="12px monospace",t.textBaseline="top";const[r,l,g]=C.getCellAllPartsLengths(o.tableRowIndex);for(let e=0;e<r.length;++e){const n=r[e],o="."===n||n.endsWith("{")||n.startsWith("}")?u:f.has(n)?h:p.has(n)?c:u;t.fillStyle=o,W(g[e],0,s,i,t,r[e],o,0,!0,1)}}}finally{t.restore()}}}var tt=function(t,e,n,r){return new(n||(n=Promise))((function(s,i){function o(t){try{a(r.next(t))}catch(t){i(t)}}function l(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,l)}a((r=r.apply(t,e||[])).next())}))};let et=null;const nt=new s.Package;function rt(){return tt(this,void 0,void 0,(function*(){return org.helm.webeditor.kCaseSensitive=!0,Promise.all([new Promise(((t,e)=>{dojo.ready((function(){t(null)}))})),n.functions.call("Bio:getBioLib")]).then((([t,e])=>{et=e,it(),et.onChanged.subscribe((t=>{try{it();const t=et.getPolymerTypes(),e="Monomer lib updated:<br />"+(0==t.length?"empty":t.map((t=>`${t} ${et.getMonomerSymbolsByType(t).length}`)).join("<br />"));n.shell.info(e)}catch(t){const e=j(t);console.error("Helm: initHelm monomerLib.onChanged() error:\n"+e)}}))})).catch((t=>{const e=t instanceof Error?t.message:t?t.toString():"Exception 'undefined'";n.shell.error(`Package 'Helm' init initHelm() error: ${e}`);const r=new Error(e);throw r.stack=t.stack,r}))}))}function st(){return et}function it(){org.helm.webeditor.Monomers.clear(),et.getPolymerTypes().forEach((t=>{et.getMonomerSymbolsByType(t).forEach((e=>{let n=!1;const r=et.getMonomer(t,e),s={id:e,m:r.molfile,n:r.name,na:r.naturalAnalog,rs:r.rgroups.length,type:r.polymerType,mt:r.monomerType,at:{}};if(r.rgroups.length>0){s.rs=r.rgroups.length;const t={};r.rgroups.forEach((e=>{t[e.label]=e.capGroupName})),s.at=t}else null!=r.smiles?(s.rs=Object.keys(ut(r.smiles.toString())).length,s.at=ut(r.smiles.toString())):n=!0;n||org.helm.webeditor.Monomers.addOneMonomer(s)}))}));const t=n.shell.tv.grid;t&&t.invalidate()}function ot(){return new X}function lt(t,e,s){const i=q(z(t&&void 0===s?t.value:e));0===i.size?function(t,e,s){const i=r.div(),o=n.shell.tv.grid.dataFrame.columns.bySemType("Macromolecule"),l=w.getOrCreate(o);org.helm.webeditor.MolViewer.molscale=.8;const a=new scil.helm.App(i,{showabout:!1,mexfontsize:"90%",mexrnapinontab:!0,topmargin:20,mexmonomerstab:!0,sequenceviewonly:!1,mexfavoritefirst:!0,mexfilter:!0}),h=a.calculateSizes();a.canvas.resize(h.rightwidth-100,h.topheight-210);let c={width:h.rightwidth-100+"px",height:h.bottomheight+"px"};scil.apply(a.sequence.style,c),scil.apply(a.notation.style,c),c={width:h.rightwidth+"px",height:h.bottomheight+a.toolbarheight+"px"},scil.apply(a.properties.parent.style,c),a.structureview.resize(h.rightwidth,h.bottomheight+a.toolbarheight),a.mex.resize(h.topheight-80),setTimeout((()=>{t&&void 0===s?a.canvas.helm.setSequence(t.value,"HELM"):a.canvas.helm.setSequence(e,"HELM")}),200),r.dialog({showHeader:!1,showFooter:!0}).add(i).onOK((()=>{const e=a.canvas.getHelm(!0).replace(/<\/span>/g,"").replace(/<span style='background:#bbf;'>/g,"");if(t)if(void 0===s)t.value=e;else{const n=l.convertHelmToFastaSeparator(e,s);t.value=n}})).show({modal:!0,fullScreen:!0})}(t,e,s):1===i.size&&i.has(T[l.HELM])?n.shell.warning(`WebEditor doesn't support Helm with gaps '${T[l.HELM]}'.`):n.shell.warning(`Monomers ${Array.from(i).map((t=>`'${t}'`)).join(", ")} are absent! <br/>Please, upload the monomer library! <br/><a href="https://datagrok.ai/help/domains/bio/macromolecules" target="_blank">Learn more</a>`)}function at(t){lt(t.cell,void 0,void 0)}function ht(t){const e=n.shell.tv.grid.dataFrame,r=e.columns.bySemType("Macromolecule"),i=w.getOrCreate(r);r.getTag(s.TAGS.UNITS)===l.HELM&<(e.currentCell,void 0,void 0);const o=i.getConverter(l.HELM)(t);lt(e.currentCell,o,r.getTag(s.TAGS.UNITS))}function ct(t){return tt(this,void 0,void 0,(function*(){const e=n.shell.tv.grid.root.parentElement,i=r.div([]);e.appendChild(i);const o=new JSDraw2.Editor(i,{viewonly:!0});i.style.width="0px",i.style.height="0px",o.setHelm(t);const l=o.getFormula(!0),a=Math.round(100*o.getMolWeight())/100,h=Math.round(100*o.getExtinctionCoefficient(!0))/100;return e.lastChild.remove(),new s.Widget(r.tableFromMap({formula:l.replace(/<sub>/g,"").replace(/<\/sub>/g,""),"molecular weight":a,"extinction coefficient":h}))}))}function ut(t){const e=t.match(/(?<=\[)[^\][]*(?=])/gm),n={};let r,s="";if(e)for(let t=0;t<e.length;t++)if(null!=e[t]&&/\d/.test(e[t])){r=e[t][e[t].length-1],e[t]=e[t].replace(/[0-9]/g,"");for(let n=0;n<e[t].length;n++)":"!=e[t][n]&&(s+=e[t][n]);n["R"+r]=s,s=""}return n}function gt(t){const e=n.shell.tv.grid.root.parentElement,i=s.Column.string("mols",t.length),o=r.div([]);e.appendChild(o);const l=new JSDraw2.Editor(o,{viewonly:!0});return o.style.width="0px",o.style.height="0px",i.init((e=>(l.setHelm(t.get(e)),l.getMolfile()))),e.lastChild.remove(),i}function mt(){return new i}helm=e})();
|
|
2
2
|
//# sourceMappingURL=package.js.map
|