@datagrok/sequence-translator 1.5.0 → 1.5.2

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.0",
4
+ "version": "1.5.2",
5
5
  "author": {
6
6
  "name": "Leonid Stolbov",
7
7
  "email": "lstolbov@datagrok.ai"
package/src/package.ts CHANGED
@@ -301,6 +301,9 @@ export async function ptEnumeratorChemApp(): Promise<void> {
301
301
  //input: column col
302
302
  //input: string separator
303
303
  export function applyNotationProviderForCyclized(col: DG.Column<string>, separator: string) {
304
+ col.setTag('aligned', 'SEQ');
305
+ col.setTag('alphabet', 'UN');
306
+ col.setTag('.alphabetIsMultichar', 'true');
304
307
  col.meta.units = NOTATION.CUSTOM;
305
308
  col.tags[PolyToolTags.dataRole] = 'template';
306
309
  col.temp[SeqTemps.notationProvider] = new CyclizedNotationProvider(separator, _package.helmHelper);
@@ -179,10 +179,20 @@ export async function getOverriddenLibrary(rules: Rules): Promise<IMonomerLibBas
179
179
  const rdkit = await getRdKitModule();
180
180
  const argLib: { [symbol: string]: Monomer } = {};
181
181
 
182
+ let names: string [] = [];
183
+ let monomers: Monomer [] = [];
184
+
182
185
  for (let i = 0; i < rules.reactionRules.length; i++) {
183
- const [names, monomers] = getNewMonomers(rdkit, systemMonomerLib, rules.reactionRules[i]);
184
- for (let j = 0; j < names.length; j ++)
185
- argLib[names[j]] = monomers[j];
186
+ try {
187
+ [names, monomers] = getNewMonomers(rdkit, systemMonomerLib, rules.reactionRules[i]);
188
+ } catch (e: any) {
189
+ names = [];
190
+ monomers = [];
191
+ console.error(e);
192
+ } finally {
193
+ for (let j = 0; j < names.length; j ++)
194
+ argLib[names[j]] = monomers[j];
195
+ }
186
196
  }
187
197
 
188
198
  const overrideMonomerLibData: MonomerLibData = {[PolymerTypes.PEPTIDE]: argLib};
@@ -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);
@@ -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,21 +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();
58
+ this.v.name = `Manage Polytool Rules - ${this.fileName}`;
40
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;
41
63
  }
42
64
 
43
65
  return this.v;
44
66
  }
45
67
 
46
68
  public static async getInstance(name: string): Promise<RulesManager> {
47
- if (!this.instance) {
69
+ // every rull will have its own instance
70
+ if (!this.instances[name]) {
48
71
  const rules = await getRules([name]);
49
- this.instance = new RulesManager(rules, name);
72
+ this.instances[name] = new RulesManager(rules, name);
50
73
  }
51
- return this.instance;
74
+ return this.instances[name]!;
52
75
  }
53
76
 
54
77
  save(): void {
@@ -94,8 +117,8 @@ export class RulesManager {
94
117
  const initCol = DG.Column.fromStrings('monomers', seqs);
95
118
  const helmCol = DG.Column.fromStrings('helm', helms);
96
119
 
97
- initCol.semType = DG.SEMTYPE.MACROMOLECULE;
98
120
  applyNotationProviderForCyclized(initCol, '-');
121
+ initCol.semType = DG.SEMTYPE.MACROMOLECULE;
99
122
 
100
123
  helmCol.semType = DG.SEMTYPE.MACROMOLECULE;
101
124
  helmCol.meta.units = NOTATION.HELM;
@@ -112,7 +135,7 @@ export class RulesManager {
112
135
  const code = this.rules.reactionRules[i].code;
113
136
  const [firstMonomers, secondMonomers] = getMonomerPairs(this.rules.reactionRules[i]);
114
137
  for (let j = 0; j < firstMonomers.length; j++) {
115
- const seq = `${firstMonomers[j]}(${code})-A-A-A-A-${secondMonomers[j]}(${code})-A`;
138
+ const seq = `${firstMonomers[j]}(${code})-A-A-A-A-${secondMonomers[j]}(${code})`;
116
139
  seqs.push(seq);
117
140
  }
118
141
  }