@datagrok/peptides 1.27.10 → 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 +32 -58
  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 -603
  63. package/test-record-1.mp4 +0 -0
  64. package/webpack.config.js +0 -60
  65. /package/dist/{9a8fbf37666e32487835.wasm → wasmDbscan.wasm} +0 -0
@@ -1,16 +1,20 @@
1
+ import * as grok from 'datagrok-api/grok';
1
2
  import * as DG from 'datagrok-api/dg';
2
3
 
3
- import {after, before, category, delay, expect, test, testViewer} from '@datagrok-libraries/test/src/test';
4
+ import {after, before, category, expect, expectFloat, settled, test, testEvent, testViewer, uiSettled,
5
+ waitUntil} from '@datagrok-libraries/test/src/test';
4
6
  import {PeptidesModel, VIEWER_TYPE} from '../model';
5
7
  import {_package} from '../package-test';
6
8
  import {NOTATION} from '@datagrok-libraries/bio/src/utils/macromolecule';
7
- import {scaleActivity} from '../utils/misc';
9
+ import {highlightMonomerPosition, scaleActivity} from '../utils/misc';
8
10
  import {startAnalysis} from '../widgets/peptides';
9
- import {MonomerPosition, MostPotentResidues, SELECTION_MODE} from '../viewers/sar-viewer';
10
- import {SCALING_METHODS} from '../utils/constants';
11
+ import {MonomerPosition, MostPotentResidues, SAR_PROPERTIES, SARViewer, SELECTION_MODE} from '../viewers/sar-viewer';
12
+ import {COLUMN_NAME, COLUMNS_NAMES, SCALING_METHODS, SEM_TYPES} from '../utils/constants';
11
13
  import {CLUSTER_TYPE, LogoSummaryTable, LST_PROPERTIES} from '../viewers/logo-summary';
14
+ import {MutationCliffsViewer} from '../viewers/mutation-cliffs-viewer';
12
15
  import {PositionHeight} from '@datagrok-libraries/bio/src/viewers/web-logo';
13
- import {TEST_COLUMN_NAMES} from './utils';
16
+ import {analyzeDemoPeptides, DEMO_COLUMN_NAMES, loadDemoPeptides, singleMutationPairs, splitSequences,
17
+ TEST_COLUMN_NAMES} from './utils';
14
18
  import {showTooltip} from '../utils/tooltips';
15
19
  import {PeptideUtils} from '../peptideUtils';
