@datagrok/peptides 1.27.11 → 1.28.0

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.
Files changed (65) hide show
  1. package/.auth.json +1 -0
  2. package/.grokignore +2 -0
  3. package/.turbo/turbo-build.log +26 -0
  4. package/.vscode/settings.json +16 -0
  5. package/CHANGELOG.md +28 -0
  6. package/CLAUDE.md +69 -5
  7. package/dist/659.js +2 -0
  8. package/dist/659.js.map +1 -0
  9. package/dist/806.js +2 -0
  10. package/dist/806.js.map +1 -0
  11. package/dist/package-test.js +396 -1
  12. package/dist/package-test.js.map +1 -1
  13. package/dist/package.js +361 -1
  14. package/dist/package.js.map +1 -1
  15. package/e2e/.auth.json +1 -0
  16. package/e2e/.auth.public.json +1 -0
  17. package/files/aligned_3.csv +6 -6
  18. package/package.json +30 -57
  19. package/rspack.config.js +3 -0
  20. package/src/demo/fasta.ts +0 -1
  21. package/src/model.ts +245 -131
  22. package/src/package-api.ts +18 -10
  23. package/src/package.g.ts +1 -0
  24. package/src/package.ts +19 -24
  25. package/src/tests/core.ts +6 -6
  26. package/src/tests/misc.ts +20 -0
  27. package/src/tests/model.ts +56 -6
  28. package/src/tests/table-view.ts +4 -4
  29. package/src/tests/utils.ts +56 -0
  30. package/src/tests/viewers.ts +270 -14
  31. package/src/tests/widgets.ts +13 -12
  32. package/src/utils/cell-renderer.ts +7 -6
  33. package/src/utils/constants.ts +10 -0
  34. package/src/utils/misc.ts +3 -3
  35. package/src/utils/statistics.ts +2 -2
  36. package/src/viewers/cluster-max-activity-viewer.ts +44 -11
  37. package/src/viewers/logo-summary.ts +126 -40
  38. package/src/viewers/mutation-cliffs-viewer.ts +56 -28
  39. package/src/viewers/peptide-generation-viewer.ts +7 -0
  40. package/src/viewers/position-statistics-viewer.ts +26 -4
  41. package/src/viewers/sar-viewer-status.ts +145 -0
  42. package/src/viewers/sar-viewer.ts +134 -42
  43. package/src/viewers/viewer-render-state.ts +68 -0
  44. package/src/widgets/distribution.ts +1 -1
  45. package/src/widgets/manual-alignment.ts +9 -22
  46. package/src/widgets/peptides.ts +101 -100
  47. package/src/widgets/selection.ts +1 -1
  48. package/src/widgets/settings.ts +11 -9
  49. package/test-playwright-report.json +73 -0
  50. package/test-report-playwright.csv +2 -0
  51. package/tsconfig.json +15 -69
  52. package/.eslintrc.json +0 -53
  53. package/dist/216.js +0 -2
  54. package/dist/216.js.map +0 -1
  55. package/dist/682.js +0 -2
  56. package/dist/682.js.map +0 -1
  57. package/dist/705.js +0 -2
  58. package/dist/705.js.map +0 -1
  59. package/dist/774.js +0 -2
  60. package/dist/774.js.map +0 -1
  61. package/dist/8473fcbfb6e85ca6c852.wasm +0 -0
  62. package/test-console-output-1.log +0 -661
  63. package/test-record-1.mp4 +0 -0
  64. package/webpack.config.js +0 -60
  65. /package/dist/{9a8fbf37666e32487835.wasm → wasmDbscan.wasm} +0 -0
@@ -8,6 +8,7 @@ import wu from 'wu';
8
8
  import $ from 'cash-dom';
9
9
  import * as rxjs from 'rxjs';
10
10
  import {filter} from 'rxjs/operators';
