@datagrok/peptides 0.4.2 → 0.6.1

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.
@@ -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
  });