@datagrok/curves 1.6.0 → 1.9.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/.eslintrc.json +39 -0
- package/.vscode/launch.json +10 -9
- package/.vscode/tasks.json +14 -0
- package/CHANGELOG.md +33 -0
- package/README.md +36 -8
- package/databases/plates/0000_init.sql +167 -0
- package/detectors.js +2 -2
- package/dist/package-test.js +15930 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +13750 -1
- package/dist/package.js.map +1 -1
- package/img/plate-dose-response-series.gif +0 -0
- package/img/plate-readers.gif +0 -0
- package/package.json +17 -11
- package/queries/plates-crud.sql +148 -0
- package/src/fit/const.ts +60 -59
- package/src/fit/data-to-curves.ts +220 -0
- package/src/fit/fit-demo.ts +6 -6
- package/src/fit/fit-grid-cell-handler.ts +94 -85
- package/src/fit/fit-renderer.ts +162 -98
- package/src/fit/multi-curve-viewer.ts +69 -28
- package/src/fit/render-utils.ts +346 -288
- package/src/package-api.ts +167 -0
- package/src/package-test.ts +7 -1
- package/src/package.g.ts +140 -2
- package/src/package.ts +221 -79
- package/src/plate/excel-plates.ts +112 -0
- package/src/plate/plate-cell-renderer.ts +48 -0
- package/src/plate/plate-drc-analysis.ts +262 -0
- package/src/plate/plate-reader.ts +28 -0
- package/src/plate/plate-well-validators.ts +41 -0
- package/src/plate/plate-widget.ts +242 -0
- package/src/plate/plate.ts +557 -0
- package/src/plate/plates-folder-preview.ts +63 -0
- package/src/plate/readers/bmg-pherastar-96.ts +42 -0
- package/src/plate/readers/delfia-envision-96-max-rlu.ts +16 -0
- package/src/plate/readers/delfia-envision-by-row.ts +18 -0
- package/src/plate/readers/spectramax.ts +42 -0
- package/src/plate/utils.ts +141 -0
- package/src/plates/numeric_matcher.ts +191 -0
- package/src/plates/objects/plate-template-handler.ts +48 -0
- package/src/plates/plates-app.ts +64 -0
- package/src/plates/plates-crud.ts +502 -0
- package/src/plates/plates-demo.ts +107 -0
- package/src/plates/plates.sql +169 -0
- package/src/plates/views/plates-create-view.ts +123 -0
- package/src/plates/views/plates-schema-view.ts +58 -0
- package/src/plates/views/plates-search-view.ts +137 -0
- package/src/plates/views/plates-templates-view.ts +38 -0
- package/src/tests/curves-cell-renderer-tests.ts +95 -75
- package/src/tests/detector-tests.ts +3 -2
- package/src/tests/fit-tests.ts +199 -163
- package/src/tests/plate-tests.ts +153 -0
- package/src/tests/transform-tests.ts +6 -6
- package/test-console-output-1.log +435 -0
- package/test-record-1.mp4 +0 -0
- package/tsconfig.json +1 -1
- package/src/fit/cell-render-viewer.ts +0 -54
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import * as DG from 'datagrok-api/dg';
|
|
3
|
+
import {MARKER_TYPE, TYPE} from 'datagrok-api/dg';
|
|
4
|
+
import * as ui from 'datagrok-api/ui';
|
|
5
|
+
import {div} from 'datagrok-api/ui';
|
|
6
|
+
import {mapFromRow, safeLog, toExcelPosition} from './utils';
|
|
7
|
+
import {Plate, PLATE_OUTLIER_WELL_NAME} from './plate';
|
|
8
|
+
//@ts-ignore
|
|
9
|
+
import * as jStat from 'jstat';
|
|
10
|
+
import {IPlateWellValidator, plateWellValidators} from './plate-well-validators';
|
|
11
|
+
import {debounceTime, filter} from 'rxjs/operators';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export type AnalysisOptions = {
|
|
15
|
+
roleName: string,
|
|
16
|
+
concentrationName: string,
|
|
17
|
+
valueName: string
|
|
18
|
+
controlColumns: string[],
|
|
19
|
+
normalize: boolean,
|
|
20
|
+
autoFilterOutliers: boolean,
|
|
21
|
+
submitAction?: (plate: Plate, curvesDf: DG.DataFrame) => void,
|
|
22
|
+
categorizeFormula: string,
|
|
23
|
+
statisticsColumns: string[],
|
|
24
|
+
plateStatistics?: {[key: string]: (plate: Plate) => string | number}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const colorScheme = [DG.Color.white, DG.Color.gray];
|
|
29
|
+
export const dimensions = new Map([
|
|
30
|
+
[96, {rows: 8, cols: 12}],
|
|
31
|
+
[384, {rows: 16, cols: 24}],
|
|
32
|
+
[1536, {rows: 32, cols: 48}],
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
/** Visualizes multiple layers of {@link Plate} in tabbed interface and lets you edit it */
|
|
36
|
+
export class PlateWidget extends DG.Widget {
|
|
37
|
+
_colorColumn?: DG.Column | undefined;
|
|
38
|
+
_plate: Plate = new Plate(8, 12);
|
|
39
|
+
grid: DG.Grid = DG.Viewer.heatMap(DG.DataFrame.create());
|
|
40
|
+
colorColumnName: string = '';
|
|
41
|
+
colorSelector?: DG.InputBase;
|
|
42
|
+
detailsDiv?: HTMLElement;
|
|
43
|
+
wellDetailsDiv?: HTMLElement;
|
|
44
|
+
plateDetailsDiv?: HTMLElement;
|
|
45
|
+
plateActionsDiv?: HTMLElement;
|
|
46
|
+
tabs: DG.TabControl = DG.TabControl.create();
|
|
47
|
+
tabsContainer: HTMLElement = ui.divH([], 'curves-plate-tabs-container');
|
|
48
|
+
_editable: boolean = false;
|
|
49
|
+
mapFromRowFunc: (row: DG.Row) => Record<string, any> = mapFromRow;
|
|
50
|
+
grids: Map<string, DG.Grid> = new Map();
|
|
51
|
+
wellValidators: IPlateWellValidator[] = plateWellValidators;
|
|
52
|
+
wellValidationErrors: Map<string, string[]> = new Map();
|
|
53
|
+
|
|
54
|
+
get editable() { return this._editable; }
|
|
55
|
+
set editable(x: boolean) {
|
|
56
|
+
this._editable = x;
|
|
57
|
+
this.syncGrids();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
constructor() {
|
|
61
|
+
super(ui.div([], 'curves-plate-widget'));
|
|
62
|
+
|
|
63
|
+
this.tabs.root.style.flexGrow = '1';
|
|
64
|
+
// this.tabs.root.style.height = '100%';
|
|
65
|
+
//this.tabs.addPane('Summary', () => this.grid.root);
|
|
66
|
+
|
|
67
|
+
this.tabsContainer.appendChild(this.tabs.root);
|
|
68
|
+
this.root.appendChild(this.tabsContainer);
|
|
69
|
+
|
|
70
|
+
this.grid.props.showHeatmapScrollbars = false;
|
|
71
|
+
this.grid.props.colHeaderHeight = 30;
|
|
72
|
+
this.grid.onCellRender.subscribe((args) => this.renderCell(args, true));
|
|
73
|
+
this.grid.onCellRendered.subscribe((args) => {
|
|
74
|
+
const cell = args.cell;
|
|
75
|
+
if (cell.gridRow >= 0 && cell.gridColumn.idx > 0) {
|
|
76
|
+
try {
|
|
77
|
+
const pos = toExcelPosition(cell.gridRow, cell.gridColumn.idx - 1);
|
|
78
|
+
const errors = this.wellValidationErrors.get(pos);
|
|
79
|
+
if (errors && errors.length > 0)
|
|
80
|
+
DG.Paint.marker(args.g, DG.MARKER_TYPE.CROSS_BORDER, cell.bounds.midX, cell.bounds.midY, DG.Color.red, 10);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.error(e);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static fromPlate(plate: Plate) {
|
|
89
|
+
return PlateWidget.detailedView(plate);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static detailedView(plate: Plate): PlateWidget {
|
|
93
|
+
const pw = new PlateWidget();
|
|
94
|
+
pw.grid.root.style.width = '100%';
|
|
95
|
+
pw.plate = plate;
|
|
96
|
+
pw.colorSelector = ui.input.column('Color by', {
|
|
97
|
+
table: plate.data,
|
|
98
|
+
value: pw._colorColumn,
|
|
99
|
+
onValueChanged: (v) => { pw._colorColumn = v; pw.grid.invalidate(); }
|
|
100
|
+
});
|
|
101
|
+
pw.detailsDiv = ui.divV([]);
|
|
102
|
+
pw.wellDetailsDiv = div();
|
|
103
|
+
pw.detailsDiv.appendChild(pw.wellDetailsDiv!);
|
|
104
|
+
pw.grid.onCurrentCellChanged.pipe(filter((gc) => gc.gridRow >= 0 && gc.gridColumn.idx > 0)).subscribe((gc) => {
|
|
105
|
+
ui.empty(pw.wellDetailsDiv!);
|
|
106
|
+
const map = pw.mapFromRowFunc(pw.plate.data.rows.get(plate._idx(gc.gridRow, gc.gridColumn.idx - 1)));
|
|
107
|
+
pw.wellDetailsDiv!.appendChild(ui.tableFromMap(map));
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
pw.root.prepend(pw.colorSelector.root);
|
|
111
|
+
pw.tabsContainer.appendChild(pw.detailsDiv);
|
|
112
|
+
return pw;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
initPlateGrid(grid: DG.Grid, isSummary: boolean = false) {
|
|
116
|
+
grid.props.showHeatmapScrollbars = false;
|
|
117
|
+
grid.props.allowColReordering = false;
|
|
118
|
+
grid.props.allowRowReordering = false;
|
|
119
|
+
grid.props.allowSorting = false;
|
|
120
|
+
grid.props.allowEdit = !isSummary;
|
|
121
|
+
grid.props.showRowGridlines = true;
|
|
122
|
+
grid.props.showColumnGridlines = true;
|
|
123
|
+
grid.props.heatmapColors = false;
|
|
124
|
+
grid.props.colHeaderHeight = 25;
|
|
125
|
+
|
|
126
|
+
grid.onCellRender.subscribe((args) => this.renderCell(args, isSummary));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get plate(): Plate { return this._plate; }
|
|
130
|
+
set plate(p: Plate) {
|
|
131
|
+
this._plate = p;
|
|
132
|
+
this.refresh();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Re-renders the UI */
|
|
136
|
+
refresh() {
|
|
137
|
+
this.tabs.clear();
|
|
138
|
+
this.tabs.addPane('Summary', () => this.grid.root);
|
|
139
|
+
for (const layer of this.plate.getLayerNames()) {
|
|
140
|
+
this.tabs.addPane(layer, () => {
|
|
141
|
+
const df = this.plate.toGridDataFrame(layer);
|
|
142
|
+
const grid = DG.Viewer.heatMap(df);
|
|
143
|
+
grid.columns.add({gridColumnName: '0', cellType: 'string', index: 1}); // to show row numbers in Excel format - will be done in initPlateGrid
|
|
144
|
+
df.onValuesChanged.pipe(debounceTime(1000)).subscribe(() => {
|
|
145
|
+
const p = this.plate;
|
|
146
|
+
for (let i = 0; i < df.rowCount; i++) {
|
|
147
|
+
for (let j = 0; j < df.columns.length - 1; j++)
|
|
148
|
+
p.data.col(layer)!.set(p._idx(i, j), df.get(`${j + 1}`, i));
|
|
149
|
+
}
|
|
150
|
+
this.wellValidationErrors = p.validateWells(this.wellValidators);
|
|
151
|
+
});
|
|
152
|
+
this.initPlateGrid(grid, false);
|
|
153
|
+
this.grids.set(layer, grid);
|
|
154
|
+
return grid.root;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
ui.tools.waitForElementInDom(this.tabs.root).then(() => {
|
|
158
|
+
this.tabs.currentPane = this.tabs.getPane('Summary');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
this.syncGrids();
|
|
162
|
+
|
|
163
|
+
const t = this.plate.data;
|
|
164
|
+
this._colorColumn = t.columns.firstWhere((col) => col.name == 'activity' && col.type == TYPE.FLOAT) ??
|
|
165
|
+
t.columns.firstWhere((col) => (col.name == 'concentration' || col.name == 'concentrations') && col.type == TYPE.FLOAT) ??
|
|
166
|
+
t.columns.firstWhere((col) => col.name != 'row' && col.name != 'col' && col.type == TYPE.FLOAT) ??
|
|
167
|
+
t.columns.firstWhere((col) => col.type == TYPE.FLOAT) ??
|
|
168
|
+
(t.columns.length > 0 ? t.columns.byIndex(0) : undefined);
|
|
169
|
+
|
|
170
|
+
// row header + all columns
|
|
171
|
+
this.grid.dataFrame = DG.DataFrame.create(this.plate.rows);
|
|
172
|
+
this.grid.columns.clear();
|
|
173
|
+
for (let i = 0; i <= this.plate.cols; i++)
|
|
174
|
+
this.grid.columns.add({gridColumnName: i.toString(), cellType: 'string'});
|
|
175
|
+
|
|
176
|
+
this.grid.invalidate();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
renderCell(args:DG.GridCellRenderArgs, summary: boolean = false) {
|
|
180
|
+
const gc = args.cell;
|
|
181
|
+
args.g.fillStyle = 'grey'; //(args.cell.isColHeader ? 'red' : (args.cell.isRowHeader ? 'green' : 'blue'));
|
|
182
|
+
args.g.strokeStyle = 'grey';
|
|
183
|
+
args.g.lineWidth = 1;
|
|
184
|
+
const g = args.g;
|
|
185
|
+
const x = args.bounds.x; const y = args.bounds.y; const w = args.bounds.width; const h = args.bounds.height;
|
|
186
|
+
g.textAlign = 'center';
|
|
187
|
+
g.textBaseline = 'middle';
|
|
188
|
+
g.font = `${Math.ceil(Math.min(...[16, w - 1, h - 1]))}px Roboto, Roboto Local`;
|
|
189
|
+
const isColoredByConc = this._colorColumn?.name?.toLowerCase()?.includes('conc');
|
|
190
|
+
|
|
191
|
+
// column header
|
|
192
|
+
const hasRowHeader = gc.grid.columns.byIndex(0)?.cellType === 'row header';
|
|
193
|
+
if (gc.isColHeader && gc.gridColumn.idx > (hasRowHeader ? 1 : 0)) {
|
|
194
|
+
g.fillText('' + (gc.gridColumn.idx - (hasRowHeader ? 1 : 0)), x + w / 2, y + h / 2);
|
|
195
|
+
args.preventDefault();
|
|
196
|
+
} else if (gc.isColHeader) {
|
|
197
|
+
args.preventDefault();
|
|
198
|
+
return;
|
|
199
|
+
} else if ((gc.gridColumn.name == '0' || gc.gridColumn.idx == 0) && gc.gridRow >= 0) {
|
|
200
|
+
const prefix = gc.gridRow > 25 ? 'A' : '';
|
|
201
|
+
g.fillText(prefix + String.fromCharCode(65 + gc.gridRow % 26), x + w / 2, y + h / 2);
|
|
202
|
+
args.preventDefault();
|
|
203
|
+
} else if (summary && h > 0 && gc.gridRow >= 0 && gc.gridColumn.idx > 0) {
|
|
204
|
+
const dataRow = this._plate._idx(gc.gridRow, gc.gridColumn.idx - 1);
|
|
205
|
+
|
|
206
|
+
g.beginPath();
|
|
207
|
+
const r = Math.min(h / 2, w / 2) * 0.8;
|
|
208
|
+
g.ellipse(x + w / 2, y + h / 2, r, r, 0, 0, 2 * Math.PI);
|
|
209
|
+
if (this._colorColumn) {
|
|
210
|
+
if (this._colorColumn.isCategorical && this._colorColumn.meta.colors.getType() !== DG.COLOR_CODING_TYPE.CATEGORICAL)
|
|
211
|
+
this._colorColumn.meta.colors.setCategorical();
|
|
212
|
+
const color = this._colorColumn.isNone(dataRow) ? DG.Color.white : this._colorColumn.isNumerical ?
|
|
213
|
+
this.getColor(dataRow, isColoredByConc) :
|
|
214
|
+
this._colorColumn.meta.colors.getColor(dataRow);
|
|
215
|
+
g.fillStyle = DG.Color.toHtml(color);
|
|
216
|
+
g.fill();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
g.stroke();
|
|
220
|
+
const outlierCol = this.plate.data.col(PLATE_OUTLIER_WELL_NAME);
|
|
221
|
+
if (outlierCol?.get(dataRow))
|
|
222
|
+
DG.Paint.marker(g, MARKER_TYPE.CROSS_X_BORDER, x + w / 2, y + h / 2, DG.Color.red, r * 2);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (summary)
|
|
226
|
+
args.preventDefault();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
getColor(dataRow: number, isLog?: boolean) {
|
|
230
|
+
const val = this._colorColumn!.get(dataRow)!;
|
|
231
|
+
const reducedVal = isLog ? safeLog((val - this._colorColumn!.min) * 1e9) : val;
|
|
232
|
+
const min = (isLog ? safeLog(Math.max(this._colorColumn!.min, 1)) : this._colorColumn!.min);
|
|
233
|
+
const max = isLog ? safeLog((this._colorColumn!.max - this._colorColumn!.min) * 1e9) : this._colorColumn!.max;
|
|
234
|
+
return DG.Color.scaleColor(reducedVal, min, max, undefined, colorScheme);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Applies plate widget options to all grids */
|
|
238
|
+
syncGrids() {
|
|
239
|
+
for (const grid of this.grids.values())
|
|
240
|
+
grid.props.allowEdit = this.editable;
|
|
241
|
+
}
|
|
242
|
+
}
|