@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
package/src/package.ts CHANGED
@@ -10,10 +10,10 @@ import {manualAlignmentWidget} from './widgets/manual-alignment';
10
10
  import {MonomerPosition, MostPotentResidues} from './viewers/sar-viewer';
11
11
  import {getTreeHelper, ITreeHelper} from '@datagrok-libraries/bio/src/trees/tree-helper';
12
12
  import {LogoSummaryTable} from './viewers/logo-summary';
13
- import {MonomerWorks} from '@datagrok-libraries/bio/src/monomer-works/monomer-works';
14
13
  import {PeptidesModel} from './model';
15
14
  import {macromoleculeSarFastaDemoUI} from './demo/fasta';
16
- import {u2} from '@datagrok-libraries/utils/src/u2';
15
+ import {AppHeader} from '@datagrok-libraries/u2';
16
+ import {ViewHost} from '@datagrok-libraries/u2/dg';
17
17
  import {ClusterMaxActivityViewer} from './viewers/cluster-max-activity-viewer';
18
18
  import {LSTPieChartRenderer} from './utils/cell-renderer';
19
19
  import {PeptideUtils} from './peptideUtils';
@@ -21,7 +21,6 @@ import {SequencePositionStatsViewer} from './viewers/position-statistics-viewer'
21
21
  import {MutationCliffsViewer} from './viewers/mutation-cliffs-viewer';
22
22
  import {PeptideGenerationViewer} from './viewers/peptide-generation-viewer';
23
23
 
24
- let monomerWorks: MonomerWorks | null = null;
25
24
  let treeHelper: ITreeHelper;
26
25
  export const _package = new DG.Package();
27
26
  export * from './package.g';
