@datagrok/hit-triage 1.10.5 → 1.10.6

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/hit-triage",
3
3
  "friendlyName": "Hit Triage",
4
- "version": "1.10.5",
4
+ "version": "1.10.6",
5
5
  "author": {
6
6
  "name": "Davit Rizhinashvili",
7
7
  "email": "drizhinashvili@datagrok.ai"
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@datagrok-libraries/bio": "^5.63.6",
20
20
  "@datagrok-libraries/compute-utils": "^1.44.9",
21
- "@datagrok-libraries/statistics": "^1.12.4",
21
+ "@datagrok-libraries/statistics": "^1.12.9",
22
22
  "@datagrok-libraries/test": "^1.1.0",
23
23
  "@datagrok-libraries/utils": "^4.6.5",
24
24
  "cash-dom": "^8.1.5",
@@ -102,7 +102,7 @@ export async function newHitDesignTemplateAccordeon(app: HitAppBase<any>,
102
102
  },
103
103
  } as unknown as PeptiHitTemplate;
104
104
  const funcInput = await chemFunctionsDialog(app, (res) => {funcDialogRes = res;}, () => null,
105
- dummyTemplate, false);
105
+ dummyTemplate, false, true);
106
106
  funcInput.root.classList.add('hit-triage-new-template-functions-input');
107
107
  const fieldsEditor = getCampaignFieldEditors(preset?.campaignFields);
108
108
  const tileCategoriesEditor = getTileCategoryEditor(preset?.stages);
@@ -167,6 +167,7 @@ export async function newHitDesignTemplateAccordeon(app: HitAppBase<any>,
167
167
  name: splitFunc[1],
168
168
  package: splitFunc[0],
169
169
  args: args,
170
+ rerunOnOpen: !!funcDialogRes?.rerunOnOpen?.[funcName],
170
171
  });
171
172
  }),
172
173
  scripts: Object.entries(funcDialogRes?.scripts ?? {})
@@ -177,6 +178,7 @@ export async function newHitDesignTemplateAccordeon(app: HitAppBase<any>,
177
178
  name: scriptNameParts[1] ?? '',
178
179
  id: scriptNameParts[2] ?? '',
179
180
  args: args,
181
+ rerunOnOpen: !!funcDialogRes?.rerunOnOpen?.[scriptId],
180
182
  });
181
183
  }),
182
184
  queries: Object.entries(funcDialogRes?.queries ?? {})
@@ -187,6 +189,7 @@ export async function newHitDesignTemplateAccordeon(app: HitAppBase<any>,
187
189
  name: queryNameParts[1] ?? '',
188
190
  id: queryNameParts[2] ?? '',
189
191
  args: args,
192
+ rerunOnOpen: !!funcDialogRes?.rerunOnOpen?.[queryName],
190
193
  });
191
194
  }),
192
195
  },
@@ -11,6 +11,9 @@ import {HTFunctionOrderingLSKey} from '../consts';
11
11
  export async function chemFunctionsDialog(app: HitAppBase<any>,
12
12
  onOk: (result: IComputeDialogResult) => void, onCancel: () => void,
13
13
  template: Omit<HitTriageTemplate, 'dataSourceType'>, dialog?: boolean,
14
+ // When true, each function/script/query gets a "re-run when campaign opens" checkbox whose state
15
+ // is persisted in the campaign's compute config (see HitDesignApp.reComputeOnCampaignOpen).
16
+ rerunOnOpen?: boolean,
14
17
  ): Promise<IChemFunctionsDialogResult> {
15
18
  return _chemFunctionsDialog(
16
19
  app.computeFunctions,
@@ -19,5 +22,11 @@ export async function chemFunctionsDialog(app: HitAppBase<any>,
19
22
  dialog,
20
23
  () => grok.chem.descriptorsTree() as Promise<IDescriptorTree>,
21
24
  HTFunctionOrderingLSKey,
25
+ undefined,
26
+ rerunOnOpen ? {
27
+ label: 'Re-run when campaign opens',
28
+ tooltip: 'Recompute this function for the whole molecule column every time this campaign is ' +
29
+ 'opened. Useful for database lookups that may resolve after the molecule was first drawn.',
30
+ } : undefined,
22
31
  );
23
32
  }
@@ -326,6 +326,11 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
326
326
  if (campaignId && this.campaign?.mergeConfig?.autoMergeOnOpen && this.campaign.mergeConfig.filePath)
327
327
  await autoMergeOnCampaignOpen(this);
328
328
 
329
+ // Recompute any compute functions flagged "re-run when campaign opens" over the whole molecule
330
+ // column. Like the auto-merge pass, this runs only for existing campaigns and is not auto-saved.
331
+ if (campaignId && this.campaign)
332
+ await this.reComputeOnCampaignOpen();
333
+
329
334
  const designV = this.designView;
330
335
  this.currentDesignViewId = designV.name;
331
336
  this.setBaseUrl();
@@ -451,6 +456,55 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
451
456
  this.saveCampaign(false);
452
457
  }
453
458
 
