@datagrok/sequence-translator 1.9.12 → 1.9.13

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/sequence-translator",
3
3
  "friendlyName": "Sequence Translator",
4
- "version": "1.9.12",
4
+ "version": "1.9.13",
5
5
  "author": {
6
6
  "name": "Davit Rizhinashvili",
7
7
  "email": "drizhinashvili@datagrok.ai"
@@ -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: await this.ruleInputs.getForm(),
52
+ form: rulesForm,
53
53
  }
54
54
  };
55
55
  }