@datagrok/sequence-translator 1.4.10 → 1.5.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.
- package/CHANGELOG.md +6 -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/files/polytool-rules/rules_example.json +35 -38
- package/package.json +1 -1
- package/src/polytool/conversion/pt-chain.ts +84 -47
- package/src/polytool/conversion/pt-conversion.ts +1 -2
- package/src/polytool/conversion/pt-misc.ts +43 -33
- package/src/polytool/conversion/pt-rules.ts +231 -0
- package/src/polytool/conversion/rule-manager.ts +205 -0
- package/src/polytool/pt-convert-editor.ts +1 -1
- package/src/polytool/pt-dialog.ts +1 -1
- package/src/polytool/pt-enumerate-seq-dialog.ts +3 -3
- package/src/polytool/pt-unrule-dialog.ts +1 -1
- package/src/polytool/pt-unrule.ts +1 -1
- package/src/tests/polytool-chain-from-notation-tests.ts +6 -14
- package/src/tests/polytool-chain-parse-notation-tests.ts +1 -1
- package/src/tests/polytool-convert-tests.ts +3 -2
- package/src/tests/polytool-unrule-tests.ts +1 -1
- package/src/tests/toAtomicLevel-tests.ts +5 -5
- package/src/polytool/pt-rules.ts +0 -93
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import * as DG from 'datagrok-api/dg';
|
|
2
|
+
import * as grok from 'datagrok-api/grok';
|
|
3
|
+
import {getMonomerPairs, getRules, Rules} from './pt-rules';
|
|
4
|
+
import {_package, applyNotationProviderForCyclized} from '../../package';
|
|
5
|
+
import {getHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
|
|
6
|
+
import {doPolyToolConvert} from './pt-conversion';
|
|
7
|
+
import {NOTATION} from '@datagrok-libraries/bio/src/utils/macromolecule/consts';
|
|
8
|
+
|
|
9
|
+
export class RulesManager {
|
|
10
|
+
rules: Rules;
|
|
11
|
+
linkRuleDataFrame: DG.DataFrame;
|
|
12
|
+
synthRuleDataFrame: DG.DataFrame;
|
|
13
|
+
fileName: string;
|
|
14
|
+
v: DG.View | null = null;
|
|
15
|
+
|
|
16
|
+
homoDimerInput: DG.InputBase;
|
|
17
|
+
heteroDimerInput: DG.InputBase;
|
|
18
|
+
|
|
19
|
+
currentTab = '';
|
|
20
|
+
|
|
21
|
+
private static instance: RulesManager;
|
|
22
|
+
|
|
23
|
+
protected constructor(rules: Rules, fileName: string) {
|
|
24
|
+
this.rules = rules;
|
|
25
|
+
this.linkRuleDataFrame = this.rules.getLinkRulesDf();
|
|
26
|
+
this.synthRuleDataFrame = this.rules.getSynthesisRulesDf();
|
|
27
|
+
this.fileName = fileName;
|
|
28
|
+
|
|
29
|
+
const homoValue = this.rules.homodimerCode ? this.rules.homodimerCode : '';
|
|
30
|
+
const heteroValue = this.rules.heterodimerCode ? this.rules.heterodimerCode : '';
|
|
31
|
+
this.homoDimerInput = ui.input.string('Homo dimer', {value: homoValue, onValueChanged: () => {}, nullable: false});
|
|
32
|
+
this.heteroDimerInput = ui.input.string(
|
|
33
|
+
'Hetero dimer', {value: heteroValue, onValueChanged: () => {}, nullable: false}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async getView(): Promise<DG.ViewBase> {
|
|
38
|
+
if (!this.v) {
|
|
39
|
+
this.v = DG.View.create();
|
|
40
|
+
this.v.append(await this.getForm());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this.v;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public static async getInstance(name: string): Promise<RulesManager> {
|
|
47
|
+
if (!this.instance) {
|
|
48
|
+
const rules = await getRules([name]);
|
|
49
|
+
this.instance = new RulesManager(rules, name);
|
|
50
|
+
}
|
|
51
|
+
return this.instance;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
save(): void {
|
|
55
|
+
this.rules.homodimerCode = this.homoDimerInput.value;
|
|
56
|
+
this.rules.heterodimerCode = this.heteroDimerInput.value;
|
|
57
|
+
this.rules.setLinkRules(this.linkRuleDataFrame);
|
|
58
|
+
this.rules.setSynthesisRules(this.synthRuleDataFrame);
|
|
59
|
+
|
|
60
|
+
const saveable = {
|
|
61
|
+
homodimerCode: this.rules.homodimerCode,
|
|
62
|
+
heterodimerCode: this.rules.heterodimerCode,
|
|
63
|
+
linkRules: this.rules.linkRules,
|
|
64
|
+
reactionRules: this.rules.reactionRules,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const rrrr = JSON.stringify(saveable, undefined, 2);
|
|
68
|
+
_package.files.writeAsText(`polytool-rules/${this.fileName}`, rrrr);
|
|
69
|
+
grok.shell.info(`Polytool rules at ${this.fileName} was updated`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private createGridDiv(name: string, grid: DG.Grid) {
|
|
73
|
+
const header = ui.h1(name, 'polytool-grid-header');
|
|
74
|
+
grid.root.prepend(header);
|
|
75
|
+
grid.root.style.height = '100%';
|
|
76
|
+
return grid.root;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
async getLinkExamplesGrid() {
|
|
80
|
+
const seqs: string[] = [];
|
|
81
|
+
|
|
82
|
+
for (let i = 0; i < this.rules.linkRules.length; i++) {
|
|
83
|
+
const code = this.rules.linkRules[i].code;
|
|
84
|
+
const [firstMonomers, secondMonomers] = getMonomerPairs(this.rules.linkRules[i]);
|
|
85
|
+
for (let j = 0; j < firstMonomers.length; j++) {
|
|
86
|
+
const seq = `${firstMonomers[j]}(${code})-A-A-A-A-${secondMonomers[j]}(${code})-A`;
|
|
87
|
+
seqs.push(seq);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const helmHelper = await getHelmHelper();
|
|
91
|
+
|
|
92
|
+
const helms = doPolyToolConvert(seqs, this.rules, helmHelper);
|
|
93
|
+
|
|
94
|
+
const initCol = DG.Column.fromStrings('monomers', seqs);
|
|
95
|
+
const helmCol = DG.Column.fromStrings('helm', helms);
|
|
96
|
+
|
|
97
|
+
initCol.semType = DG.SEMTYPE.MACROMOLECULE;
|
|
98
|
+
applyNotationProviderForCyclized(initCol, '-');
|
|
99
|
+
|
|
100
|
+
helmCol.semType = DG.SEMTYPE.MACROMOLECULE;
|
|
101
|
+
helmCol.meta.units = NOTATION.HELM;
|
|
102
|
+
helmCol.setTag(DG.TAGS.CELL_RENDERER, 'helm');
|
|
103
|
+
return DG.DataFrame.fromColumns([
|
|
104
|
+
initCol, helmCol
|
|
105
|
+
]).plot.grid();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async getReactionExamplesGrid() {
|
|
109
|
+
const seqs: string[] = [];
|
|
110
|
+
|
|
111
|
+
for (let i = 0; i < this.rules.reactionRules.length; i++) {
|
|
112
|
+
const code = this.rules.reactionRules[i].code;
|
|
113
|
+
const [firstMonomers, secondMonomers] = getMonomerPairs(this.rules.reactionRules[i]);
|
|
114
|
+
for (let j = 0; j < firstMonomers.length; j++) {
|
|
115
|
+
const seq = `${firstMonomers[j]}(${code})-A-A-A-A-${secondMonomers[j]}(${code})-A`;
|
|
116
|
+
seqs.push(seq);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const helmHelper = await getHelmHelper();
|
|
120
|
+
|
|
121
|
+
const helms = doPolyToolConvert(seqs, this.rules, helmHelper);
|
|
122
|
+
|
|
123
|
+
const initCol = DG.Column.fromStrings('monomers', seqs);
|
|
124
|
+
const helmCol = DG.Column.fromStrings('helm', helms);
|
|
125
|
+
|
|
126
|
+
initCol.semType = DG.SEMTYPE.MACROMOLECULE;
|
|
127
|
+
applyNotationProviderForCyclized(initCol, '-');
|
|
128
|
+
|
|
129
|
+
helmCol.semType = DG.SEMTYPE.MACROMOLECULE;
|
|
130
|
+
helmCol.meta.units = NOTATION.HELM;
|
|
131
|
+
helmCol.setTag(DG.TAGS.CELL_RENDERER, 'helm');
|
|
132
|
+
return DG.DataFrame.fromColumns([
|
|
133
|
+
initCol, helmCol
|
|
134
|
+
]).plot.grid();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getForm() {
|
|
138
|
+
inputsTabControl: DG.TabControl;
|
|
139
|
+
|
|
140
|
+
const dimerInputsDiv = ui.divV([
|
|
141
|
+
this.homoDimerInput,
|
|
142
|
+
this.heteroDimerInput,
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
const linkExamples = await this.getLinkExamplesGrid();
|
|
146
|
+
const reactionExamples = await this.getReactionExamplesGrid();
|
|
147
|
+
|
|
148
|
+
const inputsTabControl = ui.tabControl({
|
|
149
|
+
'Links': linkExamples,
|
|
150
|
+
'Reactions': reactionExamples,
|
|
151
|
+
'Dimers': dimerInputsDiv,
|
|
152
|
+
}, false);
|
|
153
|
+
|
|
154
|
+
inputsTabControl.root.style.height = '90%';
|
|
155
|
+
inputsTabControl.root.style.width = '100%';
|
|
156
|
+
inputsTabControl.root.classList.add('rules-manager-form-tab-control');
|
|
157
|
+
inputsTabControl.header.style.marginBottom = '10px';
|
|
158
|
+
|
|
159
|
+
const linksGridDiv = this.createGridDiv('Link rules', this.linkRuleDataFrame.plot.grid({showAddNewRowIcon: true}));
|
|
160
|
+
const reactionsGridDiv =
|
|
161
|
+
this.createGridDiv('Reaction rules', this.synthRuleDataFrame.plot.grid({showAddNewRowIcon: true}));
|
|
162
|
+
|
|
163
|
+
linksGridDiv.style.width = '100%';
|
|
164
|
+
reactionsGridDiv.style.width = '100%';
|
|
165
|
+
|
|
166
|
+
const divs = [linksGridDiv, reactionsGridDiv, ui.div()];
|
|
167
|
+
divs[0].style.removeProperty('display');
|
|
168
|
+
divs[1].style.display = 'none';
|
|
169
|
+
divs[2].style.display = 'none';
|
|
170
|
+
|
|
171
|
+
inputsTabControl.onTabChanged.subscribe(() => {
|
|
172
|
+
this.currentTab = inputsTabControl.currentPane.name;
|
|
173
|
+
|
|
174
|
+
const idx = inputsTabControl.panes.findIndex((p) => p.name == this.currentTab);
|
|
175
|
+
|
|
176
|
+
for (let i = 0; i < divs.length; i++) {
|
|
177
|
+
if (i == idx)
|
|
178
|
+
divs[i].style.removeProperty('display');
|
|
179
|
+
else
|
|
180
|
+
divs[i].style.display = 'none';
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const saveButton = ui.bigButton('Save changes', () => {
|
|
185
|
+
this.save();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
const panel = ui.divV([
|
|
190
|
+
inputsTabControl.root,
|
|
191
|
+
saveButton
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
panel.style.height = '100%';
|
|
195
|
+
panel.style.alignItems = 'center';
|
|
196
|
+
|
|
197
|
+
const form = ui.splitH([
|
|
198
|
+
panel,
|
|
199
|
+
ui.divV(divs, {style: {width: '100%'}})
|
|
200
|
+
], {style: {width: '100%'}}, true);
|
|
201
|
+
form.style.height = '100%';
|
|
202
|
+
return form;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
@@ -4,7 +4,7 @@ import * as DG from 'datagrok-api/dg';
|
|
|
4
4
|
import {_package} from '../package';
|
|
5
5
|
import {defaultErrorHandler} from '../utils/err-info';
|
|
6
6
|
import {PT_UI_DIALOG_CONVERSION, PT_UI_RULES_USED} from './const';
|
|
7
|
-
import {RuleInputs, RULES_PATH, RULES_STORAGE_NAME} from './pt-rules';
|
|
7
|
+
import {RuleInputs, RULES_PATH, RULES_STORAGE_NAME} from './conversion/pt-rules';
|
|
8
8
|
|
|
9
9
|
/** Inputs of polyToolConvert2 package function */
|
|
10
10
|
export enum P {
|
|
@@ -14,7 +14,7 @@ import {addMonomerHoverLink, buildMonomerHoverLink} from '@datagrok-libraries/bi
|
|
|
14
14
|
import {getRdKitModule} from '@datagrok-libraries/bio/src/chem/rdkit-module';
|
|
15
15
|
import {RDModule} from '@datagrok-libraries/chem-meta/src/rdkit-api';
|
|
16
16
|
|
|
17
|
-
import {getRules, RuleInputs, RULES_PATH, RULES_STORAGE_NAME} from './pt-rules';
|
|
17
|
+
import {getRules, RuleInputs, RULES_PATH, RULES_STORAGE_NAME} from './conversion/pt-rules';
|
|
18
18
|
import {doPolyToolConvert} from './conversion/pt-conversion';
|
|
19
19
|
import {getOverriddenLibrary} from './conversion/pt-misc';
|
|
20
20
|
import {defaultErrorHandler} from '../utils/err-info';
|
|
@@ -26,7 +26,7 @@ import {defaultErrorHandler} from '../utils/err-info';
|
|
|
26
26
|
import {PolyToolPlaceholdersBreadthInput} from './pt-placeholders-breadth-input';
|
|
27
27
|
import {PT_UI_DIALOG_ENUMERATION, PT_UI_GET_HELM, PT_UI_HIGHLIGHT_MONOMERS, PT_UI_RULES_USED, PT_UI_USE_CHIRALITY} from './const';
|
|
28
28
|
import {PolyToolDataRole, PolyToolTags} from '../consts';
|
|
29
|
-
import {RuleInputs, RULES_PATH, RULES_STORAGE_NAME} from './pt-rules';
|
|
29
|
+
import {RuleInputs, RULES_PATH, RULES_STORAGE_NAME} from './conversion/pt-rules';
|
|
30
30
|
import {Chain} from './conversion/pt-chain';
|
|
31
31
|
import {polyToolConvert} from './pt-dialog';
|
|
32
32
|
|
|
@@ -627,9 +627,9 @@ async function polyToolEnumerateSeq(
|
|
|
627
627
|
}
|
|
628
628
|
const enumeratorResDf = DG.DataFrame.fromColumns([enumCol]);
|
|
629
629
|
await grok.data.detectSemanticTypes(enumeratorResDf);
|
|
630
|
-
if (dataRole == PolyToolDataRole.template)
|
|
630
|
+
if (dataRole == PolyToolDataRole.template)
|
|
631
631
|
applyNotationProviderForCyclized(enumCol, '-');
|
|
632
|
-
|
|
632
|
+
|
|
633
633
|
|
|
634
634
|
if (toAtomicLevel) {
|
|
635
635
|
let resHelmCol: DG.Column<string>;
|
|
@@ -10,7 +10,7 @@ import {getHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
|
|
|
10
10
|
|
|
11
11
|
import {defaultErrorHandler} from '../utils/err-info';
|
|
12
12
|
import {doPolyToolUnrule} from './pt-unrule';
|
|
13
|
-
import {getRules, RuleInputs, RULES_PATH, RULES_STORAGE_NAME} from './pt-rules';
|
|
13
|
+
import {getRules, RuleInputs, RULES_PATH, RULES_STORAGE_NAME} from './conversion/pt-rules';
|
|
14
14
|
import {PT_ERROR_DATAFRAME, PT_UI_DIALOG_UNRULE, PT_UI_RULES_USED} from './const';
|
|
15
15
|
|
|
16
16
|
import {_package} from '../package';
|
|
@@ -6,7 +6,7 @@ import {errInfo} from '@datagrok-libraries/bio/src/utils/err-info';
|
|
|
6
6
|
|
|
7
7
|
import {Chain} from './conversion/pt-chain';
|
|
8
8
|
import {getPolyToolUnruleDialog} from './pt-unrule-dialog';
|
|
9
|
-
import {Rules} from './pt-rules';
|
|
9
|
+
import {Rules} from './conversion/pt-rules';
|
|
10
10
|
|
|
11
11
|
import {_package} from '../package';
|
|
12
12
|
import {IHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
|
|
@@ -4,7 +4,7 @@ import * as DG from 'datagrok-api/dg';
|
|
|
4
4
|
|
|
5
5
|
import {before, after, category, expect, test, expectArray, testEvent, delay} from '@datagrok-libraries/utils/src/test';
|
|
6
6
|
import {Chain} from '../polytool/conversion/pt-chain';
|
|
7
|
-
import {getRules} from '../polytool/pt-rules';
|
|
7
|
+
import {getRules} from '../polytool/conversion/pt-rules';
|
|
8
8
|
import {getHelmHelper, IHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
|
|
9
9
|
|
|
10
10
|
category('PolyTool: Chain', () => {
|
|
@@ -54,15 +54,11 @@ category('PolyTool: Chain', () => {
|
|
|
54
54
|
templateHelm: 'PEPTIDE1{[(#3)Succ]}' + '|' +
|
|
55
55
|
'PEPTIDE2{[A(CHOL)].F.[C(1)].T.G.H.Y.P.[C(1)].[NH2]}' + '$' +
|
|
56
56
|
'PEPTIDE1,PEPTIDE2,1:R1-1:R1' + '$$$' + 'V2.0',
|
|
57
|
-
mmHelm: 'PEPTIDE1{[Succ].[A(CHOL)].F.C.T.G.H.Y.P.C.[NH2]}'
|
|
58
|
-
'PEPTIDE2{[A(CHOL)].F.C.T.G.H.Y.P.C.[NH2]}' + '$' +
|
|
59
|
-
'PEPTIDE1,PEPTIDE2,1:R1-1:R1' + '|' +
|
|
60
|
-
'PEPTIDE1,PEPTIDE1,4:R3-10:R3' + '|' +
|
|
61
|
-
'PEPTIDE2,PEPTIDE2,3:R3-9:R3' + '$$$V2.0',
|
|
57
|
+
mmHelm: 'PEPTIDE1{[(#3)Succ].[{A(CHOL)].F.C.T.G.H.Y.P.C.[NH2}]}$PEPTIDE1,PEPTIDE1,4:R3-10:R3$$$V2.0',
|
|
62
58
|
},
|
|
63
59
|
tgt: {
|
|
64
60
|
templateChain: {monomerCount: [1, 10], linkageCount: 1},
|
|
65
|
-
mmChain: {monomerCount: [11
|
|
61
|
+
mmChain: {monomerCount: [11], linkageCount: 1}
|
|
66
62
|
}
|
|
67
63
|
},
|
|
68
64
|
'dimerized2': {
|
|
@@ -72,15 +68,11 @@ category('PolyTool: Chain', () => {
|
|
|
72
68
|
'PEPTIDE2{R.F.[C(1)].T.G.H.F.P.[C(1)].[NH2]}' + '|' +
|
|
73
69
|
'PEPTIDE3{[($3)A(CHOL)].F.[C(1)].Y.H.G.D.N.[C(1)].[meI]}' + '$' +
|
|
74
70
|
'PEPTIDE1,PEPTIDE2,1:R1-1:R1' + '$$$' + 'V2.0',
|
|
75
|
-
mmHelm: 'PEPTIDE1{[Succ].R.F.C.T.G.H.F.P.C.[NH2]}'
|
|
76
|
-
'PEPTIDE2{[A(CHOL)].F.C.Y.H.G.D.N.C.[meI]}' + '$' +
|
|
77
|
-
'PEPTIDE1,PEPTIDE2,1:R1-1:R1' + '|' +
|
|
78
|
-
'PEPTIDE1,PEPTIDE1,4:R3-10:R3' + '|' +
|
|
79
|
-
'PEPTIDE2,PEPTIDE2,3:R3-9:R3' + '$$$V2.0',
|
|
71
|
+
mmHelm: 'PEPTIDE1{[($3)Succ].[{R].F.C.T.G.H.F.P.C.[NH2}($3){A(CHOL)].F.[C(1)].Y.H.G.D.N.[C(1)].[meI}]}$PEPTIDE1,PEPTIDE1,4:R3-10:R3$$$V2.0',
|
|
80
72
|
},
|
|
81
73
|
tgt: {
|
|
82
|
-
templateChain: {monomerCount: [1, 10, 10], linkageCount: 1
|
|
83
|
-
mmChain: {monomerCount: [
|
|
74
|
+
templateChain: {monomerCount: [1, 10, 10], linkageCount: 1},
|
|
75
|
+
mmChain: {monomerCount: [20], linkageCount: 1}
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
78
|
};
|
|
@@ -5,7 +5,7 @@ import * as DG from 'datagrok-api/dg';
|
|
|
5
5
|
import {before, after, category, expect, test, expectArray, testEvent, delay} from '@datagrok-libraries/utils/src/test';
|
|
6
6
|
import {Chain} from '../polytool/conversion/pt-chain';
|
|
7
7
|
import {getInnerIdx, getOuterIdx} from '../polytool/conversion/pt-misc';
|
|
8
|
-
import {getRules} from '../polytool/pt-rules';
|
|
8
|
+
import {getRules} from '../polytool/conversion/pt-rules';
|
|
9
9
|
import {getHelmHelper, IHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
|
|
10
10
|
|
|
11
11
|
category('PolyTool: Chain: parseNotation', () => {
|
|
@@ -2,7 +2,8 @@ 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 {before, after, category, expect, test, expectArray, testEvent,
|
|
5
|
+
import {before, after, category, expect, test, expectArray, testEvent, expectObject}
|
|
6
|
+
from '@datagrok-libraries/utils/src/test';
|
|
6
7
|
import {getMonomerLibHelper, IMonomerLibHelper} from '@datagrok-libraries/bio/src/monomer-works/monomer-utils';
|
|
7
8
|
import {UserLibSettings} from '@datagrok-libraries/bio/src/monomer-works/types';
|
|
8
9
|
import {
|
|
@@ -16,7 +17,7 @@ import {getHelmHelper, IHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-
|
|
|
16
17
|
|
|
17
18
|
import {doPolyToolConvert} from '../polytool/conversion/pt-conversion';
|
|
18
19
|
import {getOverriddenLibrary} from '../polytool/conversion/pt-misc';
|
|
19
|
-
import {getRules} from '../polytool/pt-rules';
|
|
20
|
+
import {getRules} from '../polytool/conversion/pt-rules';
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
import {_package} from '../package-test';
|
|
@@ -5,6 +5,6 @@ import * as DG from 'datagrok-api/dg';
|
|
|
5
5
|
import {before, after, category, expect, test, expectArray, testEvent, delay} from '@datagrok-libraries/utils/src/test';
|
|
6
6
|
|
|
7
7
|
import {doPolyToolUnrule} from '../polytool/pt-unrule';
|
|
8
|
-
import {getRules} from '../polytool/pt-rules';
|
|
8
|
+
import {getRules} from '../polytool/conversion/pt-rules';
|
|
9
9
|
|
|
10
10
|
import {_package} from '../package-test';
|
|
@@ -15,8 +15,8 @@ import {getRdKitModule} from '@datagrok-libraries/bio/src/chem/rdkit-module';
|
|
|
15
15
|
import {RDModule} from '@datagrok-libraries/chem-meta/src/rdkit-api';
|
|
16
16
|
|
|
17
17
|
import {_package} from '../package-test';
|
|
18
|
-
import {
|
|
19
|
-
import {getRules, RuleReaction} from '../polytool/pt-rules';
|
|
18
|
+
import {getNewMonomers} from '../polytool/conversion/pt-misc';
|
|
19
|
+
import {getRules, RuleReaction} from '../polytool/conversion/pt-rules';
|
|
20
20
|
|
|
21
21
|
category('toAtomicLevel', () => {
|
|
22
22
|
let userLibSettings: UserLibSettings;
|
|
@@ -78,10 +78,10 @@ category('toAtomicLevel', () => {
|
|
|
78
78
|
const rules = await getRules(['rules_example.json']);
|
|
79
79
|
const reactionRule = rules.reactionRules.find((r) => r.name == 'GGaz')!;
|
|
80
80
|
|
|
81
|
-
const [
|
|
82
|
-
expect(
|
|
81
|
+
const [newSymbols, newMonomers] = getNewMonomers(rdKitModule, systemMonomerLib, reactionRule);
|
|
82
|
+
expect(newSymbols[0], reactionRule.name);
|
|
83
83
|
|
|
84
|
-
const mol = rdKitModule.get_mol(
|
|
84
|
+
const mol = rdKitModule.get_mol(newMonomers[0].molfile);
|
|
85
85
|
try {
|
|
86
86
|
const molInchi = mol.get_inchi();
|
|
87
87
|
const molInchiKey = rdKitModule.get_inchikey_for_inchi(molInchi);
|
package/src/polytool/pt-rules.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import * as DG from 'datagrok-api/dg';
|
|
2
|
-
import * as grok from 'datagrok-api/grok';
|
|
3
|
-
import {ActiveFiles} from '@datagrok-libraries/utils/src/settings/active-files-base';
|
|
4
|
-
|
|
5
|
-
export const RULES_PATH = 'System:AppData/SequenceTranslator/polytool-rules/';
|
|
6
|
-
export const RULES_STORAGE_NAME = 'Polytool';
|
|
7
|
-
export const RULES_TYPE_LINK = 'link';
|
|
8
|
-
export const RULES_TYPE_REACTION = 'reaction';
|
|
9
|
-
export const RULES_TYPE_HOMODIMER = 'fragmentDuplication';
|
|
10
|
-
export const RULES_TYPE_HETERODIMER = 'differentFragments';
|
|
11
|
-
|
|
12
|
-
export class RuleInputs extends ActiveFiles {
|
|
13
|
-
constructor(
|
|
14
|
-
path: string, userStorageName: string, ext: string,
|
|
15
|
-
options?: { onValueChanged: (value: string[]) => void }
|
|
16
|
-
) {
|
|
17
|
-
super(path, userStorageName, ext, options);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type Rules = {
|
|
22
|
-
homodimerCode: string | null,
|
|
23
|
-
heterodimerCode: string | null,
|
|
24
|
-
linkRules: RuleLink[],
|
|
25
|
-
reactionRules: RuleReaction[]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type RuleLink = {
|
|
29
|
-
code: number,
|
|
30
|
-
firstMonomer: string,
|
|
31
|
-
secondMonomer: string,
|
|
32
|
-
firstSubstitution: string,
|
|
33
|
-
secondSubstitution: string,
|
|
34
|
-
firstLinkingGroup: number,
|
|
35
|
-
secondLinkingGroup: number
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type RuleReaction = {
|
|
39
|
-
code: number,
|
|
40
|
-
firstMonomer: string,
|
|
41
|
-
secondMonomer: string,
|
|
42
|
-
reaction: string,
|
|
43
|
-
name: string
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function getRules(ruleFiles: string[]): Promise<Rules> {
|
|
47
|
-
const fileSource = new DG.FileSource(RULES_PATH);
|
|
48
|
-
const linkRules: RuleLink[] = [];
|
|
49
|
-
const reactionRules: RuleReaction[] = [];
|
|
50
|
-
const rules: Rules = {homodimerCode: null, heterodimerCode: null, linkRules: linkRules, reactionRules: reactionRules};
|
|
51
|
-
|
|
52
|
-
for (let i = 0; i < ruleFiles.length; i++) {
|
|
53
|
-
const rulesRaw = await fileSource.readAsText(ruleFiles[i].replace(RULES_PATH, ''));
|
|
54
|
-
const ruleSingle = JSON.parse(rulesRaw);
|
|
55
|
-
for (let j = 0; j < ruleSingle.length; j++) {
|
|
56
|
-
if (ruleSingle[j].type !== undefined && ruleSingle[j].code !== undefined) {
|
|
57
|
-
switch (ruleSingle[j].type) {
|
|
58
|
-
case RULES_TYPE_LINK: {
|
|
59
|
-
const rule = ruleSingle[j].monomericSubstitution;
|
|
60
|
-
rule['code'] = ruleSingle[j].code;
|
|
61
|
-
linkRules.push(rule);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
case RULES_TYPE_REACTION: {
|
|
65
|
-
const rule = ruleSingle[j].monomericSubstitution;
|
|
66
|
-
rule['code'] = ruleSingle[j].code;
|
|
67
|
-
reactionRules.push(rule);
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case RULES_TYPE_HOMODIMER: {
|
|
71
|
-
if (rules.homodimerCode)
|
|
72
|
-
grok.shell.warning(`PolyTool: homodimer code is duplicated in rules.`);
|
|
73
|
-
rules.homodimerCode = ruleSingle[j].code;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
case RULES_TYPE_HETERODIMER: {
|
|
77
|
-
if (rules.heterodimerCode)
|
|
78
|
-
grok.shell.warning(`PolyTool: heterodimer code is duplicated in rules.`);
|
|
79
|
-
rules.heterodimerCode = ruleSingle[j].code;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
default:
|
|
83
|
-
grok.shell.warning(`PolyTool: Unexpected type - '${ruleSingle[j]}'.`);
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
grok.shell.warning('Polytool: rules contain invalid rule');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return rules;
|
|
93
|
-
}
|