@datagrok/helm 2.1.23 → 2.1.24

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/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:()=>st,editMoleculeCell:()=>ct,getMolfiles:()=>pt,getMonomerLib:()=>it,helmCellRenderer:()=>at,helmWebEditor:()=>ft,initHelm:()=>ot,openEditor:()=>ut,propertiesPanel:()=>gt});const n=grok,r=ui,s=DG;function o(t){var e;return"string"==typeof t||t instanceof String?t:("object"==typeof t||t instanceof Object)&&"$thrownJsError"in t?o(t.$thrownJsError):t instanceof Error?null!==(e=t.stack)&&void 0!==e?e:t.message:t.toString()}class i{constructor(t,e,n){this.name=t,this.alphabet=e,this.cutoff=n}}class l extends i{constructor(t,e,n){super(t.name,t.alphabet,t.cutoff),this.freq=e,this.similarity=n}}var a,h;(h=a||(a={})).FASTA="fasta",h.SEPARATOR="separator",h.HELM="helm";const c=/(?:\[([A-Za-z0-9_\-,()]+)\])|([A-Za-z\-])/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 i("PT",u.fasta.peptide,.5),new i("DNA",u.fasta.dna,.55),new i("RNA",u.fasta.rna,.55)],m=wu;var p=t.n(m);function f(t={}){const e=function(){if(!t||!t.scoringMatrix||!t.alphabetIndexes)return(t,e)=>t===e?0:1;if(t.scoringMatrix.length!==Object.keys(t.alphabetIndexes).length)throw new Error("Scoring matrix and alphabet indexes should have the same length");const e=t.alphabetIndexes,n=t.scoringMatrix,r=Math.min(...Object.keys(e).map((t=>t.charCodeAt(0))))+1,s=new Float32Array((n.length+r)*(n.length+r));return Object.entries(e).forEach((([t,r])=>{const o=n[r];Object.entries(e).forEach((([e,r])=>{s[t.charCodeAt(0)*n.length+e.charCodeAt(0)]=o[r]}))})),(t,e)=>s[t.charCodeAt(0)*n.length+e.charCodeAt(0)]}(),n=t?.threshold??0;return(t,r)=>{let s=0;const o=t.length,i=r.length,l=Math.max(o,i)*(1-n);o!==i&&(s=Math.abs(o-i));let a=0;for(let n=0;n<Math.min(o,i);n++)if(t[n]!==r[n]&&(a+=e(t[n],r[n]),a>l))return 1;return a+=s,a/=Math.max(o,i),a}}const d=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 b;!function(t){t.HAMMING="Hamming",t.LEVENSHTEIN="Levenshtein",t.NEEDLEMANN_WUNSCH="Needlemann-Wunsch",t.MONOMER_CHEMICAL_DISTANCE="Monomer chemical distance"}(b||(b={}));const A={[b.HAMMING]:f,[b.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--;)d[t.charCodeAt(a)]|=1<<a;for(a=0;a<r;a++){let t=d[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--;)d[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++)d[t.charCodeAt(e)]|=1<<e;for(let t=0;t<n;t++){const n=d[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++)d[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++)d[t.charCodeAt(e)]|=1<<e;let m=r;for(let t=0;t<n;t++){const n=d[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),p=c&u;m+=g>>>r-1&1,m-=p>>>r-1&1,g>>>31^i&&(o[t/32|0]^=1<<t),p>>>31^l&&(s[t/32|0]^=1<<t),g=g<<1|i,p=p<<1|l,c=p|~(a|g),h=g&a}for(let e=u;e<g;e++)d[t.charCodeAt(e)]=0;return m})(t,e)})(t,e)/Math.max(t.length,e.length)},[b.NEEDLEMANN_WUNSCH]:function(t){return(e,n)=>{const{gapOpen:r,gapExtend:s,scoringMatrix:o,alphabetIndexes:i}={...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]+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),p=Math.max(g,m);return(p-l[c][e.length])/p}},[b.MONOMER_CHEMICAL_DISTANCE]:f},T=new RegExp("[rd]\\((\\w)\\)p?","g");const w=new class{constructor(){this.uhTemp=`units-handler.${s.SEMTYPE.MACROMOLECULE}`}},E={[a.FASTA]:"-",[a.SEPARATOR]:"",[a.HELM]:"*"};class S{static setUnitsToFastaColumn(t){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE||t.column.getTag(s.TAGS.UNITS)!==a.FASTA)throw new Error(`The column of notation '${a.FASTA}' must be '${s.SEMTYPE.MACROMOLECULE}'.`);t.column.setTag(s.TAGS.UNITS,a.FASTA),S.setTags(t)}static setUnitsToSeparatorColumn(t,e){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE||t.column.getTag(s.TAGS.UNITS)!==a.SEPARATOR)throw new Error(`The column of notation '${a.SEPARATOR}' must be '${s.SEMTYPE.MACROMOLECULE}'.`);if(!e)throw new Error(`The column of notation '${a.SEPARATOR}' must have the separator tag.`);t.column.setTag(s.TAGS.UNITS,a.SEPARATOR),t.column.setTag("separator",e),S.setTags(t)}static setUnitsToHelmColumn(t){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE)throw new Error(`The column of notation '${a.HELM}' must be '${s.SEMTYPE.MACROMOLECULE}'`);t.column.setTag(s.TAGS.UNITS,a.HELM),S.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)),[a.FASTA,a.SEPARATOR].includes(e)){if(!t.column.getTag("alphabet")&&0===Object.keys(n.freq).length)throw new Error("Alphabet is empty and not annotated.");let e=t.column.getTag("aligned");null===e&&(e=n.sameLength?"SEQ.MSA":"SEQ",t.column.setTag("aligned",e));let r=t.column.getTag("alphabet");if(null===r&&(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 N(s),l=new N(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)/(v(i)*v(l))}(t,e.alphabet,n);return new l(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),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===a.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==a.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===a.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=0===this.splitted.length?0: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())):p().count(1).take(this.maxLength).map((t=>t.toString())).toArray()}return this._posList}isFasta(){return this.notation===a.FASTA}isSeparator(){return this.notation===a.SEPARATOR}isHelm(){return this.notation===a.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===a.FASTA&&t===E[a.FASTA]||this.units===a.HELM&&t===E[a.HELM]}getNotation(){if(this.units.toLowerCase().startsWith(a.FASTA))return a.FASTA;if(this.units.toLowerCase().startsWith(a.SEPARATOR))return a.SEPARATOR;if(this.units.toLowerCase().startsWith(a.HELM))return a.HELM;throw new Error(`Column '${this.column.name}' has unexpected notation '${this.units}'.`)}getHelmWrappers(){return[this.isDna()||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,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),t===a.SEPARATOR){if(!e)throw new Error(`Notation '${a.SEPARATOR}' requires separator value.`);l.setTag("separator",e)}l.setTag(s.TAGS.CELL_RENDERER,"Macromolecule");const h=n.getTag("aligned");h&&l.setTag("aligned",h);const c=n.getTag("alphabet");null!=c&&l.setTag("alphabet",c);let u=n.getTag(".alphabetSize");null!=c&&u&&l.setTag(".alphabetSize",u);const g=n.getTag(".alphabetIsMultichar");return null!=c&&void 0!==g&&l.setTag(".alphabetIsMultichar",g),t==a.HELM&&(u=this.getAlphabetSize().toString(),l.setTag(".alphabetSize",u)),l}static getNewColumn(t){const e=S.getOrCreate(t),n=e.notation;return e.getNewColumn(n)}static unitsStringIsValid(t){return t=t.toLowerCase(),[a.FASTA,a.SEPARATOR,a.HELM].some((e=>t.startsWith(e.toLowerCase())))}static getNewColumnFromParams(t,e,n){if(!S.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(a.FASTA))return null===this.column.getTag("alphabet")||this.getAlphabetIsMultichar()?_:I;if(this.units.toLowerCase().startsWith(a.SEPARATOR))return G(this.separator,t);if(this.units.toLowerCase().startsWith(a.HELM))return k;throw new Error(`Unexpected units ${this.units} .`)}getDistanceFunctionName(){if(!this.isFasta())throw new Error("Only FASTA notation is supported");return this.isMsa()?b.HAMMING:(this.alphabet,b.LEVENSHTEIN)}getDistanceFunction(){return A[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=G(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,S.getOrCreate(t).getSplitter())),this._splitter}toFasta(t){return t===a.FASTA}toSeparator(t){return t===a.SEPARATOR}toHelm(t){return t===a.HELM}convertHelmToFastaSeparator(t,e,n,r){r||(r=this.toFasta(e)?E[a.FASTA]:E[a.SEPARATOR]),n||(n=this.toFasta(e)?"":this.separator);const s=t.startsWith("RNA"),o=this.splitter(t),i=[];for(let t=0;t<o.length;t++){let n=o[t];if(s&&(n=n.replace(T,"")),n===E[a.HELM])i.push(r);else if(this.toFasta(e)&&n.length>1){const t="["+n+"]";i.push(t)}else i.push(n)}return i.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,o=e??this.maxLength-1,i=this.getJoiner(),l=o-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]:E[this.notation]}return i(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===a.FASTA)return function(e){return M(t,e)};if(this.notation===a.SEPARATOR)return function(e){return y(t,e,t.separator)};if(this.notation===a.HELM){const e="DNA"===t.alphabet||"RNA"===t.alphabet;return function(n){return O(t,n,e)}}throw new Error}getConverter(t,e){if(t===a.SEPARATOR&&!e)throw new Error(`Target separator is not specified for target units '${a.SEPARATOR}'.`);const n=this;if(t===a.FASTA)return function(t){return function(t,e){const n=t.isHelm()?L(t,e):t.getSplitter()(e);return M(t,n)}(n,t)};if(t===a.HELM)return function(t){return function(t,e){const n=e.startsWith("DNA")||e.startsWith("RNA"),r=t.getSplitter()(e);return O(t,r,n)}(n,t)};if(t===a.SEPARATOR)return function(t){return function(t,e,n){const r=t.isHelm()?L(t,e):t.getSplitter()(e);return y(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()?E[a.FASTA]:this.isHelm()?E[a.HELM]:E[a.SEPARATOR],!this.column.tags.has("aligned")||!this.column.tags.has("alphabet")||!this.column.tags.has(".alphabetIsMultichar")&&!this.isHelm()&&"UN"===this.alphabet)if(this.isFasta())S.setUnitsToFastaColumn(this);else if(this.isSeparator()){const e=t.getTag("separator");S.setUnitsToSeparatorColumn(this,e)}else{if(!this.isHelm())throw new Error(`Unexpected units '${this.column.getTag(s.TAGS.UNITS)}'.`);S.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 w.uhTemp in t.temp||(t.temp[w.uhTemp]=new S(t)),t.temp[w.uhTemp]}}function M(t,e){const n=new Array(e.length);for(const[r,s]of p().enumerate(e)){let o=r;t.isHelm()&&(o=r.replace(T,"$1")),t.isGap(o)?o=E[a.FASTA]:o.length>1&&(o="["+e[s]+"]"),n[s]=o}return n.join("")}function y(t,e,n){const r=new Array(e.length);for(const[n,s]of p().enumerate(e)){let e=n;t.isGap(e)&&(e=E[a.SEPARATOR]),r[s]=e}return r.map((t=>t??"")).join(n)}function O(t,e,n){const[r,s,o,i]=t.getHelmWrappers();return`${r}${p()(e).map((e=>{let r=e;return r=t.isGap(r)?E[a.HELM]:n?r.replace(T,"$1"):1==e.length?`${s}${e}${o}`:`${s}[${e}]${o}`,r})).toArray().join(".")}${i}`}function L(t,e){const n=t.getSplitter()(e),r=new Array(n.length),s=e.startsWith("DNA"),o=e.startsWith("RNA");for(const[t,e]of p().enumerate(n)){let n=t;(s||o)&&(n=n.replace(T,"$1"),n="p"===n?null:n),r[e]=n}return r.filter((t=>null!==t))}class N extends Float32Array{}function v(t){let e=0;for(let n=0;n<t.length;n++)e+=t[n]*t[n];return Math.sqrt(e)}class x{static makePalette(t,e=!1,n=x){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]}}x.undefinedColor="rgb(100,100,100)",x.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 x{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 P{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]}}P.SemType="Aminoacids",P.SemTypeMultipleAlignment="AminoacidsMultipleAlignment",P.undefinedColor="rgb(100,100,100)",P.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"},P.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"},P.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(*)*"},P.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 R{}R.SemType="Nucleotides",R.SemTypeMultipleAlignment="NucleotidesMultipleAlignment",R.Names={A:"Adenine",C:"Cytosine",G:"Guanine",T:"Thymine",U:"Uracil"};class F extends class{}{static buildPalette(){return[].concat(...Object.values(x.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)%F.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)}(F.palette[e])}}function _(t){return p()(t.toString().matchAll(c)).map((t=>t[2]??t[1])).toArray()}function I(t){return t||[]}function G(t,e){return n=>n?n.replaceAll('"-"',"").replaceAll("'-'","").split(t,e):[]}F.palette=F.buildPalette();const $=/(PEPTIDE1|DNA1|RNA1)\{([^}]+)}/g,U=/\[([^\[\]]+)]/g;function k(t){$.lastIndex=0;const e=$.exec(t.toString()),n=e?e[2]:null;return(n?n.split("."):[]).map((t=>{U.lastIndex=0;const e=U.exec(t);return e&&e.length>=2?e[1]:t}))}const D=/([^\W_]+)/g;function W(t){t=z(t,"$")[0];const e=[];if(!scil.Utils.isNullOrEmpty(t)){const n=z(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 o=z(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 j(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 z(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 B(t){const e=q(t,'"');if(null!=e.tag)return e;const n=q(t,"'");return{tag:e.tag,repeat:n.tag,str:n.str}}function q(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}}class V{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}}}var Y,K;function Q(t,e,n,r,s,o,i="rgb(100,100,100)",l=0,a=!1,h=1,c="",u=!1,g=K.classic,m=[],p=0,f=null,d=[],C=null,b={}){s.textAlign="start";let A=o.substring(0),T=u?"":c;g===K.MSA&&(T="");let w=!0,E=!0,S="difference";null!=f&&null!=f.cell.column&&(w=f.cell.column.temp["color-code"]??!0,E=f.cell.column.temp["compare-with-current"]??!0,S=f.cell.column.temp["highlight-difference"]??"difference");const M=d[p];E&&d.length>0&&"difference"===S&&(h=A==M?.3:h),E&&d.length>0&&"equal"===S&&(h=A!=M?.3:h),null!=C&&(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,C));const y=A+T;b[y]??(b[y]=s.measureText(y));let O=b[y];b[A]??(b[A]=s.measureText(A));let L=b[A].width;b[T]??(b[T]=s.measureText(T));const N=b[T].width,v=r/2-(O.fontBoundingBoxAscent+O.fontBoundingBoxDescent)/2+1;function x(n,r){const o=w?i:"rgb(0,0,0)";s.fillStyle=o,s.globalAlpha=h,g===K.classic&&(s.fillText(A,t+n,e+v),s.fillStyle="#808080",s.fillText(T,t+r,e+v)),g===K.MSA&&s.fillText(A,t+n,e+v)}O=O.width,g===K.MSA&&(L=m[p],O=m[p]);const H=(m[p]??0)-(m[0]??0);if(a||O>n)return x(H,H+L),t+H+L+N;{const e=(n-O)/2;return x(e,e+L),t+H+e+L}}!function(t){t.maxMonomerLength=".mm.cellRenderer.maxMonomerLength"}(Y||(Y={})),function(t){t.MSA="MSA",t.classic="classic"}(K||(K={}));class J{constructor(t){this.col=t,this.monomerCharWidth=7,this.leftPadding=5,this.col.dataFrame.onDataChanged.subscribe(),this.monomerLib=it(),this.monomerLib.onChanged.subscribe(this.monomerLibOnChanged.bind(this)),this._allPartsList=new Array(this.col.length).fill(null),this._lengthsList=new Array(this.col.length).fill(null),this._editorList=new Array(this.col.length).fill(null)}skipCell(t){this._allPartsList[t]=[],this._lengthsList[t]=[]}getCellAllPartsLengths(t){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 p().enumerate(e)){const e=t.length*this.monomerCharWidth;n[r]=e}}return[e,n]}getAllParts(t){const e=this.col.get(t),n=e?W(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;if(t.polymerType)e=this.monomerLib.getMonomer(t.polymerType,t.symbol);else for(const n of this.monomerLib.getPolymerTypes())if(e=this.monomerLib.getMonomer(n,t.symbol),e)break;return e}monomerLibOnChanged(t){this._lengthsList.fill(null),this._allPartsList.fill(null),this._editorList.fill(null)}static getOrCreate(t){return"bio-helmMonomerPlacer"in t.temp||(t.temp["bio-helmMonomerPlacer"]=new J(t)),t.temp["bio-helmMonomerPlacer"]}setEditor(t,e){this._editorList[t]=e}getEditor(t){return this._editorList[t]}}const Z=/\{(\*\.)+/g,X=/\.(\*\.)+/g,tt=/(\.\*)+\}/g;window.dojox.gfx.svg.Text.prototype.getTextWidth=function(){const t=this.rawNode,e=t.parentNode,n=t.cloneNode(!0);n.style.visibility="hidden";let r=0;const s=n.firstChild.nodeValue;if(e.appendChild(n),""!=s){let t=100;for(;!r&&--t>0;)r=n.getBBox?parseInt(n.getBBox().width):68}return e.removeChild(n),r};class et extends s.GridCellRenderer{get name(){return"helm"}get cellType(){return"helm"}get defaultWidth(){return 400}get defaultHeight(){return 100}onMouseMove(t,e){try{let s=null;try{s=t.tableColumn}catch(t){}if(!s)return;const o=e.offsetX-t.bounds.x,i=e.offsetY-t.bounds.y,l=J.getOrCreate(s),a=l.getEditor(t.tableRowIndex),h=a?function(t,e,n,r){let s=null;function o(n){let s,o;for(let i=0;i<r.m.atoms.length;++i)if(!n.includes(i)){const n=r.m.atoms[i].p.x,l=r.m.atoms[i].p.y,a=Math.sqrt(Math.pow(t-n,2)+Math.pow(e-l,2));(void 0===o||o>a)&&(s=i,o=a)}return[s,o]}const[i,l]=o([]),[a,h]=o([i]);if(void 0!==i&&void 0!==l){const t=function(t){let e;switch(t.bio.type){case"HELM_BASE":case"HELM_SUGAR":case"HELM_LINKER":e="RNA";break;default:e="PEPTIDE"}return{symbol:t.elem,polymerType:e}}(r.m.atoms[i]);void 0!==a&&void 0!==h?l<.45*h&&(s=t):l<.35*n.bounds.height&&(s=t)}return s}(o,i,t,a):function(t,e,n,r){let s=null;const[o,i,l]=r.getCellAllPartsLengths(n.tableRowIndex);let a=0,h=Object.values(i).length-1,c=!1,u=0,g=0;if(t>l[0])for(;!c&&u<l.length;)g=Math.floor((h+a)/2),t>=l[g]&&t<=l[g+1]?(a=g,c=!0):t<l[g]?h=g-1:t>l[g+1]&&(a=g+1),a==h&&(c=!0),u++;return a=t>=l[a]?a:a-1,a>=0&&(s=function(t,e,n){let r;for(const s of n.getPolymerTypes())t.startsWith(s)&&(r={symbol:e,polymerType:s});return r||(r={symbol:e}),r}(o[0],o[a],r.monomerLib)),s}(o,0,t,l);if(!h)return void r.tooltip.hide();if(j(W(t.cell.value?t.cell.value.replaceAll(Z,"{").replaceAll(X,".").replaceAll(tt,"}").replace("{*}","{}"):"")).has(h.symbol))r.tooltip.show(r.divV([r.divText(`Monomer ${h.symbol} not found.`),r.divText("Open the Context Panel, then expand Manage Libraries")]),e.x+16,e.y+16);else{const t=l.getMonomer(h);if(t){const s={autoCrop:!0,autoCropMargin:0,suppressChiralText:!0},o=n.chem.svgMol(t.smiles,void 0,void 0,s);r.tooltip.show(r.divV([r.divText(h.symbol),o]),e.x+16,e.y+16)}}}catch(t){const e=o(t);console.error("Helm: HelmCellRenderer.onMouseMove() error:\n"+e)}finally{e.preventDefault(),e.stopPropagation()}}render(t,e,n,s,o,i,l){var a,h,c,u,g,m;t.save();try{let l=null;try{l=i.tableColumn}catch(t){}if(!l)return;const p=-1!==i.gridRow?i.grid:void 0,f="red",d="#404040",C="#C0C0C0",b=i.cell.value?i.cell.value.replaceAll(Z,"{").replaceAll(X,".").replaceAll(tt,"}").replace("{*}","{}"):"",A=W(b),T=new Set(A),w=j(A),E=J.getOrCreate(l);if(0==w.size){const t=i.element=r.div([],{style:{width:s-2+"px",height:o-2+"px",margin:"1px",backgroundColor:"#FFE0E0"}});t.setAttribute("dataformat","helm"),t.setAttribute("data",b),t.parentElement&&(null!==(c=null===(h=null===(a=i.grid)||void 0===a?void 0:a.canvas)||void 0===h?void 0:h.offsetLeft)&&void 0!==c?c:0)>0&&(t.parentElement.style.left=`${(null!==(m=null===(g=null===(u=i.grid)||void 0===u?void 0:u.canvas)||void 0===g?void 0:g.offsetLeft)&&void 0!==m?m:0)+t.parentElement.offsetLeft}px`);const e=new JSDraw2.Editor(t,{width:s,height:o,skin:"w8",viewonly:!0});return E.setEditor(i.tableRowIndex,e),void E.skipCell(i.tableRowIndex)}if(w.size>0){if(!p){const e=window.devicePixelRatio;o=28,t.canvas.height=o*e,t.canvas.style.height=`${o}px`}s=p?Math.min(p.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,l,a]=E.getCellAllPartsLengths(i.tableRowIndex);for(let e=0;e<r.length;++e){const n=r[e],i="."===n||n.endsWith("{")||n.startsWith("}")?C:w.has(n)?f:T.has(n)?d:C;t.fillStyle=i,Q(a[e],0,s,o,t,r[e],i,0,!0,1)}}}finally{t.restore()}}}var nt=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())}))};let rt=null;const st=new s.Package;function ot(){return nt(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])=>{rt=e,lt(),rt.onChanged.subscribe((t=>{try{lt();const t=rt.getPolymerTypes(),e="Monomer lib updated:<br />"+(0==t.length?"empty":t.map((t=>`${t} ${rt.getMonomerSymbolsByType(t).length}`)).join("<br />"));n.shell.info(e)}catch(t){const e=o(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 it(){return rt}function lt(){org.helm.webeditor.Monomers.clear(),rt.getPolymerTypes().forEach((t=>{rt.getMonomerSymbolsByType(t).forEach((e=>{let n=!1;const r=rt.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(mt(r.smiles.toString())).length,s.at=mt(r.smiles.toString())):n=!0;n||org.helm.webeditor.Monomers.addOneMonomer(s)}))}));const t=n.shell.tv.grid;t&&t.invalidate()}function at(){return new et}function ht(t,e,s){const o=j(W(t&&void 0===s?t.value:e));0===o.size?function(t,e,s){const o=r.div(),i=n.shell.tv.grid.dataFrame.columns.bySemType("Macromolecule"),l=S.getOrCreate(i);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):1===o.size&&o.has(E[a.HELM])?n.shell.warning(`WebEditor doesn't support Helm with gaps '${E[a.HELM]}'.`):n.shell.warning(`Monomers ${Array.from(o).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 ct(t){ht(t.cell,void 0,void 0)}function ut(t){const e=n.shell.tv.grid.dataFrame,r=e.columns.bySemType("Macromolecule"),o=S.getOrCreate(r);r.getTag(s.TAGS.UNITS)===a.HELM&&ht(e.currentCell,void 0,void 0);const i=o.getConverter(a.HELM)(t);ht(e.currentCell,i,r.getTag(s.TAGS.UNITS))}function gt(t){return nt(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 mt(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 pt(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 ft(){return new V}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:()=>ct,editMoleculeCell:()=>Ct,getMolfiles:()=>wt,getMonomerLib:()=>mt,helmCellRenderer:()=>dt,helmWebEditor:()=>Et,initHelm:()=>gt,openEditor:()=>bt,propertiesPanel:()=>At});const n=grok,r=ui,s=DG;function i(t){var e;return"string"==typeof t||t instanceof String?t:("object"==typeof t||t instanceof Object)&&"$thrownJsError"in t?i(t.$thrownJsError):t instanceof Error?null!==(e=t.stack)&&void 0!==e?e:t.message:t.toString()}class o{constructor(t,e,n){this.name=t,this.alphabet=e,this.cutoff=n}}class l extends o{constructor(t,e,n){super(t.name,t.alphabet,t.cutoff),this.freq=e,this.similarity=n}}var a,h;(h=a||(a={})).FASTA="fasta",h.SEPARATOR="separator",h.HELM="helm";const u=/(?:\[([A-Za-z0-9_\-,()]+)\])|([A-Za-z\-])/g,c=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 o("PT",c.fasta.peptide,.5),new o("DNA",c.fasta.dna,.55),new o("RNA",c.fasta.rna,.55)],m=wu;var f=t.n(m);function d(t={}){const e=function(){if(!t||!t.scoringMatrix||!t.alphabetIndexes)return(t,e)=>t===e?0:1;if(t.scoringMatrix.length!==Object.keys(t.alphabetIndexes).length)throw new Error("Scoring matrix and alphabet indexes should have the same length");const e=t.alphabetIndexes,n=t.scoringMatrix,r=Math.min(...Object.keys(e).map((t=>t.charCodeAt(0))))+1,s=new Float32Array((n.length+r)*(n.length+r));return Object.entries(e).forEach((([t,r])=>{const i=n[r];Object.entries(e).forEach((([e,r])=>{s[t.charCodeAt(0)*n.length+e.charCodeAt(0)]=i[r]}))})),(t,e)=>s[t.charCodeAt(0)*n.length+e.charCodeAt(0)]}(),n=t?.threshold??0;return(t,r)=>{let s=0;const i=t.length,o=r.length,l=Math.max(i,o)*(1-n);i!==o&&(s=Math.abs(i-o));let a=0;for(let n=0;n<Math.min(i,o);n++)if(t[n]!==r[n]&&(a+=e(t[n],r[n]),a>l))return 1;return a+=s,a/=Math.max(i,o),a}}const p=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 b;!function(t){t.HAMMING="Hamming",t.LEVENSHTEIN="Levenshtein",t.NEEDLEMANN_WUNSCH="Needlemann-Wunsch",t.MONOMER_CHEMICAL_DISTANCE="Monomer chemical distance"}(b||(b={}));const A={[b.HAMMING]:d,[b.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--;)p[t.charCodeAt(a)]|=1<<a;for(a=0;a<r;a++){let t=p[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--;)p[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,u=Math.min(32,r)+h;for(let e=h;e<u;e++)p[t.charCodeAt(e)]|=1<<e;for(let t=0;t<n;t++){const n=p[e.charCodeAt(t)],r=i[t/32|0]>>>t&1,a=s[t/32|0]>>>t&1,h=n|o,u=((n|a)&l)+l^l|n|a;let c=o|~(u|l),g=l&u;c>>>31^r&&(i[t/32|0]^=1<<t),g>>>31^a&&(s[t/32|0]^=1<<t),c=c<<1|r,g=g<<1|a,l=g|~(h|c),o=c&h}for(let e=h;e<u;e++)p[t.charCodeAt(e)]=0}let h=0,u=-1;const c=32*a,g=Math.min(32,r-c)+c;for(let e=c;e<g;e++)p[t.charCodeAt(e)]|=1<<e;let m=r;for(let t=0;t<n;t++){const n=p[e.charCodeAt(t)],o=i[t/32|0]>>>t&1,l=s[t/32|0]>>>t&1,a=n|h,c=((n|l)&u)+u^u|n|l;let g=h|~(c|u),f=u&c;m+=g>>>r-1&1,m-=f>>>r-1&1,g>>>31^o&&(i[t/32|0]^=1<<t),f>>>31^l&&(s[t/32|0]^=1<<t),g=g<<1|o,f=f<<1|l,u=f|~(a|g),h=g&a}for(let e=c;e<g;e++)p[t.charCodeAt(e)]=0;return m})(t,e)})(t,e)/Math.max(t.length,e.length)},[b.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 u=0,c=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[c][0]=-r-(t-1)*s;for(let g=1;g<e.length+1;g++){const m=l[u][g-1]+i[o[e[g-1]]][o[n[t-1]]],f=l[u][g]-(a[g]?s:r),d=l[c][g-1]-(h[g-1]?s:r);l[c][g]=Math.max(m,d,f),l[c][g]===m?(a[g]=!1,h[g]=!1):l[c][g]===d?(a[g]=!1,h[g]=!0):(a[g]=!0,h[g]=!1)}u=c,c=(c+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),f=Math.max(g,m);return(f-l[u][e.length])/f}},[b.MONOMER_CHEMICAL_DISTANCE]:d},_=new RegExp("[rd]\\((\\w)\\)p?","g");class w{constructor(t,e=!1){if(this._length=0,this._version=0,this._updateLevel=0,this._selectedCount=0,this._selectedCountVersion=-1,this._selectedIndexesVersion=-1,this._versionedName="",this._versionedNameVersion=-1,this.SHRINK_THRESHOLD=256,"number"==typeof t){const n=t,r=w._createBuffer(n);if(e)for(let t=0;t<r.length;t++)r[t]=-1;this._data=r,this._length=n}else{if(!(t instanceof Uint32Array))throw new Error("Invalid constructor");this._data=t,this._length=e}}getRawData(){return this._data}assureGoez(t,e){if(t<0)throw new Error(`${e} should be greater than zero`)}assureInRange(t,e,n,r){if(t<e||t>n)throw new Error(`Argument ${r} (${t}) out of range (${e}, ${n})`)}copy(t,e,n){for(let r=0;r<n;r++)e[r]=t[r]}copyFrom(t){if(this._length!=t._length)throw new Error(`Lengths differ (${this._length} != ${t._length})`);this.copy(t._data,this._data,this.lengthInInts),this._version++}get length(){return this._length}get buffer(){return this._data}set buffer(t){this._data=t,this._version++}get version(){return this._version}set version(t){this._version=t}incrementVersion(t=!0){this._version++}get lengthInInts(){return Math.floor((this._length+31)/32)}get versionedName(){return this._version==this._versionedNameVersion?this._versionedName:""}set versionedName(t){this._versionedName=t,this._versionedNameVersion=this._version}get self(){return this}setLength(t){if(t<0)throw new Error("should be >= 0");if(t==this._length)return;const e=Math.floor((t+31)/32);if(e>this._data.length||e+this.SHRINK_THRESHOLD<this._data.length){const t=new Uint32Array(e);this.copy(this._data,t,e>this._data.length?this._data.length:e),this._data=t}t>this._length&&(this._length%32>0&&(this._data[this.lengthInInts-1]&=(1<<(this._length%32&31))-1),this._data.fill(0,this.lengthInInts,e)),this._length=t,this._version++}static fromAnd(t,e){if(t._length!=e._length)throw new Error(`Lengths differ (${t._length} != ${e._length})`);const n=new w(t._length);n._length=t._length,n._data=w._createBuffer(n._length),n._version=0;const r=t.lengthInInts;for(let s=0;s<r;s++)n._data[s]=t._data[s]&e._data[s];return n}static _createBuffer(t){return new Uint32Array(Math.floor((t+31)/32))}static fromValues(t){const e=new w(t.length);e._version=0;for(let n=0;n<e._length;n++)t[n]&&(e._data[Math.floor(n/32)]|=1<<(n%32&31));return e}static fromSeq(t,e){const n=new w(t);for(let r=0;r<t;++r)n.setBit(r,e(r));return n._version=0,n}static fromString(t){return w.fromSeq(t.length,(e=>"1"==t.charAt(e)))}static fromUint32Array(t,e){const n=new w(t);return n._data=e,n}static fromBytes(t){const e=t.length,n=new w(8*e);n._data=new Uint32Array(Math.floor((e+3)/4)),n._length=8*e;let r=0,s=0;for(;e-s>=4;)n._data[r++]=255&t[s]|(255&t[s+1])<<8|(255&t[s+2])<<16|(255&t[s+3])<<24,s+=4;return e-s==3&&(n._data[r]=(255&t[s+2])<<16),e-s==2&&(n._data[r]|=(255&t[s+1])<<8),e-s==1&&(n._data[r]|=255&t[s]),n._version=0,n}toString(){return`${this._length} bits, ${this.countBits(!0)} set`}equals(t){if(this==t)return!0;if(null==t)return!1;if(this._length!=t._length)return!1;if(0==this._length)return!0;for(let e=0;e<this._data.length-1;e++)if(this._data[e]!=t._data[e])return!1;for(let e=8*(this._data.length-1);e<this._length;e++)if(this.getBit(e)!=t.getBit(e))return!1;return!0}clone(){const t=new w(0,!1);return t._data=Uint32Array.from(this._data),t._length=this._length,t._version=this._version,t}init(t,e){this.setAll(!1,!1);for(let e=0;e<this._length;e++)t(e)&&(this._data[Math.floor(e/32)]|=1<<(e%32&31));return this.incrementVersion(e),this}invert(t=!0){for(let t=0;t<this._data.length;t++)this._data[t]^=-1;this.incrementVersion(t)}setAll(t,e=!1){const n=t?-1:0,r=this.lengthInInts;for(let t=0;t<r;t++)this._data[t]=n;this.incrementVersion(e)}setIndexes(t,e=!0,n=!0,r=!0){n&&this.setAll(!e,!1);for(const n of t)this.setFast(n,e);this.incrementVersion(r)}everyIndex(t,e=!0){for(const n of t)if(this.getBit(n)!=e)return!1;return!0}anyIndex(t,e=!0){for(const n of t)if(this.getBit(n)==e)return!0;return!1}setWhere(t,e=!0,n=!0,r=!0,s=!0){if(n&&s&&this.setAll(!e,!1),s)for(let n=0;n<this._length;n++)t(n)&&this.setFast(n,e);else for(let n=0;n<this._length;n++)this.setFast(n,t(n)?e:!e);this.incrementVersion(r)}getRange(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const n=[];for(let r=t;r<e;++r)n.push(this.getBit(r));return w.fromValues(n)}getRangeAsList(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const n=[];for(let r=t;r<e;++r)n.push(this.getBit(r));return n}setRange(t,e,n,r=!0){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length-1,"to");const s=Math.min(t,e),i=Math.max(t,e);if(n)for(let t=s;t<=i;t++)this.setTrue(t);else for(let t=s;t<=i;t++)this.setFalse(t);return this.incrementVersion(r),this}setRandom(t,e,n=!0){if(t<0||t>this._length)throw new Error("n must be >= 0 && <= Count");t>this._length/2&&this.setRandom(this._length-t,!e),this.setAll(!e);for(let n=0;n<t;){const t=Math.floor(Math.random()*this._length);this.getBit(t)!=e&&(this.setFast(t,e),n++)}this.incrementVersion(n)}and(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]&=t._data[e];return this.incrementVersion(e),this}andNot(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");const n=this.lengthInInts;for(let e=0;e<n;e++)this._data[e]&=~t._data[e];return this.incrementVersion(e),this}notAnd(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]=~this._data[e]&t._data[e];return this.incrementVersion(e),this}not(t=!0){for(let t=0,e=this.lengthInInts;t<e;t++)this._data[t]=~this._data[t];return this.incrementVersion(t),this}or(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]|=t._data[e];return this.incrementVersion(e),this}xor(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]^=t._data[e];return this.incrementVersion(e),this}insertAt(t,e,n=!1){if(this.assureInRange(t,0,this._length,"pos"),0==e)return;const r=this._length;this.setLength(this._length+e);for(let n=r-1;n>=t;n--)this.setBit(n+e,this.getBit(n));for(let r=t;r<t+e;r++)this.setBit(r,n)}removeAt(t,e=1){if(e<0)throw new Error("n cannot be negative");if(this.assureInRange(t,0,this._length-e,"pos"),this.contains(!0))for(let n=t;n<this._length-e;n++)this.setBit(n,this.getBit(n+e));this.setLength(this._length-e)}removeByMask(t,e=!0){if(this._length!=t.length)throw new Error("length != mask.length");if(t==this)this.setLength(t.countBits(!e)),this.setAll(!e);else{let n=0;for(let r=-1;-1!=(r=t.findNext(r,!e));)this.setFast(n++,this.getBit(r));this._length=n,this._version++}return this}getBit(t){return 0!=(this._data[Math.floor(t/32)]&1<<(31&t))}setBit(t,e,n=!0){this.setFast(t,e),this._version++}setFast(t,e){e?this._data[Math.floor(t/32)]|=1<<(31&t):this._data[Math.floor(t/32)]&=~(1<<(31&t))}setTrue(t){this._data[Math.floor(t/32)]|=1<<(31&t)}setFalse(t){this._data[Math.floor(t/32)]&=~(1<<(31&t))}trueCount(){return this.countBits(!0)}falseCount(){return this.countBits(!1)}countBits(t){if(0==this._length)return 0;if(this._selectedCountVersion!=this._version){this._selectedCount=0;const t=this.lengthInInts;let e=0;for(;e<t-1;e++)for(let t=this._data[e];0!=t;t>>>=8)this._selectedCount+=w._onBitCount[255&t];let n=this._data[e];const r=31&this._length;for(0!=r&&(n&=~(4294967295<<r));0!=n;n>>>=8)this._selectedCount+=w._onBitCount[255&n];this._selectedCountVersion=this._version}return t?this._selectedCount:this._length-this._selectedCount}countWhere(t){let e=0;if(this.trueCount()==this._length)for(let n=0;n<this._length;n++)e+=t(n)?1:0;else for(let n=-1;-1!=(n=this.findNext(n,!0));)e+=t(n)?1:0;return e}andWithCountBits(t,e){if(0==this._length)return 0;let n=0;const r=this.lengthInInts;let s=0;for(;s<r-1;s++)for(let e=this._data[s]&t._data[s];0!=e;e>>>=8)n+=w._onBitCount[255&e];let i=this._data[s]&t._data[s];const o=31&this._length;for(0!=o&&(i&=~(4294967295<<o));0!=i;i>>>=8)n+=w._onBitCount[255&i];return e?n:this._length-n}clear(){this.setLength(0)}contains(t){return this.findNext(-1,t)>=0}get allTrue(){return this.countBits(!0)==this._length}get allFalse(){return this.countBits(!1)==this._length}get anyTrue(){return this.countBits(!0)>0}get anyFalse(){return this.countBits(!1)>0}findNext(t,e=!0){if(this.assureInRange(t,-1,this._length,"index"),t>=this._length-1)return-1;let n=31&(t=t<0?0:t+1);const r=this.lengthInInts;for(let s=Math.floor(t/32);s<r;s++){let r=e?this._data[s]:~this._data[s];if(0!=n)r&=4294967295<<n&4294967295,n=0;else if(!e&&-4294967296==r)continue;for(let e=0;0!=r;e+=8,r>>>=8){const n=w._firstOnBit[255&r];if(n>=0)return(t=n+32*s+e)>=this._length?-1:t}}return-1}findPrev(t,e=!0){if(0==t)return-1;this.assureInRange(t,-1,this._length,"index");let n=1+(t=t<0?this._length-1:t-1)&31;for(let r=Math.floor(t/32);r>=0;r--){let t=e?this._data[r]:~this._data[r];0!=n&&(t&=~(4294967295<<n),n=0);for(let e=24;0!=t;e-=8,t<<=8){const n=w._lastOnBit[t>>>24];if(n>=0)return n+32*r+e}}return-1}}var E,T,y,M,S,v;w._onBitCount=Int8Array.from([0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8]),w._firstOnBit=Int8Array.from([-1,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0]),w._lastOnBit=Int8Array.from([-1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]),function(t){t.Levenshtein="Levenshtein",t.JaroWinkler="Jaro-Winkler",t.Manhattan="Manhattan"}(E||(E={})),function(t){t.Euclidean="Euclidean"}(T||(T={})),function(t){t.Tanimoto="Tanimoto",t.Dice="Dice",t.Asymmetric="Asymmetric",t.BraunBlanquet="Braun-Blanquet",t.Cosine="Cosine",t.Kulczynski="Kulczynski",t.McConnaughey="Mc-Connaughey",t.RogotGoldberg="Rogot-Goldberg",t.Russel="Russel",t.Sokal="Sokal",t.Hamming="Hamming",t.Euclidean="Euclidean"}(y||(y={})),function(t){t.TanimotoIntArray="TanimotoIntArray"}(M||(M={})),function(t){t.Vector="Vector",t.String="String",t.BitArray="BitArray",t.MacroMolecule="MacroMolecule",t.Number="Number",t.IntArray="IntArray"}(S||(S={})),function(t){t.NumericDistance="NumericDistance"}(v||(v={})),y.Tanimoto,y.Dice,y.Asymmetric,y.BraunBlanquet,y.Cosine,y.Kulczynski,y.McConnaughey,y.RogotGoldberg,y.Russel,y.Sokal,y.Hamming,y.Euclidean,y.Tanimoto,y.Dice,y.Asymmetric,y.BraunBlanquet,y.Cosine,y.Kulczynski,y.McConnaughey,y.RogotGoldberg,y.Russel,y.Sokal,y.Hamming,y.Euclidean,y.Tanimoto,y.Dice,y.Cosine,y.Tanimoto,y.Asymmetric,y.Cosine,y.Sokal,b.HAMMING,b.LEVENSHTEIN,b.MONOMER_CHEMICAL_DISTANCE;const N=new class{constructor(){this.uh=`units-handler.${s.SEMTYPE.MACROMOLECULE}`}},O={[a.FASTA]:"-",[a.SEPARATOR]:"",[a.HELM]:"*"};class L{static setUnitsToFastaColumn(t){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE||t.column.getTag(s.TAGS.UNITS)!==a.FASTA)throw new Error(`The column of notation '${a.FASTA}' must be '${s.SEMTYPE.MACROMOLECULE}'.`);t.column.setTag(s.TAGS.UNITS,a.FASTA),L.setTags(t)}static setUnitsToSeparatorColumn(t,e){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE||t.column.getTag(s.TAGS.UNITS)!==a.SEPARATOR)throw new Error(`The column of notation '${a.SEPARATOR}' must be '${s.SEMTYPE.MACROMOLECULE}'.`);if(!e)throw new Error(`The column of notation '${a.SEPARATOR}' must have the separator tag.`);t.column.setTag(s.TAGS.UNITS,a.SEPARATOR),t.column.setTag("separator",e),L.setTags(t)}static setUnitsToHelmColumn(t){if(t.column.semType!==s.SEMTYPE.MACROMOLECULE)throw new Error(`The column of notation '${a.HELM}' must be '${s.SEMTYPE.MACROMOLECULE}'`);t.column.setTag(s.TAGS.UNITS,a.HELM),L.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)),[a.FASTA,a.SEPARATOR].includes(e)){if(!t.column.getTag("alphabet")&&0===Object.keys(n.freq).length)throw new Error("Alphabet is empty and not annotated.");let e=t.column.getTag("aligned");null===e&&(e=n.sameLength?"SEQ.MSA":"SEQ",t.column.setTag("aligned",e));let r=t.column.getTag("alphabet");if(null===r&&(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 P(s),l=new P(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)/(F(o)*F(l))}(t,e.alphabet,n);return new l(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,g),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===a.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==a.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===a.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=0===this.splitted.length?0: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())):f().count(1).take(this.maxLength).map((t=>t.toString())).toArray()}return this._posList}isFasta(){return this.notation===a.FASTA}isSeparator(){return this.notation===a.SEPARATOR}isHelm(){return this.notation===a.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===a.FASTA&&t===O[a.FASTA]||this.units===a.HELM&&t===O[a.HELM]}getNotation(){if(this.units.toLowerCase().startsWith(a.FASTA))return a.FASTA;if(this.units.toLowerCase().startsWith(a.SEPARATOR))return a.SEPARATOR;if(this.units.toLowerCase().startsWith(a.HELM))return a.HELM;throw new Error(`Column '${this.column.name}' has unexpected notation '${this.units}'.`)}getHelmWrappers(){return[this.isDna()||this.isRna()||this.isHelmCompatible()?"RNA1{":"PEPTIDE1{",this.isDna()?"d(":this.isRna()?"r(":"",this.isDna()||this.isRna()?")p":"","}$$$$"]}getNewColumn(t,e,n,r){const i=this.column,o=t.toLowerCase()+"("+i.name+")",l=n??i.dataFrame.columns.getUnusedName(o),h=s.Column.fromList("string",l,r??new Array(this.column.length).fill(""));if(h.semType=s.SEMTYPE.MACROMOLECULE,h.setTag(s.TAGS.UNITS,t),t===a.SEPARATOR){if(!e)throw new Error(`Notation '${a.SEPARATOR}' requires separator value.`);h.setTag("separator",e)}h.setTag(s.TAGS.CELL_RENDERER,"Macromolecule");const u=i.getTag("aligned");u&&h.setTag("aligned",u);const c=i.getTag("alphabet");null!=c&&h.setTag("alphabet",c);let g=i.getTag(".alphabetSize");null!=c&&g&&h.setTag(".alphabetSize",g);const m=i.getTag(".alphabetIsMultichar");return null!=c&&void 0!==m&&h.setTag(".alphabetIsMultichar",m),t==a.HELM&&(g=this.getAlphabetSize().toString(),h.setTag(".alphabetSize",g)),h}getNewColumnFromList(t,e){return this.getNewColumn(this.notation,this.separator,t,e)}static getNewColumn(t){const e=L.getOrCreate(t),n=e.notation;return e.getNewColumn(n)}static unitsStringIsValid(t){return t=t.toLowerCase(),[a.FASTA,a.SEPARATOR,a.HELM].some((e=>t.startsWith(e.toLowerCase())))}static getNewColumnFromParams(t,e,n){if(!L.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(a.FASTA))return null===this.column.getTag("alphabet")||this.getAlphabetIsMultichar()?D:V;if(this.units.toLowerCase().startsWith(a.SEPARATOR))return W(this.separator,t);if(this.units.toLowerCase().startsWith(a.HELM))return q;throw new Error(`Unexpected units ${this.units} .`)}getDistanceFunctionName(){if(!this.isFasta())throw new Error("Only FASTA notation is supported");return this.isMsa()?b.HAMMING:(this.alphabet,b.LEVENSHTEIN)}getDistanceFunction(){return A[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=W(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,L.getOrCreate(t).getSplitter())),this._splitter}toFasta(t){return t===a.FASTA}toSeparator(t){return t===a.SEPARATOR}toHelm(t){return t===a.HELM}convertHelmToFastaSeparator(t,e,n,r){r||(r=this.toFasta(e)?O[a.FASTA]:O[a.SEPARATOR]),n||(n=this.toFasta(e)?"":this.separator);const s=t.startsWith("RNA"),i=this.splitter(t),o=[];for(let t=0;t<i.length;t++){let n=i[t];if(s&&(n=n.replace(_,"")),n===O[a.HELM])o.push(r);else if(this.toFasta(e)&&n.length>1){const t="["+n+"]";o.push(t)}else o.push(n)}return o.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]:O[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 u=this.column.getTag(".positionLabels");return u&&r.setTag(".positionLabels",a(u)),r}getJoiner(){if(void 0===this._joiner){const t=this;if(this.notation===a.FASTA)this._joiner=function(e){return x(t,e)};else if(this.notation===a.SEPARATOR)this._joiner=function(e){return R(t,e,t.separator)};else{if(this.notation!==a.HELM)throw new Error;{const e="DNA"===t.alphabet||"RNA"===t.alphabet;this._joiner=function(n){return I(t,n,e)}}}}return this._joiner}getConverter(t,e){if(t===a.SEPARATOR&&!e)throw new Error(`Target separator is not specified for target units '${a.SEPARATOR}'.`);const n=this;if(t===a.FASTA)return function(t){return function(t,e){const n=t.isHelm()?H(t,e):t.getSplitter()(e);return x(t,n)}(n,t)};if(t===a.HELM)return function(t){return function(t,e){const n=e.startsWith("DNA")||e.startsWith("RNA"),r=t.getSplitter()(e);return I(t,r,n)}(n,t)};if(t===a.SEPARATOR)return function(t){return function(t,e,n){const r=t.isHelm()?H(t,e):t.getSplitter()(e);return R(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,this._joiner=void 0,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()?O[a.FASTA]:this.isHelm()?O[a.HELM]:O[a.SEPARATOR],!this.column.tags.has("aligned")||!this.column.tags.has("alphabet")||!this.column.tags.has(".alphabetIsMultichar")&&!this.isHelm()&&"UN"===this.alphabet)if(this.isFasta())L.setUnitsToFastaColumn(this);else if(this.isSeparator()){const e=t.getTag("separator");L.setUnitsToSeparatorColumn(this,e)}else{if(!this.isHelm())throw new Error(`Unexpected units '${this.column.getTag(s.TAGS.UNITS)}'.`);L.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){let e=t.temp[N.uh];return e||(e=t.temp[N.uh]=new L(t)),e}}function x(t,e){const n=new Array(e.length);for(const[r,s]of f().enumerate(e)){let i=r;t.isHelm()&&(i=r.replace(_,"$1")),t.isGap(i)?i=O[a.FASTA]:i.length>1&&(i="["+e[s]+"]"),n[s]=i}return n.join("")}function R(t,e,n){const r=new Array(e.length);for(const[n,s]of f().enumerate(e)){let e=n;t.isGap(e)&&(e=O[a.SEPARATOR]),r[s]=e}return r.map((t=>t??"")).join(n)}function I(t,e,n){const[r,s,i,o]=t.getHelmWrappers();return`${r}${f()(e).map((e=>{let r=e;return r=t.isGap(r)?O[a.HELM]:n?r.replace(_,"$1"):1==e.length?`${s}${e}${i}`:`${s}[${e}]${i}`,r})).toArray().join(".")}${o}`}function H(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 f().enumerate(n)){let n=t;(s||i)&&(n=n.replace(_,"$1"),n="p"===n?null:n),r[e]=n}return r.filter((t=>null!==t))}class P extends Float32Array{}function F(t){let e=0;for(let n=0;n<t.length;n++)e+=t[n]*t[n];return Math.sqrt(e)}class B{static makePalette(t,e=!1,n=B){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]}}B.undefinedColor="rgb(100,100,100)",B.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 $ extends B{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,$)),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,$)),this.grokGroups}static get RasMol(){return void 0===this.rasMol&&(this.rasMol=new $({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 $.aaSynonyms?$.aaSynonyms[t]:t;return super.get(e)}}$.aaSynonyms={MeNle:"L",MeA:"A",MeG:"G",MeF:"F"};class k{static getPalette(t="grok"){switch(t){case"grok":return $.GrokGroups;case"lesk":return $.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]}}k.SemType="Aminoacids",k.SemTypeMultipleAlignment="AminoacidsMultipleAlignment",k.undefinedColor="rgb(100,100,100)",k.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"},k.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"},k.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(*)*"},k.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 G{}G.SemType="Nucleotides",G.SemTypeMultipleAlignment="NucleotidesMultipleAlignment",G.Names={A:"Adenine",C:"Cytosine",G:"Guanine",T:"Thymine",U:"Uracil"};class U extends class{}{static buildPalette(){return[].concat(...Object.values(B.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)%U.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)}(U.palette[e])}}function D(t){return f()(t.toString().matchAll(u)).map((t=>t[2]??t[1])).toArray()}function V(t){return t||[]}function W(t,e){return n=>n?n.replaceAll('"-"',"").replaceAll("'-'","").split(t,e):[]}U.palette=U.buildPalette();const j=/(PEPTIDE1|DNA1|RNA1)\{([^}]+)}/g,z=/\[([^\[\]]+)]/g;function q(t){j.lastIndex=0;const e=j.exec(t.toString()),n=e?e[2]:null;return(n?n.split("."):[]).map((t=>{z.lastIndex=0;const e=z.exec(t);return e&&e.length>=2?e[1]:t}))}const Y=/([^\W_]+)/g;function K(t){t=J(t,"$")[0];const e=[];if(!scil.Utils.isNullOrEmpty(t)){const n=J(t,"|");for(let r=0;r<n.length;++r){let s=(t=Z(n[r]).str).indexOf("{");s=(t=t.substring(s+1)).indexOf("}");const i=J(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 J(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 Z(t){const e=X(t,'"');if(null!=e.tag)return e;const n=X(t,"'");return{tag:e.tag,repeat:n.tag,str:n.str}}function X(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}}class tt{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((()=>{n.canvas.helm.setSequence(t,"HELM")}),200),{editorDiv:e,webEditor:n}}}var et,nt;function rt(t,e,n,r,s,i,o="rgb(100,100,100)",l=0,a=!1,h=1,u="",c=!1,g=nt.classic,m=[],f=0,d=null,p=[],C=null,b={}){s.textAlign="start";let A=i.substring(0),_=c?"":u;g===nt.MSA&&(_="");let w=!0,E=!0,T="difference";null!=d&&null!=d.cell.column&&(w=d.cell.column.temp["color-code"]??!0,E=d.cell.column.temp["compare-with-current"]??!0,T=d.cell.column.temp["highlight-difference"]??"difference");const y=p[f];E&&p.length>0&&"difference"===T&&(h=A==y?.3:h),E&&p.length>0&&"equal"===T&&(h=A!=y?.3:h),null!=C&&(A=function(t,e){if(t.length<=e)return t;const n=t.match(Y),r=t.length>e||(n?.length??0)>1,s=n?.[0]??" ";return r?s.substring(0,e-1)+"…":s}(A,C));const M=A+_;b[M]??(b[M]=s.measureText(M));let S=b[M];b[A]??(b[A]=s.measureText(A));let v=b[A].width;b[_]??(b[_]=s.measureText(_));const N=b[_].width,O=r/2-(S.fontBoundingBoxAscent+S.fontBoundingBoxDescent)/2+1;function L(n,r){const i=w?o:"rgb(0,0,0)";s.fillStyle=i,s.globalAlpha=h,g===nt.classic&&(s.fillText(A,t+n,e+O),s.fillStyle="#808080",s.fillText(_,t+r,e+O)),g===nt.MSA&&s.fillText(A,t+n,e+O)}S=S.width,g===nt.MSA&&(v=m[f],S=m[f]);const x=(m[f]??0)-(m[0]??0);if(a||S>n)return L(x,x+v),t+x+v+N;{const e=(n-S)/2;return L(e,e+v),t+x+e+v}}!function(t){t.maxMonomerLength=".mm.cellRenderer.maxMonomerLength"}(et||(et={})),function(t){t.MSA="MSA",t.classic="classic"}(nt||(nt={}));class st{constructor(t){this.col=t,this.monomerCharWidth=7,this.leftPadding=5,this.col.dataFrame.onDataChanged.subscribe(),this.monomerLib=mt(),this.monomerLib.onChanged.subscribe(this.monomerLibOnChanged.bind(this)),this._allPartsList=new Array(this.col.length).fill(null),this._lengthsList=new Array(this.col.length).fill(null),this._editorList=new Array(this.col.length).fill(null)}skipCell(t){this._allPartsList[t]=[],this._lengthsList[t]=[]}getCellAllPartsLengths(t){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 f().enumerate(e)){const e=t.length*this.monomerCharWidth;n[r]=e}}return[e,n]}getAllParts(t){const e=this.col.get(t),n=e?K(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;if(t.polymerType)e=this.monomerLib.getMonomer(t.polymerType,t.symbol);else for(const n of this.monomerLib.getPolymerTypes())if(e=this.monomerLib.getMonomer(n,t.symbol),e)break;return e}monomerLibOnChanged(t){this._lengthsList.fill(null),this._allPartsList.fill(null),this._editorList.fill(null)}static getOrCreate(t){return"bio-helmMonomerPlacer"in t.temp||(t.temp["bio-helmMonomerPlacer"]=new st(t)),t.temp["bio-helmMonomerPlacer"]}setEditor(t,e){this._editorList[t]=e}getEditor(t){return this._editorList[t]}}const it=/\{(\*\.)+/g,ot=/\.(\*\.)+/g,lt=/(\.\*)+\}/g;window.dojox.gfx.svg.Text.prototype.getTextWidth=function(){const t=this.rawNode,e=t.parentNode,n=t.cloneNode(!0);n.style.visibility="hidden";let r=0;const s=n.firstChild.nodeValue;if(e.appendChild(n),""!=s){let t=100;for(;!r&&--t>0;)r=n.getBBox?parseInt(n.getBBox().width):68}return e.removeChild(n),r};class at extends s.GridCellRenderer{get name(){return"helm"}get cellType(){return"helm"}get defaultWidth(){return 400}get defaultHeight(){return 100}onMouseMove(t,e){try{let s=null;try{s=t.tableColumn}catch(t){}if(!s)return;const i=e.offsetX-t.bounds.x,o=e.offsetY-t.bounds.y,l=st.getOrCreate(s),a=l.getEditor(t.tableRowIndex),h=a?function(t,e,n,r){let s=null;function i(n){let s,i;for(let o=0;o<r.m.atoms.length;++o)if(!n.includes(o)){const n=r.m.atoms[o].p.x,l=r.m.atoms[o].p.y,a=Math.sqrt(Math.pow(t-n,2)+Math.pow(e-l,2));(void 0===i||i>a)&&(s=o,i=a)}return[s,i]}const[o,l]=i([]),[a,h]=i([o]);if(void 0!==o&&void 0!==l){const t=function(t){let e;switch(t.bio.type){case"HELM_BASE":case"HELM_SUGAR":case"HELM_LINKER":e="RNA";break;default:e="PEPTIDE"}return{symbol:t.elem,polymerType:e}}(r.m.atoms[o]);void 0!==a&&void 0!==h?l<.45*h&&(s=t):l<.35*n.bounds.height&&(s=t)}return s}(i,o,t,a):function(t,e,n,r){let s=null;const[i,o,l]=r.getCellAllPartsLengths(n.tableRowIndex);let a=0,h=Object.values(o).length-1,u=!1,c=0,g=0;if(t>l[0])for(;!u&&c<l.length;)g=Math.floor((h+a)/2),t>=l[g]&&t<=l[g+1]?(a=g,u=!0):t<l[g]?h=g-1:t>l[g+1]&&(a=g+1),a==h&&(u=!0),c++;return a=t>=l[a]?a:a-1,a>=0&&(s=function(t,e,n){let r;for(const s of n.getPolymerTypes())t.startsWith(s)&&(r={symbol:e,polymerType:s});return r||(r={symbol:e}),r}(i[0],i[a],r.monomerLib)),s}(i,0,t,l);if(!h)return void r.tooltip.hide();if(Q(K(t.cell.value?t.cell.value.replaceAll(it,"{").replaceAll(ot,".").replaceAll(lt,"}").replace("{*}","{}"):"")).has(h.symbol))r.tooltip.show(r.divV([r.divText(`Monomer ${h.symbol} not found.`),r.divText("Open the Context Panel, then expand Manage Libraries")]),e.x+16,e.y+16);else{const t=l.getMonomer(h);if(t){const s={autoCrop:!0,autoCropMargin:0,suppressChiralText:!0},i=n.chem.svgMol(t.smiles,void 0,void 0,s);r.tooltip.show(r.divV([r.divText(h.symbol),i]),e.x+16,e.y+16)}}}catch(t){const e=i(t);console.error("Helm: HelmCellRenderer.onMouseMove() error:\n"+e)}finally{e.preventDefault(),e.stopPropagation()}}render(t,e,n,s,i,o,l){var a,h,u,c,g,m;t.save();try{let l=null;try{l=o.tableColumn}catch(t){}if(!l)return;const f=-1!==o.gridRow?o.grid:void 0,d="red",p="#404040",C="#C0C0C0",b=o.cell.value?o.cell.value.replaceAll(it,"{").replaceAll(ot,".").replaceAll(lt,"}").replace("{*}","{}"):"",A=K(b),_=new Set(A),w=Q(A),E=st.getOrCreate(l);if(0==w.size){const t=o.element=r.div([],{style:{width:s-2+"px",height:i-2+"px",margin:"1px",backgroundColor:"#FFE0E0"}});t.setAttribute("dataformat","helm"),t.setAttribute("data",b),t.parentElement&&(null!==(u=null===(h=null===(a=o.grid)||void 0===a?void 0:a.canvas)||void 0===h?void 0:h.offsetLeft)&&void 0!==u?u:0)>0&&(t.parentElement.style.left=`${(null!==(m=null===(g=null===(c=o.grid)||void 0===c?void 0:c.canvas)||void 0===g?void 0:g.offsetLeft)&&void 0!==m?m:0)+t.parentElement.offsetLeft}px`);const e=new JSDraw2.Editor(t,{width:s,height:i,skin:"w8",viewonly:!0});return E.setEditor(o.tableRowIndex,e),void E.skipCell(o.tableRowIndex)}if(w.size>0){if(!f){const e=window.devicePixelRatio;i=28,t.canvas.height=i*e,t.canvas.style.height=`${i}px`}s=f?Math.min(f.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,a]=E.getCellAllPartsLengths(o.tableRowIndex);for(let e=0;e<r.length;++e){const n=r[e],o="."===n||n.endsWith("{")||n.startsWith("}")?C:w.has(n)?d:_.has(n)?p:C;t.fillStyle=o,rt(a[e],0,s,i,t,r[e],o,0,!0,1)}}}finally{t.restore()}}}var ht=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 ut=null;const ct=new s.Package;function gt(){return ht(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])=>{ut=e,ft(),ut.onChanged.subscribe((t=>{try{ft();const t=ut.getPolymerTypes(),e="Monomer lib updated:<br />"+(0==t.length?"empty":t.map((t=>`${t} ${ut.getMonomerSymbolsByType(t).length}`)).join("<br />"));n.shell.info(e)}catch(t){const e=i(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 mt(){return ut}function ft(){org.helm.webeditor.Monomers.clear(),ut.getPolymerTypes().forEach((t=>{ut.getMonomerSymbolsByType(t).forEach((e=>{let n=!1;const r=ut.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(_t(r.smiles.toString())).length,s.at=_t(r.smiles.toString())):n=!0;n||org.helm.webeditor.Monomers.addOneMonomer(s)}))}));const t=n.shell.tv.grid;t&&t.invalidate()}function dt(){return new at}function pt(t,e,s){const i=Q(K(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=L.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 u={width:h.rightwidth-100+"px",height:h.bottomheight+"px"};scil.apply(a.sequence.style,u),scil.apply(a.notation.style,u),u={width:h.rightwidth+"px",height:h.bottomheight+a.toolbarheight+"px"},scil.apply(a.properties.parent.style,u),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(O[a.HELM])?n.shell.warning(`WebEditor doesn't support Helm with gaps '${O[a.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 Ct(t){pt(t.cell,void 0,void 0)}function bt(t){const e=n.shell.tv.grid.dataFrame,r=e.columns.bySemType("Macromolecule"),i=L.getOrCreate(r);r.getTag(s.TAGS.UNITS)===a.HELM&&pt(e.currentCell,void 0,void 0);const o=i.getConverter(a.HELM)(t);pt(e.currentCell,o,r.getTag(s.TAGS.UNITS))}function At(t){return ht(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 _t(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 wt(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 Et(){return new tt}helm=e})();
2
2
  //# sourceMappingURL=package.js.map