@datagrok/peptides 0.4.3 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@datagrok/peptides",
3
- "version": "0.4.3",
3
+ "version": "0.5.6",
4
4
  "description": "",
5
5
  "dependencies": {
6
6
  "@keckelt/tsne": "^1.0.2",
7
7
  "cash-dom": "latest",
8
8
  "d3": "latest",
9
- "datagrok-api": ">=0.95.11",
9
+ "datagrok-api": ">=0.104.0",
10
10
  "dayjs": "latest",
11
11
  "jaro-winkler-typescript": "^1.0.1",
12
12
  "jstat": "^1.9.5",
13
13
  "logojs-react": "^2.1.1",
14
14
  "rxjs": "^6.5.5",
15
15
  "umap-js": "^1.3.3",
16
- "@datagrok-libraries/utils": ">=0.0.11",
16
+ "@datagrok-libraries/utils": ">=0.0.13",
17
17
  "@datagrok-libraries/statistics": ">=0.1.5",
18
18
  "@types/d3": "^7.0.0",
19
19
  "@types/jquery": "^3.5.6"
package/src/describe.ts CHANGED
@@ -45,6 +45,15 @@ const groupDescription: {[key: string]: {'description': string, 'aminoAcids': st
45
45
  '-': {'description': 'Unknown Amino Acid', 'aminoAcids': ['-']},
46
46
  };
47
47
 
48
+ /*function customGridColumnHeader(cell: DG.GridCell) {
49
+ if (cell.isColHeader && cell.tableColumn != null) {
50
+ if (highlightedColumns.includes(parseInt(cell.tableColumn.name))) {
51
+ cell.style.backColor = 0xff1f77b4;
52
+ }
53
+ }
54
+ }*/
55
+
56
+ //TODO: decomposition!
48
57
  export async function describe(
49
58
  df: DG.DataFrame,
50
59
  activityColumn: string,
@@ -60,6 +69,7 @@ export async function describe(
60
69
  const col: DG.Column = df.columns.bySemType('alignedSequence');
61
70
  [splitSeqDf, invalidIndexes] = splitAlignedPeptides(col);
62
71
  splitSeqDf.name = 'Split sequence';
72
+
63
73
  const positionColumns = splitSeqDf.columns.names();
64
74
  const activityColumnScaled = `${activityColumn}Scaled`;
65
75
  const renderColNames: string[] = splitSeqDf.columns.names();
@@ -405,7 +415,7 @@ export async function describe(
405
415
  SARgrid.onCellTooltip(onCellTooltipFunc);
406
416
  SARVgrid.onCellTooltip(onCellTooltipFunc);
407
417
 
408
- sourceGrid.onCellPrepare((cell) => {
418
+ sourceGrid.onCellPrepare((cell: DG.GridCell) => {
409
419
  const currentRowIndex = cell.tableRowIndex;
410
420
  if (currentRowIndex && invalidIndexes.includes(currentRowIndex) && !cell.isRowHeader) {
411
421
  cell.style.backColor = DG.Color.lightLightGray;
package/src/package.ts CHANGED
@@ -15,7 +15,7 @@ import {PeptideSimilaritySpaceWidget} from './utils/peptide-similarity-space';
15
15
  import {manualAlignmentWidget} from './widgets/manual-alignment';
16
16
  import {SARViewer, SARViewerVertical} from './viewers/sar-viewer';
17
17
  import {peptideMoleculeWidget} from './widgets/peptide-molecule';
18
- import {correlationAnalysisPlots} from './utils/correlation-analysis';
18
+ import {SpiralPlot} from './viewers/spiral-plot';
19
19
 
20
20
  export const _package = new DG.Package();
21
21
  let tableGrid: DG.Grid;
@@ -178,14 +178,15 @@ export async function peptideSpacePanel(col: DG.Column): Promise<DG.Widget> {
178
178
  return await widget.draw();
179
179
  }
180
180
 
181
- //name: Correllation analysis
182
- export async function correlationAnalysis() {
183
- view = (grok.shell.v as DG.TableView);
184
-
185
- const df = await grok.data.files.openTable('Demo:TestJobs:Files:DemoFiles/bio/peptides.csv');
186
- const tview = grok.shell.addTableView(df);
187
- const [cpviewer, bpviewer] = correlationAnalysisPlots(df.getCol('AlignedSequence'));
188
-
189
- tview.dockManager.dock(cpviewer, 'right');
190
- tview.dockManager.dock(bpviewer, 'down');
181
+ //name: Spiral Plot
182
+ ////input: dataframe table
183
+ ////input: column activity
184
+ //tags: viewer, panel
185
+ //output: viewer result
186
+ export async function spiralPlot(): Promise<DG.Viewer> {//(table: DG.DataFrame, activity: DG.Column) {
187
+ // Read as dataframe
188
+ const table = await grok.data.files.openTable('Demo:TestJobs:Files:DemoFiles/bio/peptides.csv');
189
+ const activity = await table.columns.addNewCalculated('-log10(Activity)', '0-Log10(${Activity})');
190
+ view = grok.shell.addTableView(table);
191
+ return view.addViewer(SpiralPlot.fromTable(table, {valuesColumnName: activity.name}));
191
192
  }
package/src/peptides.ts CHANGED
@@ -3,7 +3,24 @@ 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
 
6
+ /**
7
+ * Peptides controller class.
8
+ *
9
+ * @export
10
+ * @class Peptides
11
+ */
6
12
  export class Peptides {
13
+ /**
14
+ * Class initializer
15
+ *
16
+ * @param {DG.Grid} tableGrid Working talbe grid.
17
+ * @param {DG.TableView} view Working view.
18
+ * @param {DG.DataFrame} currentDf Working table.
19
+ * @param {{[key: string]: string}} options SAR viewer options
20
+ * @param {DG.Column} col Aligned sequences column.
21
+ * @param {string} activityColumnChoice Activity column name.
22
+ * @memberof Peptides
23
+ */
7
24
  async init(
8
25
  tableGrid: DG.Grid,
9
26
  view: DG.TableView,
@@ -13,10 +30,10 @@ export class Peptides {
13
30
  activityColumnChoice: string,
14
31
  ) {
15
32
  for (let i = 0; i < tableGrid.columns.length; i++) {
16
- const col = tableGrid.columns.byIndex(i);
17
- if (col &&
18
- col.name &&
19
- col.column?.semType != 'aminoAcids'
33
+ const aarCol = tableGrid.columns.byIndex(i);
34
+ if (aarCol &&
35
+ aarCol.name &&
36
+ aarCol.column?.semType != 'aminoAcids'
20
37
  ) {
21
38
  //@ts-ignore
22
39
  tableGrid.columns.byIndex(i)?.visible = false;
@@ -3,13 +3,22 @@ import * as DG from 'datagrok-api/dg';
3
3
 
4
4
  const cp = new ChemPalette('grok');
5
5
 
6
- export function expandColumn(col:DG.Column,
7
- grid:DG.Grid,
8
- cellRenderSize: (celVal:string)=>number,
9
- textSizeMult = 10,
10
- minSize = 30,
11
- maxSize = 650,
12
- timeout = 500) {
6
+ /**
7
+ * A function to expand column size based on its contents.
8
+ *
9
+ * @export
10
+ * @param {DG.Column} col Column to expand.
11
+ * @param {DG.Grid} grid Grid containing colum for expansion.
12
+ * @param {(cellVal: string) => number} cellRenderSize An anonymous function that calculates cell value length.
13
+ * @param {number} [textSizeMult=10] Text size muliplier.
14
+ * @param {number} [minSize=30] Minimal column width.
15
+ * @param {number} [maxSize=650] Maximum column width.
16
+ * @param {number} [timeout=500] Timeout value.
17
+ */
18
+ export function expandColumn(
19
+ col: DG.Column, grid: DG.Grid, cellRenderSize: (cellVal: string) => number,
20
+ textSizeMult = 10, minSize = 30, maxSize = 650, timeout = 500,
21
+ ) {
13
22
  let maxLen = 0;
14
23
  col.categories.forEach((ent: string) => {
15
24
  const len = cellRenderSize(ent);
@@ -23,6 +32,14 @@ export function expandColumn(col:DG.Column,
23
32
  timeout);
24
33
  }
25
34
 
35
+ /**
36
+ * A function that sets amino acid residue to the specified column.
37
+ *
38
+ * @export
39
+ * @param {DG.Column} col Column to set renderer for.
40
+ * @param {(DG.Grid | null)} [grid=null] Grid that contains the col column.
41
+ * @param {boolean} [grouping=false] Is grouping enabled.
42
+ */
26
43
  export function setAARRenderer(col: DG.Column, grid: DG.Grid | null = null, grouping = false) {
27
44
  col.semType = 'aminoAcids';
28
45
  col.setTag('cell.renderer', 'aminoAcids');
@@ -33,17 +50,39 @@ export function setAARRenderer(col: DG.Column, grid: DG.Grid | null = null, grou
33
50
  expandColumn(col, grid, (ent) => measureAAR(ent));
34
51
  }
35
52
  }
36
-
53
+ /**
54
+ * A function to measure amino acid residue
55
+ *
56
+ * @export
57
+ * @param {string} s Amino acid residue string.
58
+ * @return {number} Amino acid residue size.
59
+ */
37
60
  export function measureAAR(s: string): number {
38
61
  const end = s.lastIndexOf(')');
39
62
  const beg = s.indexOf('(');
40
63
  return end == beg ? s.length : s.length - (end - beg) + 1;
41
64
  }
42
65
 
43
- function printLeftCentered(
66
+ /**
67
+ * A function that prints a string aligned to left or centered.
68
+ *
69
+ * @param {number} x x coordinate.
70
+ * @param {number} y y coordinate.
71
+ * @param {number} w Width.
72
+ * @param {number} h Height.
73
+ * @param {CanvasRenderingContext2D} g Canvas rendering context.
74
+ * @param {string} s String to print.
75
+ * @param {string} [color=ChemPalette.undefinedColor] String color.
76
+ * @param {number} [pivot=0] Pirvot.
77
+ * @param {boolean} [left=false] Is left aligned.
78
+ * @param {boolean} [hideMod=false] Hide amino acid redidue modifications.
79
+ * @return {number} x coordinate to start printing at.
80
+ */
81
+ function printLeftOrCentered(
44
82
  x: number, y: number, w: number, h: number,
45
83
  g: CanvasRenderingContext2D, s: string, color = ChemPalette.undefinedColor,
46
- pivot: number = 0, left = false, hideMod = false) {
84
+ pivot: number = 0, left = false, hideMod = false,
85
+ ) {
47
86
  g.textAlign = 'start';
48
87
  let colorPart = pivot == -1 ? s.substring(0) : s.substring(0, pivot);
49
88
  if (colorPart.length == 1) {
@@ -100,23 +139,55 @@ function printLeftCentered(
100
139
  }
101
140
  }
102
141
 
103
-
142
+ /**
143
+ * Amino acid residue cell renderer.
144
+ *
145
+ * @export
146
+ * @class AminoAcidsCellRenderer
147
+ * @extends {DG.GridCellRenderer}
148
+ */
104
149
  export class AminoAcidsCellRenderer extends DG.GridCellRenderer {
105
150
  chemPalette: ChemPalette | null;
106
151
 
152
+ /**
153
+ * Renderer name.
154
+ *
155
+ * @readonly
156
+ * @memberof AminoAcidsCellRenderer
157
+ */
107
158
  get name() {
108
159
  return 'aminoAcidsCR';
109
160
  }
110
161
 
162
+ /**
163
+ * Cell type.
164
+ *
165
+ * @readonly
166
+ * @memberof AminoAcidsCellRenderer
167
+ */
111
168
  get cellType() {
112
169
  return 'aminoAcids';
113
170
  }
114
171
 
172
+ /**
173
+ * Constructor.
174
+ */
115
175
  constructor() {
116
176
  super();
117
177
  this.chemPalette = null;
118
178
  }
119
179
 
180
+ /**
181
+ * Cell renderer function.
182
+ *
183
+ * @param {CanvasRenderingContext2D} g Canvas rendering context.
184
+ * @param {number} x x coordinate on the canvas.
185
+ * @param {number} y y coordinate on the canvas.
186
+ * @param {number} w width of the cell.
187
+ * @param {number} h height of the cell.
188
+ * @param {DG.GridCell} gridCell Grid cell.
189
+ * @param {DG.GridCellStyle} cellStyle Cell style.
190
+ */
120
191
  render(g: CanvasRenderingContext2D, x: number, y: number, w: number, h: number,
121
192
  gridCell: DG.GridCell, cellStyle: DG.GridCellStyle) {
122
193
  if (this.chemPalette === null) {
@@ -130,21 +201,51 @@ export class AminoAcidsCellRenderer extends DG.GridCellRenderer {
130
201
  g.textBaseline = 'top';
131
202
  const s: string = gridCell.cell.value ? gridCell.cell.value : '-';
132
203
  const [color, pivot] = cp.getColorPivot(s);
133
- printLeftCentered(x, y, w, h, g, s, color, pivot, false, true);
204
+ printLeftOrCentered(x, y, w, h, g, s, color, pivot, false, true);
134
205
  g.restore();
135
206
  }
136
207
  }
137
208
 
138
-
209
+ /**
210
+ * Aligned sequence cell renderer.
211
+ *
212
+ * @export
213
+ * @class AlignedSequenceCellRenderer
214
+ * @extends {DG.GridCellRenderer}
215
+ */
139
216
  export class AlignedSequenceCellRenderer extends DG.GridCellRenderer {
217
+ /**
218
+ * Renderer name.
219
+ *
220
+ * @readonly
221
+ * @memberof AlignedSequenceCellRenderer
222
+ */
140
223
  get name() {
141
224
  return 'alignedSequenceCR';
142
225
  }
143
226
 
227
+ /**
228
+ * Cell type.
229
+ *
230
+ * @readonly
231
+ * @memberof AlignedSequenceCellRenderer
232
+ */
144
233
  get cellType() {
145
234
  return 'alignedSequence';
146
235
  }
147
236
 
237
+ /**
238
+ * Cell renderer function.
239
+ *
240
+ * @param {CanvasRenderingContext2D} g Canvas rendering context.
241
+ * @param {number} x x coordinate on the canvas.
242
+ * @param {number} y y coordinate on the canvas.
243
+ * @param {number} w width of the cell.
244
+ * @param {number} h height of the cell.
245
+ * @param {DG.GridCell} gridCell Grid cell.
246
+ * @param {DG.GridCellStyle} cellStyle Cell style.
247
+ * @memberof AlignedSequenceCellRenderer
248
+ */
148
249
  render(g: CanvasRenderingContext2D, x: number, y: number, w: number, h: number,
149
250
  gridCell: DG.GridCell, cellStyle: DG.GridCellStyle ) {
150
251
  w = Math.min(gridCell.grid.canvas.width - x, w);
@@ -169,25 +270,31 @@ export class AlignedSequenceCellRenderer extends DG.GridCellRenderer {
169
270
  const gap = simplified?'':' ';
170
271
  amino += `${amino?'':'-'}${gap}`;
171
272
  }
172
- x = printLeftCentered(x, y, w, h, g, amino, color, pivot, true);
273
+ x = printLeftOrCentered(x, y, w, h, g, amino, color, pivot, true);
173
274
  });
174
275
 
175
276
  g.restore();
176
277
  }
177
278
  }
178
279
 
179
-
180
- export function processSequence(subParts:string[]) : [string[], boolean] {
280
+ /**
281
+ * Function for sequence processing.
282
+ *
283
+ * @export
284
+ * @param {string[]} subParts Sequence subparts.
285
+ * @return {[string[], boolean]}
286
+ */
287
+ export function processSequence(subParts: string[]): [string[], boolean] {
181
288
  const simplified = !subParts.some((amino, index) =>
182
289
  amino.length > 1 &&
183
290
  index != 0 &&
184
291
  index != subParts.length - 1);
185
292
 
186
- const text:string[] = [];
293
+ const text: string[] = [];
294
+ const gap = simplified ? '' : ' ';
187
295
  subParts.forEach((amino: string, index) => {
188
296
  if (index < subParts.length) {
189
- const gap = simplified?'':' ';
190
- amino += `${amino?'':'-'}${gap}`;
297
+ amino += `${amino ? '' : '-'}${gap}`;
191
298
  }
192
299
  text.push(amino);
193
300
  });