@datagrok/peptides 0.8.9 → 0.8.13
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/.eslintrc.json +2 -1
- package/dist/package-test.js +22626 -0
- package/dist/package.js +21429 -0
- package/dist/vendors-node_modules_datagrok-libraries_ml_src_workers_dimensionality-reducer_js.js +8840 -0
- package/jest.config.js +33 -0
- package/package.json +75 -62
- package/src/__jest__/remote.test.ts +50 -0
- package/src/__jest__/test-node.ts +96 -0
- package/src/model.ts +950 -86
- package/src/monomer-library.ts +8 -0
- package/src/package-test.ts +3 -2
- package/src/package.ts +57 -22
- package/src/peptides.ts +165 -119
- package/src/styles.css +8 -0
- package/src/tests/peptides-tests.ts +17 -78
- package/src/tests/utils.ts +1 -7
- package/src/utils/SAR-multiple-filter.ts +439 -0
- package/src/utils/SAR-multiple-selection.ts +177 -0
- package/src/utils/cell-renderer.ts +49 -50
- package/src/utils/chem-palette.ts +61 -163
- package/src/utils/constants.ts +56 -0
- package/src/utils/filtering-statistics.ts +62 -0
- package/src/utils/multiple-sequence-alignment.ts +33 -2
- package/src/utils/multivariate-analysis.ts +79 -0
- package/src/utils/peptide-similarity-space.ts +12 -31
- package/src/utils/types.ts +10 -0
- package/src/viewers/logo-viewer.ts +2 -1
- package/src/viewers/peptide-space-viewer.ts +121 -0
- package/src/viewers/sar-viewer.ts +111 -313
- package/src/viewers/stacked-barchart-viewer.ts +126 -173
- package/src/widgets/analyze-peptides.ts +39 -18
- package/src/widgets/distribution.ts +61 -0
- package/src/widgets/manual-alignment.ts +3 -3
- package/src/widgets/peptide-molecule.ts +4 -4
- package/src/widgets/subst-table.ts +30 -22
- package/test-Peptides-f8114def7953-4bf59d70.html +256 -0
- package/src/describe.ts +0 -534
- package/src/utils/split-aligned.ts +0 -72
- package/src/viewers/subst-viewer.ts +0 -320
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import * as grok from 'datagrok-api/grok';
|
|
2
|
-
import * as ui from 'datagrok-api/ui';
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
|
|
5
|
-
import $ from 'cash-dom';
|
|
6
|
-
|
|
7
|
-
import {setAARRenderer} from '../utils/cell-renderer';
|
|
8
|
-
import {PeptidesController} from '../peptides';
|
|
9
|
-
// import {PeptidesModel} from '../model';
|
|
10
|
-
|
|
11
|
-
export class SubstViewer extends DG.JsViewer {
|
|
12
|
-
viewerGrid: DG.Grid | null;
|
|
13
|
-
maxSubstitutions: number;
|
|
14
|
-
activityLimit: number;
|
|
15
|
-
activityColumnName: string;
|
|
16
|
-
private _name: string = 'Substitution analysis';
|
|
17
|
-
// casesGrid: DG.Grid | null;
|
|
18
|
-
// model: PeptidesModel | null;
|
|
19
|
-
controller: PeptidesController | null;
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
super();
|
|
23
|
-
|
|
24
|
-
this.activityColumnName = this.string('activityColumnName');
|
|
25
|
-
|
|
26
|
-
this.maxSubstitutions = this.int('maxSubstitutions', 1);
|
|
27
|
-
this.activityLimit = this.float('activityLimit', 2);
|
|
28
|
-
|
|
29
|
-
this.viewerGrid = null;
|
|
30
|
-
// this.casesGrid = null;
|
|
31
|
-
this.controller = null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get name() {
|
|
35
|
-
return this._name;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
onPropertyChanged(property: DG.Property): void {
|
|
39
|
-
this.calcSubstitutions();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async onTableAttached() {
|
|
43
|
-
// this.model = PeptidesModel.getOrInit(this.dataFrame!);
|
|
44
|
-
this.controller = PeptidesController.getInstance(this.dataFrame!);
|
|
45
|
-
await this.controller.updateData(
|
|
46
|
-
this.dataFrame!, null, null, (grok.shell.v as DG.TableView).grid, null, null, null);
|
|
47
|
-
this.subs.push(this.controller.onSubstFlagChanged.subscribe(() => this.calcSubstitutions()));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
calcSubstitutions() {
|
|
51
|
-
const aarColName = 'AAR';
|
|
52
|
-
const df: DG.DataFrame = this.dataFrame!;
|
|
53
|
-
const col: DG.Column = df.columns.bySemType('alignedSequence');
|
|
54
|
-
// let values: number[] = df.columns.byName('IC50').toList();
|
|
55
|
-
const values: number[] = df.getCol(this.activityColumnName).toList();
|
|
56
|
-
// values = values;
|
|
57
|
-
const splitedMatrix = this.split(col);
|
|
58
|
-
|
|
59
|
-
const tableValues: { [aar: string]: number[] } = {};
|
|
60
|
-
const tableTooltips: { [aar: string]: {}[][] } = {};
|
|
61
|
-
const tableCases: { [aar: string]: number[][][] } = {};
|
|
62
|
-
|
|
63
|
-
const nRows = splitedMatrix.length;
|
|
64
|
-
const nCols = splitedMatrix[0].length;
|
|
65
|
-
const nColsArray = Array(nCols);
|
|
66
|
-
|
|
67
|
-
for (let i = 0; i < nRows - 1; i++) {
|
|
68
|
-
for (let j = i + 1; j < nRows; j++) {
|
|
69
|
-
let substCounter = 0;
|
|
70
|
-
const subst1: { [pos: number]: [string, {}] } = {};
|
|
71
|
-
const subst2: { [pos: number]: [string, {}] } = {};
|
|
72
|
-
const delta = values[i] - values[j];
|
|
73
|
-
|
|
74
|
-
for (let k = 0; k < nCols; k++) {
|
|
75
|
-
const smik = splitedMatrix[i][k];
|
|
76
|
-
const smjk = splitedMatrix[j][k];
|
|
77
|
-
if (smik != smjk && Math.abs(delta) >= this.activityLimit) {
|
|
78
|
-
const vi = values[i].toFixed(2);
|
|
79
|
-
const vj = values[j].toFixed(2);
|
|
80
|
-
substCounter++;
|
|
81
|
-
subst1[k] = [
|
|
82
|
-
smik,
|
|
83
|
-
{
|
|
84
|
-
key: `${smik === '-' ? 'Empty' : smik} → ${smjk === '-' ? 'Empty' : smjk}`,
|
|
85
|
-
value: `${vi} → ${vj}`,
|
|
86
|
-
diff: values[j] - values[i],
|
|
87
|
-
},
|
|
88
|
-
];
|
|
89
|
-
subst2[k] = [
|
|
90
|
-
smjk,
|
|
91
|
-
{
|
|
92
|
-
key: `${smjk === '-' ? 'Empty' : smjk} → ${smik === '-' ? 'Empty' : smik}`,
|
|
93
|
-
value: `${vj} → ${vi}`,
|
|
94
|
-
diff: values[i] - values[j],
|
|
95
|
-
},
|
|
96
|
-
];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (substCounter <= this.maxSubstitutions && substCounter > 0) {
|
|
101
|
-
for (const subst of [subst1, subst2]) {
|
|
102
|
-
Object.keys(subst).forEach((pos) => {
|
|
103
|
-
const posInt = parseInt(pos);
|
|
104
|
-
const aar = subst[posInt][0];
|
|
105
|
-
if (!Object.keys(tableValues).includes(aar)) {
|
|
106
|
-
tableValues[aar] = Array(...nColsArray).map(() => DG.INT_NULL);
|
|
107
|
-
tableTooltips[aar] = Array(...nColsArray).map(() => []);
|
|
108
|
-
tableCases[aar] = Array(...nColsArray).map(() => []);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
tableValues[aar][posInt] = tableValues[aar][posInt] === DG.INT_NULL ? 1 : tableValues[aar][posInt] + 1;
|
|
112
|
-
tableTooltips[aar][posInt] = !tableTooltips[aar][posInt].length ?
|
|
113
|
-
[{key: 'Substitution', value: 'Values'}] : tableTooltips[aar][posInt];
|
|
114
|
-
tableTooltips[aar][posInt].push(subst[posInt][1]);
|
|
115
|
-
if (subst == subst1)
|
|
116
|
-
tableCases[aar][posInt].push([i, j, delta]);
|
|
117
|
-
else
|
|
118
|
-
tableCases[aar][posInt].push([j, i, -delta]);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const tableValuesKeys = Object.keys(tableValues);
|
|
126
|
-
const dfLength = tableValuesKeys.length;
|
|
127
|
-
const cols = [...nColsArray.keys()].map((v) => DG.Column.int(v.toString(), dfLength));
|
|
128
|
-
cols.forEach(currentCol => currentCol.semType = 'Substitution');
|
|
129
|
-
const aarCol = DG.Column.string(aarColName, dfLength);
|
|
130
|
-
cols.splice(0, 1, aarCol);
|
|
131
|
-
const table = DG.DataFrame.fromColumns(cols);
|
|
132
|
-
|
|
133
|
-
for (let i = 0; i < dfLength; i++) {
|
|
134
|
-
const aar = tableValuesKeys[i];
|
|
135
|
-
tableValues[aar].splice(0, 1);
|
|
136
|
-
table.rows.setValues(i, [aar, ...tableValues[aar]]);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// let groupMapping: { [key: string]: string } = {};
|
|
140
|
-
|
|
141
|
-
//TODO: enable grouping
|
|
142
|
-
// Object.keys(aarGroups).forEach((value) => groupMapping[value] = value);
|
|
143
|
-
|
|
144
|
-
this.viewerGrid = table.plot.grid();
|
|
145
|
-
|
|
146
|
-
setAARRenderer(aarCol, this.viewerGrid);
|
|
147
|
-
|
|
148
|
-
this.viewerGrid.onCellTooltip(
|
|
149
|
-
(gCell, x, y) => {
|
|
150
|
-
if (gCell.cell.value !== DG.INT_NULL && gCell.tableColumn !== null && gCell.tableRowIndex !== null) {
|
|
151
|
-
const colName = gCell.tableColumn.name;
|
|
152
|
-
if (colName !== aarColName) {
|
|
153
|
-
const aar = this.viewerGrid!.table.get(aarColName, gCell.tableRowIndex);
|
|
154
|
-
const pos = parseInt(colName);
|
|
155
|
-
const lengthTableTooltip = tableTooltips[aar][pos].length;
|
|
156
|
-
const sortedTableTooltips = [];
|
|
157
|
-
const resTooltip: {[index: string]: string}[] = [];
|
|
158
|
-
let tooltipText: any = ui.divText('No substitutions');
|
|
159
|
-
let haveEllipsis = false;
|
|
160
|
-
|
|
161
|
-
if (lengthTableTooltip) {
|
|
162
|
-
const mn = Math.min(5, lengthTableTooltip);
|
|
163
|
-
for (let i = 0; i < lengthTableTooltip; ++i) {
|
|
164
|
-
const val: {[key: string]: any} = tableTooltips[aar][pos][i];
|
|
165
|
-
sortedTableTooltips.push([i, val['diff'], val]);
|
|
166
|
-
}
|
|
167
|
-
sortedTableTooltips.sort(function(a, b) {
|
|
168
|
-
return b[1] - a[1];
|
|
169
|
-
});
|
|
170
|
-
for (let i = 0; i < mn; ++i) {
|
|
171
|
-
const idx = sortedTableTooltips[i][0];
|
|
172
|
-
resTooltip.push(tableTooltips[aar][pos][idx]);
|
|
173
|
-
}
|
|
174
|
-
if (lengthTableTooltip > mn) {
|
|
175
|
-
for (let i = Math.max(lengthTableTooltip - mn, mn); i < lengthTableTooltip; ++i) {
|
|
176
|
-
const idx = sortedTableTooltips[i][0];
|
|
177
|
-
if (lengthTableTooltip > 2 * mn && !haveEllipsis) {
|
|
178
|
-
haveEllipsis = true;
|
|
179
|
-
resTooltip.push({key: '...', value: '...'});
|
|
180
|
-
}
|
|
181
|
-
resTooltip.push(tableTooltips[aar][pos][idx]);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
tooltipText = DG.HtmlTable.create(
|
|
185
|
-
resTooltip, (item: {[index: string]: string}, idx: number) => [item.key, item.value],
|
|
186
|
-
).root;
|
|
187
|
-
}
|
|
188
|
-
ui.tooltip.show(tooltipText, x, y);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
},
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
this.viewerGrid.columns.rowHeader!.width = 30;
|
|
196
|
-
this.viewerGrid.props.rowHeight = 20;
|
|
197
|
-
for (const col of table.columns.names()) {
|
|
198
|
-
this.viewerGrid.col(col)!.width = this.viewerGrid.props.rowHeight;
|
|
199
|
-
this.viewerGrid.col(col)!.width = 30;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
this.viewerGrid.onCellRender.subscribe((args) => {
|
|
203
|
-
if (args.cell.isRowHeader && args.cell.gridColumn.visible) {
|
|
204
|
-
args.cell.gridColumn.visible = false;
|
|
205
|
-
args.preventDefault();
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
this.viewerGrid.props.allowEdit = false;
|
|
210
|
-
|
|
211
|
-
table.onCurrentCellChanged.subscribe((_) => {
|
|
212
|
-
if (table.currentCol !== null && table.currentCol.name !== aarColName && table.currentCell.value !== null) {
|
|
213
|
-
const aar = table.get(aarColName, table.currentRowIdx);
|
|
214
|
-
const pos = parseInt(table.currentCol.name);
|
|
215
|
-
const currentCase = tableCases[aar][pos];
|
|
216
|
-
const tempDfLength = currentCase.length;
|
|
217
|
-
const initCol = DG.Column.string('Initial', tempDfLength);
|
|
218
|
-
const subsCol = DG.Column.string('Substituted', tempDfLength);
|
|
219
|
-
|
|
220
|
-
const tempDf = DG.DataFrame.fromColumns([
|
|
221
|
-
initCol,
|
|
222
|
-
subsCol,
|
|
223
|
-
DG.Column.float('Difference', tempDfLength),
|
|
224
|
-
]);
|
|
225
|
-
|
|
226
|
-
for (let i = 0; i < tempDfLength; i++) {
|
|
227
|
-
const row = currentCase[i];
|
|
228
|
-
tempDf.rows.setValues(i, [col.get(row[0]), col.get(row[1]), row[2]]);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
tempDf.temp['isReal'] = true;
|
|
232
|
-
|
|
233
|
-
initCol.semType = 'alignedSequence';
|
|
234
|
-
// initCol.setTag('isAnalysisApplicable', 'false');
|
|
235
|
-
initCol.temp['isAnalysisApplicable'] = false;
|
|
236
|
-
subsCol.semType = 'alignedSequence';
|
|
237
|
-
// subsCol.setTag('isAnalysisApplicable', 'false');
|
|
238
|
-
subsCol.temp['isAnalysisApplicable'] = false;
|
|
239
|
-
|
|
240
|
-
// this.casesGrid = tempDf.plot.grid();
|
|
241
|
-
// this.casesGrid.props.allowEdit = false;
|
|
242
|
-
grok.shell.o = DG.SemanticValue.fromValueType(tempDf, 'Substitution');
|
|
243
|
-
} else {
|
|
244
|
-
grok.shell.o = DG.SemanticValue.fromValueType(null, 'Substitution');
|
|
245
|
-
// this.casesGrid = null;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
this.render();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
this.render();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
render() {
|
|
255
|
-
$(this.root).empty();
|
|
256
|
-
const title = ui.h1(this.name, {style: {'align-self': 'center'}});
|
|
257
|
-
const gridRoot = this.viewerGrid!.root;
|
|
258
|
-
title.style.alignContent = 'center';
|
|
259
|
-
gridRoot.style.width = 'auto';
|
|
260
|
-
this.root.appendChild(ui.divV([title, gridRoot]));
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
split(peptideColumn: DG.Column, filter: boolean = true): string[][] {
|
|
264
|
-
const splitPeptidesArray: string[][] = [];
|
|
265
|
-
let currentSplitPeptide: string[];
|
|
266
|
-
let modeMonomerCount = 0;
|
|
267
|
-
let currentLength;
|
|
268
|
-
const colLength = peptideColumn.length;
|
|
269
|
-
|
|
270
|
-
// splitting data
|
|
271
|
-
const monomerLengths: { [index: string]: number } = {};
|
|
272
|
-
for (let i = 0; i < colLength; i++) {
|
|
273
|
-
currentSplitPeptide = peptideColumn.get(i).split('-').map((value: string) => value ? value : '-');
|
|
274
|
-
splitPeptidesArray.push(currentSplitPeptide);
|
|
275
|
-
currentLength = currentSplitPeptide.length;
|
|
276
|
-
monomerLengths[currentLength + ''] =
|
|
277
|
-
monomerLengths[currentLength + ''] ? monomerLengths[currentLength + ''] + 1 : 1;
|
|
278
|
-
}
|
|
279
|
-
//@ts-ignore: what I do here is converting string to number the most effective way I could find. parseInt is slow
|
|
280
|
-
modeMonomerCount = 1 * Object.keys(monomerLengths).reduce((a, b) => monomerLengths[a] > monomerLengths[b] ? a : b);
|
|
281
|
-
|
|
282
|
-
// making sure all of the sequences are of the same size
|
|
283
|
-
// and marking invalid sequences
|
|
284
|
-
let nTerminal: string;
|
|
285
|
-
const invalidIndexes: number[] = [];
|
|
286
|
-
let splitColumns: string[][] = Array.from({length: modeMonomerCount}, (_) => []);
|
|
287
|
-
modeMonomerCount--; // minus N-terminal
|
|
288
|
-
for (let i = 0; i < colLength; i++) {
|
|
289
|
-
currentSplitPeptide = splitPeptidesArray[i];
|
|
290
|
-
nTerminal = currentSplitPeptide.pop()!; // it is guaranteed that there will be at least one element
|
|
291
|
-
currentLength = currentSplitPeptide.length;
|
|
292
|
-
if (currentLength !== modeMonomerCount)
|
|
293
|
-
invalidIndexes.push(i);
|
|
294
|
-
|
|
295
|
-
for (let j = 0; j < modeMonomerCount; j++)
|
|
296
|
-
splitColumns[j].push(j < currentLength ? currentSplitPeptide[j] : '-');
|
|
297
|
-
|
|
298
|
-
splitColumns[modeMonomerCount].push(nTerminal);
|
|
299
|
-
}
|
|
300
|
-
modeMonomerCount--; // minus C-terminal
|
|
301
|
-
|
|
302
|
-
//create column names list
|
|
303
|
-
const columnNames = Array.from({length: modeMonomerCount}, (_, index) => `${index + 1 < 10 ? 0 : ''}${index + 1}`);
|
|
304
|
-
columnNames.splice(0, 0, 'N-terminal');
|
|
305
|
-
columnNames.push('C-terminal');
|
|
306
|
-
|
|
307
|
-
// filter out the columns with the same values
|
|
308
|
-
if (filter) {
|
|
309
|
-
splitColumns = splitColumns.filter((positionArray, index) => {
|
|
310
|
-
const isRetained = new Set(positionArray).size > 1;
|
|
311
|
-
if (!isRetained)
|
|
312
|
-
columnNames.splice(index, 1);
|
|
313
|
-
|
|
314
|
-
return isRetained;
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return splitPeptidesArray;
|
|
319
|
-
}
|
|
320
|
-
}
|