@datagrok/helm 2.1.7 → 2.1.8
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 +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +1 -1
- package/src/cell-renderer.ts +8 -3
package/dist/package.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var helm;(()=>{"use strict";var t={n:e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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:()=>_,editMoleculeCell:()=>z,getMolfiles:()=>q,helmCellRenderer:()=>k,helmWebEditor:()=>Y,initHelm:()=>I,openEditor:()=>j,propertiesPanel:()=>B});const r=grok,n=ui,o=DG;class i{constructor(){this.w=200,this.h=100,this.host=n.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=n.div();org.helm.webeditor.MolViewer.molscale=.8;const r=new scil.helm.App(e,{showabout:!1,mexfontsize:"90%",mexrnapinontab:!0,topmargin:20,mexmonomerstab:!0,sequenceviewonly:!1,mexfavoritefirst:!0,mexfilter:!0}),o=r.calculateSizes();r.canvas.resize(o.rightwidth-100,o.topheight-210);let i={width:o.rightwidth-100+"px",height:o.bottomheight+"px"};return scil.apply(r.sequence.style,i),scil.apply(r.notation.style,i),i={width:o.rightwidth+"px",height:o.bottomheight+r.toolbarheight+"px"},scil.apply(r.properties.parent.style,i),r.structureview.resize(o.rightwidth,o.bottomheight+r.toolbarheight),r.mex.resize(o.topheight-80),setTimeout((function(){r.canvas.helm.setSequence(t,"HELM")}),200),{editorDiv:e,webEditor:r}}}function s(t,e){let r=[];for(let n=0;n<t.length;++n){let o=e.indexOf(t[n]),i=e.slice(0,o);r.push(i),r.push(t[n]),e=e.substring(o+t[n].length)}return r.push(e),r}function l(t){t=h(t,"$")[0];var e=[];if(!scil.Utils.isNullOrEmpty(t))for(var r=h(t,"|"),n=0;n<r.length;++n){var o=(t=u(r[n]).str).indexOf("{");o=(t=t.substring(o+1)).indexOf("}");var i=h(t=t.substring(0,o),".");for(var s of i)if(s.includes("(")&&s.includes(")")){var l=s.replace(/[()]/g,"").split("");for(var a of l)e.push(a)}else if(s.includes("[")&&s.includes("]")){var c=s.match(/(?<=\[).*?(?=\])/g,"");e.push(c[0])}else e.push(s)}return e}function a(t){const e=Object.keys(org.helm.webeditor.monomerTypeList()),r=[],n=[];for(var o=0;o<e.length;o++)r.push(new scil.helm.Monomers.getMonomerSet(e[o])),Object.keys(r[o]).forEach((t=>{n.push(r[o][t].id)}));const i=l(t);return new Set(i.filter((t=>!n.includes(t))))}function h(t,e){for(var r=[],n="",o=0,i=0,s=0,l=0,a=0;a<t.length;++a){var h=t.substring(a,a+1);if(h==e&&0==i&&0==o&&0==s&&0==l)r.push(n),n="";else{if(n+=h,l>0&&"\\"==h&&a+1<t.length){++a;var u=t.substring(a,a+1);n+=u,h+=u}'"'==h?a>0&&"\\"==t.substring(a-1,a)||(l=0==l?1:0):"["==h?++i:"]"==h?--i:"("==h?++o:")"==h?--o:"{"==h?++s:"}"==h&&--s}}return r.push(n),r}function u(t){var e=c(t,'"');if(null!=e.tag)return e;var r=c(t,"'");return{tag:e.tag,repeat:r.tag,str:r.str}}function c(t,e){var r=null;if(scil.Utils.endswith(t,e)){for(var n=t.length-1;n>0&&!((n=t.lastIndexOf(e,n-1))<=0||"\\"!=t.substring(n-1,n)););n>0&&n<t.length-1&&(r=t.substring(n+1,t.length-1),t=t.substring(0,n))}return null!=r&&(r=r.replace(new RegExp("\\"+e,"g"),e)),{tag:g(r),str:t}}function g(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)}}))}const m=wu;var p=t.n(m);class d extends Float32Array{}function C(t){let e=0;for(let r=0;r<t.length;r++)e+=t[r]*t[r];return Math.sqrt(e)}class f{static makePalette(t,e=!1,r=f){const n={};return t.forEach((t=>{const r=t[0],o=t[1];r.forEach(((t,r)=>{n[t]=this.colourPalette[o][e?0:r]}))})),new r(n)}constructor(t){this._palette=t}get(t){return this._palette[t]}}f.undefinedColor="rgb(100,100,100)",f.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 b extends f{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,b)),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,b)),this.grokGroups}static get RasMol(){return void 0===this.rasMol&&(this.rasMol=new b({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 b.aaSynonyms?b.aaSynonyms[t]:t;return super.get(e)}}b.aaSynonyms={MeNle:"L",MeA:"A",MeG:"G",MeF:"F"};class w{static getPalette(t="grok"){switch(t){case"grok":return b.GrokGroups;case"lesk":return b.Lesk;default:throw new Error(`ChemPalette: scheme \`${t}\` does not exist`)}}static getInnerOuter(t){let e=0,r="",n="";for(const o of t)"("==o?e++:")"==o?e--:e?r+=o:n+=o;return isNaN(parseInt(r))?[n,r]:[n,""]}static getColorAAPivot(t="",e="grok"){var r,n,o;const i=this.getPalette(e);let[s,l]=this.getInnerOuter(t);if(s=s.length>6?`${s.slice(0,3)}...`:s,l=l.length>6?`${l.slice(0,3)}...`:l,1==t.length||"("==t[1]){const e=null===(r=t[0])||void 0===r?void 0:r.toUpperCase();return e in i?[i.get(e),e,l,1]:[this.undefinedColor,s,l,1]}if("d"==t[0]&&t[1]in i&&(2==t.length||"("==t[2])){const e=null===(n=t[1])||void 0===n?void 0:n.toUpperCase();return e in i?[i.get(e),e,l,2]:[this.undefinedColor,s,l,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 i?[i.get(e),e,l,3]:[this.undefinedColor,s,l,3]}if((null===(o=t[0])||void 0===o?void 0:o.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 i?[i.get(e),e,l,4]:[this.undefinedColor,s,l,4]}return[this.undefinedColor,s,l,0]}}w.SemType="Aminoacids",w.SemTypeMultipleAlignment="AminoacidsMultipleAlignment",w.undefinedColor="rgb(100,100,100)",w.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"},w.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"},w.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(*)*"},w.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 v{}v.SemType="Nucleotides",v.SemTypeMultipleAlignment="NucleotidesMultipleAlignment",v.Names={A:"Adenine",C:"Cytosine",G:"Guanine",T:"Thymine",U:"Uracil"};class S extends class{}{static buildPalette(){return[].concat(...Object.values(f.colourPalette))}get(t){const e=class{static hashCode(t){let e=0;if(0===t.length)return e;for(let r=0;r<t.length;r++)e=(e<<5)-e+t.charCodeAt(r),e|=0;return e}}.hashCode(t)%S.palette.length;return function(t){if(null==t)return"rgb(100,100,100)";const e=o.Color.fromHtml(t),r=o.Color.g(e),n=o.Color.r(e),i=o.Color.b(e),s=Math.sqrt(Math.pow(0-n,2)+Math.pow(0-r,2)+Math.pow(0-i,2));return s>210?`rgb(${n/s*210},${r/s*210},${i/s*210})`:o.Color.toRgb(e)}(S.palette[e])}}S.palette=S.buildPalette();class T{static setUnitsToFastaColumn(t){if(t.semType!==o.SEMTYPE.MACROMOLECULE)throw new Error("Fasta column must be MACROMOLECULE");const e=A(t,5,E),r=e.sameLength?"SEQ.MSA":"SEQ",n=function(t){const e=[["PT",T.PeptideFastaAlphabet],["DNA",T.DnaFastaAlphabet],["RNA",T.RnaFastaAlphabet]],r=e.map((e=>function(t,e,r="-"){const n=new Set([...new Set(Object.keys(t)),...e]);n.delete(r);const o=[],i=[];for(const r of n)o.push(r in t?t[r]:0),i.push(e.has(r)?1:0);const s=new d(o),l=new d(i);return function(t,e){if(t.length!=e.length)throw new Error("The dimensionality of the vectors must match");let r=0;for(let n=0;n<t.length;n++)r+=t[n]*e[n];return r}(s,l)/(C(s)*C(l))}(t.freq,e[1]))),n=Math.max(...r);return n>.65?e[r.indexOf(n)][0]:"UN"}(e);t.setTag(o.TAGS.UNITS,"fasta"),t.setTag("aligned",r),t.setTag("alphabet",n)}get units(){return this._units}get column(){return this._column}get notation(){return this._notation}get defaultGapSymbol(){return this._defaultGapSymbol}get separator(){var t;const e=null!==(t=this.column.getTag("separator"))&&void 0!==t?t:void 0;if("separator"===this.notation&&void 0===e)throw new Error(`Separator is mandatory for column '${this.column.name}' of notation '${this.notation}'.`);return e}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}getAlphabetSize(){if("helm"==this.notation||"UN"==this.alphabet){const t=this.column.getTag(".alphabetSize");let e;if(t)e=parseInt(t);else{const t=H(this.column),r=A(this.column,1,t);e=Object.keys(r.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")}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")}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){const e=this.column,r=e.length,n=t.toLowerCase()+"("+e.name+")",i=e.dataFrame.columns.getUnusedName(n),s=o.Column.fromList("string",i,new Array(r).fill(""));s.semType=o.SEMTYPE.MACROMOLECULE,s.setTag(o.TAGS.UNITS,t),s.setTag(o.TAGS.CELL_RENDERER,"Macromolecule");const l=e.getTag("aligned");l&&s.setTag("aligned",l);const a=e.getTag("alphabet");a&&s.setTag("alphabet",a);let h=e.getTag(".alphabetSize");h&&s.setTag(".alphabetSize",h);const u=e.getTag(".alphabetIsMultichar");return void 0!==u&&s.setTag(".alphabetIsMultichar",u),"helm"==t&&(h=this.getAlphabetSize().toString(),s.setTag(".alphabetSize",h)),s}static getNewColumn(t){const e=new T(t),r=e.notation;return e.getNewColumn(r)}static unitsStringIsValid(t){return t=t.toLowerCase(),["fasta","separator","helm"].some((e=>t.startsWith(e.toLowerCase())))}static getNewColumnFromParams(t,e,r){if(!T.unitsStringIsValid(r))throw new Error("Invalid format of 'units' parameter");const n=o.Column.fromList("string",e,new Array(t).fill(""));return n.semType=o.SEMTYPE.MACROMOLECULE,n.setTag(o.TAGS.UNITS,r),n}constructor(t){this._column=t;const e=this._column.tags[o.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._defaultGapSymbolsDict.FASTA:this.isHelm()?T._defaultGapSymbolsDict.HELM:T._defaultGapSymbolsDict.SEPARATOR,!this.column.tags.has("aligned")&&(this.isFasta()||this.isSeparator()))throw new Error(`For column '${this.column.name}' of notation '${this.notation}' tag 'aligned' is mandatory.`);if(!this.column.tags.has(".alphabetIsMultichar")){if(this.isHelm())throw new Error(`For column '${this.column.name}' of notation '${this.notation}' tag '.alphabetIsMultichar' is mandatory.`);if(["UN"].includes(this.alphabet))throw new Error(`For column '${this.column.name}' of alphabet '${this.alphabet}' tag '.alphabetIsMultichar' is mandatory.`)}}}function A(t,e,r){const n={};let o=!0,i=null;for(const s of t.categories){const t=r(s);if(null==i?i=t.length:t.length!==i&&(o=!1),t.length>=e)for(const e of t)e in n||(n[e]=0),n[e]+=1}return{freq:n,sameLength:o}}T._defaultGapSymbolsDict={HELM:"*",SEPARATOR:"",FASTA:"-"},T.PeptideFastaAlphabet=new Set(["G","L","Y","S","E","Q","D","N","F","A","K","R","H","C","V","P","W","I","M","T"]),T.DnaFastaAlphabet=new Set(["A","C","G","T"]),T.RnaFastaAlphabet=new Set(["A","C","G","U"]);const y=/\[(\w+)\]|(\w)|(-)/g;function E(t){return p()(t.toString().matchAll(y)).map((t=>{let e;const r=t[0];return e=r.length>1?t[1]:r,e})).toArray()}const N=/(PEPTIDE1|DNA1|RNA1)\{([^}]+)}/g,M=/\[([^\[\]]+)]/g;function O(t){N.lastIndex=0;const e=N.exec(t.toString()),r=e?e[2]:null;return(r?r.split("."):[]).map((t=>{M.lastIndex=0;const e=M.exec(t);return e&&e.length>=2?e[1]:t}))}function H(t){if(t.semType!==o.SEMTYPE.MACROMOLECULE)throw new Error(`Get splitter for semType "${o.SEMTYPE.MACROMOLECULE}" only.`);return function(t,e,r){if(t.toLowerCase().startsWith("fasta"))return E;if(t.toLowerCase().startsWith("separator"))return function(t,e){return e=>e.split(t,undefined)}(e);if(t.toLowerCase().startsWith("helm"))return O;throw new Error(`Unexpected units ${t} .`)}(t.getTag(o.TAGS.UNITS),t.getTag("separator"))}const x=/(\w+)/g;var F;!function(t){t.MSA="MSA",t.classic="classic"}(F||(F={}));const L=(t,e,r,n,o,i,s="rgb(100,100,100)",l=0,a=!1,h=1,u="",c=!1,g=F.classic,m={},p=0,d=null,C=[],f=null)=>{var b,w,v;o.textAlign="start";let S=i.substring(0),T=c?"":u;g===F.MSA&&(T="");let A=!0,y=!0,E="difference";null!=d&&null!=d.cell.column&&(A=null===(b=d.cell.column.temp["color-code"])||void 0===b||b,y=null===(w=d.cell.column.temp["compare-with-current"])||void 0===w||w,E=null!==(v=d.cell.column.temp["highlight-difference"])&&void 0!==v?v:"difference");const N=C[p];y&&C.length>0&&"difference"===E&&(h=S==N?.3:h),y&&C.length>0&&"equal"===E&&(h=S!=N?.3:h),null!=f&&(S=function(t,e){var r,n;const o=t.match(x),i=t.length>e||(null!==(r=null==o?void 0:o.length)&&void 0!==r?r:0)>1,s=null!==(n=null==o?void 0:o[0])&&void 0!==n?n:" ";return i?s.substring(0,e)+"…":s}(S,f));let M=o.measureText(S+T),O=o.measureText(S).width,H=o.measureText(S).width;const L=n/2-(M.fontBoundingBoxAscent+M.fontBoundingBoxDescent)/2+1;function P(r,n){const i=A?s:"rgb(0,0,0)";o.fillStyle=i,o.globalAlpha=h,g===F.classic&&(o.fillText(S,t+r,e+L),o.fillStyle="#808080",o.fillText(T,t+n,e+L)),g===F.MSA&&(o.fillStyle=i,o.fillText(S,t+r+(m[p]-H)/2,e+L))}if(M=M.width,g===F.MSA&&(O=m[p],M=m[p]),a||M>r)return P(5,5+O),t+O+o.measureText(T).width;{const e=(r-M)/2;return P(e,e+O),t+e+O}};function P(t){var e;return"string"==typeof t||t instanceof String?t:"$thrownJsError"in t?P(t.$thrownJsError):t instanceof Error?null!==(e=t.stack)&&void 0!==e?e:t.message:t.toString()}class G extends o.GridCellRenderer{get name(){return"helm"}get cellType(){return"helm"}get defaultWidth(){return 400}get defaultHeight(){return 100}onMouseMove(t,e){var r,o,i;try{const h=t.cell.column.temp["helm-sum-maxLengthWords"],u=Object.values(t.cell.column.temp["helm-maxLengthWords"]).length-1,c=e.offsetX-t.gridColumn.left+(t.gridColumn.left-t.bounds.x);let g=0,m=u,p=!1;h[u+1]=c+1;let d=0;if(c>h[0])for(;!p;)d=Math.floor((m+g)/2),c>=h[d]&&c<=h[d+1]?(g=d,p=!0):c<h[d]?m=d-1:c>h[d+1]&&(g=d+1),g==m&&(p=!0);g=c>=h[g]?g+1:g;const C=a(t.cell.value);let f=null!==(r=t.cell.value)&&void 0!==r?r:"",b=s(l(f),f),w=[];for(let t=0;t<b.length;++t)C.has(b[t])&&(w[t]=n.divV([n.divText(`Monomer ${b[t]} not found.`),n.divText("Open the Context Panel, then expand Manage Libraries")]));(null!==(i=null===(o=w[g])||void 0===o?void 0:o.childNodes.length)&&void 0!==i?i:0)>0?n.tooltip.show(n.div(w[g]),e.x+16,e.y+16):n.tooltip.hide()}catch(t){const e=P(t);console.error("Helm: HelmCellRenderer.onMouseMove() error:\n"+e)}}render(t,e,r,o,i,h,u){var c;const g=-1!==h.gridRow?h.grid:void 0,m=a(h.cell.value);let p=null!==(c=h.cell.value)&&void 0!==c?c:"",d=l(p);if(0!=m.size){if(m.size>0){o=g?Math.min(g.canvas.width-e,o):t.canvas.width-e,t.save(),t.beginPath(),t.rect(e,r,o,i),t.clip(),t.font="12px monospace",t.textBaseline="top";let n=e,l={},a={},u=s(d,p);for(let e=0;e<u.length;++e){l[e]=7*u[e].length;let s=m.has(u[e])?"red":"#808080";t.fillStyle="rgb(100,100,100)",n=L(n,r,o,i,t,u[e],s,0,!0,1)}a[0]=l[0];for(let t=1;t<u.length;t++)a[t]=a[t-1]+l[t];return h.cell.column.temp={"helm-sum-maxLengthWords":a,"helm-maxLengthWords":l},void t.restore()}}else{const t=n.div([],{style:{width:`${o}px`,height:`${i}px`}});t.setAttribute("dataformat","helm"),t.setAttribute("data",h.cell.value),h.element=t,new JSDraw2.Editor(t,{width:o,height:i,skin:"w8",viewonly:!0})}}}class D extends T{get splitter(){return null===this._splitter&&(this._splitter=H(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 r=this.getNewColumn("separator");return r.init((r=>{const n=this.column.get(r),o=this.splitter(n);for(let t=0;t<o.length;t++)o[t]===e&&(o[t]=T._defaultGapSymbolsDict.SEPARATOR);return o.join(t)})),r.setTag(o.TAGS.UNITS,"separator"),r.setTag("separator",t),r}getHelmWrappers(){const t=this.isDna()?"DNA1{":this.isRna()?"RNA1{":this.isPeptide()?"PEPTIDE1{":"Unknown";if("Unknown"===t)throw new Error("Neither peptide, nor nucleotide");return[t,this.isDna()?"D(":this.isRna()?"R(":"",this.isDna()||this.isRna()?")P":"","}$$$"]}convertToHelmHelper(t,e,r,n,o,i){return`${r}${this.splitter(t).map((t=>t===e?T._defaultGapSymbolsDict.HELM:`${n}${t}${o}`)).join(".")}${i}`}convertStringToHelm(t,e=null){null===e&&(e=this.defaultGapSymbol);const[r,n,o,i]=this.getHelmWrappers();return this.convertToHelmHelper(t,e,r,n,o,i)}convertToHelm(t=null){null===t&&(t=this.defaultGapSymbol);const[e,r,n,i]=this.getHelmWrappers(),s=this.getNewColumn("helm");return s.init((o=>{const s=this.column.get(o);return this.convertToHelmHelper(s,t,e,r,n,i)})),s.setTag(o.TAGS.UNITS,"helm"),s}convertSeparatorToFasta(t=null){null===t&&(t=T._defaultGapSymbolsDict.FASTA);const e=this.getNewColumn("fasta");return e.init((e=>{const r=this.column.get(e),n=this.splitter(r),o=[];for(let e=0;e<n.length;e++){const r=n[e];if(0===r.length)o.push(t);else if(r.length>1){const t="["+r+"]";o.push(t)}else o.push(r)}return o.join("")})),e.setTag(o.TAGS.UNITS,"fasta"),e}convertHelmToFastaSeparator(t,e,r,n){n||(n=this.toFasta(e)?T._defaultGapSymbolsDict.FASTA:T._defaultGapSymbolsDict.SEPARATOR),r||(r=this.toFasta(e)?"":this.separator);const o=/(R\(|D\(|\)|P)/g,i=t.startsWith("DNA")||t.startsWith("RNA"),s=this.splitter(t),l=[];for(let t=0;t<s.length;t++){let r=s[t];if(i&&(r=r.replace(o,"")),r===T._defaultGapSymbolsDict.HELM)l.push(n);else if(this.toFasta(e)&&r.length>1){const t="["+r+"]";l.push(t)}else l.push(r)}return l.join(r)}convertHelm(t,e,r){const n=this.getNewColumn(t);n.init((n=>{const o=this.column.get(n);return this.convertHelmToFastaSeparator(o,t,e,r)}));const o=A(n,5,H(n)).sameLength?"SEQ.MSA":"SEQ";return n.setTag("aligned",o),n}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 R=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{a(n.next(t))}catch(t){i(t)}}function l(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,l)}a((n=n.apply(t,e||[])).next())}))};const _=new o.Package;let $=null;function I(){return R(this,void 0,void 0,(function*(){return Promise.all([new Promise(((t,e)=>{dojo.ready((function(){t(null)}))})),yield r.functions.call("Bio:getBioLib")]).then((([t,e])=>{$=e,U(),$.onChanged.subscribe((t=>{try{U();const t=$.getTypes(),e="Monomer lib updated:<br />"+(0==t.length?"empty":t.map((t=>`${t} ${$.getMonomerNamesByType(t).length}`)).join("<br />"));r.shell.info(e)}catch(t){const e=P(t);console.error("Helm: initHelm monomerLib.onChanged() error:\n"+e)}}))}))}))}function U(){org.helm.webeditor.Monomers.clear(),$.getTypes().forEach((t=>{$.getMonomerNamesByType(t).forEach((e=>{let r=!1;const n=$.getMonomer(t,e),o={id:e,m:n.molfile,n:n.name,na:n.naturalAnalog,rs:n.rgroups.length,type:n.polymerType,mt:n.monomerType,at:{}};if(n.rgroups.length>0){o.rs=n.rgroups.length;const t={};n.rgroups.forEach((e=>{t[e.label]=e.capGroupName})),o.at=t}else null!=n.data.smiles?(o.rs=Object.keys(V(n.data.smiles.toString())).length,o.at=V(n.data.smiles.toString())):r=!0;r||org.helm.webeditor.Monomers.addOneMonomer(o)}))}));let t=r.shell.tv.grid;t&&t.invalidate()}function k(){return new G}function W(t,e,o){const i=a(void 0===o?t.value:e);0==i.size?function(t,e,o){let i=n.div(),s=r.shell.tv.grid.dataFrame,l=new D(s.columns.bySemType("Macromolecule"));org.helm.webeditor.MolViewer.molscale=.8;let a=new scil.helm.App(i,{showabout:!1,mexfontsize:"90%",mexrnapinontab:!0,topmargin:20,mexmonomerstab:!0,sequenceviewonly:!1,mexfavoritefirst:!0,mexfilter:!0});var h=a.calculateSizes();a.canvas.resize(h.rightwidth-100,h.topheight-210);var 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((function(){void 0===o?a.canvas.helm.setSequence(t.value,"HELM"):a.canvas.helm.setSequence(e,"HELM")}),200),n.dialog({showHeader:!1,showFooter:!0}).add(i).onOK((()=>{let e=a.canvas.getHelm(!0).replace(/<\/span>/g,"").replace(/<span style='background:#bbf;'>/g,"");if(void 0===o)t.value=e;else{let r=l.convertHelmToFastaSeparator(e,o);t.value=r}})).show({modal:!0,fullScreen:!0})}(t,e,o):r.shell.warning(`Monomers ${Array.from(i).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 z(t){W(t.cell,void 0,void 0)}function j(t){let e=r.shell.tv.grid.dataFrame,n=e.columns.bySemType("Macromolecule");"helm"===n.getTag(o.TAGS.UNITS)&&W(e.currentCell,void 0,void 0);const i=new D(n).convertStringToHelm(t,"/");W(e.currentCell,i,n.getTag(o.TAGS.UNITS))}function B(t){return R(this,void 0,void 0,(function*(){let e=r.shell.tv.grid.root.parentElement;const i=n.div([]);e.appendChild(i);let s=new JSDraw2.Editor(i,{viewonly:!0});i.style.width="0px",i.style.height="0px",s.setHelm(t);let l=s.getFormula(!0),a=Math.round(100*s.getMolWeight())/100,h=Math.round(100*s.getExtinctionCoefficient(!0))/100;return e.lastChild.remove(),new o.Widget(n.tableFromMap({formula:l.replace(/<sub>/g,"").replace(/<\/sub>/g,""),"molecular weight":a,"extinction coefficient":h}))}))}function V(t){const e=t.match(/(?<=\[)[^\][]*(?=])/gm),r={};let n,o="";for(let t=0;t<e.length;t++)if(null!=e[t]&&/\d/.test(e[t])){n=e[t][e[t].length-1],e[t]=e[t].replace(/[0-9]/g,"");for(let r=0;r<e[t].length;r++)":"!=e[t][r]&&(o+=e[t][r]);r["R"+n]=o,o=""}return r}function q(t){let e=r.shell.tv.grid.root.parentElement,i=o.Column.string("mols",t.length);const s=n.div([]);e.appendChild(s);let l=new JSDraw2.Editor(s,{viewonly:!0});return s.style.width="0px",s.style.height="0px",i.init((e=>(l.setHelm(t.get(e)),l.getMolfile()))),e.lastChild.remove(),i}function Y(){return new i}helm=e})();
|
|
1
|
+
var helm;(()=>{"use strict";var t={n:e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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:()=>_,editMoleculeCell:()=>z,getMolfiles:()=>q,helmCellRenderer:()=>k,helmWebEditor:()=>Y,initHelm:()=>I,openEditor:()=>j,propertiesPanel:()=>B});const r=grok,n=ui,o=DG;class i{constructor(){this.w=200,this.h=100,this.host=n.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=n.div();org.helm.webeditor.MolViewer.molscale=.8;const r=new scil.helm.App(e,{showabout:!1,mexfontsize:"90%",mexrnapinontab:!0,topmargin:20,mexmonomerstab:!0,sequenceviewonly:!1,mexfavoritefirst:!0,mexfilter:!0}),o=r.calculateSizes();r.canvas.resize(o.rightwidth-100,o.topheight-210);let i={width:o.rightwidth-100+"px",height:o.bottomheight+"px"};return scil.apply(r.sequence.style,i),scil.apply(r.notation.style,i),i={width:o.rightwidth+"px",height:o.bottomheight+r.toolbarheight+"px"},scil.apply(r.properties.parent.style,i),r.structureview.resize(o.rightwidth,o.bottomheight+r.toolbarheight),r.mex.resize(o.topheight-80),setTimeout((function(){r.canvas.helm.setSequence(t,"HELM")}),200),{editorDiv:e,webEditor:r}}}function s(t,e){let r=[];for(let n=0;n<t.length;++n){let o=e.indexOf(t[n]),i=e.slice(0,o);r.push(i),r.push(t[n]),e=e.substring(o+t[n].length)}return r.push(e),r}function l(t){t=h(t,"$")[0];var e=[];if(!scil.Utils.isNullOrEmpty(t))for(var r=h(t,"|"),n=0;n<r.length;++n){var o=(t=u(r[n]).str).indexOf("{");o=(t=t.substring(o+1)).indexOf("}");var i=h(t=t.substring(0,o),".");for(var s of i)if(s.includes("(")&&s.includes(")")){var l=s.replace(/[()]/g,"").split("");for(var a of l)e.push(a)}else if(s.includes("[")&&s.includes("]")){var c=s.match(/(?<=\[).*?(?=\])/g,"");e.push(c[0])}else e.push(s)}return e}function a(t){const e=Object.keys(org.helm.webeditor.monomerTypeList()),r=[],n=[];for(var o=0;o<e.length;o++)r.push(new scil.helm.Monomers.getMonomerSet(e[o])),Object.keys(r[o]).forEach((t=>{n.push(r[o][t].id)}));const i=l(t);return new Set(i.filter((t=>!n.includes(t))))}function h(t,e){for(var r=[],n="",o=0,i=0,s=0,l=0,a=0;a<t.length;++a){var h=t.substring(a,a+1);if(h==e&&0==i&&0==o&&0==s&&0==l)r.push(n),n="";else{if(n+=h,l>0&&"\\"==h&&a+1<t.length){++a;var u=t.substring(a,a+1);n+=u,h+=u}'"'==h?a>0&&"\\"==t.substring(a-1,a)||(l=0==l?1:0):"["==h?++i:"]"==h?--i:"("==h?++o:")"==h?--o:"{"==h?++s:"}"==h&&--s}}return r.push(n),r}function u(t){var e=c(t,'"');if(null!=e.tag)return e;var r=c(t,"'");return{tag:e.tag,repeat:r.tag,str:r.str}}function c(t,e){var r=null;if(scil.Utils.endswith(t,e)){for(var n=t.length-1;n>0&&!((n=t.lastIndexOf(e,n-1))<=0||"\\"!=t.substring(n-1,n)););n>0&&n<t.length-1&&(r=t.substring(n+1,t.length-1),t=t.substring(0,n))}return null!=r&&(r=r.replace(new RegExp("\\"+e,"g"),e)),{tag:g(r),str:t}}function g(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)}}))}const m=wu;var p=t.n(m);class d extends Float32Array{}function C(t){let e=0;for(let r=0;r<t.length;r++)e+=t[r]*t[r];return Math.sqrt(e)}class f{static makePalette(t,e=!1,r=f){const n={};return t.forEach((t=>{const r=t[0],o=t[1];r.forEach(((t,r)=>{n[t]=this.colourPalette[o][e?0:r]}))})),new r(n)}constructor(t){this._palette=t}get(t){return this._palette[t]}}f.undefinedColor="rgb(100,100,100)",f.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 b extends f{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,b)),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,b)),this.grokGroups}static get RasMol(){return void 0===this.rasMol&&(this.rasMol=new b({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 b.aaSynonyms?b.aaSynonyms[t]:t;return super.get(e)}}b.aaSynonyms={MeNle:"L",MeA:"A",MeG:"G",MeF:"F"};class w{static getPalette(t="grok"){switch(t){case"grok":return b.GrokGroups;case"lesk":return b.Lesk;default:throw new Error(`ChemPalette: scheme \`${t}\` does not exist`)}}static getInnerOuter(t){let e=0,r="",n="";for(const o of t)"("==o?e++:")"==o?e--:e?r+=o:n+=o;return isNaN(parseInt(r))?[n,r]:[n,""]}static getColorAAPivot(t="",e="grok"){var r,n,o;const i=this.getPalette(e);let[s,l]=this.getInnerOuter(t);if(s=s.length>6?`${s.slice(0,3)}...`:s,l=l.length>6?`${l.slice(0,3)}...`:l,1==t.length||"("==t[1]){const e=null===(r=t[0])||void 0===r?void 0:r.toUpperCase();return e in i?[i.get(e),e,l,1]:[this.undefinedColor,s,l,1]}if("d"==t[0]&&t[1]in i&&(2==t.length||"("==t[2])){const e=null===(n=t[1])||void 0===n?void 0:n.toUpperCase();return e in i?[i.get(e),e,l,2]:[this.undefinedColor,s,l,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 i?[i.get(e),e,l,3]:[this.undefinedColor,s,l,3]}if((null===(o=t[0])||void 0===o?void 0:o.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 i?[i.get(e),e,l,4]:[this.undefinedColor,s,l,4]}return[this.undefinedColor,s,l,0]}}w.SemType="Aminoacids",w.SemTypeMultipleAlignment="AminoacidsMultipleAlignment",w.undefinedColor="rgb(100,100,100)",w.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"},w.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"},w.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(*)*"},w.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 v{}v.SemType="Nucleotides",v.SemTypeMultipleAlignment="NucleotidesMultipleAlignment",v.Names={A:"Adenine",C:"Cytosine",G:"Guanine",T:"Thymine",U:"Uracil"};class S extends class{}{static buildPalette(){return[].concat(...Object.values(f.colourPalette))}get(t){const e=class{static hashCode(t){let e=0;if(0===t.length)return e;for(let r=0;r<t.length;r++)e=(e<<5)-e+t.charCodeAt(r),e|=0;return e}}.hashCode(t)%S.palette.length;return function(t){if(null==t)return"rgb(100,100,100)";const e=o.Color.fromHtml(t),r=o.Color.g(e),n=o.Color.r(e),i=o.Color.b(e),s=Math.sqrt(Math.pow(0-n,2)+Math.pow(0-r,2)+Math.pow(0-i,2));return s>210?`rgb(${n/s*210},${r/s*210},${i/s*210})`:o.Color.toRgb(e)}(S.palette[e])}}S.palette=S.buildPalette();class T{static setUnitsToFastaColumn(t){if(t.semType!==o.SEMTYPE.MACROMOLECULE)throw new Error("Fasta column must be MACROMOLECULE");const e=A(t,5,E),r=e.sameLength?"SEQ.MSA":"SEQ",n=function(t){const e=[["PT",T.PeptideFastaAlphabet],["DNA",T.DnaFastaAlphabet],["RNA",T.RnaFastaAlphabet]],r=e.map((e=>function(t,e,r="-"){const n=new Set([...new Set(Object.keys(t)),...e]);n.delete(r);const o=[],i=[];for(const r of n)o.push(r in t?t[r]:0),i.push(e.has(r)?1:0);const s=new d(o),l=new d(i);return function(t,e){if(t.length!=e.length)throw new Error("The dimensionality of the vectors must match");let r=0;for(let n=0;n<t.length;n++)r+=t[n]*e[n];return r}(s,l)/(C(s)*C(l))}(t.freq,e[1]))),n=Math.max(...r);return n>.65?e[r.indexOf(n)][0]:"UN"}(e);t.setTag(o.TAGS.UNITS,"fasta"),t.setTag("aligned",r),t.setTag("alphabet",n)}get units(){return this._units}get column(){return this._column}get notation(){return this._notation}get defaultGapSymbol(){return this._defaultGapSymbol}get separator(){var t;const e=null!==(t=this.column.getTag("separator"))&&void 0!==t?t:void 0;if("separator"===this.notation&&void 0===e)throw new Error(`Separator is mandatory for column '${this.column.name}' of notation '${this.notation}'.`);return e}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}getAlphabetSize(){if("helm"==this.notation||"UN"==this.alphabet){const t=this.column.getTag(".alphabetSize");let e;if(t)e=parseInt(t);else{const t=H(this.column),r=A(this.column,1,t);e=Object.keys(r.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")}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")}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){const e=this.column,r=e.length,n=t.toLowerCase()+"("+e.name+")",i=e.dataFrame.columns.getUnusedName(n),s=o.Column.fromList("string",i,new Array(r).fill(""));s.semType=o.SEMTYPE.MACROMOLECULE,s.setTag(o.TAGS.UNITS,t),s.setTag(o.TAGS.CELL_RENDERER,"Macromolecule");const l=e.getTag("aligned");l&&s.setTag("aligned",l);const a=e.getTag("alphabet");a&&s.setTag("alphabet",a);let h=e.getTag(".alphabetSize");h&&s.setTag(".alphabetSize",h);const u=e.getTag(".alphabetIsMultichar");return void 0!==u&&s.setTag(".alphabetIsMultichar",u),"helm"==t&&(h=this.getAlphabetSize().toString(),s.setTag(".alphabetSize",h)),s}static getNewColumn(t){const e=new T(t),r=e.notation;return e.getNewColumn(r)}static unitsStringIsValid(t){return t=t.toLowerCase(),["fasta","separator","helm"].some((e=>t.startsWith(e.toLowerCase())))}static getNewColumnFromParams(t,e,r){if(!T.unitsStringIsValid(r))throw new Error("Invalid format of 'units' parameter");const n=o.Column.fromList("string",e,new Array(t).fill(""));return n.semType=o.SEMTYPE.MACROMOLECULE,n.setTag(o.TAGS.UNITS,r),n}constructor(t){this._column=t;const e=this._column.tags[o.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._defaultGapSymbolsDict.FASTA:this.isHelm()?T._defaultGapSymbolsDict.HELM:T._defaultGapSymbolsDict.SEPARATOR,!this.column.tags.has("aligned")&&(this.isFasta()||this.isSeparator()))throw new Error(`For column '${this.column.name}' of notation '${this.notation}' tag 'aligned' is mandatory.`);if(!this.column.tags.has(".alphabetIsMultichar")){if(this.isHelm())throw new Error(`For column '${this.column.name}' of notation '${this.notation}' tag '.alphabetIsMultichar' is mandatory.`);if(["UN"].includes(this.alphabet))throw new Error(`For column '${this.column.name}' of alphabet '${this.alphabet}' tag '.alphabetIsMultichar' is mandatory.`)}}}function A(t,e,r){const n={};let o=!0,i=null;for(const s of t.categories){const t=r(s);if(null==i?i=t.length:t.length!==i&&(o=!1),t.length>=e)for(const e of t)e in n||(n[e]=0),n[e]+=1}return{freq:n,sameLength:o}}T._defaultGapSymbolsDict={HELM:"*",SEPARATOR:"",FASTA:"-"},T.PeptideFastaAlphabet=new Set(["G","L","Y","S","E","Q","D","N","F","A","K","R","H","C","V","P","W","I","M","T"]),T.DnaFastaAlphabet=new Set(["A","C","G","T"]),T.RnaFastaAlphabet=new Set(["A","C","G","U"]);const y=/\[(\w+)\]|(\w)|(-)/g;function E(t){return p()(t.toString().matchAll(y)).map((t=>{let e;const r=t[0];return e=r.length>1?t[1]:r,e})).toArray()}const N=/(PEPTIDE1|DNA1|RNA1)\{([^}]+)}/g,M=/\[([^\[\]]+)]/g;function O(t){N.lastIndex=0;const e=N.exec(t.toString()),r=e?e[2]:null;return(r?r.split("."):[]).map((t=>{M.lastIndex=0;const e=M.exec(t);return e&&e.length>=2?e[1]:t}))}function H(t){if(t.semType!==o.SEMTYPE.MACROMOLECULE)throw new Error(`Get splitter for semType "${o.SEMTYPE.MACROMOLECULE}" only.`);return function(t,e,r){if(t.toLowerCase().startsWith("fasta"))return E;if(t.toLowerCase().startsWith("separator"))return function(t,e){return e=>e.split(t,undefined)}(e);if(t.toLowerCase().startsWith("helm"))return O;throw new Error(`Unexpected units ${t} .`)}(t.getTag(o.TAGS.UNITS),t.getTag("separator"))}const x=/(\w+)/g;var F;!function(t){t.MSA="MSA",t.classic="classic"}(F||(F={}));const L=(t,e,r,n,o,i,s="rgb(100,100,100)",l=0,a=!1,h=1,u="",c=!1,g=F.classic,m={},p=0,d=null,C=[],f=null)=>{var b,w,v;o.textAlign="start";let S=i.substring(0),T=c?"":u;g===F.MSA&&(T="");let A=!0,y=!0,E="difference";null!=d&&null!=d.cell.column&&(A=null===(b=d.cell.column.temp["color-code"])||void 0===b||b,y=null===(w=d.cell.column.temp["compare-with-current"])||void 0===w||w,E=null!==(v=d.cell.column.temp["highlight-difference"])&&void 0!==v?v:"difference");const N=C[p];y&&C.length>0&&"difference"===E&&(h=S==N?.3:h),y&&C.length>0&&"equal"===E&&(h=S!=N?.3:h),null!=f&&(S=function(t,e){var r,n;const o=t.match(x),i=t.length>e||(null!==(r=null==o?void 0:o.length)&&void 0!==r?r:0)>1,s=null!==(n=null==o?void 0:o[0])&&void 0!==n?n:" ";return i?s.substring(0,e)+"…":s}(S,f));let M=o.measureText(S+T),O=o.measureText(S).width,H=o.measureText(S).width;const L=n/2-(M.fontBoundingBoxAscent+M.fontBoundingBoxDescent)/2+1;function P(r,n){const i=A?s:"rgb(0,0,0)";o.fillStyle=i,o.globalAlpha=h,g===F.classic&&(o.fillText(S,t+r,e+L),o.fillStyle="#808080",o.fillText(T,t+n,e+L)),g===F.MSA&&(o.fillStyle=i,o.fillText(S,t+r+(m[p]-H)/2,e+L))}if(M=M.width,g===F.MSA&&(O=m[p],M=m[p]),a||M>r)return P(5,5+O),t+O+o.measureText(T).width;{const e=(r-M)/2;return P(e,e+O),t+e+O}};function P(t){var e;return"string"==typeof t||t instanceof String?t:"$thrownJsError"in t?P(t.$thrownJsError):t instanceof Error?null!==(e=t.stack)&&void 0!==e?e:t.message:t.toString()}class G extends o.GridCellRenderer{get name(){return"helm"}get cellType(){return"helm"}get defaultWidth(){return 400}get defaultHeight(){return 100}onMouseMove(t,e){var r,o,i;try{const h=t.cell.column.temp["helm-sum-maxLengthWords"],u=Object.values(t.cell.column.temp["helm-maxLengthWords"]).length-1,c=e.offsetX-t.gridColumn.left+(t.gridColumn.left-t.bounds.x);let g=0,m=u,p=!1;h[u+1]=c+1;let d=0;if(c>h[0])for(;!p;)d=Math.floor((m+g)/2),c>=h[d]&&c<=h[d+1]?(g=d,p=!0):c<h[d]?m=d-1:c>h[d+1]&&(g=d+1),g==m&&(p=!0);g=c>=h[g]?g+1:g;const C=a(t.cell.value);let f=null!==(r=t.cell.value)&&void 0!==r?r:"",b=s(l(f),f),w=[];for(let t=0;t<b.length;++t)C.has(b[t])&&(w[t]=n.divV([n.divText(`Monomer ${b[t]} not found.`),n.divText("Open the Context Panel, then expand Manage Libraries")]));(null!==(i=null===(o=w[g])||void 0===o?void 0:o.childNodes.length)&&void 0!==i?i:0)>0?n.tooltip.show(n.div(w[g]),e.x+16,e.y+16):n.tooltip.hide()}catch(t){const e=P(t);console.error("Helm: HelmCellRenderer.onMouseMove() error:\n"+e)}}render(t,e,r,o,i,h,u){var c;const g=-1!==h.gridRow?h.grid:void 0,m=a(h.cell.value);let p=null!==(c=h.cell.value)&&void 0!==c?c:"",d=l(p);if(0!=m.size||!g){if(!g){const e=window.devicePixelRatio;i=28,t.canvas.height=i*e,t.canvas.style.height=`${i}px`}o=g?Math.min(g.canvas.width-e,o):t.canvas.width-e,t.save(),t.beginPath(),t.rect(e,r,o,i),t.clip(),t.font="12px monospace",t.textBaseline="top";let n=e,l={},a={},u=s(d,p);for(let e=0;e<u.length;++e){l[e]=7*u[e].length;let s=m.has(u[e])?"red":"#808080";t.fillStyle="rgb(100,100,100)",n=L(n,r,o,i,t,u[e],s,0,!0,1)}a[0]=l[0];for(let t=1;t<u.length;t++)a[t]=a[t-1]+l[t];return h.cell.column.temp={"helm-sum-maxLengthWords":a,"helm-maxLengthWords":l},void t.restore()}{const t=n.div([],{style:{width:`${o}px`,height:`${i}px`}});t.setAttribute("dataformat","helm"),t.setAttribute("data",h.cell.value),h.element=t,new JSDraw2.Editor(t,{width:o,height:i,skin:"w8",viewonly:!0})}}}class D extends T{get splitter(){return null===this._splitter&&(this._splitter=H(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 r=this.getNewColumn("separator");return r.init((r=>{const n=this.column.get(r),o=this.splitter(n);for(let t=0;t<o.length;t++)o[t]===e&&(o[t]=T._defaultGapSymbolsDict.SEPARATOR);return o.join(t)})),r.setTag(o.TAGS.UNITS,"separator"),r.setTag("separator",t),r}getHelmWrappers(){const t=this.isDna()?"DNA1{":this.isRna()?"RNA1{":this.isPeptide()?"PEPTIDE1{":"Unknown";if("Unknown"===t)throw new Error("Neither peptide, nor nucleotide");return[t,this.isDna()?"D(":this.isRna()?"R(":"",this.isDna()||this.isRna()?")P":"","}$$$"]}convertToHelmHelper(t,e,r,n,o,i){return`${r}${this.splitter(t).map((t=>t===e?T._defaultGapSymbolsDict.HELM:`${n}${t}${o}`)).join(".")}${i}`}convertStringToHelm(t,e=null){null===e&&(e=this.defaultGapSymbol);const[r,n,o,i]=this.getHelmWrappers();return this.convertToHelmHelper(t,e,r,n,o,i)}convertToHelm(t=null){null===t&&(t=this.defaultGapSymbol);const[e,r,n,i]=this.getHelmWrappers(),s=this.getNewColumn("helm");return s.init((o=>{const s=this.column.get(o);return this.convertToHelmHelper(s,t,e,r,n,i)})),s.setTag(o.TAGS.UNITS,"helm"),s}convertSeparatorToFasta(t=null){null===t&&(t=T._defaultGapSymbolsDict.FASTA);const e=this.getNewColumn("fasta");return e.init((e=>{const r=this.column.get(e),n=this.splitter(r),o=[];for(let e=0;e<n.length;e++){const r=n[e];if(0===r.length)o.push(t);else if(r.length>1){const t="["+r+"]";o.push(t)}else o.push(r)}return o.join("")})),e.setTag(o.TAGS.UNITS,"fasta"),e}convertHelmToFastaSeparator(t,e,r,n){n||(n=this.toFasta(e)?T._defaultGapSymbolsDict.FASTA:T._defaultGapSymbolsDict.SEPARATOR),r||(r=this.toFasta(e)?"":this.separator);const o=/(R\(|D\(|\)|P)/g,i=t.startsWith("DNA")||t.startsWith("RNA"),s=this.splitter(t),l=[];for(let t=0;t<s.length;t++){let r=s[t];if(i&&(r=r.replace(o,"")),r===T._defaultGapSymbolsDict.HELM)l.push(n);else if(this.toFasta(e)&&r.length>1){const t="["+r+"]";l.push(t)}else l.push(r)}return l.join(r)}convertHelm(t,e,r){const n=this.getNewColumn(t);n.init((n=>{const o=this.column.get(n);return this.convertHelmToFastaSeparator(o,t,e,r)}));const o=A(n,5,H(n)).sameLength?"SEQ.MSA":"SEQ";return n.setTag("aligned",o),n}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 R=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{a(n.next(t))}catch(t){i(t)}}function l(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,l)}a((n=n.apply(t,e||[])).next())}))};const _=new o.Package;let $=null;function I(){return R(this,void 0,void 0,(function*(){return Promise.all([new Promise(((t,e)=>{dojo.ready((function(){t(null)}))})),yield r.functions.call("Bio:getBioLib")]).then((([t,e])=>{$=e,U(),$.onChanged.subscribe((t=>{try{U();const t=$.getTypes(),e="Monomer lib updated:<br />"+(0==t.length?"empty":t.map((t=>`${t} ${$.getMonomerNamesByType(t).length}`)).join("<br />"));r.shell.info(e)}catch(t){const e=P(t);console.error("Helm: initHelm monomerLib.onChanged() error:\n"+e)}}))}))}))}function U(){org.helm.webeditor.Monomers.clear(),$.getTypes().forEach((t=>{$.getMonomerNamesByType(t).forEach((e=>{let r=!1;const n=$.getMonomer(t,e),o={id:e,m:n.molfile,n:n.name,na:n.naturalAnalog,rs:n.rgroups.length,type:n.polymerType,mt:n.monomerType,at:{}};if(n.rgroups.length>0){o.rs=n.rgroups.length;const t={};n.rgroups.forEach((e=>{t[e.label]=e.capGroupName})),o.at=t}else null!=n.data.smiles?(o.rs=Object.keys(V(n.data.smiles.toString())).length,o.at=V(n.data.smiles.toString())):r=!0;r||org.helm.webeditor.Monomers.addOneMonomer(o)}))}));let t=r.shell.tv.grid;t&&t.invalidate()}function k(){return new G}function W(t,e,o){const i=a(void 0===o?t.value:e);0==i.size?function(t,e,o){let i=n.div(),s=r.shell.tv.grid.dataFrame,l=new D(s.columns.bySemType("Macromolecule"));org.helm.webeditor.MolViewer.molscale=.8;let a=new scil.helm.App(i,{showabout:!1,mexfontsize:"90%",mexrnapinontab:!0,topmargin:20,mexmonomerstab:!0,sequenceviewonly:!1,mexfavoritefirst:!0,mexfilter:!0});var h=a.calculateSizes();a.canvas.resize(h.rightwidth-100,h.topheight-210);var 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((function(){void 0===o?a.canvas.helm.setSequence(t.value,"HELM"):a.canvas.helm.setSequence(e,"HELM")}),200),n.dialog({showHeader:!1,showFooter:!0}).add(i).onOK((()=>{let e=a.canvas.getHelm(!0).replace(/<\/span>/g,"").replace(/<span style='background:#bbf;'>/g,"");if(void 0===o)t.value=e;else{let r=l.convertHelmToFastaSeparator(e,o);t.value=r}})).show({modal:!0,fullScreen:!0})}(t,e,o):r.shell.warning(`Monomers ${Array.from(i).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 z(t){W(t.cell,void 0,void 0)}function j(t){let e=r.shell.tv.grid.dataFrame,n=e.columns.bySemType("Macromolecule");"helm"===n.getTag(o.TAGS.UNITS)&&W(e.currentCell,void 0,void 0);const i=new D(n).convertStringToHelm(t,"/");W(e.currentCell,i,n.getTag(o.TAGS.UNITS))}function B(t){return R(this,void 0,void 0,(function*(){let e=r.shell.tv.grid.root.parentElement;const i=n.div([]);e.appendChild(i);let s=new JSDraw2.Editor(i,{viewonly:!0});i.style.width="0px",i.style.height="0px",s.setHelm(t);let l=s.getFormula(!0),a=Math.round(100*s.getMolWeight())/100,h=Math.round(100*s.getExtinctionCoefficient(!0))/100;return e.lastChild.remove(),new o.Widget(n.tableFromMap({formula:l.replace(/<sub>/g,"").replace(/<\/sub>/g,""),"molecular weight":a,"extinction coefficient":h}))}))}function V(t){const e=t.match(/(?<=\[)[^\][]*(?=])/gm),r={};let n,o="";for(let t=0;t<e.length;t++)if(null!=e[t]&&/\d/.test(e[t])){n=e[t][e[t].length-1],e[t]=e[t].replace(/[0-9]/g,"");for(let r=0;r<e[t].length;r++)":"!=e[t][r]&&(o+=e[t][r]);r["R"+n]=o,o=""}return r}function q(t){let e=r.shell.tv.grid.root.parentElement,i=o.Column.string("mols",t.length);const s=n.div([]);e.appendChild(s);let l=new JSDraw2.Editor(s,{viewonly:!0});return s.style.width="0px",s.style.height="0px",i.init((e=>(l.setHelm(t.get(e)),l.getMolfile()))),e.lastChild.remove(),i}function Y(){return new i}helm=e})();
|
|
2
2
|
//# sourceMappingURL=package.js.map
|