459
+ /**
460
+ * Recomputes the compute functions/scripts/queries flagged with `rerunOnOpen` over the whole
461
+ * molecule column. Called once when an existing campaign is opened, before the design view is
462
+ * shown. Mirrors the auto-merge-on-open pass: values are updated in memory but the campaign is
463
+ * not auto-saved, and failures never bubble up so the campaign still opens.
464
+ */
465
+ private async reComputeOnCampaignOpen(): Promise<void> {
466
+ const compute = this.template?.compute;
467
+ if (!compute || !this.dataFrame || !this.molColName)
468
+ return;
469
+
470
+ // Descriptors are deterministic from structure, so they are intentionally never re-run on open.
471
+ const functions = (compute.functions ?? []).filter((f) => f.rerunOnOpen);
472
+ const scripts = (compute.scripts ?? []).filter((s) => s.rerunOnOpen);
473
+ const queries = (compute.queries ?? []).filter((q) => q.rerunOnOpen);
474
+ if (!functions.length && !scripts.length && !queries.length)
475
+ return;
476
+
477
+ const molCol = this.dataFrame.col(this.molColName);
478
+ if (!molCol)
479
+ return;
480
+
481
+ try {
482
+ // Compute against a temporary molecule-only table, then merge the results back in. Merging by
483
+ // column name lets us overwrite an existing column in place instead of appending a duplicate
484
+ // "<name> (2)" column — e.g. a query that re-resolves a ChEMBL molregno already in the table.
485
+ const values = molCol.toList();
486
+ const calcDf = await calculateCellValues(values, [], functions, scripts, queries);
487
+ for (const resCol of calcDf.columns.toList()) {
488
+ if (resCol.name === this.molColName || resCol.name === HitDesignMolColName)
489
+ continue;
490
+ let targetCol = this.dataFrame.col(resCol.name);
491
+ if (!targetCol || targetCol.type !== resCol.type) {
492
+ if (targetCol) // existing column of a different type: replace it wholesale
493
+ this.dataFrame.columns.remove(resCol.name);
494
+ targetCol = this.dataFrame.columns.addNew(resCol.name, resCol.type);
495
+ }
496
+ targetCol.semType = resCol.semType;
497
+ const rows = Math.min(resCol.length, targetCol.length);
498
+ for (let i = 0; i < rows; i++)
499
+ targetCol.set(i, resCol.isNone(i) ? null : resCol.get(i), false);
500
+ }
501
+ this.dataFrame.fireValuesChanged();
502
+ } catch (e) {
503
+ _package.logger.error(e);
504
+ grok.shell.warning('Re-run on open failed for some functions; opening the campaign anyway.');
505
+ }
506
+ }
507
+
454
508
  private _refreshCampaignIcon: HTMLElement | null = null;
455
509
  protected initDesignViewRibbons(view: DG.TableView, subs: Subscription[], addDesignerButton = false) {
456
510
  const onRemoveSub = grok.events.onViewRemoved.subscribe((v) => {
@@ -489,6 +543,7 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
489
543
  name: splitFunc[1],
490
544
  package: splitFunc[0],
491
545
  args: args,
546
+ rerunOnOpen: !!resultMap?.rerunOnOpen?.[funcName],
492
547
  });
493
548
  }),
494
549
  scripts: Object.entries(resultMap?.scripts ?? {})
@@ -499,6 +554,7 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
499
554
  name: scriptNameParts[1] ?? '',
500
555
  id: scriptNameParts[2] ?? '',
501
556
  args: args,
557
+ rerunOnOpen: !!resultMap?.rerunOnOpen?.[scriptId],
502
558
  });
503
559
  }),
504
560
  queries: Object.entries(resultMap?.queries ?? {})
@@ -509,6 +565,7 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
509
565
  name: queryNameParts[1] ?? '',
510
566
  id: queryNameParts[2] ?? '',
511
567
  args: args,
568
+ rerunOnOpen: !!resultMap?.rerunOnOpen?.[queryName],
512
569
  });
513
570
  }),
514
571
  };
@@ -551,7 +608,7 @@ export class HitDesignApp<T extends HitDesignTemplate = HitDesignTemplate> exten
551
608
  ui.setUpdateIndicator(view.grid.root, false);
552
609
  this.saveCampaign(false);
553
610
  }
554
- }, () => null, this.campaign?.template!, true);
611
+ }, () => null, this.campaign?.template!, true, true);
555
612
  };
556
613
 
557
614
  const calculateRibbon = ui.iconFA('wrench', getComputeDialog, 'Calculate additional properties');
@@ -59,6 +59,10 @@ export namespace queries {
59
59
  }
60
60
 
61
61
  export namespace funcs {
62
+ export async function initHT(): Promise<void> {
63
+ return await grok.functions.call('HitTriage:InitHT', {});
64
+ }
65
+
62
66
  export async function hitTriageAppTreeBrowser(treeNode: any ): Promise<void> {
63
67
  return await grok.functions.call('HitTriage:HitTriageAppTreeBrowser', { treeNode });
64
68
  }
package/src/package.g.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import {PackageFunctions} from './package';
2
2
  import * as DG from 'datagrok-api/dg';
3
3
 
4
+ //meta.role: init
5
+ export async function initHT() : Promise<void> {
6
+ await PackageFunctions.initHT();
7
+ }
8
+
4
9
  //input: dynamic treeNode
5
10
  //meta.app: Hit Triage
6
11
  export async function hitTriageAppTreeBrowser(treeNode: any) : Promise<void> {
package/src/package.ts CHANGED
@@ -132,6 +132,10 @@ async function hitAppTB(treeNode: DG.TreeViewGroup, name: AppName) {
132
132
  }
133
133
 
134
134
  export class PackageFunctions {
135
+ @grok.decorators.init()
136
+ static async initHT() {
137
+ await grok.functions.call('Chem:init', {});
138
+ }
135
139
  @grok.decorators.treeBrowser({meta: {app: 'Hit Triage'}})
136
140
  static async hitTriageAppTreeBrowser(treeNode: DG.TreeViewGroup) {
137
141
  await hitAppTB(treeNode, 'Hit Triage');