@datagrok/sequence-translator 1.5.1 → 1.5.3

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.5.1",
4
+ "version": "1.5.3",
5
5
  "author": {
6
6
  "name": "Leonid Stolbov",
7
7
  "email": "lstolbov@datagrok.ai"
@@ -31,7 +31,9 @@ export class RuleInputs extends ActiveFiles {
31
31
  const editIcon = ui.icons.edit(async () => {
32
32
  const rulesManager = await RulesManager.getInstance(available);
33
33
  //await rulesManager.show();
34
- grok.shell.addView(await rulesManager.getView());
34
+ // close the dialogs, its easier if we just close it from active dialogs with filtering
35
+ DG.Dialog.getOpenDialogs()?.filter((d) => d.root.contains(editIcon)).forEach((d) => d.close());
36
+ await rulesManager.getAndAddView();
35
37
  }, 'Edit rules');
36
38
 
37
39
  res.addOptions(editIcon);
@@ -153,10 +155,13 @@ export class Rules {
153
155
 
154
156
 
155
157
  for (let i = 0; i < length; i++) {
158
+ const fSplit = firstMonomerCol.get(i).split(',');
159
+ const sSplit = secondMonomerCol.get(i).split(',');
160
+
156
161
  const rule = {
157
162
  code: codeCol.get(i),
158
- firstMonomers: firstMonomerCol.get(i).split(','),
159
- secondMonomers: secondMonomerCol.get(i).split(','),
163
+ firstMonomers: fSplit[0] !== '' ? fSplit : [],
164
+ secondMonomers: sSplit[0] !== '' ? sSplit : [],
160
165
  firstLinkingGroup: firstLink.get(i),
161
166
  secondLinkingGroup: secondLink.get(i)
162
167
  };
@@ -180,11 +185,13 @@ export class Rules {
180
185
 
181
186
  for (let i = 0; i < length; i++) {
182
187
  const smartsReaction = `${firstReactant.get(i)}.${secondReactant.get(i)}>>${product.get(i)}`;
188
+ const fSplit = firstMonomerCol.get(i).split(',');
189
+ const sSplit = secondMonomerCol.get(i).split(',');
183
190
 
184
191
  const rule = {
185
192
  code: codeCol.get(i),
186
- firstMonomers: firstMonomerCol.get(i).split(','),
187
- secondMonomers: secondMonomerCol.get(i).split(','),
193
+ firstMonomers: fSplit[0] !== '' ? fSplit : [],
194
+ secondMonomers: sSplit[0] !== '' ? sSplit : [],
188
195
  reaction: smartsReaction,
189
196
  name: name.get(i)
190
197
  };
@@ -11,14 +11,15 @@ export class RulesManager {
11
11
  linkRuleDataFrame: DG.DataFrame;
12
12
  synthRuleDataFrame: DG.DataFrame;
13
13
  fileName: string;
14
- v: DG.View | null = null;
14
+ private v: DG.ViewBase | null = null;
15
15
 
16
16
  homoDimerInput: DG.InputBase;
17
17
  heteroDimerInput: DG.InputBase;
18
18
 
19
19
  currentTab = '';
20
20
 
21
- private static instance: RulesManager;
21
+ // every rule set will have its editor instance
22
+ private static instances: Record<string, RulesManager> = {};
22
23
 
23
24
  protected constructor(rules: Rules, fileName: string) {
24
25
  this.rules = rules;
@@ -34,22 +35,43 @@ export class RulesManager {
34
35
  );
35
36
  }
36
37
 
37
- async getView(): Promise<DG.ViewBase> {
38
+ async getAndAddView(): Promise<DG.ViewBase> {
39
+ if (this.v) {
40
+ try {
41
+ //find active view; name is unique due to file names in name
42
+ const activeView = Array.from(grok.shell.views).find((v) => v.name === this.v!.name);
43
+ if (!activeView) {
44
+ this.v.detach();
45
+ this.v.close();
46
+ throw new Error('View is closed, making it null in catch statement');
47
+ }
48
+ // switch to existing view
49
+ grok.shell.v = activeView;
50
+ } catch (_) {
51
+ //here we only come if some error is caused due to double detaching, so no handling needed
52
+ this.v = null;
53
+ }
54
+ }
55
+
38
56
  if (!this.v) {
39
57
  this.v = DG.View.create();
40
- this.v.name = 'Manage Polytool Rules';
58
+ this.v.name = `Manage Polytool Rules - ${this.fileName}`;
41
59
  this.v.append(await this.getForm());
60
+ this.v = grok.shell.addView(this.v);
61
+ grok.shell.v = this.v!; // just in any case, to make sure it switches
62
+ return this.v;
42
63
  }
43
64
 
44
65
  return this.v;
45
66
  }
46
67
 
47
68
  public static async getInstance(name: string): Promise<RulesManager> {
48
- if (!this.instance) {
69
+ // every rull will have its own instance
70
+ if (!this.instances[name]) {
49
71
  const rules = await getRules([name]);
50
- this.instance = new RulesManager(rules, name);
72
+ this.instances[name] = new RulesManager(rules, name);
51
73
  }
52
- return this.instance;
74
+ return this.instances[name]!;
53
75
  }
54
76
 
55
77
  save(): void {
@@ -84,7 +106,7 @@ export class RulesManager {
84
106
  const code = this.rules.linkRules[i].code;
85
107
  const [firstMonomers, secondMonomers] = getMonomerPairs(this.rules.linkRules[i]);
86
108
  for (let j = 0; j < firstMonomers.length; j++) {
87
- const seq = `${firstMonomers[j]}(${code})-A-A-A-A-${secondMonomers[j]}(${code})-A`;
109
+ const seq = `${firstMonomers[j]}(${code})-A-A-A-A-${secondMonomers[j]}(${code})`;
88
110
  seqs.push(seq);
89
111
  }
90
112
  }