@datagrok/helm 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/package-test.js +1 -1
  3. package/dist/package-test.js.map +1 -1
  4. package/dist/package.js +1 -1
  5. package/dist/package.js.map +1 -1
  6. package/package.json +15 -16
  7. package/src/cell-renderer.ts +13 -36
  8. package/src/constants.ts +0 -11
  9. package/src/helm-helper.ts +67 -17
  10. package/src/helm-monomer-placer.ts +8 -26
  11. package/src/helm-web-editor.ts +33 -3
  12. package/src/package-test.ts +12 -4
  13. package/src/package-utils.ts +160 -0
  14. package/src/package.ts +123 -197
  15. package/src/tests/findMonomers-tests.ts +2 -0
  16. package/src/tests/get-all-parts-tests.ts +5 -0
  17. package/src/tests/{get-molfiles.ts → get-molfiles-tests.ts} +3 -1
  18. package/src/tests/get-monomer-tests.ts +279 -0
  19. package/src/tests/helm-service-tests.ts +4 -0
  20. package/src/tests/helm-tests.ts +8 -1
  21. package/src/tests/helm-web-editor-tests.ts +55 -0
  22. package/src/tests/parse-helm-tests.ts +98 -0
  23. package/src/tests/properties-widget-tests.ts +33 -4
  24. package/src/tests/renderers-tests.ts +3 -1
  25. package/src/tests/utils.ts +6 -0
  26. package/src/types/index.ts +5 -0
  27. package/src/utils/get-hovered.ts +9 -21
  28. package/src/utils/get-monomer-dummy.ts +149 -0
  29. package/src/utils/get-monomer-of-library.ts +90 -0
  30. package/src/utils/get-monomer.ts +113 -0
  31. package/src/utils/helm-grid-cell-renderer.ts +12 -7
  32. package/src/utils/helm-service.ts +19 -45
  33. package/src/utils/index.ts +11 -17
  34. package/src/widgets/properties-widget.ts +29 -9
  35. package/tsconfig.json +1 -1
  36. package/vendor/helm-web-editor.development.js +39640 -0
  37. package/vendor/helm-web-editor.production.js +2 -0
  38. package/vendor/helm-web-editor.production.js.map +1 -0
  39. package/webpack.config.js +14 -11
  40. package/helm/JSDraw/Pistoia.HELM-uncompressed.js +0 -9694
  41. package/helm/JSDraw/Pistoia.HELM.js +0 -27
  42. package/helm/JSDraw/ReadMe.txt +0 -8
  43. package/helm/JSDraw/Scilligence.JSDraw2.Lite-uncompressed.js +0 -31126
  44. package/helm/JSDraw/Scilligence.JSDraw2.Lite.js +0 -12
  45. package/helm/JSDraw/Scilligence.JSDraw2.Resources.js +0 -762
  46. package/helm/JSDraw/dojo.js +0 -250
  47. package/helm/JSDraw/test.html +0 -24
  48. package/src/utils/dummy-monomer.ts +0 -69
@@ -2,25 +2,26 @@ import * as grok from 'datagrok-api/grok';
2
2
  import * as ui from 'datagrok-api/ui';
3
3
  import * as DG from 'datagrok-api/dg';
4
4
 
5
- import * as org from 'org';
6
- import * as scil from 'scil';
7
- import * as JSDraw2 from 'JSDraw2';
8
-
9
5
  import $ from 'cash-dom';
10
6
  import {Subject, Unsubscribable} from 'rxjs';
11
7
 
12
8
  import {errInfo} from '@datagrok-libraries/bio/src/utils/err-info';
13
- import {HelmAux, HelmProps, HelmServiceBase} from '@datagrok-libraries/bio/src/viewers/helm-service';
9
+ import {IMonomerLib} from '@datagrok-libraries/bio/src/types/index';
10
+ import {Editor, HelmType} from '@datagrok-libraries/bio/src/helm/types';
14
11
  import {RenderTask} from '@datagrok-libraries/bio/src/utils/cell-renderer-async-base';
12
+ import {HelmAux, HelmProps, HelmServiceBase} from '@datagrok-libraries/bio/src/viewers/helm-service';
15
13
  import {svgToImage} from '@datagrok-libraries/utils/src/svg';
16
14
 
15
+ import {JSDraw2HelmModule} from '../types';
16
+
17
17
  import {_package} from '../package';
18
- import {DummyWebEditorMonomer} from './dummy-monomer';
18
+
19
+ declare const JSDraw2: JSDraw2HelmModule;
19
20
 
