@datagrok/helm 2.2.0 → 2.2.1
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/CHANGELOG.md +11 -0
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +10 -10
- package/src/cell-renderer.ts +5 -3
- package/src/constants.ts +0 -11
- package/src/helm-monomer-placer.ts +3 -19
- package/src/package-test.ts +5 -2
- package/src/package-utils.ts +133 -0
- package/src/package.ts +33 -87
- package/src/tests/get-monomer-tests.ts +210 -0
- package/src/tests/helm-tests.ts +1 -0
- package/src/types/index.ts +0 -0
- package/src/utils/dummy-monomer.ts +163 -48
- package/src/utils/get-hovered.ts +7 -18
- package/src/utils/get-monomer.ts +111 -0
- package/src/utils/helm-grid-cell-renderer.ts +3 -5
- package/src/utils/helm-service.ts +14 -41
- /package/src/tests/{get-molfiles.ts → get-molfiles-tests.ts} +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as grok from 'datagrok-api/grok';
|
|
2
|
+
import * as ui from 'datagrok-api/ui';
|
|
3
|
+
import * as DG from 'datagrok-api/dg';
|
|
4
|
+
|
|
5
|
+
import * as org from 'org';
|
|
6
|
+
import * as scil from 'scil';
|
|
7
|
+
import * as JSDraw2 from 'JSDraw2';
|
|
8
|
+
import Atom = JSDraw2.Atom;
|
|
9
|
+
|
|
10
|
+
import {ILogger} from '@datagrok-libraries/bio/src/utils/logger';
|
|
11
|
+
import {HelmType, IMonomerLib, Monomer, WebEditorMonomer} from '@datagrok-libraries/bio/src/types';
|
|
12
|
+
import {helmTypeToPolymerType} from '@datagrok-libraries/bio/src/monomer-works/monomer-works';
|
|
13
|
+
import {PolymerTypes, HelmTypes} from '@datagrok-libraries/bio/src/utils/const';
|
|
14
|
+
import {
|
|
15
|
+
HELM_REQUIRED_FIELD as REQ
|
|
16
|
+
} from '@datagrok-libraries/bio/src/utils/const';
|
|
17
|
+
|
|
18
|
+
import {AmbiguousWebEditorMonomer, GapWebEditorMonomer, LibraryWebEditorMonomer} from './dummy-monomer';
|
|
19
|
+
|
|
20
|
+
const monomerRe = /[\w()]+/;
|
|
21
|
+
//** Do not mess with monomer symbol with parenthesis enclosed in square brackets */
|
|
22
|
+
const ambMonomerRe = RegExp(String.raw`\(${monomerRe}(,${monomerRe})+\)`);
|
|
23
|
+
|
|
24
|
+
export type GetMonomerResType = WebEditorMonomer | null;
|
|
25
|
+
|
|
26
|
+
export type GetMonomerFunc = (a: Atom<HelmType> | HelmType, name: string | undefined) => GetMonomerResType;
|
|
27
|
+
type GetMonomerOverridingFunc = (
|
|
28
|
+
a: Atom<HelmType> | HelmType, name: string, monomerLib: IMonomerLib,
|
|
29
|
+
originalGetMonomer: (a: Atom<HelmType> | HelmType, name: string) => GetMonomerResType) => GetMonomerResType;
|
|
30
|
+
|
|
31
|
+
export function getMonomerOverrideAndLogAlert(
|
|
32
|
+
monomerLib: IMonomerLib, getMonomerOverriding: GetMonomerOverridingFunc, trigger: () => void, logger: ILogger,
|
|
33
|
+
): void {
|
|
34
|
+
const logPrefix = 'Helm: overrideGetMonomerAndAlert()';
|
|
35
|
+
const monomers = org.helm.webeditor.Monomers;
|
|
36
|
+
const getMonomerOriginal = monomers.getMonomer.bind(monomers);
|
|
37
|
+
const alertOriginal = scil.Utils.alert;
|
|
38
|
+
try {
|
|
39
|
+
org.helm.webeditor.Monomers.getMonomer = (
|
|
40
|
+
a: Atom<HelmType> | HelmType, name: string
|
|
41
|
+
): GetMonomerResType => {
|
|
42
|
+
return getMonomerOverriding(a, name, monomerLib, getMonomerOriginal);
|
|
43
|
+
};
|
|
44
|
+
// Preventing alert message box for missing monomers with compressed Scilligence.JSDraw2.Lite.js
|
|
45
|
+
scil.Utils.alert = (s: string): void => {
|
|
46
|
+
logger.warning(`${logPrefix}, scil.Utils.alert() s = 's'.`);
|
|
47
|
+
};
|
|
48
|
+
trigger();
|
|
49
|
+
} finally {
|
|
50
|
+
monomers.getMonomer = getMonomerOriginal;
|
|
51
|
+
scil.Utils.alert = alertOriginal;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Inputs logic */
|
|
56
|
+
export function getMonomerHandleArgs(
|
|
57
|
+
a: Atom<HelmType> | HelmType, name?: string
|
|
58
|
+
): [/** biotype */ HelmType, /** elem */ string] {
|
|
59
|
+
let biotype: HelmType;
|
|
60
|
+
let elem: string;
|
|
61
|
+
if ((a as Atom<HelmType>).T === 'ATOM') {
|
|
62
|
+
biotype = (a as Atom<HelmType>).biotype();
|
|
63
|
+
elem = (a as Atom<HelmType>).elem;
|
|
64
|
+
} else {
|
|
65
|
+
biotype = a as HelmType;
|
|
66
|
+
elem = org.helm.webeditor.IO.trimBracket(name!);
|
|
67
|
+
}
|
|
68
|
+
return [biotype, elem];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/** Substitutes {@link org.helm.webeditor.Monomers.getMonomer()} */
|
|
73
|
+
export function getWebEditorMonomer(
|
|
74
|
+
monomerLib: IMonomerLib,
|
|
75
|
+
a: Atom<HelmType> | HelmType, argName: string,
|
|
76
|
+
): WebEditorMonomer | null {
|
|
77
|
+
const [biotype, elem] = getMonomerHandleArgs(a, argName);
|
|
78
|
+
const pt = helmTypeToPolymerType(biotype);
|
|
79
|
+
|
|
80
|
+
/** Get or create {@link Monomer} object (in case it is missing in monomer library current config) */
|
|
81
|
+
let m: Monomer | null = monomerLib.getMonomer(pt, elem);
|
|
82
|
+
if (m && biotype == HelmTypes.LINKER && m[REQ.RGROUPS].length != 2) {
|
|
83
|
+
// Web Editor expects null
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (m && biotype == HelmTypes.SUGAR && m[REQ.RGROUPS].length != 3) {
|
|
87
|
+
// Web Editor expects null
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (!m /* && biotype != HelmTypes.LINKER*/)
|
|
91
|
+
m = monomerLib.addMissingMonomer(pt, elem);
|
|
92
|
+
|
|
93
|
+
/** Get or create {@link org,helm.WebEditorMonomer} */
|
|
94
|
+
let resWem: WebEditorMonomer | undefined = m.wem;
|
|
95
|
+
if (!resWem) {
|
|
96
|
+
if (elem === '*')
|
|
97
|
+
resWem = m.wem = new GapWebEditorMonomer(biotype, elem);
|
|
98
|
+
else if (
|
|
99
|
+
(biotype === 'HELM_NUCLETIDE' && elem === 'N') ||
|
|
100
|
+
(biotype === 'HELM_AA' && elem === 'X') ||
|
|
101
|
+
(biotype === 'HELM_CHEM' && false) || // TODO: Ambiguous monomer for CHEM
|
|
102
|
+
ambMonomerRe.test(elem) // e.g. (A,R,_)
|
|
103
|
+
)
|
|
104
|
+
resWem = m.wem = new AmbiguousWebEditorMonomer(biotype, elem);
|
|
105
|
+
|
|
106
|
+
if (!resWem)
|
|
107
|
+
resWem = m.wem = LibraryWebEditorMonomer.fromMonomer(biotype, m);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return resWem;
|
|
111
|
+
}
|
|
@@ -16,7 +16,6 @@ import {_getHelmService} from '../package-utils';
|
|
|
16
16
|
import {errInfo} from '@datagrok-libraries/bio/src/utils/err-info';
|
|
17
17
|
import {ILogger} from '@datagrok-libraries/bio/src/utils/logger';
|
|
18
18
|
import {getGridCellRendererBack} from '@datagrok-libraries/bio/src/utils/cell-renderer-back-base';
|
|
19
|
-
import {IMonomerLib} from '@datagrok-libraries/bio/src/types/index';
|
|
20
19
|
|
|
21
20
|
import {_package, getMonomerLib} from '../package';
|
|
22
21
|
|
|
@@ -44,15 +43,12 @@ class WrapLogger implements ILogger {
|
|
|
44
43
|
|
|
45
44
|
export class HelmGridCellRendererBack extends CellRendererBackAsyncBase<HelmProps, HelmAux> {
|
|
46
45
|
private _auxList: (HelmAux | null)[];
|
|
47
|
-
private readonly monomerLib: IMonomerLib;
|
|
48
46
|
|
|
49
47
|
constructor(
|
|
50
48
|
gridCol: DG.GridColumn | null,
|
|
51
49
|
tableCol: DG.Column<string>,
|
|
52
50
|
) {
|
|
53
51
|
super(gridCol, tableCol, new WrapLogger(_package.logger) /* _package.logger */, true);
|
|
54
|
-
this.monomerLib = getMonomerLib();
|
|
55
|
-
this.subs.push(this.monomerLib.onChanged.subscribe(this.monomerLibOnChanged.bind(this)));
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
protected override reset(): void {
|
|
@@ -146,7 +142,9 @@ export class HelmGridCellRendererBack extends CellRendererBackAsyncBase<HelmProp
|
|
|
146
142
|
const seqMonomer: ISeqMonomer | null = getHoveredMonomerFromEditorMol(argsX, argsY, gridCell, editorMol);
|
|
147
143
|
|
|
148
144
|
if (seqMonomer) {
|
|
149
|
-
const
|
|
145
|
+
const monomerLib = getMonomerLib();
|
|
146
|
+
const tooltipEl = monomerLib ? monomerLib.getTooltip(seqMonomer.polymerType, seqMonomer.symbol) :
|
|
147
|
+
ui.divText('Monomer library is not available');
|
|
150
148
|
ui.tooltip.show(tooltipEl, e.x + 16, e.y + 16);
|
|
151
149
|
} else {
|
|
152
150
|
// Tooltip for missing monomers
|
|
@@ -10,17 +10,17 @@ import $ from 'cash-dom';
|
|
|
10
10
|
import {Subject, Unsubscribable} from 'rxjs';
|
|
11
11
|
|
|
12
12
|
import {errInfo} from '@datagrok-libraries/bio/src/utils/err-info';
|
|
13
|
-
import {
|
|
13
|
+
import {IMonomerLib} from '@datagrok-libraries/bio/src/types/index';
|
|
14
14
|
import {RenderTask} from '@datagrok-libraries/bio/src/utils/cell-renderer-async-base';
|
|
15
|
+
import {HelmAux, HelmProps, HelmServiceBase} from '@datagrok-libraries/bio/src/viewers/helm-service';
|
|
15
16
|
import {svgToImage} from '@datagrok-libraries/utils/src/svg';
|
|
16
17
|
|
|
17
18
|
import {_package} from '../package';
|
|
18
|
-
import {DummyWebEditorMonomer} from './dummy-monomer';
|
|
19
19
|
|
|
20
20
|
export class HelmService extends HelmServiceBase {
|
|
21
21
|
private readonly hostDiv: HTMLDivElement;
|
|
22
22
|
|
|
23
|
-
private editor
|
|
23
|
+
private editor!: JSDraw2.Editor;
|
|
24
24
|
private image: HTMLImageElement | null = null;
|
|
25
25
|
|
|
26
26
|
constructor() {
|
|
@@ -57,46 +57,18 @@ export class HelmService extends HelmServiceBase {
|
|
|
57
57
|
this.editor.options.height = task.props.height;
|
|
58
58
|
this.editor.resize(task.props.width, task.props.height);
|
|
59
59
|
const helmStr = task.props.helm;
|
|
60
|
-
let hasMissing: boolean = false;
|
|
61
60
|
if (helmStr) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
}
|
|
61
|
+
// getMonomerOverrideAndLogAlert(
|
|
62
|
+
// this.monomerLib,
|
|
63
|
+
// getMonomerPatched,
|
|
64
|
+
// () => {
|
|
65
|
+
// this.logger.debug(`${logPrefix}, editor.setData( '${helmStr}' )`);
|
|
66
|
+
// this.editor.setData(helmStr, 'helm');
|
|
67
|
+
// }, this.logger);
|
|
68
|
+
this.logger.debug(`${logPrefix}, editor.setData( '${helmStr}' )`);
|
|
69
|
+
this.editor.setData(helmStr, 'helm');
|
|
98
70
|
}
|
|
99
|
-
if (!helmStr
|
|
71
|
+
if (!helmStr)
|
|
100
72
|
this.editor.reset();
|
|
101
73
|
|
|
102
74
|
const bBox = (this.editor.div.children[0] as SVGSVGElement).getBBox();
|
|
@@ -155,3 +127,4 @@ export class HelmService extends HelmServiceBase {
|
|
|
155
127
|
|
|
156
128
|
async reset(): Promise<void> { }
|
|
157
129
|
}
|
|
130
|
+
|
|
File without changes
|