@datagrok/peptides 0.0.1 → 0.2.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.
- package/detectors.js +2 -2
- package/package.json +18 -11
- package/scripts/smiles-to-3D.py +13 -0
- package/src/{peptide-sar-viewer/describe.ts → describe.ts} +32 -64
- package/src/package.ts +66 -137
- package/src/utils/cell-renderer.ts +49 -91
- package/src/utils/chem-palette.ts +63 -41
- package/src/utils/molecular-measure.ts +175 -0
- package/src/utils/peptide-similarity-space.ts +242 -0
- package/src/utils/split-aligned.ts +65 -0
- package/src/{peptide-logo-viewer → viewers}/logo-viewer.ts +6 -4
- package/src/viewers/model.ts +63 -0
- package/src/{peptide-sar-viewer → viewers}/sar-viewer.ts +62 -24
- package/src/{stacked-barchart → viewers}/stacked-barchart-viewer.ts +29 -31
- package/src/widgets/analyze-peptides.ts +113 -0
- package/src/widgets/manual-alignment.ts +35 -0
- package/src/widgets/peptide-molecule.ts +42 -0
- package/src/workers/dimensionality-reducer.ts +29 -0
- package/tsconfig.json +12 -13
- package/webpack.config.js +4 -4
- package/.eslintrc.json +0 -29
- package/src/split-aligned.ts +0 -42
- package/src/utils/misc.ts +0 -101
|
@@ -2,13 +2,14 @@ import * as DG from 'datagrok-api/dg';
|
|
|
2
2
|
import * as ui from 'datagrok-api/ui';
|
|
3
3
|
import {scaleBand, scaleLinear} from 'd3';
|
|
4
4
|
import {ChemPalette} from '../utils/chem-palette';
|
|
5
|
-
//@ts-ignore: I should be able to install it somehow
|
|
6
5
|
import * as rxjs from 'rxjs';
|
|
7
6
|
const cp = new ChemPalette('grok');
|
|
8
7
|
|
|
8
|
+
//TODO: the function should not accept promise. Await the parameters where it is used
|
|
9
9
|
export function addViewerToHeader(grid: DG.Grid, viewer: Promise<DG.Widget>) {
|
|
10
10
|
viewer.then((viewer) => {
|
|
11
|
-
const barchart = viewer as StackedBarChart;
|
|
11
|
+
const barchart = viewer as StackedBarChart; //TODO: accept specifically StackedBarChart object
|
|
12
|
+
// The following event makes the barchart interactive
|
|
12
13
|
rxjs.fromEvent(grid.overlay, 'mousemove').subscribe((mm:any) => {
|
|
13
14
|
mm = mm as MouseEvent;
|
|
14
15
|
const cell = grid.hitTest(mm.offsetX, mm.offsetY);
|
|
@@ -73,9 +74,9 @@ export function addViewerToHeader(grid: DG.Grid, viewer: Promise<DG.Widget>) {
|
|
|
73
74
|
export class StackedBarChart extends DG.JsViewer {
|
|
74
75
|
public dataEmptyAA: string;
|
|
75
76
|
public initialized: boolean;
|
|
76
|
-
highlighted:{'colName':string, 'aaName':string}|null = null;
|
|
77
|
+
highlighted: {'colName' : string, 'aaName' : string} | null = null;
|
|
77
78
|
private ord: { [Key: string]: number; } = {};
|
|
78
|
-
private margin: {
|
|
79
|
+
private margin: {top: number; left: number; bottom: number; right: number} = {
|
|
79
80
|
top: 10,
|
|
80
81
|
right: 10,
|
|
81
82
|
bottom: 50,
|
|
@@ -83,18 +84,17 @@ export class StackedBarChart extends DG.JsViewer {
|
|
|
83
84
|
};
|
|
84
85
|
private yScale: any;
|
|
85
86
|
private xScale: any;
|
|
86
|
-
private data: {
|
|
87
|
+
private data: {'name': string, 'data': {'name': string, 'count': number, 'selectedCount': number}[]}[] = [];
|
|
87
88
|
private selectionMode: boolean = false;
|
|
88
89
|
public aminoColumnNames: string[] = [];
|
|
89
|
-
// @ts-ignore
|
|
90
90
|
|
|
91
|
-
private aminoColumnIndices: {
|
|
92
|
-
private aggregatedTables: {
|
|
93
|
-
private aggregatedTablesUnselected: {
|
|
91
|
+
private aminoColumnIndices: {[Key: string]: number} = {};
|
|
92
|
+
private aggregatedTables: {[Key: string]: DG.DataFrame} = {};
|
|
93
|
+
private aggregatedTablesUnselected: {[Key: string]: DG.DataFrame} = {};
|
|
94
94
|
private max = 0;
|
|
95
|
-
private barStats: {
|
|
95
|
+
private barStats: {[Key: string]: {'name': string, 'count': number, 'selectedCount': number}[]} = {};
|
|
96
96
|
tableCanvas: HTMLCanvasElement | undefined;
|
|
97
|
-
private registered: {
|
|
97
|
+
private registered: {[Key: string]: DG.GridCell} = {};
|
|
98
98
|
|
|
99
99
|
constructor() {
|
|
100
100
|
super();
|
|
@@ -103,22 +103,22 @@ export class StackedBarChart extends DG.JsViewer {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
init() {
|
|
106
|
-
const groups: [string
|
|
107
|
-
[
|
|
108
|
-
[
|
|
109
|
-
[
|
|
110
|
-
[
|
|
111
|
-
[
|
|
112
|
-
[
|
|
106
|
+
const groups: {[key: string]: string[]} = {
|
|
107
|
+
'yellow': ['C', 'U'],
|
|
108
|
+
'red': ['G', 'P'],
|
|
109
|
+
'all_green': ['A', 'V', 'I', 'L', 'M', 'F', 'Y', 'W'],
|
|
110
|
+
'light_blue': ['R', 'H', 'K'],
|
|
111
|
+
'dark_blue': ['D', 'E'],
|
|
112
|
+
'orange': ['S', 'T', 'N', 'Q'],
|
|
113
|
+
};
|
|
113
114
|
|
|
114
115
|
let i = 0;
|
|
115
|
-
|
|
116
|
+
for (const value of Object.values(groups)) {
|
|
116
117
|
i++;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.ord[item[0][obj]] = i;
|
|
118
|
+
for (const obj in value) {
|
|
119
|
+
this.ord[value[obj]] = i;
|
|
120
120
|
}
|
|
121
|
-
}
|
|
121
|
+
}
|
|
122
122
|
this.yScale = scaleLinear();
|
|
123
123
|
this.xScale = scaleBand();
|
|
124
124
|
this.data = [];
|
|
@@ -152,8 +152,8 @@ export class StackedBarChart extends DG.JsViewer {
|
|
|
152
152
|
{
|
|
153
153
|
// @ts-ignore
|
|
154
154
|
if (df.getCol(name).semType === 'aminoAcids' &&
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
!df.getCol(name).categories.includes('COOH') &&
|
|
156
|
+
!df.getCol(name).categories.includes('NH2')) {
|
|
157
157
|
this.aminoColumnIndices[name] = this.aminoColumnNames.length + 1;
|
|
158
158
|
this.aminoColumnNames.push(name);
|
|
159
159
|
}
|
|
@@ -170,7 +170,7 @@ export class StackedBarChart extends DG.JsViewer {
|
|
|
170
170
|
resbuf[i] = buf1[i] & buf2[i];
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
//TODO: optimize it, why store so many tables?
|
|
174
174
|
const mask = DG.BitSet.fromBytes(resbuf.buffer, df.rowCount);
|
|
175
175
|
if (mask.trueCount !== df.filter.trueCount) {
|
|
176
176
|
this.selectionMode = true;
|
|
@@ -214,10 +214,9 @@ export class StackedBarChart extends DG.JsViewer {
|
|
|
214
214
|
this.barStats = {};
|
|
215
215
|
for (const [name, df] of Object.entries(this.aggregatedTables)) {
|
|
216
216
|
const colObj: {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
{'name': name, 'data': []};
|
|
217
|
+
'name': string,
|
|
218
|
+
'data': { 'name': string, 'count': number, 'selectedCount': number }[],
|
|
219
|
+
} = {'name': name, 'data': []};
|
|
221
220
|
this.barStats[colObj['name']] = colObj['data'];
|
|
222
221
|
this.data.push(colObj);
|
|
223
222
|
for (let i = 0; i < df.rowCount; i++) {
|
|
@@ -263,7 +262,6 @@ export class StackedBarChart extends DG.JsViewer {
|
|
|
263
262
|
g.fillStyle = 'black';
|
|
264
263
|
g.textBaseline = 'top';
|
|
265
264
|
g.font = `${h * margin / 2}px`;
|
|
266
|
-
// eslint-disable-next-line no-unused-vars
|
|
267
265
|
|
|
268
266
|
const name = cell.tableColumn!.name;
|
|
269
267
|
const colNameSize = g.measureText(name).width;
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
import {createPeptideSimilaritySpaceViewer} from '../utils/peptide-similarity-space';
|
|
5
|
+
import {addViewerToHeader} from '../viewers/stacked-barchart-viewer';
|
|
6
|
+
import {model} from '../viewers/model';
|
|
7
|
+
|
|
8
|
+
export async function analyzePeptidesWidget(
|
|
9
|
+
col: DG.Column, view: DG.TableView, tableGrid: DG.Grid, currentDf: DG.DataFrame,
|
|
10
|
+
): Promise<DG.Widget> {
|
|
11
|
+
let tempCol = null;
|
|
12
|
+
for (const column of currentDf.columns.numerical) {
|
|
13
|
+
tempCol = column.type === DG.TYPE.FLOAT ? column : null;
|
|
14
|
+
}
|
|
15
|
+
const defaultColumn: DG.Column = currentDf.col('activity') || currentDf.col('IC50') || tempCol;
|
|
16
|
+
const histogramHost = ui.div([]);
|
|
17
|
+
|
|
18
|
+
let hist: DG.Viewer;
|
|
19
|
+
|
|
20
|
+
const activityScalingMethod = ui.choiceInput(
|
|
21
|
+
'Activity scaling',
|
|
22
|
+
'none',
|
|
23
|
+
['none', 'lg', '-lg'],
|
|
24
|
+
async (currentMethod: string) => {
|
|
25
|
+
const currentActivityCol = activityColumnChoice.value.name;
|
|
26
|
+
const tempDf = currentDf.clone(currentDf.filter, [currentActivityCol]);
|
|
27
|
+
switch (currentMethod) {
|
|
28
|
+
case 'lg':
|
|
29
|
+
await tempDf.columns.addNewCalculated('scaledActivity', 'Log10(${' + currentActivityCol + '})');
|
|
30
|
+
break;
|
|
31
|
+
case '-lg':
|
|
32
|
+
await tempDf.columns.addNewCalculated('scaledActivity', '-1*Log10(${' + currentActivityCol + '})');
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
await tempDf.columns.addNewCalculated('scaledActivity', '${' + currentActivityCol + '}');
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
hist = tempDf.plot.histogram({
|
|
39
|
+
filteringEnabled: false,
|
|
40
|
+
valueColumnName: 'scaledActivity',
|
|
41
|
+
legendVisibility: 'Never',
|
|
42
|
+
showXAxis: true,
|
|
43
|
+
showColumnSelector: false,
|
|
44
|
+
showRangeSlider: false,
|
|
45
|
+
// bins: b,
|
|
46
|
+
});
|
|
47
|
+
histogramHost.lastChild?.remove();
|
|
48
|
+
histogramHost.appendChild(hist.root);
|
|
49
|
+
});
|
|
50
|
+
activityScalingMethod.setTooltip('Function to apply for each value in activity column');
|
|
51
|
+
|
|
52
|
+
const activityScalingMethodState = function(_: any) {
|
|
53
|
+
activityScalingMethod.enabled =
|
|
54
|
+
activityColumnChoice.value && DG.Stats.fromColumn(activityColumnChoice.value, currentDf.filter).min > 0;
|
|
55
|
+
activityScalingMethod.fireChanged();
|
|
56
|
+
};
|
|
57
|
+
const activityColumnChoice = ui.columnInput(
|
|
58
|
+
'Activity column',
|
|
59
|
+
currentDf,
|
|
60
|
+
defaultColumn,
|
|
61
|
+
activityScalingMethodState,
|
|
62
|
+
);
|
|
63
|
+
activityColumnChoice.fireChanged();
|
|
64
|
+
activityScalingMethod.fireChanged();
|
|
65
|
+
|
|
66
|
+
const startBtn = ui.button('Launch SAR', async () => {
|
|
67
|
+
const progress = DG.TaskBarProgressIndicator.create('Loading SAR...');
|
|
68
|
+
if (activityColumnChoice.value.type === DG.TYPE.FLOAT) {
|
|
69
|
+
const options: {[key: string]: string} = {
|
|
70
|
+
'activityColumnColumnName': activityColumnChoice.value.name,
|
|
71
|
+
'activityScalingMethod': activityScalingMethod.value,
|
|
72
|
+
};
|
|
73
|
+
for (let i = 0; i < tableGrid.columns.length; i++) {
|
|
74
|
+
const col = tableGrid.columns.byIndex(i);
|
|
75
|
+
if (col &&
|
|
76
|
+
col.name &&
|
|
77
|
+
col.column?.semType != 'aminoAcids'
|
|
78
|
+
) {
|
|
79
|
+
//@ts-ignore
|
|
80
|
+
tableGrid.columns.byIndex(i)?.visible = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const sarViewer = view.addViewer('peptide-sar-viewer', options);
|
|
85
|
+
const sarViewerVertical = view.addViewer('peptide-sar-viewer-vertical');
|
|
86
|
+
const peptideSpaceViewer = await createPeptideSimilaritySpaceViewer(
|
|
87
|
+
currentDf,
|
|
88
|
+
col,
|
|
89
|
+
't-SNE',
|
|
90
|
+
'Levenshtein',
|
|
91
|
+
100,
|
|
92
|
+
`${activityColumnChoice}Scaled`,
|
|
93
|
+
);
|
|
94
|
+
let refNode = view.dockManager.dock(peptideSpaceViewer, 'down');
|
|
95
|
+
refNode = view.dockManager.dock(sarViewer, 'right', refNode);
|
|
96
|
+
view.dockManager.dock(sarViewerVertical, 'right', refNode);
|
|
97
|
+
|
|
98
|
+
const StackedBarchartProm = currentDf.plot.fromType('StackedBarChartAA');
|
|
99
|
+
addViewerToHeader(tableGrid, StackedBarchartProm);
|
|
100
|
+
|
|
101
|
+
// currentDf.onValuesChanged.subscribe(async () => await model.updateDefault());
|
|
102
|
+
} else {
|
|
103
|
+
grok.shell.error('The activity column must be of floating point number type!');
|
|
104
|
+
}
|
|
105
|
+
progress.close();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const viewer = await currentDf.plot.fromType('peptide-logo-viewer');
|
|
109
|
+
|
|
110
|
+
return new DG.Widget(
|
|
111
|
+
ui.divV([viewer.root, ui.inputs([activityColumnChoice, activityScalingMethod]), startBtn, histogramHost]),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as ui from 'datagrok-api/ui';
|
|
2
|
+
import * as DG from 'datagrok-api/dg';
|
|
3
|
+
|
|
4
|
+
import $ from 'cash-dom';
|
|
5
|
+
import { model } from '../viewers/model';
|
|
6
|
+
import { splitAlignedPeptides } from '../utils/split-aligned';
|
|
7
|
+
|
|
8
|
+
export function manualAlignmentWidget(alignedSequenceCol: DG.Column, currentDf: DG.DataFrame) {
|
|
9
|
+
const sequenceInput = ui.textInput('', alignedSequenceCol.get(currentDf.currentRowIdx));
|
|
10
|
+
(sequenceInput.input as HTMLElement).style.height = '50px';
|
|
11
|
+
(sequenceInput.input as HTMLElement).style.overflow = 'hidden';
|
|
12
|
+
|
|
13
|
+
const applyChangesBtn = ui.button('Apply', async () => {
|
|
14
|
+
const newSequence = sequenceInput.value;
|
|
15
|
+
const affectedRowIndex = currentDf.currentRowIdx;
|
|
16
|
+
const [splitSequence,] = splitAlignedPeptides(DG.Column.fromStrings('splitSequence', [newSequence]), false);
|
|
17
|
+
|
|
18
|
+
alignedSequenceCol.set(affectedRowIndex, newSequence);
|
|
19
|
+
for (const part of splitSequence.columns) {
|
|
20
|
+
if (currentDf.col(part.name) !== null)
|
|
21
|
+
currentDf.set(part.name, affectedRowIndex, part.get(0));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await model.updateDefault();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const resetBtn = ui.button(
|
|
28
|
+
ui.iconFA('redo'),
|
|
29
|
+
() => sequenceInput.value = alignedSequenceCol.get(currentDf.currentRowIdx),
|
|
30
|
+
'Reset',
|
|
31
|
+
);
|
|
32
|
+
$(resetBtn).addClass('dt-snippet-editor-icon dt-reset-icon');
|
|
33
|
+
|
|
34
|
+
return new DG.Widget(ui.divV([resetBtn, sequenceInput.root, applyChangesBtn], 'dt-textarea-box'));
|
|
35
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import {ChemPalette} from '../utils/chem-palette';
|
|
5
|
+
|
|
6
|
+
export async function peptideMoleculeWidget(pep: string): Promise<DG.Widget> {
|
|
7
|
+
const pi = DG.TaskBarProgressIndicator.create('Creating NGL view');
|
|
8
|
+
|
|
9
|
+
const split = pep.split('-');
|
|
10
|
+
const mols = [];
|
|
11
|
+
for (let i = 1; i < split.length - 1; i++) {
|
|
12
|
+
if (split[i] in ChemPalette.AASmiles) {
|
|
13
|
+
const aar = ChemPalette.AASmiles[split[i]];
|
|
14
|
+
mols[i] = aar.substr(0, aar.length - 1);
|
|
15
|
+
} else if (!split[i] || split[i] == '-') {
|
|
16
|
+
mols[i] = '';
|
|
17
|
+
} else {
|
|
18
|
+
return new DG.Widget(ui.divH([]));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const smiles = mols.join('') + 'O';
|
|
22
|
+
let molfileStr = (await grok.functions.call('Peptides:SmiTo3D', {smiles}));
|
|
23
|
+
|
|
24
|
+
molfileStr = molfileStr.replaceAll('\\n', '\n'); ;
|
|
25
|
+
const stringBlob = new Blob([molfileStr], {type: 'text/plain'});
|
|
26
|
+
const nglHost = ui.div([], {classes: 'd4-ngl-viewer', id: 'ngl-3d-host'});
|
|
27
|
+
|
|
28
|
+
//@ts-ignore
|
|
29
|
+
const stage = new NGL.Stage(nglHost, {backgroundColor: 'white'});
|
|
30
|
+
//@ts-ignore
|
|
31
|
+
stage.loadFile(stringBlob, {ext: 'sdf'}).then(function(comp: NGL.StructureComponent) {
|
|
32
|
+
stage.setSize(300, 300);
|
|
33
|
+
comp.addRepresentation('ball+stick');
|
|
34
|
+
comp.autoView();
|
|
35
|
+
});
|
|
36
|
+
const sketch = grok.chem.svgMol(smiles);
|
|
37
|
+
const panel = ui.divH([sketch]);
|
|
38
|
+
|
|
39
|
+
pi.close();
|
|
40
|
+
|
|
41
|
+
return new DG.Widget(ui.div([panel, nglHost]));
|
|
42
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {DimensionalityReducer} from '@datagrok-libraries/utils/src/reduce-dimensionality';
|
|
2
|
+
import {Coordinates} from '@datagrok-libraries/utils/src/type_declarations';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Worker thread receiving data function.
|
|
6
|
+
*
|
|
7
|
+
* @param {any[]} columnData Samples to process.
|
|
8
|
+
* @param {string} method Embedding method.
|
|
9
|
+
* @param {string} measure Distance metric.
|
|
10
|
+
* @param {number} cyclesCount Number of cycles to repeat.
|
|
11
|
+
* @return {Coordinates} Embedding.
|
|
12
|
+
*/
|
|
13
|
+
function onMessage(columnData: [], method: string, measure: string, cyclesCount: number): Coordinates {
|
|
14
|
+
const reducer = new DimensionalityReducer(
|
|
15
|
+
columnData,
|
|
16
|
+
method,
|
|
17
|
+
measure,
|
|
18
|
+
{cycles: cyclesCount},
|
|
19
|
+
);
|
|
20
|
+
return reducer.transform(true);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
self.onmessage = ({data: {columnData, method, measure, cyclesCount}}) => {
|
|
24
|
+
const embedding = onMessage(columnData, method, measure, cyclesCount);
|
|
25
|
+
self.postMessage({
|
|
26
|
+
embedding: embedding,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
package/tsconfig.json
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
/* Basic Options */
|
|
6
6
|
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
-
"target": "
|
|
8
|
-
"module": "es2020",
|
|
9
|
-
|
|
10
|
-
"allowJs": true, /* Allow javascript files to be compiled. */
|
|
7
|
+
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
+
"module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
|
+
"lib": ["es2020", "dom"], /* Specify library files to be included in the compilation. */
|
|
10
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
11
|
// "checkJs": true, /* Report errors in .js files. */
|
|
12
12
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
13
13
|
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
14
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
15
|
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
16
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
-
"outDir": "./
|
|
17
|
+
// "outDir": "./", /* Redirect output structure to the directory. */
|
|
18
18
|
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
19
|
// "composite": true, /* Enable project compilation */
|
|
20
20
|
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
/* Strict Type-Checking Options */
|
|
28
28
|
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
-
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
29
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
30
|
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
31
|
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
32
|
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
@@ -40,11 +40,10 @@
|
|
|
40
40
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
41
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
42
|
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
43
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
|
|
44
43
|
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
|
45
44
|
|
|
46
45
|
/* Module Resolution Options */
|
|
47
|
-
"moduleResolution": "node",
|
|
46
|
+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
48
47
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
49
48
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
50
49
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
@@ -56,17 +55,17 @@
|
|
|
56
55
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
57
56
|
|
|
58
57
|
/* Source Map Options */
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
"sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
59
|
+
"mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
60
|
+
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
61
|
+
"inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
63
62
|
|
|
64
63
|
/* Experimental Options */
|
|
65
64
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
66
65
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
67
66
|
|
|
68
67
|
/* Advanced Options */
|
|
69
|
-
"skipLibCheck": true,
|
|
68
|
+
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
70
69
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
71
70
|
}
|
|
72
71
|
}
|
package/webpack.config.js
CHANGED
|
@@ -3,19 +3,19 @@ const path = require('path');
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
mode: 'development',
|
|
5
5
|
entry: {
|
|
6
|
-
package: './src/package.ts'
|
|
6
|
+
package: './src/package.ts',
|
|
7
7
|
},
|
|
8
8
|
module: {
|
|
9
9
|
rules: [
|
|
10
10
|
{
|
|
11
|
-
test: /\.
|
|
11
|
+
test: /\.ts?$/,
|
|
12
12
|
use: 'ts-loader',
|
|
13
13
|
exclude: /node_modules/,
|
|
14
14
|
},
|
|
15
15
|
],
|
|
16
16
|
},
|
|
17
17
|
resolve: {
|
|
18
|
-
extensions: ['.tsx', '.
|
|
18
|
+
extensions: ['.tsx', '.js', '.ts'],
|
|
19
19
|
},
|
|
20
20
|
devtool: 'inline-source-map',
|
|
21
21
|
externals: {
|
|
@@ -24,7 +24,7 @@ module.exports = {
|
|
|
24
24
|
'datagrok-api/ui': 'ui',
|
|
25
25
|
'openchemlib/full.js': 'OCL',
|
|
26
26
|
'rxjs': 'rxjs',
|
|
27
|
-
'rxjs/operators': 'rxjs.operators'
|
|
27
|
+
'rxjs/operators': 'rxjs.operators',
|
|
28
28
|
},
|
|
29
29
|
output: {
|
|
30
30
|
filename: '[name].js',
|
package/.eslintrc.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"browser": true,
|
|
4
|
-
"es2021": true
|
|
5
|
-
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"google"
|
|
8
|
-
],
|
|
9
|
-
"parser": "@typescript-eslint/parser",
|
|
10
|
-
"parserOptions": {
|
|
11
|
-
"ecmaVersion": 12,
|
|
12
|
-
"sourceType": "module"
|
|
13
|
-
},
|
|
14
|
-
"plugins": [
|
|
15
|
-
"@typescript-eslint"
|
|
16
|
-
],
|
|
17
|
-
"rules": {
|
|
18
|
-
"indent": [
|
|
19
|
-
"error",
|
|
20
|
-
2
|
|
21
|
-
],
|
|
22
|
-
"max-len": [
|
|
23
|
-
"error",
|
|
24
|
-
120
|
|
25
|
-
],
|
|
26
|
-
"spaced-comment": "off",
|
|
27
|
-
"require-jsdoc": "off"
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/split-aligned.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as DG from 'datagrok-api/dg';
|
|
2
|
-
|
|
3
|
-
export function splitAlignedPeptides(peptideColumn: DG.Column) {
|
|
4
|
-
let splitPeptidesArray: string[][] = [];
|
|
5
|
-
let isFirstRun = true;
|
|
6
|
-
let splitted: string[];
|
|
7
|
-
|
|
8
|
-
for (const peptideStr of peptideColumn.toList()) {
|
|
9
|
-
splitted = peptideStr.split('-');
|
|
10
|
-
|
|
11
|
-
if (isFirstRun) {
|
|
12
|
-
for (let i = 0; i < splitted.length; i++) {
|
|
13
|
-
splitPeptidesArray.push([]);
|
|
14
|
-
}
|
|
15
|
-
isFirstRun = false;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
splitted.forEach((value, index) => {
|
|
19
|
-
splitPeptidesArray[index].push(value === '' ? '-' : value);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//create column names list
|
|
24
|
-
let columnNames = ['N'];
|
|
25
|
-
columnNames = columnNames.concat(splitPeptidesArray.map((_, index) => `${index + 1 < 10 ? 0 : ''}${index +1 }`));
|
|
26
|
-
columnNames.push('C');
|
|
27
|
-
|
|
28
|
-
// filter out the columns with the same values
|
|
29
|
-
splitPeptidesArray = splitPeptidesArray.filter((positionArray, index) => {
|
|
30
|
-
const isRetained = new Set(positionArray).size > 1;
|
|
31
|
-
if (!isRetained) {
|
|
32
|
-
columnNames.splice(index, 1);
|
|
33
|
-
}
|
|
34
|
-
return isRetained;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const columnsArray = splitPeptidesArray.map((positionArray, index) => {
|
|
38
|
-
return DG.Column.fromList('string', columnNames[index], positionArray);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return DG.DataFrame.fromColumns(columnsArray);
|
|
42
|
-
}
|
package/src/utils/misc.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
//@ts-ignore: no types
|
|
2
|
-
import * as jStat from 'jstat';
|
|
3
|
-
|
|
4
|
-
type testStats = {
|
|
5
|
-
'p-value': number,
|
|
6
|
-
'Mean difference'?: number,
|
|
7
|
-
'Median difference'?: number,
|
|
8
|
-
'p-value more': number,
|
|
9
|
-
'p-value less': number,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export function tTest(arr1: number[], arr2: number[], alpha=0.05, devKnown=false, devEqual=false): testStats {
|
|
13
|
-
const m1: number = jStat.mean(arr1);
|
|
14
|
-
const m2: number = jStat.mean(arr2);
|
|
15
|
-
const v1: number = jStat.variance(arr1);
|
|
16
|
-
const v2: number = jStat.variance(arr2);
|
|
17
|
-
const n1 = arr1.length;
|
|
18
|
-
const n2 = arr2.length;
|
|
19
|
-
|
|
20
|
-
let wv1;
|
|
21
|
-
let wv2;
|
|
22
|
-
let wv;
|
|
23
|
-
let Z;
|
|
24
|
-
let K;
|
|
25
|
-
let pMore;
|
|
26
|
-
let pLess;
|
|
27
|
-
let pTot;
|
|
28
|
-
|
|
29
|
-
if (!devKnown) {
|
|
30
|
-
if (!devEqual) {
|
|
31
|
-
wv1 = v1 / n1;
|
|
32
|
-
wv2 = v2 / n2;
|
|
33
|
-
Z = (m1 - m2) / Math.sqrt(wv1 + wv2);
|
|
34
|
-
K = Math.pow((wv1 + wv2), 2) / (wv1 * wv1 / (n1 - 1) + wv2 * wv2 / (n2 - 1));
|
|
35
|
-
|
|
36
|
-
pLess = jStat.studentt.cdf(Z, K);
|
|
37
|
-
pMore = 1 - pLess;
|
|
38
|
-
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
39
|
-
} else {
|
|
40
|
-
K = n1 + n2 - 2;
|
|
41
|
-
wv = (v1 * (n1 - 1) + v2 * (n2 - 1)) / K;
|
|
42
|
-
Z = Math.sqrt(n1 * n2 / (n1 + n2)) * (m1 - m2) / wv;
|
|
43
|
-
|
|
44
|
-
pMore = 1 - jStat.studentt.cdf(Z, K);
|
|
45
|
-
pLess = jStat.studentt.cdf(Z, K);
|
|
46
|
-
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
wv1 = v1 / n1;
|
|
50
|
-
wv2 = v2 / n2;
|
|
51
|
-
Z = (m1 - m2) / Math.sqrt(wv1 + wv2);
|
|
52
|
-
|
|
53
|
-
pLess = jStat.normal.pdf(Z, 0, 1);
|
|
54
|
-
pMore = 1 - pLess;
|
|
55
|
-
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
56
|
-
}
|
|
57
|
-
return {'p-value': pTot, 'Mean difference': m1 - m2, 'p-value more': pMore, 'p-value less': pLess};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function uTest(x: number[], y: number[], continuity=true): testStats {
|
|
61
|
-
const xy = x.concat(y);
|
|
62
|
-
const n1 = x.length;
|
|
63
|
-
const n2 = y.length;
|
|
64
|
-
const med1 = jStat.median(x);
|
|
65
|
-
const med2 = jStat.median(y);
|
|
66
|
-
|
|
67
|
-
const ranks = jStat.rank(xy);
|
|
68
|
-
|
|
69
|
-
const R1 = jStat.sum(ranks.slice(0, n1));
|
|
70
|
-
const U1 = R1 - n1 * (n1 + 1) / 2;
|
|
71
|
-
const U2 = n1 * n2 - U1;
|
|
72
|
-
const U = U1 > U2 ? U1 : U2;
|
|
73
|
-
|
|
74
|
-
const mu = n1 * n2 / 2;
|
|
75
|
-
const n = n1 + n2;
|
|
76
|
-
|
|
77
|
-
const tieTerm = _tieTerm(ranks);
|
|
78
|
-
const s = Math.sqrt(n1 * n2 / 12 * ((n + 1) - tieTerm / (n* (n - 1))));
|
|
79
|
-
|
|
80
|
-
let numerator = U - mu;
|
|
81
|
-
|
|
82
|
-
if (continuity) {
|
|
83
|
-
numerator -= 0.5;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const z = numerator / s;
|
|
87
|
-
|
|
88
|
-
const p = 2 * (1 - jStat.normal.cdf(z, 0, 1));
|
|
89
|
-
|
|
90
|
-
return {'p-value': p, 'Median difference': med1 - med2, 'p-value more': p, 'p-value less': p};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function _tieTerm(ranks: number[]): number {
|
|
94
|
-
const ties: {[key: number]: number} = {};
|
|
95
|
-
|
|
96
|
-
ranks.forEach((num) => {
|
|
97
|
-
ties[num] = (ties[num] || 0) + 1;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
return jStat.sum(Object.values(ties));
|
|
101
|
-
}
|