20
21
  export class HelmService extends HelmServiceBase {
21
22
  private readonly hostDiv: HTMLDivElement;
22
23
 
23
- private editor: JSDraw2.Editor | null = null;
24
+ private editor!: Editor<HelmType>;
24
25
  private image: HTMLImageElement | null = null;
25
26
 
26
27
  constructor() {
@@ -57,46 +58,18 @@ export class HelmService extends HelmServiceBase {
57
58
  this.editor.options.height = task.props.height;
58
59
  this.editor.resize(task.props.width, task.props.height);
59
60
  const helmStr = task.props.helm;
60
- let hasMissing: boolean = false;
61
61
  if (helmStr) {
62
- const monomers = org.helm.webeditor.Monomers;
63
- const originalGetMonomer = monomers.getMonomer;
64
- const originalAlert = scil.Utils.alert;
65
- try {
66
- org.helm.webeditor.Monomers.getMonomer = (a: org.helm.IAtom | string, name: string): org.helm.IAtom | null => {
67
- let resAtom: any = originalGetMonomer.bind(monomers)(a, name);
68
-
69
- if (!resAtom) {
70
- // Input logic
71
- if (a == null && name == null)
72
- return null;
73
-
74
- let s: string;
75
- let biotype: string;
76
- if (name == null) {
77
- biotype = (a as org.helm.IAtom).biotype();
78
- s = (a as org.helm.IAtom).elem;
79
- } else {
80
- biotype = a as string;
81
- s = org.helm.webeditor.IO.trimBracket(name);
82
- }
83
- resAtom = new DummyWebEditorMonomer(biotype, s);
84
- //hasMissing = true;
85
- }
86
- return resAtom;
87
- };
88
- // Preventing alert message box for missing monomers with compressed Scilligence.JSDraw2.Lite.js
89
- scil.Utils.alert = (s: string): void => {
90
- this.logger.warning(`${logPrefix}, scil.Utils.alert() s = 's'.`);
91
- };
92
- this.logger.debug(`${logPrefix}, editor.setData( '${helmStr}' )`);
93
- this.editor.setData(helmStr, 'helm');
94
- } finally {
95
- monomers.getMonomer = originalGetMonomer;
96
- scil.Utils.alert = originalAlert;
97
- }
62
+ // getMonomerOverrideAndLogAlert(
63
+ // this.monomerLib,
64
+ // getMonomerPatched,
65
+ // () => {
66
+ // this.logger.debug(`${logPrefix}, editor.setData( '${helmStr}' )`);
67
+ // this.editor.setData(helmStr, 'helm');
68
+ // }, this.logger);
69
+ this.logger.debug(`${logPrefix}, editor.setData( '${helmStr}' )`);
70
+ this.editor.setData(helmStr, 'helm');
98
71
  }
99
- if (!helmStr || hasMissing)
72
+ if (!helmStr)
100
73
  this.editor.reset();
101
74
 
102
75
  const bBox = (this.editor.div.children[0] as SVGSVGElement).getBBox();
@@ -155,3 +128,4 @@ export class HelmService extends HelmServiceBase {
155
128
 
156
129
  async reset(): Promise<void> { }
157
130
  }
131
+
@@ -1,9 +1,8 @@
1
+ import * as grok from 'datagrok-api/grok';
2
+ import * as ui from 'datagrok-api/ui';
1
3
  import * as DG from 'datagrok-api/dg';
2
4
 
3
- import * as scil from 'scil';
4
- import * as org from 'org';
5
-
6
- import {_package} from '../package';
5
+ import {OrgHelmModule, ScilModule} from '../types';
7
6
 
8
7
  import {
9
8
  RGROUP_CAP_GROUP_NAME,
@@ -16,6 +15,11 @@ import {
16
15
  SDF_MONOMER_NAME
17
16
  } from '../constants';
18
17
 
18
+ import {getMonomerLib} from '../package';
19
+
20
+ declare const scil: ScilModule;
21
+ declare const org: OrgHelmModule;
22
+
19
23
  // Global flag is for replaceAll
20
24
  const helmGapStartRe = /\{(\*\.)+/g;
21
25
  const helmGapIntRe = /\.(\*\.)+/g;
@@ -109,19 +113,9 @@ export function parseHelm(s: string): string[] {
109
113
  // }
110
114
 
111
115
  /** Searches monomers of helmString for missed. */
112
- export function findMonomers(monomerSymbolList: string[]): Set<string> {
113
- const types = Object.keys(org.helm.webeditor.monomerTypeList());
114
- const monomers: any = [];
115
- const monomerNames: any = [];
116
- for (let i = 0; i < types.length; i++) {
117
- // @ts-ignore
118
- // eslint-disable-next-line new-cap
119
- monomers.push(new org.helm.webeditor.Monomers.getMonomerSet(types[i]));
120
- Object.keys(monomers[i]).forEach((k) => {
121
- monomerNames.push(monomers[i][k].id);
122
- });
123
- }
124
- return new Set(monomerSymbolList.filter((val) => !monomerNames.includes(val)));
116
+ export function findMonomers(seqMonomerSymbolList: string[]): Set<string> {
117
+ const monomerLib = getMonomerLib();
118
+ return new Set(seqMonomerSymbolList.filter((s) => monomerLib?.getMonomer(null, s)));
125
119
  }
126
120
 
127
121
  function findClosing(s: string, start: number, open: string, close: string) {
@@ -7,22 +7,34 @@ import $ from 'cash-dom';
7
7
  import {SeqHandler} from '@datagrok-libraries/bio/src/utils/seq-handler';
8
8
  import {NOTATION} from '@datagrok-libraries/bio/src/utils/macromolecule';
9
9
 
10
+ import {JSDraw2HelmModule} from '../types';
10
11
  import {removeGapsFromHelm} from '../utils';
11
12
 
12
- export function getPropertiesDict(seq: string, sh: SeqHandler): {} {
13
- const helmString = sh.isHelm() ? seq : sh.getConverter(NOTATION.HELM)(seq);
14
- // Remove gap symbols for compatibility with WebEditor
15
- const helmString2 = removeGapsFromHelm(helmString);
13
+ declare const JSDraw2: JSDraw2HelmModule;
16
14
 
15
+ export class SeqPropertiesError extends Error {
16
+ constructor(message?: string, options?: ErrorOptions) {
17
+ super(message, options);
18
+ }
19
+ }
20
+
21
+ export function getPropertiesDict(seq: string, sh: SeqHandler): {} {
17
22
  const host = ui.div([], {style: {width: '0', height: '0'}});
18
23
  document.documentElement.appendChild(host);
19
24
  try {
25
+ if (seq.length > 1000)
26
+ throw new SeqPropertiesError('Too long sequence to calculate molecular properties.');
27
+
28
+ const helmString = sh.isHelm() ? seq : sh.getConverter(NOTATION.HELM)(seq);
29
+ // Remove gap symbols for compatibility with WebEditor
30
+ const helmString2 = removeGapsFromHelm(helmString);
31
+
20
32
  const editor = new JSDraw2.Editor(host, {viewonly: true});
21
33
  editor.setHelm(helmString2);
22
34
 
23
35
  const formula = editor.getFormula(true);
24
36
  const molWeight = Math.round(editor.getMolWeight() * 100) / 100;
25
- const coef = Math.round(editor.getExtinctionCoefficient(true) * 100) / 100;
37
+ const coef = Math.round(editor.getExtinctionCoefficient() * 100) / 100;
26
38
  return {
27
39
  'formula': formula.replace(/<sub>/g, '').replace(/<\/sub>/g, ''),
28
40
  'molecular weight': molWeight,
@@ -37,8 +49,16 @@ export function getPropertiesDict(seq: string, sh: SeqHandler): {} {
37
49
 
38
50
  export function getPropertiesWidget(value: DG.SemanticValue): DG.Widget {
39
51
  const sh = SeqHandler.forColumn(value.cell.column);
40
- const propDict = getPropertiesDict(value.value, sh);
41
- return new DG.Widget(
42
- ui.tableFromMap(propDict)
43
- );
52
+ try {
53
+ const propDict = getPropertiesDict(value.value, sh);
54
+ return new DG.Widget(
55
+ ui.tableFromMap(propDict)
56
+ );
57
+ } catch (err: any) {
58
+ if (err instanceof SeqPropertiesError) {
59
+ // Display warning from err.message
60
+ return new DG.Widget(ui.divText(err.message));
61
+ }
62
+ throw err;
63
+ }
44
64
  }
package/tsconfig.json CHANGED
@@ -65,7 +65,7 @@
65
65
  "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
66
66
 
67
67
  /* Advanced Options */
68
- "skipLibCheck": false, /* Skip type checking of declaration files. */
68
+ "skipLibCheck": true, /* Skip type checking of declaration files. */
69
69
  "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
70
70
  //"jsx": "react"
71
71
  }