@@ -57,11 +56,6 @@ decorators.forEach((decorator) => {
57
56
 
58
57
  /** End temporary polyfill */
59
58
 
60
- export function getMonomerWorksInstance(): MonomerWorks | null {
61
- return monomerWorks;
62
- }
63
-
64
-
65
59
  export function getTreeHelperInstance(): ITreeHelper {
66
60
  return treeHelper;
67
61
  }
@@ -74,7 +68,7 @@ async function openDemoData(chosenFile: string): Promise<void> {
74
68
  peptides.name = 'Peptides';
75
69
  const view = grok.shell.addTableView(peptides);
76
70
  view.name = 'PeptidesView';
77
- grok.shell.windows.showProperties = true;
71
+ grok.shell.windows.showContextPanel = true;
78
72
  pi.close();
79
73
  }
80
74
 
@@ -83,7 +77,6 @@ export class PackageFunctions {
83
77
  @grok.decorators.init({tags: ['init']})
84
78
  static async initPeptides(): Promise<void> {
85
79
  try {
86
- monomerWorks ??= new MonomerWorks(await grok.functions.call('Bio:getBioLib'));
87
80
  treeHelper ??= await getTreeHelper();
88
81
  await PeptideUtils.loadComponents();
89
82
  } catch (e) {
@@ -93,25 +86,26 @@ export class PackageFunctions {
93
86
 
94
87
  @grok.decorators.func()
95
88
  static Peptides(): DG.View {
96
- const appHeader = u2.appHeader({
97
- iconPath: _package.getIconUrl(),
98
- learnMoreUrl: 'https://github.com/datagrok-ai/public/blob/master/help/domains/bio/peptides.md',
99
- description:
100
- '- Automatically recognizes peptides in your data\n' +
101
- '- Invariant map and mutation cliffs\n' +
102
- '- Logo plots to explore sequence composition\n' +
103
- '- Hierarchical clustering\n' +
104
- '- Sequence space to analyze clustering and activity cliffs\n' +
105
- '- Finds statistically significant changes in activity for monomer/positions\n',
106
- });
89
+ const view = View.create();
90
+ view.name = 'Peptides';
91
+ const appHeader = ViewHost.of(view).build(() => new AppHeader({
92
+ icon: _package.getIconUrl(),
93
+ learnMore: 'https://github.com/datagrok-ai/help/blob/master/datagrok/solutions/domains/bio/peptides-sar.md',
94
+ items: [
95
+ 'Automatically recognizes peptides in your data',
96
+ 'Invariant map and mutation cliffs',
97
+ 'Logo plots to explore sequence composition',
98
+ 'Hierarchical clustering',
99
+ 'Sequence space to analyze clustering and activity cliffs',
100
+ 'Finds statistically significant changes in activity for monomer/positions',
101
+ ],
102
+ })).root;
107
103
 
108
104
  const windows = grok.shell.windows;
109
105
  windows.showToolbox = false;
110
106
  windows.showHelp = false;
111
- windows.showProperties = false;
107
+ windows.showContextPanel = false;
112
108
 
113
- const view = View.create();
114
- view.name = 'Peptides';
115
109
  ui.appendAll(view.root, [
116
110
  appHeader,
117
111
  ui.divH([
@@ -126,6 +120,7 @@ export class PackageFunctions {
126
120
 
127
121
  @grok.decorators.func({
128
122
  'top-menu': 'Bio | Analyze | SAR...',
123
+ 'requiresSemType': 'Macromolecule',
129
124
  'name': 'Bio Peptides',
130
125
  'outputs': [],
131
126
  })
package/src/tests/core.ts CHANGED
@@ -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 {awaitCheck, before, category, delay, expect, test} from '@datagrok-libraries/test/src/test';
4
+ import {before, category, expect, test, uiSettled, waitUntil} from '@datagrok-libraries/test/src/test';
5
5
 
6
6
  import {_package} from '../package-test';
7
7
  import {startAnalysis} from '../widgets/peptides';
@@ -35,7 +35,7 @@ category('Core', () => {
35
35
 
36
36
  const MPViewer = model!.findViewer(VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP) as MonomerPosition | null;
37
37
  MPViewer!.mutationCliffsSelection = {'11': ['D']};
38
- await delay(3000);
38
+ await uiSettled('Peptides analysis');
39
39
  });
40
40
 
41
41
  test('Start analysis: сomplex', async () => {
@@ -56,7 +56,7 @@ category('Core', () => {
56
56
 
57
57
  const MPViewer = model!.findViewer(VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP) as MonomerPosition | null;
58
58
  MPViewer!.mutationCliffsSelection = {'13': ['-']};
59
- await delay(3000);
59
+ await uiSettled('Peptides analysis');
60
60
  });
61
61
 
62
62
  test('Save and load project', async () => {
@@ -73,7 +73,7 @@ category('Core', () => {
73
73
  model = await startAnalysis(simpleActivityCol, simpleAlignedSeqCol, null, simpleTable, simpleScaledCol,
74
74
  C.SCALING_METHODS.MINUS_LG);
75
75
 
76
- let v = grok.shell.getTableView('Peptides analysis');
76
+ let v = grok.shell.tableView('Peptides analysis');
77
77
 
78
78
  const d = v.dataFrame;
79
79
  const layout = v.saveLayout();
@@ -89,11 +89,11 @@ category('Core', () => {
89
89
  const sp = await grok.dapi.projects.save(project);
90
90
 
91
91
  v.close();
92
- await awaitCheck(() => typeof grok.shell.tableView('Peptides analysis') === 'undefined',
92
+ await waitUntil(() => typeof grok.shell.tableView('Peptides analysis') === 'undefined',
93
93
  'Table never closed', 3000);
94
94
 
95
95
  await sp.open();
96
- v = grok.shell.getTableView('Peptides analysis');
96
+ v = grok.shell.tableView('Peptides analysis');
97
97
 
98
98
  await grok.dapi.layouts.delete(sl);
99
99
  await grok.dapi.tables.delete(sti);
package/src/tests/misc.ts CHANGED
@@ -6,6 +6,7 @@ import {findMutations, MutationCliffsOptions} from '../utils/algorithms';
6
6
  import * as type from '../utils/types';
7
7
  import {extractColInfo} from '../utils/misc';
8
8
  import {PeptideUtils} from '../peptideUtils';
9
+ import {getStats} from '../utils/statistics';
9
10
  import BitArray from '@datagrok-libraries/utils/src/bit-array';
10
11
 
11
12
  category('Algorithms', () => {
@@ -60,4 +61,23 @@ category('Algorithms', () => {
60
61
  mutationCliffsInfo = await findMutations(activityCol, monomerColumns, settings);
61
62
  expect(mutationCliffsInfo.size, 0, `MutationCliffsInfo should be empty for target '1'`);
62
63
  });
64
+
65
+ test('getStats: capacity-padded raw data', async () => {
66
+ // Raw data buffers keep their capacity after row removal, so they can be longer than the mask
67
+ const data = new Float64Array([1, 2, 3, 4, 5, 100, 100]);
68
+ const mask = new BitArray(5, false);
69
+ mask.setBit(2, true);
70
+ const stats = getStats(data, mask);
71
+ expect(stats.count, 1, 'Stats should be computed when raw data is longer than the mask');
72
+ expect(stats.mean, 3, 'Mean should only consider rows within the mask length');
73
+ expect(stats.meanDifference, 0, 'Mean difference should ignore padded values beyond the mask length');
74
+
75
+ let error = '';
76
+ try {
77
+ getStats(new Float64Array(3), new BitArray(5, false));
78
+ } catch (e) {
79
+ error = String(e);
80
+ }
81
+ expect(error.includes('different lengths'), true, 'Data shorter than the mask should still throw');
82
+ });
63
83
  });
@@ -3,13 +3,13 @@ import * as DG
3
3
 
4
4
  import {
5
5
  after,
6
- awaitCheck,
7
6
  before,
8
7
  category,
9
- delay,
10
8
  expect,
11
9
  expectFloat,
12
10
  test,
11
+ uiSettled,
12
+ waitUntil,
13
13
  } from '@datagrok-libraries/test/src/test';
14
14
  import {
15
15
  _package,
@@ -29,12 +29,15 @@ import {
29
29
  } from '@datagrok-libraries/bio/src/utils/macromolecule';
30
30
  import {
31
31
  COLUMNS_NAMES,
32
+ LST_COLUMN_NAMES,
32
33
  SCALING_METHODS,
33
34
  } from '../utils/constants';
34
35
  import {
35
36
  LogoSummaryTable,
36
37
  } from '../viewers/logo-summary';
37
38
  import {
39
+ analyzeDemoPeptides,
40
+ loadDemoPeptides,
38
41
  TEST_COLUMN_NAMES,
39
42
  } from './utils';
40
43
  import {
@@ -81,10 +84,10 @@ category('Model: Settings', () => {
81
84
 
82
85
  model = tempModel;
83
86
 
84
- await delay(500);
87
+ await uiSettled('Peptides analysis');
85
88
  });
86
89
 
87
- after(async () => await delay(3000));
90
+ after(async () => await uiSettled('Peptides analysis'));
88
91
 
89
92
  test('Activity scaling', async () => {
90
93
  const getError = (row: number, method: SCALING_METHODS): string =>
@@ -163,13 +166,60 @@ category('Model: Settings', () => {
163
166
  model.settings = {showDendrogram: true};
164
167
  expect(model.settings?.showDendrogram, true, 'Dendrogram is disabled after enabling');
165
168
 
166
- await awaitCheck(() => model.findViewer(VIEWER_TYPE.DENDROGRAM) !== null,
169
+ await waitUntil(() => model.dendrogramCloseButton !== null,
167
170
  'Dendrogram is not present in the view after 5s delay', 5000);
168
171
 
169
172
  // Disable dendrogram
170
173
  model.settings = {showDendrogram: false};
171
174
  expect(model.settings?.showDendrogram, false, 'Dendrogram is enabled after disabling');
172
- expect(model.findViewer(VIEWER_TYPE.DENDROGRAM) === null, true,
175
+ expect(model.dendrogramCloseButton === null, true,
173
176
  'Dendrogram is present in the view after disabling');
174
177
  }, {skipReason: 'Need to find a way to replace _package variable to call for Bio function with tests'});
175
178
  }, {clear: false});
179
+
180
+ category('Model: MCL clusters', () => {
181
+ before(async () => {
182
+ await PeptideUtils.loadComponents();
183
+ });
184
+
185
+ /** Checks every Logo Summary Table row against the source rows of its cluster and the rest. */
186
+ function expectClusterSummary(lst: LogoSummaryTable): void {
187
+ const df = lst.dataFrame;
188
+ const clusters = df.getCol(lst.clustersColumnName);
189
+ const activity = df.getCol(COLUMNS_NAMES.ACTIVITY);
190
+ const summary = lst.logoSummaryTable;
191
+ const pValues = summary.getCol(LST_COLUMN_NAMES.P_VALUE);
192
+ const mean = (values: number[]): number => values.reduce((sum, value) => sum + value, 0) / values.length;
193
+ let members = 0;
194
+ for (let row = 0; row < summary.rowCount; row++) {
195
+ const cluster = String(summary.get(LST_COLUMN_NAMES.CLUSTER, row));
196
+ const selected: number[] = [];
197
+ const rest: number[] = [];
198
+ for (let i = 0; i < df.rowCount; i++)
199
+ (String(clusters.get(i)) === cluster ? selected : rest).push(activity.get(i));
200
+ members += selected.length;
201
+ expect(summary.get(LST_COLUMN_NAMES.MEMBERS, row), selected.length, `members of cluster ${cluster}`);
202
+ const meanDifference = rest.length === 0 ? 0 : mean(selected) - mean(rest);
203
+ expectFloat(summary.get(LST_COLUMN_NAMES.MEAN_DIFFERENCE, row), meanDifference,
204
+ Math.max(Math.abs(meanDifference) * 1e-4, 1e-9), `mean difference of cluster ${cluster}`);
205
+ const pValue = pValues.get(row);
206
+ expect(selected.length > 1 && rest.length > 1 ? pValue >= 0 && pValue <= 1 : pValues.isNone(row), true,
207
+ `p-value ${pValue} of cluster ${cluster}, which has no t-test with fewer than two rows on a side`);
208
+ }
209
+ expect(members, df.rowCount, 'members total');
210
+ }
211
+
212
+ // 96 splits the first 200 peptides into five clusters on some stands and six on others
213
+ for (const [threshold, fewest, most] of [[10, 1, 1], [75, 2, 2], [96, 5, 6]]) {
214
+ test(`Similarity threshold ${threshold}`, async () => {
215
+ const model = await analyzeDemoPeptides(await loadDemoPeptides(200), threshold);
216
+ expect(model.findViewer(VIEWER_TYPE.MCL)?.getWidgetStatus().values?.['completed threshold'], threshold,
217
+ 'completed MCL threshold');
218
+ const lst = model.findViewer(VIEWER_TYPE.LOGO_SUMMARY_TABLE) as LogoSummaryTable;
219
+ const clusterCount = lst.logoSummaryTable.rowCount;
220
+ expect(clusterCount >= fewest && clusterCount <= most, true,
221
+ `${clusterCount} clusters at threshold ${threshold}, expected ${fewest}-${most}`);
222
+ expectClusterSummary(lst);
223
+ }, {timeout: 120000});
224
+ }
225
+ });
@@ -1,6 +1,6 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
2
 
3
- import {after, awaitCheck, before, category, delay, expect, test} from '@datagrok-libraries/test/src/test';
3
+ import {after, before, category, expect, test, uiSettled, waitUntil} from '@datagrok-libraries/test/src/test';
4
4
  import {_package} from '../package-test';
5
5
  import {PeptidesModel, VIEWER_TYPE} from '../model';
6
6
  import {startAnalysis} from '../widgets/peptides';
@@ -41,10 +41,10 @@ category('Table view', () => {
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('Visible columns', async () => {
50
50
  const gridCols = model.analysisView.grid.columns;
@@ -63,7 +63,7 @@ category('Table view', () => {
63
63
  const selection = model.df.selection;
64
64
 
65
65
  const mpViewer = model.findViewer(VIEWER_TYPE.SEQUENCE_VARIABILITY_MAP) as MonomerPosition;
66
- await awaitCheck(() => mpViewer.mutationCliffs !== null, 'mutation cliffs haven\'t been generated', 2000);
66
+ await waitUntil(() => mpViewer.mutationCliffs !== null, 'mutation cliffs haven\'t been generated', 2000);
67
67
 
68
68
  for (const [position, selectedMonomers] of Object.entries(mpViewer.mutationCliffsSelection))
69
69
  expect(selectedMonomers.length, 0, `Selection is not empty for position ${position} after initialization`);
@@ -1,5 +1,61 @@
1
+ import * as grok from 'datagrok-api/grok';
2
+ import * as DG from 'datagrok-api/dg';
3
+
4
+ import {PeptidesModel} from '../model';
5
+ import {startAnalysis} from '../widgets/peptides';
6
+ import {scaleActivity} from '../utils/misc';
7
+ import {SCALING_METHODS, TAGS} from '../utils/constants';
8
+ import {MCLSettings} from '../utils/types';
9
+
1
10
  export enum TEST_COLUMN_NAMES {
2
11
  SEQUENCE = 'sequence',
3
12
  ACTIVITY = 'activity',
4
13
  CLUSTER = 'cluster',
5
14
  }
15
+
16
+ export enum DEMO_COLUMN_NAMES {
17
+ ID = 'ID',
18
+ SEQUENCE = 'AlignedSequence',
19
+ ACTIVITY = 'IC50',
20
+ }
21
+
22
+ /** The demo peptides: 647 aligned separator sequences of 17 positions with ID and IC50, or their first rows. */
23
+ export async function loadDemoPeptides(rowCount?: number): Promise<DG.DataFrame> {
24
+ const csv = await grok.dapi.files.readCsv('System:DemoFiles/bio/peptides.csv');
25
+ const df = rowCount === undefined ? csv : csv.clone(DG.BitSet.create(csv.rowCount, (i) => i < rowCount));
26
+ df.name = 'peptides';
27
+ await grok.data.detectSemanticTypes(df);
28
+ return df;
29
+ }
30
+
31
+ /** Starts SAR on unscaled IC50; with a similarity threshold, MCL clusters feed the Logo Summary Table. */
32
+ export async function analyzeDemoPeptides(df: DG.DataFrame, mclThreshold?: number): Promise<PeptidesModel> {
33
+ const activityCol = df.getCol(DEMO_COLUMN_NAMES.ACTIVITY);
34
+ const mclSettings = new MCLSettings();
35
+ mclSettings.threshold = mclThreshold ?? mclSettings.threshold;
36
+ const addMCL = mclThreshold !== undefined;
37
+ const model = await startAnalysis(activityCol, df.getCol(DEMO_COLUMN_NAMES.SEQUENCE), null, df,
38
+ scaleActivity(activityCol, SCALING_METHODS.NONE), SCALING_METHODS.NONE,
39
+ {addMCL, useEmbeddingsClusters: addMCL, mclSettings});
40
+ if (model === null)
41
+ throw new Error('Model is null');
42
+ return model;
43
+ }
44
+
45
+ /** Monomers of every separator sequence, gaps as empty strings. */
46
+ export function splitSequences(sequences: DG.Column<string>): string[][] {
47
+ const separator = sequences.getTag(TAGS.SEPARATOR);
48
+ return sequences.toList().map((s) => s.split(separator));
49
+ }
50
+
51
+ /** Row pairs `a:b` (a < b) of equally aligned sequences that differ at exactly one position. */
52
+ export function singleMutationPairs(split: string[][]): Set<string> {
53
+ const pairs = new Set<string>();
54
+ for (let a = 0; a < split.length; a++) {
55
+ for (let b = a + 1; b < split.length; b++) {
56
+ if (split[a].filter((monomer, position) => monomer !== split[b][position]).length === 1)
57
+ pairs.add(`${a}:${b}`);
58
+ }
59
+ }
60
+ return pairs;
61
+ }