16
20
  import {GEN_COLUMN_NAMES, PEPTIDE_GENERATION_PROPS, PEPTIDE_GENERATION_VIEWER_NAME,
@@ -50,6 +54,7 @@ category('Viewers: Monomer-Position', () => {
50
54
  let mpViewer: MonomerPosition;
51
55
 
52
56
  before(async () => {
57
+ await PeptideUtils.loadComponents();
53
58
  df = DG.DataFrame.fromCsv(await _package.files.readAsText('tests/HELM_small.csv'));
54
59
  activityCol = df.getCol(TEST_COLUMN_NAMES.ACTIVITY);
55
60
  sequenceCol = df.getCol(TEST_COLUMN_NAMES.SEQUENCE);
@@ -64,10 +69,10 @@ category('Viewers: Monomer-Position', () => {
64
69
  model = tempModel;
65
70
  mpViewer = model.findViewer(VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP) as MonomerPosition;
66
71
 
67
- await delay(500);
72
+ await settled(mpViewer);
68
73
  });
69
74
 
70
- after(async () => await delay(3000));
75
+ after(async () => await uiSettled('Peptides analysis'));
71
76
 
72
77
  test('Tooltip', async () => {
73
78
  const cellCoordinates = {col: '9', row: 6};
@@ -97,6 +102,49 @@ category('Viewers: Monomer-Position', () => {
97
102
  expect(mpViewer.mode, SELECTION_MODE.MUTATION_CLIFFS,
98
103
  `Monomer-Position mode is not ${SELECTION_MODE.MUTATION_CLIFFS} after switching`);
99
104
  });
105
+
106
+ test('Mode switch stays inside a narrow viewer', async () => {
107
+ const root = mpViewer.root;
108
+ const width = root.style.width;
109
+ root.style.width = '200px';
110
+ try {
111
+ const rootRect = root.getBoundingClientRect();
112
+ const radios = Array.from(root.querySelectorAll<HTMLElement>('#pep-viewer-title input'));
113
+ expect(radios.length, 2, 'the mode switch has two radios');
114
+ for (const radio of radios) {
115
+ const rect = radio.getBoundingClientRect();
116
+ expect(rect.left >= rootRect.left && rect.right <= rootRect.right, true,
117
+ `the ${radio.getAttribute('name')} radio is cut off by the viewer edge`);
118
+ const hit = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
119
+ expect(radio.closest('#pep-viewer-title')!.contains(hit), true,
120
+ `the ${radio.getAttribute('name')} radio is covered`);
121
+ }
122
+ } finally {
123
+ root.style.width = width;
124
+ }
125
+ });
126
+
127
+ test('Highlighting after row removal', async () => {
128
+ const monomerPosition = mpViewer.getMonomerPosition(mpViewer.viewerGrid.cell('9', 6));
129
+ await testEvent(df.onRowsRemoved, () => {}, () => df.rows.removeAt(0, 2), 5000, 'Rows removal is not reported');
130
+
131
+ // Highlighting or's a fresh row-count-sized mask with the cached ones, so stale masks throw 'Array lengths differ'
132
+ highlightMonomerPosition(monomerPosition, df, mpViewer.monomerPositionStats);
133
+ });
134
+
135
+ test('Highlighting after row removal with viewer-specific scaling', async () => {
136
+ // Scaling differing from the analysis settings makes the viewer compute stats from its own cached activity column
137
+ mpViewer.getProperty(SAR_PROPERTIES.ACTIVITY_SCALING)!.set(mpViewer, SCALING_METHODS.LG);
138
+ expect(mpViewer.monomerPositionStats != null, true, 'Stats should be computed with viewer-specific scaling');
139
+ await testEvent(df.onRowsRemoved, () => {}, () => df.rows.removeAt(0, 2), 5000, 'Rows removal is not reported');
140
+
141
+ const stats = mpViewer.monomerPositionStats;
142
+ const position = Object.keys(stats).find((key) => key !== 'general')!;
143
+ const monomer = Object.keys(stats[position]).find((key) => key !== 'general')!;
144
+ expect(stats[position][monomer].mask.length, df.rowCount,
145
+ 'Recomputed masks should match the row count after removal');
146
+ highlightMonomerPosition({monomerOrCluster: monomer, positionOrClusterType: position}, df, stats);
147
+ });
100
148
  }, {clear: false});
101
149
 
102
150
  category('Viewers: Most Potent Residues', () => {
@@ -109,6 +157,7 @@ category('Viewers: Most Potent Residues', () => {
109
157
  let mprViewer: MostPotentResidues;
110
158
 
111
159
  before(async () => {
160
+ await PeptideUtils.loadComponents();
112
161
  df = DG.DataFrame.fromCsv(await _package.files.readAsText('tests/HELM_small.csv'));
113
162
  activityCol = df.getCol(TEST_COLUMN_NAMES.ACTIVITY);
114
163
  sequenceCol = df.getCol(TEST_COLUMN_NAMES.SEQUENCE);
@@ -123,10 +172,10 @@ category('Viewers: Most Potent Residues', () => {
123
172
  model = tempModel;
124
173
  mprViewer = model.findViewer(VIEWER_TYPE.MOST_POTENT_RESIDUES) as MostPotentResidues;
125
174
 
126
- await delay(500);
175
+ await settled(mprViewer);
127
176
  });
128
177
 
129
- after(async () => await delay(3000));
178
+ after(async () => await uiSettled('Peptides analysis'));
130
179
 
131
180
  test('Tooltip', async () => {
132
181
  const cellCoordinates = {col: 'Diff', row: 6};
@@ -152,6 +201,7 @@ category('Viewers: Logo Summary Table', () => {
152
201
  let lstViewer: LogoSummaryTable;
153
202
 
154
203
  before(async () => {
204
+ await PeptideUtils.loadComponents();
155
205
  df = DG.DataFrame.fromCsv(await _package.files.readAsText('tests/HELM_small.csv'));
156
206
  activityCol = df.getCol(TEST_COLUMN_NAMES.ACTIVITY);
157
207
  sequenceCol = df.getCol(TEST_COLUMN_NAMES.SEQUENCE);
@@ -167,10 +217,10 @@ category('Viewers: Logo Summary Table', () => {
167
217
 
168
218
  lstViewer = model.findViewer(VIEWER_TYPE.LOGO_SUMMARY_TABLE) as LogoSummaryTable;
169
219
 
170
- await delay(500);
220
+ await settled(lstViewer);
171
221
  });
172
222
 
173
- after(async () => await delay(3000));
223
+ after(async () => await uiSettled('Peptides analysis'));
174
224
 
175
225
  test('Properties', async () => {
176
226
  // Change Logo Summary Table Web Logo Mode property to full
@@ -197,6 +247,13 @@ category('Viewers: Logo Summary Table', () => {
197
247
  }, 0, 0);
198
248
  expect(tooltipElement !== null, true, `Tooltip is not shown for cluster '${cluster}'`);
199
249
  });
250
+
251
+ test('Property change after close', async () => {
252
+ lstViewer.close();
253
+ await waitUntil(() => lstViewer.dataFrame == null, 'Expected the closed viewer to have no dataFrame');
254
+ lstViewer.getProperty(LST_PROPERTIES.COLUMNS)!.set(lstViewer, [TEST_COLUMN_NAMES.ACTIVITY]);
255
+ lstViewer.render();
256
+ });
200
257
  }, {clear: false});
201
258
 
202
259
  category('Viewers: Peptide Generation', () => {
@@ -213,11 +270,8 @@ category('Viewers: Peptide Generation', () => {
213
270
  [PEPTIDE_GENERATION_PROPS.SEQUENCE]: TEST_COLUMN_NAMES.SEQUENCE,
214
271
  [PEPTIDE_GENERATION_PROPS.ACTIVITY]: TEST_COLUMN_NAMES.ACTIVITY,
215
272
  }) as PeptideGenerationViewer;
216
- await delay(500);
217
273
  });
218
274
 
219
- after(async () => await delay(1000));
220
-
221
275
  test('Generates peptides', async () => {
222
276
  const peptideCount = 10;
223
277
  genViewer.getProperty(PEPTIDE_GENERATION_PROPS.PEPTIDE_COUNT)!.set(genViewer, peptideCount);
@@ -251,3 +305,205 @@ category('Viewers: Peptide Generation', () => {
251
305
  'High-target peptides should reach at least as high a predicted activity as the Low-target minimum');
252
306
  });
253
307
  });
308
+
309
+ category('Viewers: Export', () => {
310
+ let df: DG.DataFrame;
311
+ let model: PeptidesModel;
312
+ let split: string[][];
313
+
314
+ before(async () => {
315
+ await PeptideUtils.loadComponents();
316
+ df = await loadDemoPeptides();
317
+ split = splitSequences(df.getCol(DEMO_COLUMN_NAMES.SEQUENCE));
318
+ model = await analyzeDemoPeptides(df);
319
+ const mpViewer = model.findViewer(VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP) as MonomerPosition;
320
+ await waitUntil(() => mpViewer.mutationCliffs !== null, 'Mutation cliffs are not calculated', 30000);
321
+ });
322
+
323
+ after(async () => grok.shell.closeAll());
324
+
325
+ test('Invariant map', async () => {
326
+ const monomers = [...new Set(split.flat().filter((monomer) => monomer !== ''))].sort();
327
+ const positions = split[0].map((_, i) => `${i + 1}`);
328
+ expect(monomers.length, 22, 'monomers');
329
+ expect(positions.length, 17, 'positions');
330
+ for (const viewerType of [VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP, VIEWER_TYPE.MOST_POTENT_RESIDUES]) {
331
+ (model.findViewer(viewerType) as SARViewer).exportInvariantMap();
332
+ const view = grok.shell.tv;
333
+ const exported = view.dataFrame;
334
+ try {
335
+ expect(exported.name, 'Invariant Map', `${viewerType} export`);
336
+ expect(exported.columns.names().join(', '), [COLUMNS_NAMES.MONOMER, ...positions].join(', '),
337
+ `${viewerType} export columns`);
338
+ expect(exported.getCol(COLUMNS_NAMES.MONOMER).toList().join(', '), monomers.join(', '),
339
+ `${viewerType} export monomers`);
340
+ for (const position of positions) {
341
+ const counts = exported.getCol(position);
342
+ expect(counts.type, DG.COLUMN_TYPE.INT, `${viewerType} export column ${position}`);
343
+ for (let row = 0; row < monomers.length; row++) {
344
+ expect(counts.get(row), split.filter((s) => s[Number(position) - 1] === monomers[row]).length,
345
+ `${viewerType} export count of ${monomers[row]} at ${position}`);
346
+ }
347
+ }
348
+ } finally {
349
+ view.close();
350
+ }
351
+ }
352
+ });
353
+
354
+ test('Mutation cliffs', async () => {
355
+ const sequences = df.getCol(DEMO_COLUMN_NAMES.SEQUENCE);
356
+ const activities = df.getCol(DEMO_COLUMN_NAMES.ACTIVITY);
357
+ const ids = df.getCol(DEMO_COLUMN_NAMES.ID);
358
+ const rowByActivity = new Map(activities.toList().map((activity, row) => [activity, row]));
359
+ expect(rowByActivity.size, df.rowCount, 'IC50 identifies the source rows');
360
+ const expectedPairs = singleMutationPairs(split);
361
+ expect(expectedPairs.size, 6253, 'single-mutation pairs');
362
+
363
+ (model.findViewer(VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP) as MonomerPosition)['_doExportMutationCliffs']([ids]);
364
+ const view = grok.shell.tv;
365
+ const exported = view.dataFrame;
366
+ try {
367
+ expect(exported.name, 'Mutation Cliffs');
368
+ expect(exported.columns.names().join(', '),
369
+ 'Seq 1, Seq 2, Mutation, Seq 1 IC50, Seq 2 IC50, Delta, Seq 1 ID, Seq 2 ID', 'export columns');
370
+ for (const name of ['Seq 1', 'Seq 2']) {
371
+ expect(exported.getCol(name).semType, DG.SEMTYPE.MACROMOLECULE, `${name} semantic type`);
372
+ expect(exported.getCol(name).meta.units, NOTATION.SEPARATOR, `${name} units`);
373
+ }
374
+ expect(exported.getCol('Mutation').semType, SEM_TYPES.MACROMOLECULE_DIFFERENCE, 'Mutation semantic type');
375
+ const exportedPairs = new Set<string>();
376
+ for (let row = 0; row < exported.rowCount; row++) {
377
+ const activity1 = exported.get('Seq 1 IC50', row);
378
+ const activity2 = exported.get('Seq 2 IC50', row);
379
+ const a = rowByActivity.get(activity1)!;
380
+ const b = rowByActivity.get(activity2)!;
381
+ const pair = `${Math.min(a, b)}:${Math.max(a, b)}`;
382
+ expect(expectedPairs.has(pair) && !exportedPairs.has(pair), true, `row ${row}: duplicate or non-cliff pair`);
383
+ exportedPairs.add(pair);
384
+ const seq1 = exported.get('Seq 1', row);
385
+ const seq2 = exported.get('Seq 2', row);
386
+ expect(seq1, sequences.get(a), `row ${row}: Seq 1`);
387
+ expect(seq2, sequences.get(b), `row ${row}: Seq 2`);
388
+ expect(exported.get('Mutation', row), `${seq1}#${seq2}`, `row ${row}: Mutation`);
389
+ expectFloat(exported.get('Delta', row), activity1 - activity2, 1e-12, `row ${row}: Delta`);
390
+ expect(exported.get('Seq 1 ID', row), ids.get(a), `row ${row}: Seq 1 ID`);
391
+ expect(exported.get('Seq 2 ID', row), ids.get(b), `row ${row}: Seq 2 ID`);
392
+ }
393
+ expect(exportedPairs.size, expectedPairs.size, 'exported single-mutation pairs');
394
+ } finally {
395
+ view.close();
396
+ }
397
+ });
398
+ }, {clear: false});
399
+
400
+ category('Viewers: Mutation Cliffs', () => {
401
+ let df: DG.DataFrame;
402
+ let model: PeptidesModel;
403
+ let split: string[][];
404
+
405
+ before(async () => {
406
+ await PeptideUtils.loadComponents();
407
+ df = await loadDemoPeptides(200);
408
+ split = splitSequences(df.getCol(DEMO_COLUMN_NAMES.SEQUENCE));
409
+ model = await analyzeDemoPeptides(df);
410
+ });
411
+
412
+ after(async () => grok.shell.closeAll());
413
+
414
+ test('Cliff counts', async () => {
415
+ const mpViewer = model.findViewer(VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP) as MonomerPosition;
416
+ await waitUntil(() => mpViewer.mutationCliffs !== null, 'Mutation cliffs are not calculated', 30000);
417
+ const cliffs = mpViewer.mutationCliffs!;
418
+ const cliffCount = (monomer: string, position: string): number =>
419
+ Array.from(cliffs.get(monomer)?.get(position)?.values() ?? []).reduce((sum, targets) => sum + targets.length, 0);
420
+ let pairs = 0;
421
+ const uniquePairs = new Set<string>();
422
+ for (const [monomer, positions] of cliffs) {
423
+ for (const [position, indexes] of positions) {
424
+ pairs += cliffCount(monomer, position);
425
+ for (const [from, targets] of indexes) {
426
+ for (const to of targets)
427
+ uniquePairs.add(`${Math.min(from, to)}:${Math.max(from, to)}`);
428
+ }
429
+ }
430
+ }
431
+ expect(pairs, 4484, 'cliff pairs, one per mutated monomer of a pair');
432
+ expect(uniquePairs.size, 2242, 'unique cliff pairs');
433
+ const expectedPairs = singleMutationPairs(split);
434
+ expect(expectedPairs.size === uniquePairs.size && [...expectedPairs].every((pair) => uniquePairs.has(pair)), true,
435
+ 'cliff pairs are the single-mutation pairs');
436
+ expect(cliffCount('A', '2'), 100, 'cliffs of A at 2');
437
+ expect(cliffCount('A', '3'), 0, 'cliffs of A at 3');
438
+
439
+ expect(model.positionColumns?.length, 17, 'positions');
440
+ expect(df.getCol('2').semType, SEM_TYPES.MONOMER, 'position column semantic type');
441
+ const stats = mpViewer.monomerPositionStats['2']['A'];
442
+ expect(stats.count, 59, 'count of A at 2');
443
+ expect(Number.isFinite(stats.meanDifference), true, 'mean difference of A at 2');
444
+ expect(stats.pValue !== null && stats.pValue >= 0 && stats.pValue <= 1, true, `p-value ${stats.pValue} of A at 2`);
445
+ });
446
+
447
+ test('Position chart', async () => {
448
+ const participants = (position: number): number[] => {
449
+ const rows = new Set<number>();
450
+ for (const pair of singleMutationPairs(split)) {
451
+ const [a, b] = pair.split(':').map(Number);
452
+ if (split[a][position - 1] !== split[b][position - 1])
453
+ rows.add(a).add(b);
454
+ }
455
+ return [...rows].sort((a, b) => a - b);
456
+ };
457
+ const viewer = await df.plot.fromType(VIEWER_TYPE.SEQUENCE_MUTATION_CLIFFS, {
458
+ sequenceColumnName: DEMO_COLUMN_NAMES.SEQUENCE, activityColumnName: DEMO_COLUMN_NAMES.ACTIVITY, position: 2,
459
+ }) as MutationCliffsViewer;
460
+ model.analysisView.addViewer(viewer);
461
+ const chartAt = async (position: number): Promise<DG.DataFrame> => {
462
+ viewer.getProperty('position')!.set(viewer, position);
463
+ await waitUntil(() => viewer.getWidgetStatus().values.position === position && !viewer.isRenderPending,
464
+ `The position ${position} chart is not rendered`, 15000);
465
+ return viewer.innerDf;
466
+ };
467
+
468
+ const rows = participants(2);
469
+ expect(rows.length, 115, 'peptides in position 2 cliffs');
470
+ const chart = await chartAt(2);
471
+ expect(chart.rowCount, rows.length, 'position 2 chart rows');
472
+ const monomers = chart.getCol('Position 2');
473
+ const plotted = chart.getCol(viewer.activityColumnName);
474
+ const activities = df.getCol(DEMO_COLUMN_NAMES.ACTIVITY);
475
+ for (let i = 0; i < rows.length; i++) {
476
+ expect(monomers.get(i) ?? '', split[rows[i]][1], `position 2 chart row ${i}: monomer`);
477
+ expect(Math.fround(plotted.get(i)), Math.fround(activities.get(rows[i])), `position 2 chart row ${i}: activity`);
478
+ }
479
+ expect(participants(1).length, 0, 'peptides in position 1 cliffs');
480
+ expect((await chartAt(1)).rowCount, 0, 'position 1 chart rows');
481
+ });
482
+ }, {clear: false});
483
+
484
+ category('Viewers: Logo Summary Table WebLogo', () => {
485
+ before(async () => await PeptideUtils.loadComponents());
486
+
487
+ after(async () => grok.shell.closeAll());
488
+
489
+ // WebLogo aggregation must use the same filtered rows as the cluster bitsets
490
+ test('WebLogo aggregation on a filtered table', async () => {
491
+ const df = await loadDemoPeptides();
492
+ const model = await analyzeDemoPeptides(df, 90);
493
+ const lst = model.findViewer(VIEWER_TYPE.LOGO_SUMMARY_TABLE) as LogoSummaryTable;
494
+ const unfilteredGrid = lst.viewerGrid;
495
+ const mask = DG.BitSet.create(df.rowCount, (i) => i % 10 !== 0);
496
+ const filterSub = df.onRowsFiltering.subscribe(() => df.filter.and(mask));
497
+ try {
498
+ df.rows.requestFilter();
499
+ await waitUntil(() => lst.viewerGrid !== unfilteredGrid, 'Logo Summary Table is not rebuilt on filter', 5000);
500
+ lst.getProperty(`${LST_PROPERTIES.WEB_LOGO_AGGREGATION_COLUMN_NAME}${COLUMN_NAME}`)!
501
+ .set(lst, DEMO_COLUMN_NAMES.ACTIVITY);
502
+ lst.getProperty(LST_PROPERTIES.WEB_LOGO_AGGREGATION_TYPE)!.set(lst, DG.AGG.AVG);
503
+ await waitUntil(() => lst.viewerGrid.root.querySelector('.bio-wl-host') !== null,
504
+ 'WebLogo is not rendered for the filtered table', 10000);
505
+ } finally {
506
+ filterSub.unsubscribe();
507
+ }
508
+ }, {timeout: 120000});
509
+ }, {clear: false});
@@ -1,7 +1,7 @@
1
1
  import * as grok from 'datagrok-api/grok';
2
2
  import * as DG from 'datagrok-api/dg';
3
3
 
4
- import {after, before, category, delay, expect, test} from '@datagrok-libraries/test/src/test';
4
+ import {after, before, category, expect, settled, test, uiSettled, waitUntil} from '@datagrok-libraries/test/src/test';
5
5
  import {_package} from '../package-test';
6
6
  import {PeptidesModel, VIEWER_TYPE} from '../model';
7
7
  import {scaleActivity} from '../utils/misc';
@@ -41,10 +41,10 @@ category('Widgets: Settings', () => {
41
41
  throw new Error('Model is null');
42
42
  model = tempModel;
43
43
 
44
- await delay(500);
44
+ await uiSettled('Peptides analysis');
45
45
  });
46
46
 
47
- after(async () => await delay(3000));
47
+ after(async () => await uiSettled('Peptides analysis'));
48
48
 
49
49
  test('UI', async () => {
50
50
  const settingsElements = getSettingsDialog(model);
@@ -88,14 +88,14 @@ category('Widgets: Distribution panel', () => {
88
88
  throw new Error('Model is null');
89
89
  model = tempModel;
90
90
 
91
- await delay(500);
91
+ await uiSettled('Peptides analysis');
92
92
  });
93
93
 
94
- after(async () => await delay(3000));
94
+ after(async () => await uiSettled('Peptides analysis'));
95
95
 
96
96
  test('UI', async () => {
97
97
  model.df.selection.set(0, true);
98
- await delay(1000);
98
+ await uiSettled('Selection');
99
99
  const lstViewer = model.findViewer(VIEWER_TYPE.LOGO_SUMMARY_TABLE) as LogoSummaryTable | null;
100
100
  getDistributionWidget(model.df, {
101
101
  columns: model.settings!.columns!,
@@ -129,16 +129,16 @@ category('Widgets: Mutation cliffs', () => {
129
129
  throw new Error('Model is null');
130
130
  model = tempModel;
131
131
 
132
- await delay(500);
132
+ await uiSettled('Peptides analysis');
133
133
  });
134
134
 
135
- after(async () => await delay(3000));
135
+ after(async () => await uiSettled('Peptides analysis'));
136
136
 
137
137
  test('UI', async () => {
138
138
  const sarViewer = model.findViewer(VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP) as MonomerPosition;
139
139
  sarViewer.keyPressed = true; //required to emulate cell selection
140
140
  sarViewer._viewerGrid!.dataFrame.currentCell = sarViewer._viewerGrid?.dataFrame.cell(0, '1')!;
141
- await delay(1000);
141
+ await settled(sarViewer);
142
142
  mutationCliffsWidget(model.df, {
143
143
  mutationCliffs: sarViewer.mutationCliffs!,
144
144
  mutationCliffsSelection: sarViewer.mutationCliffsSelection,
@@ -176,10 +176,10 @@ category('Widgets: Actions', () => {
176
176
  throw new Error('Model is null');
177
177
  model = tempModel;
178
178
 
179
- await delay(500);
179
+ await uiSettled('Peptides analysis');
180
180
  });
181
181
 
182
- after(async () => await delay(3000));
182
+ after(async () => await uiSettled('Peptides analysis'));
183
183
 
184
184
  test('New view', async () => {
185
185
  // Set compound bitset: filter out 2 rows and select 1 among them
@@ -199,7 +199,8 @@ category('Widgets: Actions', () => {
199
199
  expect(currentTable.getTag(DG.TAGS.ID), newViewId, 'Current table is expected to have the same UUID as new view');
200
200
  expect(currentTable.rowCount, 2, 'Current table is expected to have 2 rows');
201
201
 
202
- await delay(500);
202
+ await waitUntil(() => currentTable.temp[PeptidesModel.modelName] != null,
203
+ 'Logo Summary Table of the new view did not create its Peptides model');
203
204
  const currentTableModel = currentTable.temp[PeptidesModel.modelName] as PeptidesModel;
204
205
  const lstViewer = currentTableModel.findViewer(VIEWER_TYPE.LOGO_SUMMARY_TABLE);
205
206
  expect(lstViewer !== null, true, 'New view is expected to have Logo Summary Table viewer attached');
@@ -303,13 +303,13 @@ export type WebLogoBounds = { [position: string]: { [monomer: string]: DG.Rect }
303
303
  /**
304
304
  * Sets WebLogo renderer.
305
305
  * @param grid - Grid to set renderer to.
306
- * @param monomerPositionStats - Monomer position statistics.
306
+ * @param monomerPositionStats - Monomer position statistics getter, invoked on each render/event to avoid stale masks.
307
307
  * @param positionColumns - Position columns.
308
308
  * @param activityCol - Activity column.
309
309
  * @param options - Cell renderer options.
310
310
  * @param tooltipOptions - Tooltip options.
311
311
  */
312
- export function setWebLogoRenderer(grid: DG.Grid, monomerPositionStats: MonomerPositionStats,
312
+ export function setWebLogoRenderer(grid: DG.Grid, monomerPositionStats: () => MonomerPositionStats,
313
313
  positionColumns: DG.Column<string>[], activityCol: DG.Column<number>, options: WebLogoCellRendererOptions,
314
314
  tooltipOptions: TooltipOptions = {
315
315
  x: 0, y: 0, mpStats: {} as MonomerPositionStats,
@@ -317,7 +317,7 @@ export function setWebLogoRenderer(grid: DG.Grid, monomerPositionStats: MonomerP
317
317
  }): void {
318
318
  options.isSelectionTable ??= false;
319
319
  if (Object.keys(tooltipOptions.mpStats).length == 0)
320
- tooltipOptions.mpStats = monomerPositionStats;
320
+ tooltipOptions.mpStats = monomerPositionStats();
321
321
 
322
322
 
323
323
  if (options.isSelectionTable && (!options.webLogoBounds || !options.cachedWebLogoTooltip)) {
@@ -367,7 +367,7 @@ export function setWebLogoRenderer(grid: DG.Grid, monomerPositionStats: MonomerP
367
367
  columns: [col.name],
368
368
  })[col.name];
369
369
  } else
370
- stats = monomerPositionStats[col.name];
370
+ stats = monomerPositionStats()[col.name];
371
371
 
372
372
 
373
373
  if (!stats)
@@ -410,12 +410,13 @@ export function setWebLogoRenderer(grid: DG.Grid, monomerPositionStats: MonomerP
410
410
  return;
411
411
  }
412
412
  tooltipOptions.monomerPosition = monomerPosition;
413
+ tooltipOptions.mpStats = monomerPositionStats();
413
414
  const isDfFiltered = df.filter.anyFalse;
414
415
  const actionDf = isDfFiltered ? df.clone(df.filter) : df;
415
416
  const actionActivityCol = actionDf.getCol(activityCol.name) as DG.Column<number>;
416
417
  requestWebLogoAction(ev, monomerPosition, actionDf, actionActivityCol, options, tooltipOptions);
417
418
  if (!options.isSelectionTable && options.highlightCallback != null)
418
- options.highlightCallback(monomerPosition, df, monomerPositionStats);
419
+ options.highlightCallback(monomerPosition, df, monomerPositionStats());
419
420
  } else if (options.unhighlightCallback != null)
420
421
  options.unhighlightCallback();
421
422
  };
@@ -441,7 +442,7 @@ export function setWebLogoRenderer(grid: DG.Grid, monomerPositionStats: MonomerP
441
442
  function requestWebLogoAction(ev: MouseEvent, monomerPosition: type.SelectionItem, df: DG.DataFrame,
442
443
  activityCol: DG.Column<number>, options: WebLogoCellRendererOptions, tooltipOptions: TooltipOptions): void {
443
444
  if (ev.type === 'click' && !options.isSelectionTable && options.selectionCallback != null)
444
- options.selectionCallback(monomerPosition, {shiftPressed: ev.shiftKey, ctrlPressed: ev.ctrlKey});
445
+ options.selectionCallback(monomerPosition, {shiftPressed: ev.shiftKey, ctrlPressed: (ev.ctrlKey || ev.metaKey)});
445
446
  else {
446
447
  const bar = `${monomerPosition.positionOrClusterType} = ${monomerPosition.monomerOrCluster}`;
447
448
  if (options.cachedWebLogoTooltip()!.bar === bar)
@@ -1,5 +1,15 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
2
 
3
+ export enum VIEWER_TYPE {
4
+ SEQUENCE_VARIABILITY_MAP = 'Sequence Variability Map',
5
+ MOST_POTENT_RESIDUES = 'Most Potent Residues',
6
+ LOGO_SUMMARY_TABLE = 'Logo Summary Table',
7
+ DENDROGRAM = 'Dendrogram',
8
+ CLUSTER_MAX_ACTIVITY = 'Active peptide selection',
9
+ MCL = 'MCL',
10
+ SEQUENCE_MUTATION_CLIFFS = 'Sequence Mutation Cliffs',
11
+ }
12
+
3
13
  export enum COLUMNS_NAMES {
4
14
  SPLIT_COL = '~split',
5
15
  ACTIVITY = 'Activity',
package/src/utils/misc.ts CHANGED
@@ -363,8 +363,8 @@ export function modifySelection(selection: type.Selection, clusterOrMonomerPosit
363
363
  * @param monomerPositionStats - Object with statistics for monomer-positions.
364
364
  */
365
365
  export function highlightMonomerPosition(monomerPosition: type.SelectionItem, dataFrame: DG.DataFrame,
366
- monomerPositionStats: MonomerPositionStats): void {
367
- if (!dataFrame) return;
366
+ monomerPositionStats: MonomerPositionStats): number {
367
+ if (!dataFrame) return 0;
368
368
  const bitArray = new BitArray(dataFrame.rowCount);
369
369
  if (monomerPosition.positionOrClusterType === C.COLUMNS_NAMES.MONOMER) {
370
370
  const positionStats = Object.values(monomerPositionStats);
@@ -383,6 +383,7 @@ export function highlightMonomerPosition(monomerPosition: type.SelectionItem, da
383
383
  }
384
384
 
385
385
  dataFrame.rows.highlight((i) => bitArray.getBit(i));
386
+ return bitArray.trueCount();
386
387
  }
387
388
 
388
389
  /**
@@ -509,4 +510,3 @@ export function dartLike<T extends any>(obj: T) {
509
510
  },
510
511
  };
511
512
  }
512
-
@@ -60,8 +60,8 @@ export function bitArrayToBitSet(bitArray: BitArray): DG.BitSet {
60
60
  */
61
61
  export function getStats(data: RawData | number[], bitArray: BitArray, filter?: BitArray,
62
62
  aggData?: {col: DG.Column, type: DG.AGG}): StatsItem {
63
- // if column length is less than 16, raw data will be still of length 16
64
- if ((data.length !== bitArray.length && data.length !== 16) || (filter && data.length !== filter.length && data.length !== 16))
63
+ // raw data can be longer than the logical length: capacity is padded (min 16) and is kept after row removal
64
+ if (data.length < bitArray.length || (filter && data.length < filter.length))
65
65
  throw new Error('PeptidesError: Data and bit array have different lengths');
66
66
  if (filter && filter.allTrue)
67
67
  filter = undefined; // no need to filter if all true