@datagrok/sequence-translator 1.9.12 → 1.9.14
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-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 +7 -0
- package/package.json +3 -3
- package/src/package.g.ts +2 -2
- package/src/polytool/conversion/pt-rules.ts +64 -0
- package/src/polytool/pt-convert-editor.ts +2 -2
- package/test-console-output-1.log +61 -74
- package/test-record-1.mp4 +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/sequence-translator",
|
|
3
3
|
"friendlyName": "Sequence Translator",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.14",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Davit Rizhinashvili",
|
|
7
7
|
"email": "drizhinashvili@datagrok.ai"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@datagrok-libraries/bio": "^5.54.8",
|
|
26
26
|
"@datagrok-libraries/chem-meta": "^1.2.8",
|
|
27
27
|
"@datagrok-libraries/tutorials": "^1.6.1",
|
|
28
|
-
"@datagrok-libraries/utils": "^4.6.
|
|
28
|
+
"@datagrok-libraries/utils": "^4.6.5",
|
|
29
29
|
"@types/react": "^18.0.15",
|
|
30
30
|
"cash-dom": "^8.1.0",
|
|
31
31
|
"datagrok-api": "^1.25.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
55
55
|
"@typescript-eslint/parser": "^7.2.0",
|
|
56
56
|
"css-loader": "^6.7.3",
|
|
57
|
-
"datagrok-tools": "^4.14.
|
|
57
|
+
"datagrok-tools": "^4.14.55",
|
|
58
58
|
"eslint": "^8.57.0",
|
|
59
59
|
"eslint-config-google": "^0.14.0",
|
|
60
60
|
"style-loader": "^3.3.1",
|
package/src/package.g.ts
CHANGED
|
@@ -119,8 +119,8 @@ export async function getPolyToolConvertEditor(call: DG.FuncCall) : Promise<any>
|
|
|
119
119
|
|
|
120
120
|
//input: dataframe table
|
|
121
121
|
//input: column seqCol { caption: Sequence }
|
|
122
|
-
//input: bool generateHelm
|
|
123
|
-
//input: bool chiralityEngine
|
|
122
|
+
//input: bool generateHelm = true
|
|
123
|
+
//input: bool chiralityEngine = true
|
|
124
124
|
//input: object rules
|
|
125
125
|
//output: column result
|
|
126
126
|
//editor: SequenceTranslator:getPolyToolConvertEditor
|
|
@@ -7,6 +7,7 @@ import {RulesManager} from './rule-manager';
|
|
|
7
7
|
import {RuleCards} from './pt-rule-cards';
|
|
8
8
|
import {getMonomerLibHelper} from '@datagrok-libraries/bio/src/monomer-works/monomer-utils';
|
|
9
9
|
import {
|
|
10
|
+
_package,
|
|
10
11
|
PackageFunctions} from '../../package';
|
|
11
12
|
import {MmcrTemps} from '@datagrok-libraries/bio/src/utils/cell-renderer-consts';
|
|
12
13
|
import {ReactionEditorProps} from './rule-reaction-editor';
|
|
@@ -26,6 +27,7 @@ const NAME_FIRST_LINK = 'firstLinkingGroup';
|
|
|
26
27
|
const NAME_SECOND_LINK = 'secondLinkingGroup';
|
|
27
28
|
|
|
28
29
|
export class RuleInputs extends ActiveFiles {
|
|
30
|
+
static ruleDescriptions: Record<string, Promise<HTMLElement>> = {};
|
|
29
31
|
constructor(
|
|
30
32
|
path: string, userStorageName: string, ext: string,
|
|
31
33
|
options?: { onValueChanged: (value: string[]) => void }
|
|
@@ -48,8 +50,70 @@ export class RuleInputs extends ActiveFiles {
|
|
|
48
50
|
|
|
49
51
|
return res;
|
|
50
52
|
}
|
|
53
|
+
|
|
54
|
+
override async getForm(): Promise<HTMLDivElement> {
|
|
55
|
+
const form = await super.getForm();
|
|
56
|
+
this.processRulesForm(form);
|
|
57
|
+
return form;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private async processRulesForm(rulesForm: HTMLElement) {
|
|
61
|
+
const ruleNameLabels = Array.from(rulesForm.getElementsByTagName('label') ?? [])
|
|
62
|
+
.filter((l) => l.textContent?.endsWith('.json') && l.parentElement != null);
|
|
63
|
+
for (const label of ruleNameLabels) {
|
|
64
|
+
const ruleName = label.textContent!.trim();
|
|
65
|
+
const inputRoot = label.parentElement!.getElementsByTagName('input')[0]!;
|
|
66
|
+
ui.tooltip.bind(inputRoot, ui.wait(async () => {
|
|
67
|
+
RuleInputs.ruleDescriptions[ruleName] ??= (async () => {
|
|
68
|
+
try {
|
|
69
|
+
const rule = JSON.parse(await grok.dapi.files.readAsText(`${RULES_PATH}/${ruleName}`));
|
|
70
|
+
const descDiv = ui.divV([ui.h1(ruleName)]);
|
|
71
|
+
const linkRules: RuleLink[] = rule.linkRules ?? [];
|
|
72
|
+
// link rules
|
|
73
|
+
if (linkRules.length > 0) {
|
|
74
|
+
descDiv.appendChild(ui.h3('Linkage Rules'));
|
|
75
|
+
const table = ui.table(linkRules, (item) => [
|
|
76
|
+
item.code?.toString() ?? '',
|
|
77
|
+
shortenToMaxLen((item.firstMonomers ?? []).join(', ')),
|
|
78
|
+
shortenToMaxLen((item.secondMonomers ?? []).join(', ')),
|
|
79
|
+
item.firstLinkingGroup?.toString() ?? '',
|
|
80
|
+
item.secondLinkingGroup?.toString() ?? ''
|
|
81
|
+
], ['Code', 'M1', 'M2', 'L1', 'L2']);
|
|
82
|
+
descDiv.appendChild(table);
|
|
83
|
+
}
|
|
84
|
+
// reaction rules
|
|
85
|
+
const reactionRules: RuleReaction[] = rule.reactionRules ?? [];
|
|
86
|
+
if (reactionRules.length > 0) {
|
|
87
|
+
descDiv.appendChild(ui.h3('Synthesis Rules'));
|
|
88
|
+
const table = ui.table(reactionRules, (item) => [
|
|
89
|
+
item.code?.toString() ?? '',
|
|
90
|
+
shortenToMaxLen((item.firstMonomers ?? []).join(', ')),
|
|
91
|
+
shortenToMaxLen((item.secondMonomers ?? []).join(', ')),
|
|
92
|
+
shortenToMaxLen(item.name ?? ''),
|
|
93
|
+
grok.chem.drawMolecule(item.reaction?.split('>>')[1] ?? '', 70, 70)
|
|
94
|
+
], ['Code', 'M1', 'M2', 'Name', 'Product']);
|
|
95
|
+
descDiv.appendChild(table);
|
|
96
|
+
}
|
|
97
|
+
return descDiv;
|
|
98
|
+
} catch (e: any) {
|
|
99
|
+
_package.logger.error(`Failed to load rule ${ruleName}: ${e?.toString?.()}`);
|
|
100
|
+
console.error(e);
|
|
101
|
+
return ui.divText(`Failed to load rule ${ruleName}`);
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
return await RuleInputs.ruleDescriptions[ruleName];
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
51
108
|
}
|
|
52
109
|
|
|
110
|
+
|
|
111
|
+
function shortenToMaxLen(s: string, maxLen: number = 30): string {
|
|
112
|
+
if (s.length <= maxLen) return s;
|
|
113
|
+
return `${s.substring(0, maxLen)}...`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
53
117
|
export type RuleLink = {
|
|
54
118
|
code: number,
|
|
55
119
|
firstMonomers: string[],
|
|
@@ -35,7 +35,7 @@ export class PolyToolConvertFuncEditor {
|
|
|
35
35
|
|
|
36
36
|
private async initInputs(): Promise<void> {
|
|
37
37
|
const getParam = (pName: string) => this.call.inputParams[pName];
|
|
38
|
-
|
|
38
|
+
const rulesForm = await this.ruleInputs.getForm();
|
|
39
39
|
this.inputs = {
|
|
40
40
|
table: (() => {
|
|
41
41
|
const p = getParam(P.table);
|
|
@@ -49,7 +49,7 @@ export class PolyToolConvertFuncEditor {
|
|
|
49
49
|
chiralityEngine: ui.input.forProperty(getParam(P.chiralityEngine).property),
|
|
50
50
|
rules: {
|
|
51
51
|
header: ui.inlineText([PT_UI_RULES_USED]),
|
|
52
|
-
form:
|
|
52
|
+
form: rulesForm,
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
}
|