11
+ import {ViewerRenderState} from './viewer-render-state';
11
12
  export const enum ClusterMaxActivityProps {
12
13
  CLUSTER_COLUMN = 'cluster',
13
14
  ACTIVITY_COLUMN = 'activity',
@@ -38,8 +39,9 @@ export class ClusterMaxActivityViewer extends DG.JsViewer implements IClusterMax
38
39
  activityTarget: ACTIVITY_TARGET = ACTIVITY_TARGET.HIGH;
39
40
  _scViewer?: DG.ScatterPlotViewer | null;
40
41
  viewerError: string = '';
41
- renderTimeout: NodeJS.Timeout | number | null = null;
42
42
  renderDebounceTime = 500;
43
+ private readonly renderState = new ViewerRenderState();
44
+ private drawnThresholds: {clusterSize: number, activity: number} | null = null;
43
45
  clusterSizeThreshold: number;
44
46
  activityThreshold: number;
45
47
  static clusterSizeColName = '~cluster.size' as const;
@@ -51,6 +53,29 @@ export class ClusterMaxActivityViewer extends DG.JsViewer implements IClusterMax
51
53
  private scFilterQuery = `\$\{${ClusterMaxActivityViewer.maxActivityInClusterColName}\} == 1` as const;
52
54
  private selectionSubscription: rxjs.Subscription | null = null;
53
55
  private linesDrawSubscription: rxjs.Subscription | null = null;
56
+
57
+ get isRenderPending(): boolean { return this.renderState.isPending; }
58
+ get onRendered() { return this.renderState.rendered.asObservable(); }
59
+ get immediateRendering(): boolean { return this.renderState.immediateRendering; }
60
+ set immediateRendering(value: boolean) { this.renderState.immediateRendering = value; }
61
+
62
+ getWidgetStatus(): any {
63
+ const status = (this._scViewer as any)?.getWidgetStatus() ?? {};
64
+ return {...status, values: {...status.values,
65
+ 'cluster size threshold': this.drawnThresholds?.clusterSize ?? '',
66
+ 'activity threshold': this.drawnThresholds?.activity ?? '',
67
+ 'activity target': this._scViewer ?
68
+ (this._scViewer.props.invertYAxis ? ACTIVITY_TARGET.LOW : ACTIVITY_TARGET.HIGH) : '',
69
+ message: this.viewerError}};
70
+ }
71
+
72
+ detach(): void {
73
+ this.selectionSubscription?.unsubscribe();
74
+ this.linesDrawSubscription?.unsubscribe();
75
+ this.renderState.dispose();
76
+ this._scViewer = null;
77
+ super.detach();
78
+ }
54
79
  get scViewer(): DG.ScatterPlotViewer | null {
55
80
  if (!this._scViewer)
56
81
  this._scViewer = this.createSCViewer();
@@ -190,6 +215,7 @@ export class ClusterMaxActivityViewer extends DG.JsViewer implements IClusterMax
190
215
  scatterPlotProps.filter = this.scFilterQuery;
191
216
  this.viewerError = '';
192
217
  const sc = DG.Viewer.scatterPlot(this.dataFrame, scatterPlotProps);
218
+ this.renderState.add(sc);
193
219
 
194
220
  if (this.selectionSubscription)
195
221
  this.selectionSubscription.unsubscribe();
@@ -216,9 +242,9 @@ export class ClusterMaxActivityViewer extends DG.JsViewer implements IClusterMax
216
242
  if (maxConnectivityIndexPerClusterMap[cluster] != null)
217
243
  filterBitset.set(maxConnectivityIndexPerClusterMap[cluster], true);
218
244
  }
219
- setTimeout(() => {
245
+ this.renderState.defer('selection', () => {
220
246
  this.dataFrame.selection.copyFrom(filterBitset, true);
221
- setTimeout(() => {
247
+ this.renderState.defer('accordion', () => {
222
248
  if (this.model)
223
249
  this.model.createAccordion();
224
250
  }, 200);
@@ -268,6 +294,7 @@ export class ClusterMaxActivityViewer extends DG.JsViewer implements IClusterMax
268
294
  ctx.lineTo(endPointVer.x, endPointVer.y);
269
295
  ctx.stroke();
270
296
  ctx.closePath();
297
+ this.drawnThresholds = {clusterSize: this.clusterSizeThreshold, activity: this.activityThreshold};
271
298
  });
272
299
 
273
300
  return sc;
@@ -290,15 +317,13 @@ export class ClusterMaxActivityViewer extends DG.JsViewer implements IClusterMax
290
317
 
291
318
  this.render();
292
319
 
293
- this.dataFrame?.onDataChanged.subscribe(() => {
320
+ this.subs.push(this.dataFrame.onDataChanged.subscribe(() => {
294
321
  this.render();
295
- });
322
+ }));
296
323
  }
297
324
 
298
325
  render(): void {
299
- if (this.renderTimeout)
300
- clearTimeout(this.renderTimeout);
301
- this.renderTimeout = setTimeout(() => {
326
+ this.renderState.defer('render', () => {
302
327
  if (!this.dataFrame)
303
328
  return;
304
329
  $(this.root).empty();
@@ -342,7 +367,7 @@ export class ClusterMaxActivityViewer extends DG.JsViewer implements IClusterMax
342
367
  );
343
368
  scViewer.root.style.width = '100%';
344
369
  //this.root.appendChild(scViewer.root);
345
- setTimeout(() => {
370
+ this.renderState.defer('invalidate', () => {
346
371
  scViewer.props.filter = this.scFilterQuery;
347
372
  scViewer.invalidateCanvas();
348
373
  }, 100);
@@ -351,9 +376,17 @@ export class ClusterMaxActivityViewer extends DG.JsViewer implements IClusterMax
351
376
 
352
377
  onPropertyChanged(property: DG.Property | null): void {
353
378
  super.onPropertyChanged(property);
354
- if (property?.name !== `${ClusterMaxActivityProps.COLOR_COLUMN}${COLUMN_NAME}`)
379
+ if (property?.name !== `${ClusterMaxActivityProps.COLOR_COLUMN}${COLUMN_NAME}`) {
380
+ this.renderState.cancel('selection');
381
+ this.renderState.cancel('accordion');
382
+ this.renderState.cancel('invalidate');
383
+ this.selectionSubscription?.unsubscribe();
384
+ this.linesDrawSubscription?.unsubscribe();
385
+ if (this._scViewer)
386
+ this.renderState.remove(this._scViewer);
355
387
  this._scViewer = null;
388
+ this.drawnThresholds = null;
389
+ }
356
390
  this.render();
357
391
  }
358
392
  }
359
-
@@ -37,6 +37,7 @@ import {calculateClusterStatistics} from '../utils/algorithms';
37
37
  import {splitAlignedSequences} from '@datagrok-libraries/bio/src/utils/splitter';
38
38
  import {SARViewer} from './sar-viewer';
39
39
  import {PeptideUtils} from '../peptideUtils';
40
+ import {ViewerRenderState} from './viewer-render-state';
40
41
 
41
42
  const getAggregatedColName = (aggF: string, colName: string): string => `${aggF}(${colName})`;
42
43
 
@@ -93,6 +94,57 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
93
94
  webLogoAggregationType: DG.AggregationType;
94
95
 
95
96
  private _webLogoCacheGeneration: number = 0;
97
+ private readonly renderState = new ViewerRenderState();
98
+ private clearGridResources: (() => void) | null = null;
99
+ private message = '';
100
+
101
+ get isRenderPending(): boolean { return this.renderState.isPending; }
102
+ get onRendered() { return this.renderState.rendered.asObservable(); }
103
+ get immediateRendering(): boolean { return this.renderState.immediateRendering; }
104
+ set immediateRendering(value: boolean) { this.renderState.immediateRendering = value; }
105
+
106
+ getWidgetStatus(): any {
107
+ const status = this._viewerGrid && this.root.contains(this._viewerGrid.root) ?
108
+ (this._viewerGrid as any).getWidgetStatus() : {};
109
+ const hitAreas = {...status.hitAreas};
110
+ const table = this._logoSummaryTable;
111
+ const values: {[name: string]: string | number} = {
112
+ clusters: table?.rowCount ?? 0,
113
+ 'clusters shown': table?.filter.trueCount ?? 0,
114
+ 'members total': table?.col(C.LST_COLUMN_NAMES.MEMBERS)?.stats.sum ?? 0,
115
+ 'clusters column': this.clustersColumnName ?? '',
116
+ 'selected clusters': Object.values(this._clusterSelection ?? {}).flat().join(', '),
117
+ message: this.message,
118
+ };
119
+ if (table) {
120
+ for (let row = 0; row < table.rowCount; row++) {
121
+ const cluster = table.get(C.LST_COLUMN_NAMES.CLUSTER, row);
122
+ for (const name of [C.LST_COLUMN_NAMES.MEMBERS, C.LST_COLUMN_NAMES.MEAN_DIFFERENCE, C.LST_COLUMN_NAMES.P_VALUE]) {
123
+ const column = table.getCol(name);
124
+ values[`${name} of cluster ${cluster}`] = column.isNone(row) ? '' : column.get(row);
125
+ }
126
+ }
127
+ for (const [name, area] of Object.entries(status.hitAreas ?? {})) {
128
+ const match = /^cell (\d+) of (.+)$/.exec(name);
129
+ if (!match)
130
+ continue;
131
+ const cluster = table.get(C.LST_COLUMN_NAMES.CLUSTER, Number(match[1]) - 1);
132
+ if (match[2] === C.LST_COLUMN_NAMES.CLUSTER)
133
+ hitAreas[`cluster ${cluster}`] = area;
134
+ else if (match[2] === C.LST_COLUMN_NAMES.WEB_LOGO)
135
+ hitAreas[`weblogo of cluster ${cluster}`] = area;
136
+ else if (match[2] === C.LST_COLUMN_NAMES.DISTRIBUTION)
137
+ hitAreas[`distribution of cluster ${cluster}`] = area;
138
+ }
139
+ }
140
+ return {...status, hitAreas, values};
141
+ }
142
+
143
+ private clearGrid(): void {
144
+ this.clearGridResources?.();
145
+ this.clearGridResources = null;
146
+ this._viewerGrid = null;
147
+ }
96
148
 
97
149
  /** Creates LogoSummaryTable properties. */
98
150
  constructor() {
@@ -350,22 +402,29 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
350
402
 
351
403
  /** Removes all the active subscriptions. */
352
404
  detach(): void {
353
- this.subs.forEach((sub) => sub.unsubscribe());
405
+ this.clearGrid();
406
+ this.renderState.dispose();
407
+ super.detach();
354
408
  }
355
409
 
356
410
  /** Renders Logo Summary Table body. */
357
411
  render(): void {
358
412
  $(this.root).empty();
359
- if (this.clustersColumnName == null || this.sequenceColumnName == null || this.activityColumnName == null) {
360
- this.root.appendChild(
361
- ui.divText('Please, select a sequence, cluster and activity columns in the viewer properties'));
413
+ this.message = '';
414
+ if (!this.dataFrame || this.clustersColumnName == null || this.sequenceColumnName == null ||
415
+ this.activityColumnName == null) {
416
+ this.message = 'Please, select a sequence, cluster and activity columns in the viewer properties';
417
+ this.root.appendChild(ui.divText(this.message));
418
+ this.renderState.rendered.next();
362
419
  return;
363
420
  }
364
421
 
365
422
  if (!this.logoSummaryTable.filter.anyTrue) {
366
- const emptyDf = ui.divText('No clusters to satisfy the threshold. ' +
367
- 'Please, lower the threshold in viewer proeperties to include clusters');
423
+ this.message = 'No clusters to satisfy the threshold. ' +
424
+ 'Please, lower the threshold in viewer proeperties to include clusters';
425
+ const emptyDf = ui.divText(this.message);
368
426
  this.root.appendChild(ui.divV([emptyDf]));
427
+ this.renderState.rendered.next();
369
428
  return;
370
429
  }
371
430
  const expand = ui.iconFA('expand-alt', () => {
@@ -397,6 +456,8 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
397
456
  */
398
457
  onPropertyChanged(property: DG.Property): void {
399
458
  super.onPropertyChanged(property);
459
+ if (!this.dataFrame)
460
+ return;
400
461
  let doRender = false;
401
462
  switch (property.name) {
402
463
  case LST_PROPERTIES.MEMBERS_RATIO_THRESHOLD:
@@ -405,14 +466,14 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
405
466
  this.updateFilter();
406
467
  break;
407
468
  case `${LST_PROPERTIES.SEQUENCE}${COLUMN_NAME}`:
408
- this._viewerGrid = null;
469
+ this.clearGrid();
409
470
  this._logoSummaryTable = null;
410
471
  doRender = true;
411
472
  break;
412
473
  case `${LST_PROPERTIES.CLUSTERS}${COLUMN_NAME}`:
413
474
  this._clusterStats = null;
414
475
  this._clusterSelection = null;
415
- this._viewerGrid = null;
476
+ this.clearGrid();
416
477
  this._logoSummaryTable = null;
417
478
  doRender = true;
418
479
  break;
@@ -423,14 +484,14 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
423
484
  case LST_PROPERTIES.WEB_LOGO_AGGREGATION_TYPE:
424
485
  this._webLogoCacheGeneration++; // Increment to invalidate cache
425
486
  this._scaledActivityColumn = null;
426
- this._viewerGrid = null;
487
+ this.clearGrid();
427
488
  this._clusterStats = null;
428
489
  this._logoSummaryTable = null;
429
490
  doRender = true;
430
491
  break;
431
492
  case LST_PROPERTIES.COLUMNS:
432
493
  case LST_PROPERTIES.AGGREGATION:
433
- this._viewerGrid = null;
494
+ this.clearGrid();
434
495
  this._logoSummaryTable = null;
435
496
  doRender = true;
436
497
  break;
@@ -650,6 +711,8 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
650
711
  const aggColNames = aggColsEntries.map(([colName, aggFn]) => getAggregatedColName(aggFn, colName));
651
712
 
652
713
  const grid = this.logoSummaryTable.plot.grid();
714
+ grid.root.setAttribute('name', 'Logo-Summary-Table-grid');
715
+ this.renderState.add(grid, grid.onAfterDrawContent);
653
716
  grid.sort([C.LST_COLUMN_NAMES.MEMBERS], [false]);
654
717
  this.updateFilter();
655
718
  const gridClustersCol = grid.col(C.LST_COLUMN_NAMES.CLUSTER)!;
@@ -664,15 +727,28 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
664
727
  const webLogoCache = new DG.LruCache<string, DG.Viewer & IWebLogoViewer>();
665
728
  const webLogoPromiseCache = new Map<string, boolean>(); // this map will keep promises for weblogo creation
666
729
 
667
- let invalidateTimeout: any = null;
668
-
669
730
  const debouncedInvalidate = (): void => {
670
- if (invalidateTimeout)
671
- clearTimeout(invalidateTimeout);
672
- invalidateTimeout = setTimeout(() => grid.invalidate(), 200);
731
+ this.renderState.defer('invalidate', () => grid.invalidate(), 200);
673
732
  };
674
733
 
675
734
  const distCache = new DG.LruCache<number, DG.Viewer<DG.IHistogramSettings>>();
735
+ let disposed = false;
736
+ const children = new Set<DG.Viewer>();
737
+ const removeChild = (viewer: DG.Viewer): void => {
738
+ children.delete(viewer);
739
+ this.renderState.remove(viewer);
740
+ };
741
+ webLogoCache.onItemEvicted = removeChild;
742
+ distCache.onItemEvicted = removeChild;
743
+ this.clearGridResources = () => {
744
+ disposed = true;
745
+ this.renderState.cancel('invalidate');
746
+ this.renderState.cancel('current cell');
747
+ tooltipSubscription.cancel();
748
+ for (const viewer of children)
749
+ removeChild(viewer);
750
+ this.renderState.remove(grid);
751
+ };
676
752
  const maxSequenceLen = this.positionColumns.length;
677
753
  const webLogoGridCol = grid.columns.byName(C.LST_COLUMN_NAMES.WEB_LOGO)!;
678
754
  webLogoGridCol.cellType = 'html';
@@ -680,7 +756,7 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
680
756
  const activityCol = this.getScaledActivityColumn(isDfFiltered);
681
757
  const pepCol: DG.Column<string> = filteredDf.getCol(this.sequenceColumnName);
682
758
 
683
- grid.onCellRender.subscribe((gridCellArgs) => {
759
+ grid.sub(grid.onCellRender.subscribe((gridCellArgs) => {
684
760
  const gridCell = gridCellArgs.cell;
685
761
  const currentRowIdx = gridCell.tableRowIndex;
686
762
  if (!gridCell.isTableCell || currentRowIdx == null || currentRowIdx === -1)
@@ -732,7 +808,7 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
732
808
  } else {
733
809
  const columnsToInclude = [pepCol];
734
810
  if (this.webLogoAggregationType !== DG.AGG.TOTAL_COUNT && this.webLogoAggregationColumnName) {
735
- const aggCol = this.dataFrame.columns.byName(this.webLogoAggregationColumnName);
811
+ const aggCol = filteredDf.columns.byName(this.webLogoAggregationColumnName);
736
812
  if (aggCol)
737
813
  columnsToInclude.push(aggCol);
738
814
  }
@@ -740,22 +816,30 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
740
816
  webLogoTable.filter.copyFrom(clusterBitSet);
741
817
 
742
818
  webLogoPromiseCache.set(cacheKey, true);
743
- webLogoTable.plot
744
- .fromType('WebLogo', {
745
- valueColumnName: this.webLogoAggregationColumnName,
746
- valueAggrType: this.webLogoAggregationType,
747
- positionHeight: this.webLogoMode,
748
- horizontalAlignment: HorizontalAlignments.LEFT,
749
- maxHeight: 1000,
750
- minHeight: height,
751
- positionWidth: positionWidth,
752
- showPositionLabels: false,
753
- })
754
- .then((v) => {
755
- webLogoCache.set(cacheKey, v);
756
- webLogoPromiseCache.delete(cacheKey);
819
+ void this.renderState.run(async () => {
820
+ try {
821
+ const viewer = await webLogoTable.plot.fromType('WebLogo', {
822
+ valueColumnName: this.webLogoAggregationColumnName,
823
+ valueAggrType: this.webLogoAggregationType,
824
+ positionHeight: this.webLogoMode,
825
+ horizontalAlignment: HorizontalAlignments.LEFT,
826
+ maxHeight: 1000,
827
+ minHeight: height,
828
+ positionWidth: positionWidth,
829
+ showPositionLabels: false,
830
+ }) as DG.Viewer & IWebLogoViewer;
831
+ if (disposed) {
832
+ viewer.detach();
833
+ return;
834
+ }
835
+ children.add(viewer);
836
+ this.renderState.add(viewer, (viewer as any).onRendered);
837
+ webLogoCache.set(cacheKey, viewer);
757
838
  debouncedInvalidate();
758
- });
839
+ } finally {
840
+ webLogoPromiseCache.delete(cacheKey);
841
+ }
842
+ });
759
843
  gridCellArgs.preventDefault();
760
844
  }
761
845
  } else if (gridCell.tableColumn?.name === C.LST_COLUMN_NAMES.DISTRIBUTION) {
@@ -773,11 +857,13 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
773
857
  showColumnSelector: false,
774
858
  showRangeSlider: false,
775
859
  showBinSelector: false,
776
- backColor: DG.Color.toHtml(DG.Color.white),
860
+ backColor: DG.Color.white,
777
861
  xAxisHeight: 1,
778
862
  showSplitSelector: false,
779
863
  });
780
864
  viewer.root.style.width = 'auto';
865
+ children.add(viewer);
866
+ this.renderState.add(viewer);
781
867
  distCache.set(currentRowIdx, viewer);
782
868
  }
783
869
  viewer.root.style.height = `${height}px`;
@@ -787,9 +873,9 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
787
873
  } finally {
788
874
  canvasContext.restore();
789
875
  }
790
- });
876
+ }));
791
877
  grid.root.addEventListener('mouseleave', (_ev) => this.model.unhighlight());
792
- DG.debounce(grid.onCurrentCellChanged, 500).subscribe((gridCell) => {
878
+ grid.sub(grid.onCurrentCellChanged.subscribe((gridCell) => this.renderState.defer('current cell', () => {
793
879
  if (!gridCell.isTableCell || gridCell.gridRow === -1) {
794
880
  this.initClusterSelection({notify: false});
795
881
  this.model.fireBitsetChanged(VIEWER_TYPE.LOGO_SUMMARY_TABLE);
@@ -820,16 +906,16 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
820
906
  this.keyPress = false;
821
907
  this.currentRowIndex = gridCell.gridRow;
822
908
  }
823
- });
909
+ }, 500)));
824
910
  grid.root.addEventListener('keydown', (ev) => {
825
911
  this.keyPress = ev.key.startsWith('Arrow');
826
912
  if (this.keyPress)
827
913
  return;
828
914
 
829
915
 
830
- if (ev.key === 'Escape' || (ev.code === 'KeyA' && ev.shiftKey && ev.ctrlKey))
916
+ if (ev.key === 'Escape' || (ev.code === 'KeyA' && ev.shiftKey && (ev.ctrlKey || ev.metaKey)))
831
917
  this.initClusterSelection({notify: false});
832
- else if (ev.code === 'KeyA' && ev.ctrlKey) {
918
+ else if (ev.code === 'KeyA' && (ev.ctrlKey || ev.metaKey)) {
833
919
  for (let rowIdx = 0; rowIdx < this.logoSummaryTable.rowCount; ++rowIdx) {
834
920
  this.modifyClusterSelection(this.getCluster(grid.cell(C.LST_COLUMN_NAMES.CLUSTER, rowIdx)),
835
921
  {
@@ -850,11 +936,11 @@ export class LogoSummaryTable extends DG.JsViewer implements ILogoSummaryTable {
850
936
  const selection = this.getCluster(gridCell);
851
937
  this.modifyClusterSelection(selection, {
852
938
  shiftPressed: ev.shiftKey,
853
- ctrlPressed: ev.ctrlKey,
939
+ ctrlPressed: ev.ctrlKey || ev.metaKey,
854
940
  });
855
941
  grid.invalidate();
856
942
  });
857
- grid.onCellTooltip((gridCell, x, y) => {
943
+ const tooltipSubscription = grid.onCellTooltip((gridCell, x, y) => {
858
944
  if (!gridCell.isTableCell) {
859
945
  this.model.unhighlight();
860
946
  return true;
@@ -12,6 +12,7 @@ import {extractColInfo} from '../utils/misc';
12
12
  import {Subscription} from 'rxjs';
13
13
  import {SeqTemps} from '@datagrok-libraries/bio/src/utils/macromolecule/seq-handler';
14
14
  import {MONOMER_CANONICALIZER_FUNC_TAG} from '@datagrok-libraries/bio/src/utils/macromolecule/consts';
15
+ import {ViewerRenderState} from './viewer-render-state';
15
16
  export type MutationCliffsWithMonomers = {
16
17
  cliffs: MutationCliffs,
17
18
  monomers: string[]
@@ -24,6 +25,22 @@ export class MutationCliffsViewer extends DG.JsViewer {
24
25
  public position = 1;
25
26
  public currentRowMutationsOnly: boolean = false;
26
27
  public yAxisType: 'Linear' | 'Logarithmic' = 'Linear';
28
+ private readonly renderState = new ViewerRenderState();
29
+ private renderGeneration = 0;
30
+ private message = '';
31
+ private cliffRows = 0;
32
+ private renderedPosition: number | null = null;
33
+
34
+ get isRenderPending(): boolean { return this.renderState.isPending; }
35
+ get onRendered() { return this.renderState.rendered.asObservable(); }
36
+ get immediateRendering(): boolean { return this.renderState.immediateRendering; }
37
+ set immediateRendering(value: boolean) { this.renderState.immediateRendering = value; }
38
+
39
+ getWidgetStatus(): any {
40
+ const status = (this._lineChart as any)?.getWidgetStatus() ?? {};
41
+ return {...status, values: {...status.values, position: this.renderedPosition ?? '',
42
+ 'cliff rows': this.cliffRows, message: this.message}};
43
+ }
27
44
  constructor() {
28
45
  super();
29
46
  this.sequenceColumnName = this.column('sequence', {semType: DG.SEMTYPE.MACROMOLECULE, nullable: false});
@@ -45,10 +62,10 @@ export class MutationCliffsViewer extends DG.JsViewer {
45
62
  if (seriesCol)
46
63
  this.getProperty('seriesColumnName')!.set(this, seriesCol.name);
47
64
 
48
- this.subs.push(DG.debounce(this.dataFrame.onFilterChanged, 200).subscribe(() => {
65
+ this.subs.push(this.dataFrame.onFilterChanged.subscribe(() => this.renderState.defer('filter', () => {
49
66
  this.clearCache();
50
67
  this.debouncedRender();
51
- }));
68
+ }, 200)));
52
69
  this.debouncedRender();
53
70
 
54
71
 
@@ -103,9 +120,12 @@ export class MutationCliffsViewer extends DG.JsViewer {
103
120
  private _dfSubs: Subscription[] = [];
104
121
 
105
122
  private async calculateDf() {
123
+ const generation = this.renderGeneration;
106
124
  if (!this.dataFrame || !this.activityColumnName || !this.sequenceColumnName || !this.position)
107
125
  throw new Error('Activity column or Sequence column is not set, or position is invalid');
108
126
  const mutationCliffs = await this.mutationCliffsData;
127
+ if (generation !== this.renderGeneration)
128
+ return DG.DataFrame.create();
109
129
  const uniqueIndexes = new Set<number>();
110
130
  mutationCliffs.cliffs.forEach((positionMap) => {
111
131
  positionMap.forEach((mcData) => { // should be only one position
@@ -198,7 +218,7 @@ export class MutationCliffsViewer extends DG.JsViewer {
198
218
  let firedFromTable = false;
199
219
  // Handle selection
200
220
  this._dfSubs.push(
201
- DG.debounce(df.onSelectionChanged, 100).subscribe((_) => {
221
+ df.onSelectionChanged.subscribe(() => this.renderState.defer('chart selection', () => {
202
222
  const selected = df.selection;
203
223
  if (firedFromViewer) {
204
224
  firedFromViewer = false;
@@ -215,11 +235,11 @@ export class MutationCliffsViewer extends DG.JsViewer {
215
235
  this.dataFrame.selection.set(originalIdx, true, false);
216
236
  }
217
237
  this.dataFrame.selection.fireChanged();
218
- }),
238
+ }, 100)),
219
239
  );
220
240
 
221
241
  this._dfSubs.push(
222
- DG.debounce(this.dataFrame.onSelectionChanged, 100).subscribe((_) => {
242
+ this.dataFrame.onSelectionChanged.subscribe(() => this.renderState.defer('table selection', () => {
223
243
  const selected = this.dataFrame.selection;
224
244
  if (firedFromTable) {
225
245
  firedFromTable = false;
@@ -237,7 +257,7 @@ export class MutationCliffsViewer extends DG.JsViewer {
237
257
  df.selection.set(viewerDfIdx, true, false);
238
258
  }
239
259
  df.selection.fireChanged();
240
- }),
260
+ }, 100)),
241
261
  );
242
262
 
243
263
  // mouse over row GROUP handling one way
@@ -300,36 +320,39 @@ export class MutationCliffsViewer extends DG.JsViewer {
300
320
  private _lineChart: DG.LineChartViewer | null = null;
301
321
 
302
322
  private async render() {
323
+ const generation = this.renderGeneration;
303
324
  $(this.root).empty();
325
+ this.message = '';
326
+ this.cliffRows = 0;
327
+ this.renderedPosition = null;
328
+ if (this._lineChart) {
329
+ this.renderState.remove(this._lineChart);
330
+ this._lineChart = null;
331
+ }
304
332
  if (!this.dataFrame || !this.activityColumnName || !this.sequenceColumnName || !this.position) {
305
333
  ui.setUpdateIndicator(this.root, false);
306
- this.root.appendChild(noDataDiv('Please set Activity column, Sequence column and Position properties.'));
334
+ this.showMessage('Please set Activity column, Sequence column and Position properties.');
307
335
  return;
308
336
  }
309
337
 
310
- if (this._lineChart) {
311
- try {
312
- this._lineChart.detach();
313
- } catch (e) {
314
- console.error('Error detaching previous line chart:', e);
315
- }
316
- this._lineChart = null;
317
- }
318
-
319
338
  ui.setUpdateIndicator(this.root, true);
320
339
  this.root.style.display = 'flex';
321
340
  this.root.style.flexDirection = 'column';
322
341
 
323
342
  const df = await this.innerDf;
343
+ if (generation !== this.renderGeneration)
344
+ return;
345
+ this.cliffRows = df.rowCount;
346
+ this.renderedPosition = this.position;
324
347
  ui.setUpdateIndicator(this.root, false);
325
348
  if (df.rowCount === 0) {
326
349
  if (this.currentRowMutationsOnly) {
327
350
  if (this.dataFrame.currentRowIdx >= 0)
328
- this.root.appendChild(noDataDiv('No mutations cliffs found for the current peptide at the selected position.'));
351
+ this.showMessage('No mutations cliffs found for the current peptide at the selected position.');
329
352
  else
330
- this.root.appendChild(noDataDiv('Please select a row in the main table to see mutation cliffs for the corresponding peptide at the selected position.'));
353
+ this.showMessage('Please select a row in the main table to see mutation cliffs for the corresponding peptide at the selected position.');
331
354
  } else
332
- this.root.appendChild(noDataDiv('No mutation cliffs found for the selected position.'));
355
+ this.showMessage('No mutation cliffs found for the selected position.');
333
356
  } else {
334
357
  this._lineChart = df.plot.line({
335
358
  xColumnName: `Position ${this.position}`,
@@ -345,12 +368,12 @@ export class MutationCliffsViewer extends DG.JsViewer {
345
368
  axisFont: 'normal normal 14px "Roboto"',
346
369
  controlsFont: 'normal normal 14px "Roboto"',
347
370
  } as Partial<DG.ILineChartSettings>) as DG.LineChartViewer;
348
-
371
+ this.renderState.add(this._lineChart);
349
372
 
350
373
  this._lineChart.sub(this._lineChart.onPropertyValueChanged.subscribe((_e) => {
351
374
  if (this._lineChart?.props?.yColumnNames && this._lineChart?.props?.yColumnNames?.[0] !== this.activityColumnName) {
352
375
  const value = this._lineChart?.props?.yColumnNames?.[0];
353
- setTimeout(() => this.getProperty('activityColumnName')!.set(this, value), 1);
376
+ this.renderState.defer('activity column', () => this.getProperty('activityColumnName')!.set(this, value), 1);
354
377
  }
355
378
  }));
356
379
 
@@ -384,15 +407,20 @@ export class MutationCliffsViewer extends DG.JsViewer {
384
407
  }
385
408
  }
386
409
 
387
- private _debounceTimer: any = null;
410
+ private showMessage(message: string): void {
411
+ this.message = message;
412
+ this.root.appendChild(noDataDiv(message));
413
+ }
414
+
388
415
  public debouncedRender() {
389
416
  ui.setUpdateIndicator(this.root, true);
390
- if (this._debounceTimer)
391
- clearTimeout(this._debounceTimer);
392
- this._debounceTimer = setTimeout(() => this.render(), 300);
417
+ this.renderState.defer('render', () => this.render(), 300);
393
418
  }
394
419
 
395
420
  private clearCache(clearMutationCliffsData: boolean = true) {
421
+ this.renderGeneration++;
422
+ this.renderState.cancel('chart selection');
423
+ this.renderState.cancel('table selection');
396
424
  // while following current row, makes no sense to clear mutation cliffs data.
397
425
  if (clearMutationCliffsData)
398
426
  this._mutationCliffsData = null;
@@ -402,10 +430,10 @@ export class MutationCliffsViewer extends DG.JsViewer {
402
430
  }
403
431
 
404
432
  detach(): void {
433
+ this.clearCache();
434
+ this.renderState.dispose();
435
+ this._lineChart = null;
405
436
  super.detach();
406
- this._dfSubs.forEach((s) => s.unsubscribe());
407
- this._dfSubs = [];
408
- clearTimeout(this._debounceTimer);
409
437
  }
410
438
 
411
439
 
@@ -168,6 +168,13 @@ export class PeptideGenerationViewer extends DG.JsViewer {
168
168
  this._grid = null;
169
169
  this.render();
170
170
  }));
171
+ // Not debounced: a hover before the reset would highlight with a stale-length mask
172
+ this.subs.push(rxjs.merge(this.dataFrame.onRowsRemoved, this.dataFrame.onRowsAdded).subscribe(() => {
173
+ this._propChangeTimer && clearTimeout(this._propChangeTimer);
174
+ this._monomerPositionStats = null;
175
+ this._grid = null;
176
+ this.render();
177
+ }));
171
178
  this.render();
172
179
  }
173
180