@datagrok/peptides 0.8.6 → 0.8.7

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,13 +1,13 @@
1
1
  {
2
2
  "name": "@datagrok/peptides",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
4
4
  "description": "",
5
5
  "dependencies": {
6
6
  "@biowasm/aioli": ">=2.4.0",
7
7
  "@datagrok-libraries/bio": ">=0.0.4",
8
- "@datagrok-libraries/ml": ">=0.0.10",
8
+ "@datagrok-libraries/ml": ">=0.0.14",
9
9
  "@datagrok-libraries/statistics": ">=0.1.5",
10
- "@datagrok-libraries/utils": ">=0.0.18",
10
+ "@datagrok-libraries/utils": ">=0.0.22",
11
11
  "@types/d3": "^7.0.0",
12
12
  "@types/jquery": "^3.5.6",
13
13
  "cash-dom": "latest",
package/src/describe.ts CHANGED
@@ -3,6 +3,7 @@ import * as DG from 'datagrok-api/dg';
3
3
  import {splitAlignedPeptides} from './utils/split-aligned';
4
4
  import {tTest} from '@datagrok-libraries/statistics/src/tests';
5
5
  import {fdrcorrection} from '@datagrok-libraries/statistics/src/multiple-tests';
6
+ import {StringDictionary} from '@datagrok-libraries/utils/src/type-declarations';
6
7
  import {ChemPalette} from './utils/chem-palette';
7
8
  import {setAARRenderer} from './utils/cell-renderer';
8
9
 
@@ -132,7 +133,7 @@ async function calculateStatistics(
132
133
  activityColumnScaled: string,
133
134
  peptidesCount: number,
134
135
  splitSeqDf: DG.DataFrame,
135
- groupMapping: {[key: string]: string},
136
+ groupMapping: StringDictionary,
136
137
  ) {
137
138
  matrixDf = matrixDf.groupBy([positionColName, aminoAcidResidue])
138
139
  .add('count', activityColumnScaled, 'Count')
@@ -446,7 +447,7 @@ export async function describe(
446
447
  twoColorMode: boolean,
447
448
  initialBitset: DG.BitSet | null,
448
449
  grouping: boolean,
449
- ): Promise<[DG.Grid, DG.Grid, DG.DataFrame, {[key: string]: string}]> {
450
+ ): Promise<[DG.Grid, DG.Grid, DG.DataFrame, StringDictionary]> {
450
451
  //Split the aligned sequence into separate AARs
451
452
  let splitSeqDf: DG.DataFrame | undefined;
452
453
  let invalidIndexes: number[];
@@ -484,7 +485,7 @@ export async function describe(
484
485
  let matrixDf = splitSeqDf.unpivot([activityColumnScaled], positionColumns, positionColName, aminoAcidResidue);
485
486
 
486
487
  //TODO: move to chem palette
487
- let groupMapping: {[key: string]: string} = {};
488
+ let groupMapping: StringDictionary = {};
488
489
  if (grouping) {
489
490
  groupMapping = aarGroups;
490
491
  const aarCol = matrixDf.getCol(aminoAcidResidue);
package/src/model.ts CHANGED
@@ -2,6 +2,7 @@ import * as DG from 'datagrok-api/dg';
2
2
 
3
3
  import {describe} from './describe';
4
4
  import {Subject} from 'rxjs';
5
+ import {StringDictionary} from '@datagrok-libraries/utils/src/type-declarations';
5
6
 
6
7
  /**
7
8
  * Model class for SAR viewers that retrieves and stores data.
@@ -12,7 +13,7 @@ class SARViewerModel {
12
13
  private viewerGrid: Subject<DG.Grid> = new Subject<DG.Grid>();
13
14
  private viewerVGrid: Subject<DG.Grid> = new Subject<DG.Grid>();
14
15
  private statsDf: Subject<DG.DataFrame> = new Subject<DG.DataFrame>();
15
- private groupMapping: Subject<{[key: string]: string}> = new Subject<{[key: string]: string}>();
16
+ private groupMapping: Subject<StringDictionary> = new Subject<StringDictionary>();
16
17
  public viewerGrid$;
17
18
  public viewerVGrid$;
18
19
  public statsDf$;
@@ -4,6 +4,7 @@ import {runTests} from '@datagrok-libraries/utils/src/test';
4
4
 
5
5
  import './tests/peptide-space-test';
6
6
  import './tests/peptides-tests';
7
+ import './tests/msa-tests';
7
8
 
8
9
  export const _package = new DG.Package();
9
10
 
package/src/package.ts CHANGED
@@ -5,6 +5,7 @@ import * as DG from 'datagrok-api/dg';
5
5
 
6
6
  import {
7
7
  AlignedSequenceCellRenderer,
8
+ AlignedSequenceDifferenceCellRenderer,
8
9
  AminoAcidsCellRenderer,
9
10
  } from './utils/cell-renderer';
10
11
  import {Logo} from './viewers/logo-viewer';
@@ -17,6 +18,7 @@ import {SARViewer, SARViewerVertical} from './viewers/sar-viewer';
17
18
  import {peptideMoleculeWidget, getMolecule} from './widgets/peptide-molecule';
18
19
  import {SubstViewer} from './viewers/subst-viewer';
19
20
  import {runKalign} from './utils/multiple-sequence-alignment';
21
+ import { SemanticValue } from 'datagrok-api/dg';
20
22
 
21
23
  export const _package = new DG.Package();
22
24
  let tableGrid: DG.Grid;
@@ -221,3 +223,33 @@ export async function multipleSequenceAlignment(col: DG.Column): Promise<DG.Data
221
223
  table.columns.add(msaCol);
222
224
  return table;
223
225
  }
226
+
227
+ //name: Substitution
228
+ //tags: panel, widgets
229
+ //input: dataframe table {semType: Substitution}
230
+ //output: widget result
231
+ export async function peptideSubstitution(table: DG.DataFrame): Promise<DG.Widget> {
232
+ if (!table) {
233
+ return new DG.Widget(ui.label('No difference'));
234
+ }
235
+ let initialCol: DG.Column = table.columns.byName('Initial');
236
+ let substitutedCol: DG.Column = table.columns.byName('Substituted');
237
+
238
+ for (let i = 0; i < initialCol.length; ++i) {
239
+ let concat = initialCol.get(i) + '#' + substitutedCol.get(i);
240
+ initialCol.set(i, concat);
241
+ }
242
+
243
+ initialCol.semType = 'alignedSequenceDifference';
244
+ initialCol.name = 'Substitution';
245
+ table.columns.remove('Substituted');
246
+ return new DG.Widget(ui.divH([table.plot.grid().root]));
247
+ }
248
+
249
+ //name: alignedSequenceDifferenceCellRenderer
250
+ //tags: cellRenderer, cellRenderer-alignedSequenceDifference
251
+ //meta-cell-renderer-sem-type: alignedSequenceDifference
252
+ //output: grid_cell_renderer result
253
+ export function alignedSequenceDifferenceCellRenderer() {
254
+ return new AlignedSequenceDifferenceCellRenderer();
255
+ }
package/src/peptides.ts CHANGED
@@ -3,6 +3,7 @@ import * as DG from 'datagrok-api/dg';
3
3
  import {createPeptideSimilaritySpaceViewer} from './utils/peptide-similarity-space';
4
4
  import {addViewerToHeader} from './viewers/stacked-barchart-viewer';
5
5
  import {model} from './model';
6
+ import {StringDictionary} from '@datagrok-libraries/utils/src/type-declarations';
6
7
  // import $ from 'cash-dom';
7
8
 
8
9
  /**
@@ -24,16 +25,15 @@ export class Peptides {
24
25
  * @param {DG.Grid} tableGrid Working talbe grid.
25
26
  * @param {DG.TableView} view Working view.
26
27
  * @param {DG.DataFrame} currentDf Working table.
27
- * @param {{[key: string]: string}} options SAR viewer options
28
+ * @param {StringDictionary} options SAR viewer options
28
29
  * @param {DG.Column} col Aligned sequences column.
29
- * @param {string} activityColumnChoice Activity column name.
30
30
  * @memberof Peptides
31
31
  */
32
32
  async init(
33
33
  tableGrid: DG.Grid,
34
34
  view: DG.TableView,
35
35
  currentDf: DG.DataFrame,
36
- options: {[key: string]: string},
36
+ options: StringDictionary,
37
37
  col: DG.Column,
38
38
  ) {
39
39
  for (let i = 0; i < tableGrid.columns.length; i++) {
@@ -52,7 +52,7 @@ export class Peptides {
52
52
  const originalDfName = currentDf.name;
53
53
 
54
54
  // const substViewer = view.addViewer(
55
- // 'substitution-analysis-viewer', {'activityColumnName': options['activityColumnName']},
55
+ // 'substitution-analysis-viewer', {'activityColumnName': `${options['activityColumnName']}Scaled`},
56
56
  // );
57
57
  // const substNode = view.dockManager.dock(substViewer, DG.DOCK_TYPE.RIGHT, null, 'Substitution Analysis');
58
58
 
@@ -76,11 +76,11 @@ export class Peptides {
76
76
  'Levenshtein',
77
77
  100,
78
78
  view,
79
- `${options['activityColumnChoice']}Scaled`,
79
+ `${options['activityColumnName']}Scaled`,
80
80
  );
81
81
  const psNode = view.dockManager.dock(peptideSpaceViewer, DG.DOCK_TYPE.LEFT, sarNode, 'Peptide Space Viewer', 0.3);
82
82
 
83
- const layout2 = view.saveLayout();
83
+ // const layout2 = view.saveLayout();
84
84
 
85
85
  const nodeList = [sarNode, sarVNode, psNode];
86
86
 
@@ -142,7 +142,7 @@ export class Peptides {
142
142
  const sarVNode = view.dockManager.dock(sarViewerVertical, DG.DOCK_TYPE.RIGHT, sarNode, 'SAR Vertical Viewer');
143
143
 
144
144
  const peptideSpaceViewer = await createPeptideSimilaritySpaceViewer(
145
- currentDf, col, 't-SNE', 'Levenshtein', 100, view, `${options['activityColumnChoice']}Scaled`);
145
+ currentDf, col, 't-SNE', 'Levenshtein', 100, view, `${options['activityColumnName']}Scaled`);
146
146
  const psNode = view.dockManager.dock(
147
147
  peptideSpaceViewer, DG.DOCK_TYPE.LEFT, sarNode, 'Peptide Space Viewer', 0.3);
148
148
 
@@ -154,7 +154,7 @@ export class Peptides {
154
154
  $(switchViewers).addClass('fa-toggle-on');
155
155
  } else {
156
156
  const substViewer = view.addViewer(
157
- 'substitution-analysis-viewer', {'activityColumnName': options['activityColumnName']},
157
+ 'substitution-analysis-viewer', {'activityColumnName': `${options['activityColumnName']}Scaled`},
158
158
  );
159
159
  substViewer.helpUrl = helpUrl;
160
160
  nodeList.push(view.dockManager.dock(substViewer, DG.DOCK_TYPE.DOWN, null, 'Substitution Analysis'));
@@ -0,0 +1,27 @@
1
+ import {category, test} from '@datagrok-libraries/utils/src/test';
2
+ import {
3
+ _testMSAIsCorrect,
4
+ _testTableIsNotEmpty,
5
+ } from './utils';
6
+ import {aligned1} from './test-data';
7
+
8
+ import * as DG from 'datagrok-api/dg';
9
+ //import * as grok from 'datagrok-api/grok';
10
+
11
+ export const _package = new DG.Package();
12
+
13
+ let table: DG.DataFrame;
14
+
15
+ category('peptides', async () => {
16
+ //table = await grok.data.files.openTable('Demo:Files/bio/peptides.csv');
17
+ table = DG.DataFrame.fromCsv(aligned1);
18
+ const alignedSequencesColumn = table.getCol('AlignedSequence');
19
+
20
+ test('MSA.test_table.is_not_empty', async () => {
21
+ _testTableIsNotEmpty(table);
22
+ });
23
+
24
+ test('MSA.is_correct', async () => {
25
+ _testMSAIsCorrect(alignedSequencesColumn);
26
+ });
27
+ });
@@ -1,21 +1,53 @@
1
- import {category, test} from '@datagrok-libraries/utils/src/test';
1
+ import {/*before, after, */category, test} from '@datagrok-libraries/utils/src/test';
2
2
  import {
3
3
  _testViewerIsDrawing,
4
4
  _testDimensionalityReducer,
5
5
  _testPeptideSimilaritySpaceViewer,
6
+ _testTableIsNotEmpty,
6
7
  } from './utils';
7
8
  import {DimensionalityReducer} from '@datagrok-libraries/ml/src/reduce-dimensionality';
8
9
  import {cleanAlignedSequencesColumn} from '../utils/peptide-similarity-space';
10
+ import {aligned1} from './test-data';
9
11
 
10
12
  import * as DG from 'datagrok-api/dg';
11
13
  import * as grok from 'datagrok-api/grok';
14
+ import { StringMetrics } from '@datagrok-libraries/ml/src/typed-metrics';
12
15
 
16
+ export const _package = new DG.Package();
17
+
18
+ let table: DG.DataFrame;
19
+ let view: DG.TableView;
20
+
21
+ //const table = await grok.data.loadTable(`${_package.webRoot}files/aligned.csv`);
22
+ //'/home/www/data/dev/packages/data/peptides/aligned.csv');
23
+ //console.log(table);
24
+ //const table = await grok.data.files.openTable('Demo:Files/bio/peptides.csv');
13
25
 
14
26
  category('peptides', async () => {
15
- const table = await grok.data.files.openTable('Demo:TestJobs:Files:DemoFiles/bio/peptides.csv');
16
- const view = grok.shell.v as DG.TableView;
27
+ /*before(async () => {
28
+ console.log(['before']);
29
+ // const text = await _package.files.readAsText('aligned.csv');
30
+ // console.log([text]);
31
+ // table = DG.DataFrame.fromCsv(text);
32
+
33
+ // const path = `${_package.webRoot}files/aligned.csv`;
34
+ // console.log([path]);
35
+ // table = await grok.data.loadTable(path);
36
+ // console.log([table]);
37
+
38
+ table = await grok.data.files.openTable('Demo:Files/bio/peptides.csv');
39
+ view = grok.shell.addTableView(table);
40
+ });*/
17
41
 
18
- test('PeptideSimilaritySpaceWidget.is_drawing', async () => {
42
+ //table = await grok.data.files.openTable('Demo:Files/bio/peptides.csv');
43
+ table = DG.DataFrame.fromCsv(aligned1);
44
+ view = grok.shell.addTableView(table);
45
+
46
+ test('peptide_space.test_table.is_not_empty', async () => {
47
+ _testTableIsNotEmpty(table);
48
+ });
49
+
50
+ test('peptide_space.PeptideSimilaritySpaceWidget.is_drawing', async () => {
19
51
  await _testViewerIsDrawing(table, view);
20
52
  });
21
53
 
@@ -23,18 +55,23 @@ category('peptides', async () => {
23
55
  const columnData = cleanAlignedSequencesColumn(alignedSequencesColumn);
24
56
 
25
57
  for (const method of DimensionalityReducer.availableMethods) {
26
- for (const measure of DimensionalityReducer.availableMetrics) {
27
- test(`DimensinalityReducer.${method}.${measure}.is_numeric`, async () => {
28
- await _testDimensionalityReducer(columnData, method, measure);
58
+ for (const measure of DimensionalityReducer.availableMetricsByType('String')) {
59
+ test(`peptide_space.DimensinalityReducer.${method}.${measure}.is_numeric`, async () => {
60
+ await _testDimensionalityReducer(columnData, method as StringMetrics, measure);
29
61
  });
30
62
  }
31
63
  }
32
64
 
33
65
  for (const method of DimensionalityReducer.availableMethods) {
34
- for (const measure of DimensionalityReducer.availableMetrics) {
35
- test(`peptides.PeptideSimilaritySpaceViewer.${method}.${measure}.is_proper`, async () => {
66
+ for (const measure of DimensionalityReducer.availableMetricsByType('String')) {
67
+ test(`peptide_space.PeptideSimilaritySpaceViewer.${method}.${measure}.is_proper`, async () => {
36
68
  await _testPeptideSimilaritySpaceViewer(table, alignedSequencesColumn, method, measure, 100);//, view);
37
69
  });
38
70
  }
39
71
  }
72
+
73
+ /*after(async () => {
74
+ view.close();
75
+ grok.shell.closeTable(table!);
76
+ });*/
40
77
  });
@@ -1,4 +1,5 @@
1
1
  import {after, before, category, test} from '@datagrok-libraries/utils/src/test';
2
+ import {StringDictionary} from '@datagrok-libraries/utils/src/type-declarations';
2
3
  import {splitAlignedPeptides} from '../utils/split-aligned';
3
4
  import * as DG from 'datagrok-api/dg';
4
5
  import * as grok from 'datagrok-api/grok';
@@ -13,7 +14,7 @@ import * as P from '../package';
13
14
 
14
15
  category('peptides', async () => {
15
16
  let peptidesDf: DG.DataFrame;
16
- let options: {[key: string]: string};
17
+ let options: StringDictionary;
17
18
  let peptidesGrid: DG.Grid;
18
19
  let asCol: DG.Column;
19
20
  let pepView: DG.TableView;