@datagrok/curves 1.8.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/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/package.json +12 -8
- package/queries/plates-crud.sql +148 -0
- package/src/fit/const.ts +60 -60
- 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 +48 -44
- package/src/fit/fit-renderer.ts +56 -55
- package/src/fit/multi-curve-viewer.ts +38 -18
- package/src/fit/render-utils.ts +315 -315
- package/src/package-api.ts +167 -0
- package/src/package-test.ts +1 -1
- package/src/package.g.ts +133 -3
- package/src/package.ts +198 -299
- package/src/plate/excel-plates.ts +1 -1
- package/src/plate/plate-cell-renderer.ts +20 -12
- package/src/plate/plate-drc-analysis.ts +262 -0
- package/src/plate/plate-reader.ts +5 -5
- package/src/plate/plate-well-validators.ts +41 -0
- package/src/plate/plate-widget.ts +132 -368
- package/src/plate/plate.ts +168 -57
- package/src/plate/plates-folder-preview.ts +63 -0
- package/src/plate/readers/bmg-pherastar-96.ts +7 -7
- package/src/plate/readers/delfia-envision-96-max-rlu.ts +4 -3
- package/src/plate/readers/delfia-envision-by-row.ts +3 -3
- package/src/plate/readers/spectramax.ts +7 -8
- package/src/plate/utils.ts +22 -10
- 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 +93 -92
- package/src/tests/detector-tests.ts +3 -2
- package/src/tests/fit-tests.ts +199 -198
- package/src/tests/plate-tests.ts +6 -7
- package/src/tests/transform-tests.ts +4 -4
- package/test-console-output-1.log +435 -0
- package/test-record-1.mp4 +0 -0
- package/tsconfig.json +1 -1
package/src/plate/plate.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
1
2
|
import * as DG from 'datagrok-api/dg';
|
|
2
3
|
import * as grok from 'datagrok-api/grok';
|
|
3
4
|
import * as ui from 'datagrok-api/ui';
|
|
@@ -9,13 +10,16 @@ import {
|
|
|
9
10
|
jstatStatistics,
|
|
10
11
|
JSTATStatistics,
|
|
11
12
|
numToExcel,
|
|
12
|
-
parseExcelPosition, toStandardSize
|
|
13
|
-
} from
|
|
13
|
+
parseExcelPosition, standardPlateSizes, toExcelPosition, toStandardSize
|
|
14
|
+
} from './utils';
|
|
14
15
|
import type ExcelJS from 'exceljs';
|
|
15
|
-
import {findPlatePositions, getPlateFromSheet} from
|
|
16
|
+
import {findPlatePositions, getPlateFromSheet} from './excel-plates';
|
|
16
17
|
import {FitFunctionType, FitSeries} from '@datagrok-libraries/statistics/src/fit/new-fit-API';
|
|
17
18
|
import {AnalysisOptions, PlateWidget} from './plate-widget';
|
|
18
19
|
import {inspectCurve} from '../fit/fit-renderer';
|
|
20
|
+
import {plateDbColumn, wellProperties, plateTypes} from '../plates/plates-crud';
|
|
21
|
+
import {PlateDrcAnalysis} from './plate-drc-analysis';
|
|
22
|
+
import {IPlateWellValidator} from './plate-well-validators';
|
|
19
23
|
|
|
20
24
|
|
|
21
25
|
/** Represents a well in the experimental plate */
|
|
@@ -34,7 +38,7 @@ interface IPlateCsvImportOptions {
|
|
|
34
38
|
positionColumn?: string;
|
|
35
39
|
volumeColumn?: string;
|
|
36
40
|
concentrationColumn?: string;
|
|
37
|
-
field?: string;
|
|
41
|
+
field?: string; // used as a field name when a 12x8 table is passed; if not passed, defaults to 'value'
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
|
|
@@ -77,7 +81,13 @@ export function randomizeTableId() {
|
|
|
77
81
|
|
|
78
82
|
/** Represents experimental plate (typically 96-, 384-, or 1536-well assay plates) */
|
|
79
83
|
export class Plate {
|
|
80
|
-
|
|
84
|
+
id?: number; // database id
|
|
85
|
+
plateTemplateId?: number; // database plate template id
|
|
86
|
+
plateTypeId?: number; // database plate type id
|
|
87
|
+
barcode?: string; // database barcode
|
|
88
|
+
|
|
89
|
+
data: DG.DataFrame; // each column is a layer, layed out like (r1 c1) (r1 c2) ... (r2 c1)
|
|
90
|
+
details: {[index: string]: any} = {}; // dynamic plate properties, stored in db: plates.plate_details
|
|
81
91
|
//layers: PlateLayer[];
|
|
82
92
|
rows: number = 8;
|
|
83
93
|
cols: number = 12;
|
|
@@ -86,6 +96,8 @@ export class Plate {
|
|
|
86
96
|
this.data = DG.DataFrame.create(rows * cols);
|
|
87
97
|
this.rows = rows;
|
|
88
98
|
this.cols = cols;
|
|
99
|
+
this.plateTypeId = plateTypes.find((pt) => pt.rows == this.rows && pt.cols == this.cols)?.id;
|
|
100
|
+
this.barcode = Math.round(Math.random() * 10000).toString().padStart(10, '0');
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
/** Creates an empty plate of the standard size to fit the specified positions. t*/
|
|
@@ -94,10 +106,21 @@ export class Plate {
|
|
|
94
106
|
return new Plate(rows, cols);
|
|
95
107
|
}
|
|
96
108
|
|
|
109
|
+
/** Returns the internal index of the DataFrame row that stores information
|
|
110
|
+
* for the grid cell with 0-based (row, col) coordinates. */
|
|
97
111
|
_idx(row: number, col: number): number {
|
|
98
112
|
return row * this.cols + col;
|
|
99
113
|
}
|
|
100
114
|
|
|
115
|
+
/** Converts a row index in the internal dataframe to 0-based row/col position. */
|
|
116
|
+
rowIndexToExcel(dataFrameRow: number): [row: number, col: number] {
|
|
117
|
+
return Plate._idxToPos(dataFrameRow, this.cols);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static _idxToPos(dataFrameRow: number, cols: number): [row: number, col: number] {
|
|
121
|
+
return [Math.floor(dataFrameRow / cols), dataFrameRow % cols];
|
|
122
|
+
}
|
|
123
|
+
|
|
101
124
|
//well(row: number, col: number): PlateWell { return new PlateWell(); }
|
|
102
125
|
|
|
103
126
|
_markOutlier(row: number, flag: boolean = true) {
|
|
@@ -119,12 +142,15 @@ export class Plate {
|
|
|
119
142
|
|
|
120
143
|
markOutliersWhere(field: string, valueFunc: (fieldValue: any) => boolean, filter?: IPlateWellFilter) {
|
|
121
144
|
this.values([field], filter).forEach((v) => {
|
|
122
|
-
if(valueFunc(v[field]))
|
|
145
|
+
if (valueFunc(v[field]))
|
|
123
146
|
this._markOutlier(v.innerDfRow, true);
|
|
124
|
-
})
|
|
147
|
+
});
|
|
125
148
|
}
|
|
126
149
|
|
|
127
|
-
|
|
150
|
+
/** Constructs a plate from a table of size 8x12, 16x24 or 32x48
|
|
151
|
+
* This plate will have one layer.
|
|
152
|
+
* The opposite of {@link toGridDataFrame}. */
|
|
153
|
+
static fromGridDataFrame(table: DG.DataFrame, field?: string): Plate {
|
|
128
154
|
const rows = table.rowCount;
|
|
129
155
|
// remove row letters
|
|
130
156
|
function containsRowLetters(c: DG.Column): boolean {
|
|
@@ -137,48 +163,109 @@ export class Plate {
|
|
|
137
163
|
|
|
138
164
|
const nonEmptyCols = dataColumns.filter((c) => c.stats.missingValueCount != rows);
|
|
139
165
|
const toString = (nonEmptyCols.length > 0 && nonEmptyCols.findIndex((c) => c.type != nonEmptyCols[0].type) != -1);
|
|
140
|
-
const type = toString
|
|
141
|
-
|
|
142
|
-
|
|
166
|
+
const type = toString ?
|
|
167
|
+
DG.TYPE.STRING :
|
|
168
|
+
firstWhere(dataColumns, (c) => c.stats.missingValueCount != rows)?.type ?? DG.TYPE.STRING;
|
|
143
169
|
|
|
144
170
|
const dataColumn = plate.data.columns.addNew(table.name ?? field, type);
|
|
145
171
|
|
|
146
|
-
for (let colIdx = 0; colIdx < dataColumns.length; colIdx ++)
|
|
147
|
-
if (dataColumns[colIdx].stats.missingValueCount != rows)
|
|
172
|
+
for (let colIdx = 0; colIdx < dataColumns.length; colIdx ++) {
|
|
173
|
+
if (dataColumns[colIdx].stats.missingValueCount != rows) {
|
|
148
174
|
for (let i = 0; i < rows; i++)
|
|
149
175
|
dataColumn.set(plate._idx(i, colIdx), type != DG.TYPE.STRING ? dataColumns[colIdx].get(i) : dataColumns[colIdx].getString(i), false);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
150
178
|
|
|
151
179
|
return plate;
|
|
152
180
|
}
|
|
153
181
|
|
|
182
|
+
/** Returns a dataframe representing the specified layer with the same layout as the plate.
|
|
183
|
+
* The opposite of {@link fromGridDataFrame}. */
|
|
184
|
+
toGridDataFrame(layer: string): DG.DataFrame {
|
|
185
|
+
const df = DG.DataFrame.create(this.rows, layer);
|
|
186
|
+
const col = this.data.columns.byName(layer);
|
|
187
|
+
|
|
188
|
+
for (let i = 0; i < this.cols; i++)
|
|
189
|
+
df.columns.addNew(`${i + 1}`, col.type).init((r) => col.get(this._idx(r, i)));
|
|
190
|
+
|
|
191
|
+
return df;
|
|
192
|
+
}
|
|
193
|
+
|
|
154
194
|
|
|
155
195
|
/** Constructs a plate from a dataframe where each row corresponds to a well.
|
|
156
|
-
* Automatically detects position column (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
196
|
+
* Automatically detects position column (either one column in Excel notation, or two integer "row" and "col" columns).
|
|
197
|
+
* If positions columns are not provided, assumes the data is sorted by [row, col] asc. */
|
|
198
|
+
static fromTableByRow(
|
|
199
|
+
table: DG.DataFrame, options?: {
|
|
200
|
+
posColName?: string,
|
|
201
|
+
rowColName?: string,
|
|
202
|
+
colColName?: string
|
|
203
|
+
}): Plate {
|
|
204
|
+
const posCol = wu(table.columns).find((c) =>
|
|
205
|
+
(!options?.posColName || c.name.toLowerCase() == options.posColName) &&
|
|
206
|
+
c.type == DG.TYPE.STRING && /^([A-Za-z]+)(\d+)$/.test(c.get(0)));
|
|
207
|
+
|
|
208
|
+
const rowColName = options?.rowColName ?? 'row';
|
|
209
|
+
const colColName = options?.colColName ?? 'col';
|
|
210
|
+
const rowCol = table.col(rowColName)?.type === DG.TYPE.INT ? table.col(rowColName) : null;
|
|
211
|
+
const colCol = table.col(colColName)?.type === DG.TYPE.INT ? table.col(colColName) : null;
|
|
212
|
+
|
|
213
|
+
const rowToPos: ((i: number) => [row: number, col: number]) | null = posCol ?
|
|
214
|
+
((i) => parseExcelPosition(posCol!.get(i))) :
|
|
215
|
+
rowCol && colCol ? ((i) => [rowCol!.get(i), colCol?.get(i)]) :
|
|
216
|
+
standardPlateSizes[table.rowCount] ? ((i) => Plate._idxToPos(i, standardPlateSizes[table.rowCount][1])) :
|
|
217
|
+
null;
|
|
218
|
+
|
|
219
|
+
if (rowToPos == null)
|
|
220
|
+
throw new Error('Columns with well positions not identified');
|
|
221
|
+
|
|
222
|
+
const positions = DG.range(table.rowCount).map(rowToPos);
|
|
223
|
+
const [rows, cols] = toStandardSize(getMaxPosition(positions));
|
|
224
|
+
|
|
164
225
|
const plate = new Plate(rows, cols);
|
|
165
226
|
|
|
166
227
|
for (const col of table.columns) {
|
|
167
|
-
if (col.isEmpty || col == posCol)
|
|
228
|
+
if (col.isEmpty || col == posCol || col == rowCol || col == colCol)
|
|
168
229
|
continue;
|
|
169
230
|
|
|
170
231
|
const plateCol = plate.data.columns.addNew(col.name, col.type);
|
|
171
232
|
for (let r = 0; r < col.length; r++) {
|
|
172
|
-
const [wellRow, wellCol] =
|
|
173
|
-
plateCol.set(wellRow
|
|
233
|
+
const [wellRow, wellCol] = rowToPos!(r);
|
|
234
|
+
plateCol.set(plate._idx(wellRow, wellCol), col.get(r), false);
|
|
174
235
|
}
|
|
175
236
|
}
|
|
176
237
|
|
|
177
238
|
return plate;
|
|
178
239
|
}
|
|
179
240
|
|
|
241
|
+
/** Constructs a plate from the Datagrok database format. The dataframe should have these columns:
|
|
242
|
+
* property_id, row, col, value_num, value_string, value_bool.
|
|
243
|
+
* See also plates-crud.sql/getWellValuesByBarcode
|
|
244
|
+
* */
|
|
245
|
+
static fromDbDataFrame(df: DG.DataFrame): Plate {
|
|
246
|
+
const plate = new Plate(df.col('row')!.stats.max + 1, df.col('col')!.stats.max + 1);
|
|
247
|
+
const pidCol = df.col('property_id');
|
|
248
|
+
for (let propBlock = 0; propBlock < df.rowCount / (plate.rows * plate.cols); propBlock++) {
|
|
249
|
+
const start = propBlock * plate.rows * plate.cols;
|
|
250
|
+
const pid = pidCol?.get(start);
|
|
251
|
+
const property = wellProperties.find((p) => p.id == pid)!;
|
|
252
|
+
const valueColumn = df.col(plateDbColumn[property.type])!;
|
|
253
|
+
//@ts-ignore
|
|
254
|
+
plate.data.columns.addNew(property.name, property.type)
|
|
255
|
+
.init((i) => valueColumn.get(start + i));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return plate;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// /** Constructs a plate from the format used by the PlateWidget */
|
|
262
|
+
// static fromPlateData(df: DG.DataFrame): Plate {
|
|
263
|
+
// const plate = new Plate(df.col('row')!.stats.max + 1, df.col('col')!.stats.max + 1);
|
|
264
|
+
// }
|
|
265
|
+
|
|
266
|
+
|
|
180
267
|
static async fromCsvTableFile(csvPath: string, field: string, options?: DG.CsvImportOptions): Promise<Plate> {
|
|
181
|
-
return this.
|
|
268
|
+
return this.fromGridDataFrame(await grok.dapi.files.readCsv(csvPath, options), field);
|
|
182
269
|
}
|
|
183
270
|
|
|
184
271
|
// getClosestRoleName(fileName: string): string {
|
|
@@ -190,7 +277,7 @@ export class Plate {
|
|
|
190
277
|
// }
|
|
191
278
|
|
|
192
279
|
static fromCsvTable(csv: string, field: string, options?: DG.CsvImportOptions): Plate {
|
|
193
|
-
return this.
|
|
280
|
+
return this.fromGridDataFrame(DG.DataFrame.fromCsv(csv, options), field);
|
|
194
281
|
}
|
|
195
282
|
|
|
196
283
|
static fromCsv(csv: string, options?: IPlateCsvImportOptions): Plate {
|
|
@@ -208,13 +295,13 @@ export class Plate {
|
|
|
208
295
|
// if (df.columns.contains('pos'))
|
|
209
296
|
// return new Plate(0, 0);
|
|
210
297
|
|
|
211
|
-
return this.
|
|
298
|
+
return this.fromGridDataFrame(df, options?.field ?? 'value');
|
|
212
299
|
}
|
|
213
300
|
|
|
214
301
|
/** Merges the attributes from {@link plates} into one plate. */
|
|
215
302
|
static fromPlates(plates: Plate[], name?: string) {
|
|
216
303
|
assure(plates.length > 0, 'Array is empty.');
|
|
217
|
-
assure(plates.every(p => p.rows == plates[0].rows && p.cols == plates[0].cols), 'Plate dimensions differ.');
|
|
304
|
+
assure(plates.every((p) => p.rows == plates[0].rows && p.cols == plates[0].cols), 'Plate dimensions differ.');
|
|
218
305
|
|
|
219
306
|
const result = plates.reduce((p1, p2) => p1 ? p1.merge(p2) : p2.clone());
|
|
220
307
|
if (name != null)
|
|
@@ -222,7 +309,7 @@ export class Plate {
|
|
|
222
309
|
return result;
|
|
223
310
|
}
|
|
224
311
|
|
|
225
|
-
static async
|
|
312
|
+
static async fromExcelFile(fi: DG.FileInfo): Promise<Plate> {
|
|
226
313
|
return fi.data && fi.data.length ? await Plate.fromExcel(fi.data, fi.friendlyName) : await Plate.fromExcelPath(fi.fullPath, fi.friendlyName);
|
|
227
314
|
}
|
|
228
315
|
|
|
@@ -243,18 +330,24 @@ export class Plate {
|
|
|
243
330
|
const wb= await workbook.xlsx.load(excelBytes);
|
|
244
331
|
|
|
245
332
|
const platePositions = findPlatePositions(wb);
|
|
246
|
-
if (platePositions.length == 0) throw 'Plates not found in "${excelPath}"';
|
|
333
|
+
if (platePositions.length == 0) throw new Error('Plates not found in "${excelPath}"');
|
|
247
334
|
const p0 = platePositions[0];
|
|
248
335
|
if (!platePositions.every((pc) => pc.rows == p0.rows || pc.cols == p0.cols))
|
|
249
|
-
throw `Plate sizes differ in "${name}"
|
|
336
|
+
throw new Error(`Plate sizes differ in "${name}"`);
|
|
337
|
+
|
|
338
|
+
return Plate.fromPlates(platePositions.map((p) => getPlateFromSheet(p)), name);
|
|
339
|
+
}
|
|
250
340
|
|
|
251
|
-
|
|
341
|
+
static demo(): Plate {
|
|
342
|
+
const plate = Plate.fromTableByRow(grok.data.demo.wells(96));
|
|
343
|
+
plate.barcode = 'demo-' + Math.round(Math.random() * 10000).toString().padStart(6, '0');
|
|
344
|
+
return plate;
|
|
252
345
|
}
|
|
253
346
|
|
|
254
347
|
/** Generates [count] increasing integer numbers, starting with 0. */
|
|
255
|
-
get wells():
|
|
348
|
+
get wells(): wu.WuIterable<PlateWell> {
|
|
256
349
|
const self = this; // Capture this context
|
|
257
|
-
return (function* () {
|
|
350
|
+
return wu((function* () {
|
|
258
351
|
for (let row = 0; row < self.rows; row++) {
|
|
259
352
|
for (let col = 0; col < self.cols; col++) {
|
|
260
353
|
const well: PlateWell = {
|
|
@@ -262,14 +355,13 @@ export class Plate {
|
|
|
262
355
|
col: col,
|
|
263
356
|
};
|
|
264
357
|
for (const field of self.data.columns) {
|
|
265
|
-
if (!field.isNone(self._idx(row, col)))
|
|
358
|
+
if (field.name.toLowerCase() != 'row' && field.name.toLowerCase() != 'col' && !field.isNone(self._idx(row, col)))
|
|
266
359
|
well[field.name] = field.get(self._idx(row, col));
|
|
267
|
-
}
|
|
268
360
|
}
|
|
269
361
|
yield well;
|
|
270
362
|
}
|
|
271
363
|
}
|
|
272
|
-
})();
|
|
364
|
+
})());
|
|
273
365
|
}
|
|
274
366
|
|
|
275
367
|
/** Returns the specified field value at the specified positions (0-based).
|
|
@@ -279,8 +371,8 @@ export class Plate {
|
|
|
279
371
|
* */
|
|
280
372
|
get(field: string, rowIdxOrPos: number | string, colIdx?: number): any {
|
|
281
373
|
assure(this.data.columns.byName(field) != null, `Field does not exist: ${field}`);
|
|
282
|
-
if (typeof rowIdxOrPos === 'number' &&
|
|
283
|
-
throw 'Column not defined';
|
|
374
|
+
if (typeof rowIdxOrPos === 'number' && colIdx == null)
|
|
375
|
+
throw new Error('Column not defined');
|
|
284
376
|
|
|
285
377
|
const [row, col] = (typeof rowIdxOrPos === 'string') ? parseExcelPosition(rowIdxOrPos) : [rowIdxOrPos, colIdx!];
|
|
286
378
|
return this.data.columns.byName(field).get(this._idx(row, col));
|
|
@@ -297,11 +389,11 @@ export class Plate {
|
|
|
297
389
|
matches(i: number, filter: IPlateWellFilter): boolean {
|
|
298
390
|
const cols = this.data.columns;
|
|
299
391
|
// we allow both any and array of any things in matches object, so we need to convert it to array to have one api
|
|
300
|
-
const arMatches = filter.match ? Object.entries(filter.match).reduce((acc, [key, value]) => {acc[key] = Array.isArray(value) ? value : [value]; return acc;}, {} as Record<string, any[]>) : null;
|
|
301
|
-
const arExclude = filter.exclude ? Object.entries(filter.exclude).reduce((acc, [key, value]) => {acc[key] = Array.isArray(value) ? value : [value]; return acc;}, {} as Record<string, any[]>) : null;
|
|
392
|
+
const arMatches = filter.match ? Object.entries(filter.match).reduce((acc, [key, value]) => { acc[key] = Array.isArray(value) ? value : [value]; return acc; }, {} as Record<string, any[]>) : null;
|
|
393
|
+
const arExclude = filter.exclude ? Object.entries(filter.exclude).reduce((acc, [key, value]) => { acc[key] = Array.isArray(value) ? value : [value]; return acc; }, {} as Record<string, any[]>) : null;
|
|
302
394
|
return !filter || (!arMatches && !arExclude) ||
|
|
303
395
|
(
|
|
304
|
-
|
|
396
|
+
Object.keys(arMatches ?? {}).filter((m) => cols.contains(m)).every((key) => arMatches![key].some((m) => this.data.columns.byName(key).get(i) === m)) &&
|
|
305
397
|
Object.keys(arExclude ?? {}).filter((m) => cols.contains(m)).every((key) => arExclude![key].every((e) => this.data.columns.byName(key).get(i) !== e)));
|
|
306
398
|
}
|
|
307
399
|
|
|
@@ -309,9 +401,10 @@ export class Plate {
|
|
|
309
401
|
if (!filter)
|
|
310
402
|
return this.rows * this.cols;
|
|
311
403
|
let c = 0;
|
|
312
|
-
for (let i = 0; i < this.rows * this.cols; i++)
|
|
404
|
+
for (let i = 0; i < this.rows * this.cols; i++) {
|
|
313
405
|
if (this.matches(i, filter))
|
|
314
406
|
c++;
|
|
407
|
+
}
|
|
315
408
|
return c;
|
|
316
409
|
}
|
|
317
410
|
|
|
@@ -322,7 +415,7 @@ export class Plate {
|
|
|
322
415
|
const colsObj: Record<string, DG.Column> = {};
|
|
323
416
|
for (let i = 0; i < fields.length; i++)
|
|
324
417
|
colsObj[fields[i]] = cols[i];
|
|
325
|
-
const result: (Record<string, any> & {innerDfRow: number}) []
|
|
418
|
+
const result: (Record<string, any> & {innerDfRow: number}) [] = [];
|
|
326
419
|
for (let i = 0; i < this.rows * this.cols; i++) {
|
|
327
420
|
if (((filter?.includeEmpty ?? false) || cols.every((col) => !col.isNone(i))) && (!filter || this.matches(i, filter))) {
|
|
328
421
|
const res = fields.reduce((acc, f) => { acc[f] = colsObj[f].isNone(i) ? null : colsObj[f].get(i); return acc; }, {} as Record<string, any> & {innerDfRow: number});
|
|
@@ -337,9 +430,9 @@ export class Plate {
|
|
|
337
430
|
getStatistics<T extends JSTATStatistics[]>(field: string, statistics: T, filter?: IPlateWellFilter): Record<T[number], number> {
|
|
338
431
|
const values = this.fieldValues(field, filter);
|
|
339
432
|
const result: Record<JSTATStatistics, number> = {} as Record<JSTATStatistics, number>;
|
|
340
|
-
for (const stat of statistics)
|
|
433
|
+
for (const stat of statistics)
|
|
341
434
|
result[stat] = jstatStatistics[stat](values);
|
|
342
|
-
|
|
435
|
+
|
|
343
436
|
return result;
|
|
344
437
|
}
|
|
345
438
|
|
|
@@ -347,6 +440,10 @@ export class Plate {
|
|
|
347
440
|
return this.values([field], filter).map((v) => v[field]);
|
|
348
441
|
}
|
|
349
442
|
|
|
443
|
+
getLayerNames(): string[] {
|
|
444
|
+
return this.data.columns.names();
|
|
445
|
+
}
|
|
446
|
+
|
|
350
447
|
static inspectSeriesByName(records: Record<string, FitSeries>, seriesName: string, fitFunctionName: FitFunctionType): void {
|
|
351
448
|
if (!seriesName || !fitFunctionName)
|
|
352
449
|
return;
|
|
@@ -378,7 +475,7 @@ export class Plate {
|
|
|
378
475
|
}
|
|
379
476
|
|
|
380
477
|
doseResponseSeries(options?: IPlateWellFilter & { concentration?: string; value?: string, groupBy?: string}): Record<string, FitSeries> {
|
|
381
|
-
const valueOptions = {includeEmpty: options?.includeEmpty ?? false, exclude: options?.exclude ?? {'role': ['High Control', 'Low Control']}}
|
|
478
|
+
const valueOptions = {includeEmpty: options?.includeEmpty ?? false, exclude: options?.exclude ?? {'role': ['High Control', 'Low Control']}};
|
|
382
479
|
const concKey = options?.concentration ?? 'concentration';
|
|
383
480
|
const valueKey = options?.value ?? 'value';
|
|
384
481
|
const values = this.values([concKey, valueKey, ...(options?.groupBy ? [options.groupBy] : [])], valueOptions);
|
|
@@ -402,21 +499,21 @@ export class Plate {
|
|
|
402
499
|
|
|
403
500
|
getAnalysisDialog(options: AnalysisOptions) {
|
|
404
501
|
ui.dialog('Plate Analysis')
|
|
405
|
-
|
|
406
|
-
|
|
502
|
+
.add(PlateDrcAnalysis.analysisView(this, options))
|
|
503
|
+
.showModal(true);
|
|
407
504
|
}
|
|
408
505
|
|
|
409
506
|
getAnalysisView(options: AnalysisOptions) {
|
|
410
|
-
const view = DG.View.fromRoot(
|
|
507
|
+
const view = DG.View.fromRoot(PlateDrcAnalysis.analysisView(this, options).root);
|
|
411
508
|
view.name = 'Plate Analysis';
|
|
412
509
|
return grok.shell.addView(view);
|
|
413
510
|
}
|
|
414
511
|
|
|
415
512
|
/** Adds data from the other plate to this plate. Typically, you would apply plate layout */
|
|
416
513
|
merge(plate: Plate) {
|
|
417
|
-
for (const col of plate.data.columns)
|
|
514
|
+
for (const col of plate.data.columns)
|
|
418
515
|
this.data.columns.add(col.clone());
|
|
419
|
-
|
|
516
|
+
|
|
420
517
|
return this;
|
|
421
518
|
}
|
|
422
519
|
|
|
@@ -438,9 +535,23 @@ export class Plate {
|
|
|
438
535
|
}
|
|
439
536
|
}
|
|
440
537
|
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
538
|
|
|
539
|
+
/** Validates the wells of the plate using the specified validators.
|
|
540
|
+
* Returns a map of well positions to the errors. */
|
|
541
|
+
validateWells(validators: IPlateWellValidator[]): Map<string, string[]> {
|
|
542
|
+
const result = new Map<string, string[]>();
|
|
543
|
+
for (const validator of validators) {
|
|
544
|
+
for (let row = 0; row < this.rows; row++) {
|
|
545
|
+
for (let col = 0; col < this.cols; col++) {
|
|
546
|
+
const error = validator.validate(this, row, col);
|
|
547
|
+
if (error) {
|
|
548
|
+
const errors = result.get(`${numToExcel(row)}${col}`) ?? [];
|
|
549
|
+
errors.push(error);
|
|
550
|
+
result.set(`${toExcelPosition(row, col)}`, errors);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return result;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as DG from 'datagrok-api/dg';
|
|
2
|
+
import * as ui from 'datagrok-api/ui';
|
|
3
|
+
import * as grok from 'datagrok-api/grok';
|
|
4
|
+
|
|
5
|
+
import {Plate} from './plate';
|
|
6
|
+
//@ts-ignore
|
|
7
|
+
import * as jStat from 'jstat';
|
|
8
|
+
import {FIT_FUNCTION_4PL_REGRESSION, FIT_FUNCTION_SIGMOID, FitMarkerType, IFitPoint} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
9
|
+
import { FitConstants } from '../fit/const';
|
|
10
|
+
import {FitCellOutlierToggleArgs, setOutlier} from '../fit/fit-renderer';
|
|
11
|
+
import { _package } from '../package';
|
|
12
|
+
import {savePlate} from "../plates/plates-crud";
|
|
13
|
+
import { PlateWidget } from './plate-widget';
|
|
14
|
+
import { PlateDrcAnalysis } from './plate-drc-analysis';
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export async function getPlatesFolderPreview(files: DG.FileInfo[]): Promise<DG.Widget | DG.ViewBase | undefined> {
|
|
19
|
+
|
|
20
|
+
const csvFiles = files.filter((f) => f?.name?.toLowerCase()?.endsWith('.csv'));
|
|
21
|
+
let csvView: DG.Widget | undefined = undefined;
|
|
22
|
+
if (csvFiles.length > 2) {
|
|
23
|
+
|
|
24
|
+
const plate = Plate.fromPlates(await Promise.all(csvFiles.map(async (f) => await Plate.fromCsvTableFile(f.fullPath, f.name.toLowerCase().substring(0, f.name.length - 4)))));
|
|
25
|
+
csvView = PlateDrcAnalysis.analysisView(plate, {submitAction: () => {grok.shell.info('Plate Submitted')}});
|
|
26
|
+
plate.data.name = `${csvFiles.map((file) => file.name.slice(0, file.name.length - 4)).join('_')}.csv`;
|
|
27
|
+
if (csvFiles.length === files.length)
|
|
28
|
+
return csvView;
|
|
29
|
+
}
|
|
30
|
+
const multiView = new DG.MultiView({viewFactories: {}});
|
|
31
|
+
|
|
32
|
+
if (csvView) {
|
|
33
|
+
multiView.addView('Plate 1', () => DG.View.fromRoot(csvView!.root), true);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const xlsxFiles = files.filter((f) => f?.name?.toLowerCase()?.endsWith('.xlsx') && f?.name?.toLowerCase().includes('plate'));
|
|
37
|
+
|
|
38
|
+
if (xlsxFiles.length == 0)
|
|
39
|
+
return csvView;
|
|
40
|
+
|
|
41
|
+
for (const xlsxFile of xlsxFiles) {
|
|
42
|
+
try {
|
|
43
|
+
const plate = await Plate.fromExcelFile(xlsxFile);
|
|
44
|
+
const pw = PlateDrcAnalysis.analysisView(plate, {submitAction: () => {grok.shell.info('Plate Submitted')}});
|
|
45
|
+
const v = DG.View.fromRoot(pw.root);
|
|
46
|
+
v.name = xlsxFile.name.substring(0, xlsxFile.name.length - 5);
|
|
47
|
+
multiView.addView(v.name, () => v, true);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
_package.logger.error(e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
const header: HTMLElement | null = multiView.root.querySelector('.d4-tab-header-stripe');
|
|
54
|
+
if (!header)
|
|
55
|
+
return;
|
|
56
|
+
header.style.overflow = 'scroll';
|
|
57
|
+
|
|
58
|
+
const headerItems = header.querySelectorAll('.d4-tab-header');
|
|
59
|
+
headerItems?.forEach((el) => (el as HTMLElement).style.whiteSpace = 'nowrap');
|
|
60
|
+
}, 300)
|
|
61
|
+
|
|
62
|
+
return multiView;
|
|
63
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {Plate} from
|
|
2
|
-
import {IPlateReader} from
|
|
3
|
-
import {
|
|
1
|
+
import {Plate} from '../plate';
|
|
2
|
+
import {IPlateReader} from '../plate-reader';
|
|
3
|
+
import {parseExcelPosition} from '../utils';
|
|
4
4
|
|
|
5
5
|
export class BmgPherastar96PlateReader implements IPlateReader {
|
|
6
6
|
isApplicable(s: string): boolean {
|
|
@@ -14,9 +14,9 @@ export class BmgPherastar96PlateReader implements IPlateReader {
|
|
|
14
14
|
|
|
15
15
|
// Split into lines and process each line
|
|
16
16
|
const lines = s.substring(dataStart).split('\n')
|
|
17
|
-
.map(line => line.trim())
|
|
18
|
-
.filter(line => line.length > 0)
|
|
19
|
-
.map(line => line.split(';').map(s => s.trim()));
|
|
17
|
+
.map((line) => line.trim())
|
|
18
|
+
.filter((line) => line.length > 0)
|
|
19
|
+
.map((line) => line.split(';').map((s) => s.trim()));
|
|
20
20
|
|
|
21
21
|
const plate = Plate.autoSize(lines.map((line) => parseExcelPosition(line[0])));
|
|
22
22
|
|
|
@@ -39,4 +39,4 @@ export class BmgPherastar96PlateReader implements IPlateReader {
|
|
|
39
39
|
|
|
40
40
|
return plate;
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import {Plate} from '../plate';
|
|
3
|
+
import {IPlateReader} from '../plate-reader';
|
|
3
4
|
|
|
4
5
|
export class DelfiaEnvision96MaxRluPlateReader implements IPlateReader {
|
|
5
6
|
isApplicable(s: string): boolean {
|
|
@@ -12,4 +13,4 @@ export class DelfiaEnvision96MaxRluPlateReader implements IPlateReader {
|
|
|
12
13
|
end = end != -1 ? end : s.indexOf('\r\n\r\n', start + 1);
|
|
13
14
|
return Plate.fromCsv(s.substring(start, end));
|
|
14
15
|
}
|
|
15
|
-
}
|
|
16
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as DG from 'datagrok-api/dg';
|
|
2
|
-
import {Plate} from
|
|
3
|
-
import {IPlateReader} from
|
|
2
|
+
import {Plate} from '../plate';
|
|
3
|
+
import {IPlateReader} from '../plate-reader';
|
|
4
4
|
|
|
5
5
|
export class DelfiaEnvisionByRowPlateReader implements IPlateReader {
|
|
6
6
|
isApplicable(s: string): boolean {
|
|
@@ -15,4 +15,4 @@ export class DelfiaEnvisionByRowPlateReader implements IPlateReader {
|
|
|
15
15
|
|
|
16
16
|
return Plate.fromTableByRow(table);
|
|
17
17
|
}
|
|
18
|
-
}
|
|
18
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as DG from 'datagrok-api/dg';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import {Plate} from '../plate';
|
|
3
|
+
import {IPlateReader} from '../plate-reader';
|
|
4
4
|
|
|
5
5
|
export class SpectramaxPlateReader implements IPlateReader {
|
|
6
6
|
isApplicable(s: string): boolean {
|
|
@@ -9,11 +9,11 @@ export class SpectramaxPlateReader implements IPlateReader {
|
|
|
9
9
|
|
|
10
10
|
read(content: string): Plate {
|
|
11
11
|
const lines = content.split(/\r\n|\r|\n/);
|
|
12
|
-
const header = lines[2].split('\t').filter(s => s !== '');
|
|
12
|
+
const header = lines[2].split('\t').filter((s) => s !== '');
|
|
13
13
|
const plateCount = parseInt(lines[1].split('\t')[8]);
|
|
14
14
|
|
|
15
15
|
// empty measurements names in the beginning are ok - need for indexing, will be ignored later
|
|
16
|
-
const plateMeasurementNames = header.filter((s, i) => s ==
|
|
16
|
+
const plateMeasurementNames = header.filter((s, i) => s == '' && i < 5 || !/^-?\d+$/.test(s));
|
|
17
17
|
const cols = header.filter((s) => /^-?\d+$/.test(s)).length;
|
|
18
18
|
const rows = cols * 2 / 3;
|
|
19
19
|
const plates = [];
|
|
@@ -23,16 +23,15 @@ export class SpectramaxPlateReader implements IPlateReader {
|
|
|
23
23
|
const headerValues = lines[plateIdx * (rows + 1) + 3].split('\t');
|
|
24
24
|
const plateMeasurements = plateMeasurementNames
|
|
25
25
|
.map((v, i) => v + ': ' + headerValues[i])
|
|
26
|
-
.filter((v,
|
|
26
|
+
.filter((v, _i) => v != '')
|
|
27
27
|
.join(', ');
|
|
28
28
|
|
|
29
29
|
const data = plate.data.columns.addNewFloat(plateMeasurements);
|
|
30
30
|
for (let row = 0; row < rows; row++) {
|
|
31
31
|
const rowIdx = plateIdx * (rows + 1) + 3 + row;
|
|
32
32
|
const values = lines[rowIdx].split('\t');
|
|
33
|
-
for (let col = 0; col < cols; col++)
|
|
33
|
+
for (let col = 0; col < cols; col++)
|
|
34
34
|
data.set(row * cols + col, parseFloat(values[col + 2].replace(',', '.')), false);
|
|
35
|
-
}
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
plates.push(plate);
|
|
@@ -40,4 +39,4 @@ export class SpectramaxPlateReader implements IPlateReader {
|
|
|
40
39
|
|
|
41
40
|
return Plate.fromPlates(plates);
|
|
42
41
|
}
|
|
43
|
-
}
|
|
42
|
+
}
|