@datagrok/curves 1.10.12 → 1.10.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/CHANGELOG.md +51 -0
- package/dist/package-test.js +470 -4270
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +254 -3895
- package/dist/package.js.map +1 -1
- package/package.json +4 -4
- package/src/fit/fit-demo.ts +1 -1
- package/src/fit/fit-grid-cell-handler.ts +385 -385
- package/src/fit/fit-inspection.ts +39 -0
- package/src/fit/fit-renderer.ts +1 -8
- package/src/fit/multi-curve-viewer.ts +1 -3
- package/src/fit/render-utils.ts +4 -2
- package/src/package-api.ts +2 -125
- package/src/package-test.ts +2 -3
- package/src/package.g.ts +0 -82
- package/src/package.ts +21 -128
- package/src/tests/curves-cell-renderer-tests.ts +15 -15
- package/src/tests/detector-tests.ts +1 -1
- package/src/tests/transform-tests.ts +1 -1
- package/test-console-output-1.log +22 -242
- package/test-record-1.mp4 +0 -0
- package/databases/plates/0000_init.sql +0 -167
- package/queries/plates-crud.sql +0 -148
- package/src/fit/const.ts +0 -73
- package/src/plate/excel-plates.ts +0 -112
- package/src/plate/plate-cell-renderer.ts +0 -50
- package/src/plate/plate-drc-analysis.ts +0 -262
- package/src/plate/plate-reader.ts +0 -28
- package/src/plate/plate-well-validators.ts +0 -41
- package/src/plate/plate-widget.ts +0 -242
- package/src/plate/plate.ts +0 -557
- package/src/plate/plates-folder-preview.ts +0 -63
- package/src/plate/readers/bmg-pherastar-96.ts +0 -42
- package/src/plate/readers/delfia-envision-96-max-rlu.ts +0 -16
- package/src/plate/readers/delfia-envision-by-row.ts +0 -18
- package/src/plate/readers/spectramax.ts +0 -42
- package/src/plate/utils.ts +0 -141
- package/src/plates/numeric_matcher.ts +0 -191
- package/src/plates/objects/plate-template-handler.ts +0 -48
- package/src/plates/plates-app.ts +0 -64
- package/src/plates/plates-crud.ts +0 -502
- package/src/plates/plates-demo.ts +0 -107
- package/src/plates/plates.sql +0 -169
- package/src/plates/views/plates-create-view.ts +0 -123
- package/src/plates/views/plates-schema-view.ts +0 -58
- package/src/plates/views/plates-search-view.ts +0 -137
- package/src/plates/views/plates-templates-view.ts +0 -37
- package/src/tests/plate-tests.ts +0 -153
package/src/plate/plate.ts
DELETED
|
@@ -1,557 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import * as DG from 'datagrok-api/dg';
|
|
3
|
-
import * as grok from 'datagrok-api/grok';
|
|
4
|
-
import * as ui from 'datagrok-api/ui';
|
|
5
|
-
import wu from 'wu';
|
|
6
|
-
import {
|
|
7
|
-
assure,
|
|
8
|
-
firstWhere,
|
|
9
|
-
getMaxPosition,
|
|
10
|
-
jstatStatistics,
|
|
11
|
-
JSTATStatistics,
|
|
12
|
-
numToExcel,
|
|
13
|
-
parseExcelPosition, standardPlateSizes, toExcelPosition, toStandardSize
|
|
14
|
-
} from './utils';
|
|
15
|
-
import type ExcelJS from 'exceljs';
|
|
16
|
-
import {findPlatePositions, getPlateFromSheet} from './excel-plates';
|
|
17
|
-
import {FitFunctionType, FitSeries} from '@datagrok-libraries/statistics/src/fit/new-fit-API';
|
|
18
|
-
import {AnalysisOptions, PlateWidget} from './plate-widget';
|
|
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';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/** Represents a well in the experimental plate */
|
|
26
|
-
export interface PlateWell {
|
|
27
|
-
row: number;
|
|
28
|
-
col: number;
|
|
29
|
-
volume?: number;
|
|
30
|
-
concentration?: number;
|
|
31
|
-
[key: string]: any;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
interface IPlateCsvImportOptions {
|
|
36
|
-
rowColumn?: string;
|
|
37
|
-
colColumn?: string;
|
|
38
|
-
positionColumn?: string;
|
|
39
|
-
volumeColumn?: string;
|
|
40
|
-
concentrationColumn?: string;
|
|
41
|
-
field?: string; // used as a field name when a 12x8 table is passed; if not passed, defaults to 'value'
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export interface IPlateWellFilter {
|
|
46
|
-
includeEmpty?: boolean;
|
|
47
|
-
match?: {[key: string]: any};
|
|
48
|
-
exclude?: {[key: string]: any};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
interface ISeriesData {
|
|
53
|
-
x: number[];
|
|
54
|
-
y: number[];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// export class PlateLayer<TData> {
|
|
58
|
-
// plate: Plate;
|
|
59
|
-
// data: Float64Array ArrayLike<number> DG.Column<TData>;
|
|
60
|
-
// role: 'concentration' | 'volume';
|
|
61
|
-
//
|
|
62
|
-
// /** Array of non-empty values */
|
|
63
|
-
// values(filter?: IPlateWellFilter): Array<any> {
|
|
64
|
-
// const col = this.data.columns.byName(data.name);
|
|
65
|
-
// assure(col != null, `Field does not exist: ${field}`);
|
|
66
|
-
//
|
|
67
|
-
// const result = [];
|
|
68
|
-
// for (let i = 0; i < this.rows * this.cols; i++)
|
|
69
|
-
// if ((filter?.includeEmpty ?? false) || !col.isNone(i))
|
|
70
|
-
// result.push(col.isNone(i) ? null : col.get(i));
|
|
71
|
-
//
|
|
72
|
-
// return result;
|
|
73
|
-
// }
|
|
74
|
-
// }
|
|
75
|
-
|
|
76
|
-
export const PLATE_OUTLIER_WELL_NAME = 'Outlier';
|
|
77
|
-
|
|
78
|
-
export function randomizeTableId() {
|
|
79
|
-
return `${Math.random()}-${Math.random()}-${Math.random()}-${Math.random()}-${Math.random()}-${Math.random()}-${Math.random()}-${Math.random()}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Represents experimental plate (typically 96-, 384-, or 1536-well assay plates) */
|
|
83
|
-
export class Plate {
|
|
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
|
|
91
|
-
//layers: PlateLayer[];
|
|
92
|
-
rows: number = 8;
|
|
93
|
-
cols: number = 12;
|
|
94
|
-
|
|
95
|
-
constructor(rows: number, cols: number) {
|
|
96
|
-
this.data = DG.DataFrame.create(rows * cols);
|
|
97
|
-
this.rows = rows;
|
|
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');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Creates an empty plate of the standard size to fit the specified positions. t*/
|
|
104
|
-
static autoSize(positions: Iterable<[number, number]>): Plate {
|
|
105
|
-
const [rows, cols] = toStandardSize(getMaxPosition(positions));
|
|
106
|
-
return new Plate(rows, cols);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Returns the internal index of the DataFrame row that stores information
|
|
110
|
-
* for the grid cell with 0-based (row, col) coordinates. */
|
|
111
|
-
_idx(row: number, col: number): number {
|
|
112
|
-
return row * this.cols + col;
|
|
113
|
-
}
|
|
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
|
-
|
|
124
|
-
//well(row: number, col: number): PlateWell { return new PlateWell(); }
|
|
125
|
-
|
|
126
|
-
_markOutlier(row: number, flag: boolean = true) {
|
|
127
|
-
const outlierCol = this.data.columns.getOrCreate(PLATE_OUTLIER_WELL_NAME, DG.TYPE.BOOL);
|
|
128
|
-
outlierCol.set(row, flag);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
markOutlier(row: number, col: number, flag: boolean = true) {
|
|
132
|
-
this._markOutlier(this._idx(row, col), flag);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
_isOutlier(row: number): boolean {
|
|
136
|
-
const outlierCol = this.data.columns.getOrCreate(PLATE_OUTLIER_WELL_NAME, DG.TYPE.BOOL);
|
|
137
|
-
return outlierCol.get(row);
|
|
138
|
-
}
|
|
139
|
-
isOutlier(row: number, col: number): boolean {
|
|
140
|
-
return this._isOutlier(this._idx(row, col));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
markOutliersWhere(field: string, valueFunc: (fieldValue: any) => boolean, filter?: IPlateWellFilter) {
|
|
144
|
-
this.values([field], filter).forEach((v) => {
|
|
145
|
-
if (valueFunc(v[field]))
|
|
146
|
-
this._markOutlier(v.innerDfRow, true);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
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 {
|
|
154
|
-
const rows = table.rowCount;
|
|
155
|
-
// remove row letters
|
|
156
|
-
function containsRowLetters(c: DG.Column): boolean {
|
|
157
|
-
return c.type == DG.TYPE.STRING && DG.range(rows).every((i) => numToExcel(i) == c.get(i).toUpperCase());
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const dataColumns = wu(table.columns).filter((c) => !containsRowLetters(c)).toArray();
|
|
161
|
-
const cols = dataColumns.length;
|
|
162
|
-
const plate = new Plate(rows, cols);
|
|
163
|
-
|
|
164
|
-
const nonEmptyCols = dataColumns.filter((c) => c.stats.missingValueCount != rows);
|
|
165
|
-
const toString = (nonEmptyCols.length > 0 && nonEmptyCols.findIndex((c) => c.type != nonEmptyCols[0].type) != -1);
|
|
166
|
-
const type = toString ?
|
|
167
|
-
DG.TYPE.STRING :
|
|
168
|
-
firstWhere(dataColumns, (c) => c.stats.missingValueCount != rows)?.type ?? DG.TYPE.STRING;
|
|
169
|
-
|
|
170
|
-
const dataColumn = plate.data.columns.addNew(table.name ?? field, type);
|
|
171
|
-
|
|
172
|
-
for (let colIdx = 0; colIdx < dataColumns.length; colIdx ++) {
|
|
173
|
-
if (dataColumns[colIdx].stats.missingValueCount != rows) {
|
|
174
|
-
for (let i = 0; i < rows; i++)
|
|
175
|
-
dataColumn.set(plate._idx(i, colIdx), type != DG.TYPE.STRING ? dataColumns[colIdx].get(i) : dataColumns[colIdx].getString(i), false);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return plate;
|
|
180
|
-
}
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
/** Constructs a plate from a dataframe where each row corresponds to a well.
|
|
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
|
-
|
|
225
|
-
const plate = new Plate(rows, cols);
|
|
226
|
-
|
|
227
|
-
for (const col of table.columns) {
|
|
228
|
-
if (col.isEmpty || col == posCol || col == rowCol || col == colCol)
|
|
229
|
-
continue;
|
|
230
|
-
|
|
231
|
-
const plateCol = plate.data.columns.addNew(col.name, col.type);
|
|
232
|
-
for (let r = 0; r < col.length; r++) {
|
|
233
|
-
const [wellRow, wellCol] = rowToPos!(r);
|
|
234
|
-
plateCol.set(plate._idx(wellRow, wellCol), col.get(r), false);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return plate;
|
|
239
|
-
}
|
|
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
|
-
|
|
267
|
-
static async fromCsvTableFile(csvPath: string, field: string, options?: DG.CsvImportOptions): Promise<Plate> {
|
|
268
|
-
return this.fromGridDataFrame(await grok.dapi.files.readCsv(csvPath, options), field);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// getClosestRoleName(fileName: string): string {
|
|
272
|
-
// const roleRoleNames = ['role', 'compound', 'compound name'];
|
|
273
|
-
// const concentrationRoleNames = ['concentration', 'conc', 'dilution'];
|
|
274
|
-
// const valueRoleNames = ['value', 'readout', 'response', 'activity', 'signal', 'absorbance', 'fluorescence', 'luminescence', 'intensity', 'od', 'optical density'];
|
|
275
|
-
// const foundRoleIndex = [roleRoleNames, concentrationRoleNames, valueRoleNames];
|
|
276
|
-
|
|
277
|
-
// }
|
|
278
|
-
|
|
279
|
-
static fromCsvTable(csv: string, field: string, options?: DG.CsvImportOptions): Plate {
|
|
280
|
-
return this.fromGridDataFrame(DG.DataFrame.fromCsv(csv, options), field);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
static fromCsv(csv: string, options?: IPlateCsvImportOptions): Plate {
|
|
284
|
-
const df = DG.DataFrame.fromCsv(csv);
|
|
285
|
-
|
|
286
|
-
// we do not need first row with row letters
|
|
287
|
-
if (DG.range(df.rowCount).every((i) => df.col(0)!.get(i) == String.fromCharCode(65 + i)))
|
|
288
|
-
df.columns.remove(df.columns.byIndex(0).name);
|
|
289
|
-
|
|
290
|
-
// sometimes there is an unnecessary last column in the end
|
|
291
|
-
if (df.columns.length == 13 || df.columns.length == 25 || df.columns.length == 49 && df.col(df.columns.length - 1)?.isEmpty)
|
|
292
|
-
df.columns.remove(df.columns.length - 1);
|
|
293
|
-
|
|
294
|
-
// TODO: tall format?
|
|
295
|
-
// if (df.columns.contains('pos'))
|
|
296
|
-
// return new Plate(0, 0);
|
|
297
|
-
|
|
298
|
-
return this.fromGridDataFrame(df, options?.field ?? 'value');
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/** Merges the attributes from {@link plates} into one plate. */
|
|
302
|
-
static fromPlates(plates: Plate[], name?: string) {
|
|
303
|
-
assure(plates.length > 0, 'Array is empty.');
|
|
304
|
-
assure(plates.every((p) => p.rows == plates[0].rows && p.cols == plates[0].cols), 'Plate dimensions differ.');
|
|
305
|
-
|
|
306
|
-
const result = plates.reduce((p1, p2) => p1 ? p1.merge(p2) : p2.clone());
|
|
307
|
-
if (name != null)
|
|
308
|
-
result.data.name = name;
|
|
309
|
-
return result;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
static async fromExcelFile(fi: DG.FileInfo): Promise<Plate> {
|
|
313
|
-
return fi.data && fi.data.length ? await Plate.fromExcel(fi.data, fi.friendlyName) : await Plate.fromExcelPath(fi.fullPath, fi.friendlyName);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
static async fromExcelPath(excelPath: string, name?: string): Promise<Plate> {
|
|
317
|
-
const content = await grok.dapi.files.readAsBytes(excelPath);
|
|
318
|
-
return this.fromExcel(content, name);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/** Constructs the plates from the specified Excel file.
|
|
322
|
-
* Plate positions are detected automatically. */
|
|
323
|
-
static async fromExcel(excelBytes: Uint8Array, name?: string): Promise<Plate> {
|
|
324
|
-
await DG.Utils.loadJsCss(['/js/common/exceljs.min.js']);
|
|
325
|
-
|
|
326
|
-
//@ts-ignore
|
|
327
|
-
const loadedExcelJS = window.ExcelJS as ExcelJS;
|
|
328
|
-
const workbook = new loadedExcelJS.Workbook() as ExcelJS.Workbook;
|
|
329
|
-
// @ts-ignore reason: some typescript error with araryLike and arrayBufferLike
|
|
330
|
-
const wb= await workbook.xlsx.load(excelBytes);
|
|
331
|
-
|
|
332
|
-
const platePositions = findPlatePositions(wb);
|
|
333
|
-
if (platePositions.length == 0) throw new Error('Plates not found in "${excelPath}"');
|
|
334
|
-
const p0 = platePositions[0];
|
|
335
|
-
if (!platePositions.every((pc) => pc.rows == p0.rows || pc.cols == p0.cols))
|
|
336
|
-
throw new Error(`Plate sizes differ in "${name}"`);
|
|
337
|
-
|
|
338
|
-
return Plate.fromPlates(platePositions.map((p) => getPlateFromSheet(p)), name);
|
|
339
|
-
}
|
|
340
|
-
|
|
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;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/** Generates [count] increasing integer numbers, starting with 0. */
|
|
348
|
-
get wells(): wu.WuIterable<PlateWell> {
|
|
349
|
-
const self = this; // Capture this context
|
|
350
|
-
return wu((function* () {
|
|
351
|
-
for (let row = 0; row < self.rows; row++) {
|
|
352
|
-
for (let col = 0; col < self.cols; col++) {
|
|
353
|
-
const well: PlateWell = {
|
|
354
|
-
row: row,
|
|
355
|
-
col: col,
|
|
356
|
-
};
|
|
357
|
-
for (const field of self.data.columns) {
|
|
358
|
-
if (field.name.toLowerCase() != 'row' && field.name.toLowerCase() != 'col' && !field.isNone(self._idx(row, col)))
|
|
359
|
-
well[field.name] = field.get(self._idx(row, col));
|
|
360
|
-
}
|
|
361
|
-
yield well;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
})());
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/** Returns the specified field value at the specified positions (0-based).
|
|
368
|
-
* The following examples all return volume for the C4 well:
|
|
369
|
-
* - plate.get('volume', 2, 3)
|
|
370
|
-
* - plate.get('volume', 'C4')
|
|
371
|
-
* */
|
|
372
|
-
get(field: string, rowIdxOrPos: number | string, colIdx?: number): any {
|
|
373
|
-
assure(this.data.columns.byName(field) != null, `Field does not exist: ${field}`);
|
|
374
|
-
if (typeof rowIdxOrPos === 'number' && colIdx == null)
|
|
375
|
-
throw new Error('Column not defined');
|
|
376
|
-
|
|
377
|
-
const [row, col] = (typeof rowIdxOrPos === 'string') ? parseExcelPosition(rowIdxOrPos) : [rowIdxOrPos, colIdx!];
|
|
378
|
-
return this.data.columns.byName(field).get(this._idx(row, col));
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/** Changes all numerical values to the results of the specified normalization function */
|
|
382
|
-
normalize(field: string, f: (value: number) => number, inplace: boolean = false) {
|
|
383
|
-
const originalCol = this.data.getCol(field);
|
|
384
|
-
const col = inplace ? originalCol : this.data.columns.addNewFloat(this.data.columns.getUnusedName(`${field}_normalized`));
|
|
385
|
-
col.init((i) => originalCol.isNone(i) ? null : f(originalCol.get(i)));
|
|
386
|
-
return col;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
matches(i: number, filter: IPlateWellFilter): boolean {
|
|
390
|
-
const cols = this.data.columns;
|
|
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
|
|
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;
|
|
394
|
-
return !filter || (!arMatches && !arExclude) ||
|
|
395
|
-
(
|
|
396
|
-
Object.keys(arMatches ?? {}).filter((m) => cols.contains(m)).every((key) => arMatches![key].some((m) => this.data.columns.byName(key).get(i) === m)) &&
|
|
397
|
-
Object.keys(arExclude ?? {}).filter((m) => cols.contains(m)).every((key) => arExclude![key].every((e) => this.data.columns.byName(key).get(i) !== e)));
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
count(filter?: IPlateWellFilter): number {
|
|
401
|
-
if (!filter)
|
|
402
|
-
return this.rows * this.cols;
|
|
403
|
-
let c = 0;
|
|
404
|
-
for (let i = 0; i < this.rows * this.cols; i++) {
|
|
405
|
-
if (this.matches(i, filter))
|
|
406
|
-
c++;
|
|
407
|
-
}
|
|
408
|
-
return c;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/** Array of non-empty values */
|
|
412
|
-
values(fields: string[], filter?: IPlateWellFilter): Array<Record<string, any> & {innerDfRow: number}> {
|
|
413
|
-
const cols = fields.map((f) => this.data.columns.byName(f));
|
|
414
|
-
assure(cols.every((c) => c != null), `Field does not exist: ${fields.find((_, i) => cols[i] == null)}`);
|
|
415
|
-
const colsObj: Record<string, DG.Column> = {};
|
|
416
|
-
for (let i = 0; i < fields.length; i++)
|
|
417
|
-
colsObj[fields[i]] = cols[i];
|
|
418
|
-
const result: (Record<string, any> & {innerDfRow: number}) [] = [];
|
|
419
|
-
for (let i = 0; i < this.rows * this.cols; i++) {
|
|
420
|
-
if (((filter?.includeEmpty ?? false) || cols.every((col) => !col.isNone(i))) && (!filter || this.matches(i, filter))) {
|
|
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});
|
|
422
|
-
res.innerDfRow = i;
|
|
423
|
-
result.push(res);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return result;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/// Returns specified field statistics for the specified filter and specified field name
|
|
430
|
-
getStatistics<T extends JSTATStatistics[]>(field: string, statistics: T, filter?: IPlateWellFilter): Record<T[number], number> {
|
|
431
|
-
const values = this.fieldValues(field, filter);
|
|
432
|
-
const result: Record<JSTATStatistics, number> = {} as Record<JSTATStatistics, number>;
|
|
433
|
-
for (const stat of statistics)
|
|
434
|
-
result[stat] = jstatStatistics[stat](values);
|
|
435
|
-
|
|
436
|
-
return result;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
fieldValues(field: string, filter?: IPlateWellFilter): Array<any> {
|
|
440
|
-
return this.values([field], filter).map((v) => v[field]);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
getLayerNames(): string[] {
|
|
444
|
-
return this.data.columns.names();
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
static inspectSeriesByName(records: Record<string, FitSeries>, seriesName: string, fitFunctionName: FitFunctionType): void {
|
|
448
|
-
if (!seriesName || !fitFunctionName)
|
|
449
|
-
return;
|
|
450
|
-
Plate.inspectSeries(records[seriesName], fitFunctionName);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
static inspectSeries(series: FitSeries, fitFunctionName: FitFunctionType) {
|
|
454
|
-
const seriesName = series?.name ?? 'Series';
|
|
455
|
-
if (!series || !fitFunctionName)
|
|
456
|
-
return;
|
|
457
|
-
const curveCol = DG.Column.string('Curve', 1);
|
|
458
|
-
curveCol.set(0, JSON.stringify({
|
|
459
|
-
chartOptions: {
|
|
460
|
-
logX: true,
|
|
461
|
-
title: seriesName,
|
|
462
|
-
},
|
|
463
|
-
series: [{...series, fit: undefined, fitFunction: fitFunctionName, clickToToggle: true, droplines: ['IC50'], name: seriesName}]
|
|
464
|
-
}), false);
|
|
465
|
-
const df = DG.DataFrame.fromColumns([curveCol]);
|
|
466
|
-
df.name = seriesName;
|
|
467
|
-
df.id = randomizeTableId();
|
|
468
|
-
curveCol.semType = 'fit';
|
|
469
|
-
curveCol.tags[DG.Tags.CellRenderer] = 'fit';
|
|
470
|
-
const grid = DG.Viewer.grid(df);
|
|
471
|
-
const gridCell = grid.cell('Curve', 0);
|
|
472
|
-
grok.shell.windows.showContextPanel = true;
|
|
473
|
-
grok.shell.o = gridCell;
|
|
474
|
-
inspectCurve(gridCell, {width: 480, height: 370}, true);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
doseResponseSeries(options?: IPlateWellFilter & { concentration?: string; value?: string, groupBy?: string}): Record<string, FitSeries> {
|
|
478
|
-
const valueOptions = {includeEmpty: options?.includeEmpty ?? false, exclude: options?.exclude ?? {'role': ['High Control', 'Low Control']}};
|
|
479
|
-
const concKey = options?.concentration ?? 'concentration';
|
|
480
|
-
const valueKey = options?.value ?? 'value';
|
|
481
|
-
const values = this.values([concKey, valueKey, ...(options?.groupBy ? [options.groupBy] : [])], valueOptions);
|
|
482
|
-
|
|
483
|
-
const series: Record<string, ISeriesData & Record<string, any>> = {};
|
|
484
|
-
for (const v of values) {
|
|
485
|
-
const group = options?.groupBy ? v[options.groupBy] : '0';
|
|
486
|
-
if (!series[group])
|
|
487
|
-
series[group] = {x: [], y: [], meta: [], outlier: []};
|
|
488
|
-
series[group].x.push(v[concKey]);
|
|
489
|
-
series[group].y.push(v[valueKey]);
|
|
490
|
-
series[group].meta.push(v.innerDfRow);
|
|
491
|
-
series[group].outlier.push(this._isOutlier(v.innerDfRow));
|
|
492
|
-
}
|
|
493
|
-
return Object.fromEntries(Object.entries(series).map(([k, v]) => {
|
|
494
|
-
const fitSeries = new FitSeries(v.x.map((_, i) => ({x: v.x[i], y: v.y[i], outlier: v.outlier[i], meta: v.meta[i]})).sort((a, b) => a.x - b.x));
|
|
495
|
-
fitSeries.name = k;
|
|
496
|
-
return [k, fitSeries];
|
|
497
|
-
}));
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
getAnalysisDialog(options: AnalysisOptions) {
|
|
501
|
-
ui.dialog('Plate Analysis')
|
|
502
|
-
.add(PlateDrcAnalysis.analysisView(this, options))
|
|
503
|
-
.showModal(true);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
getAnalysisView(options: AnalysisOptions) {
|
|
507
|
-
const view = DG.View.fromRoot(PlateDrcAnalysis.analysisView(this, options).root);
|
|
508
|
-
view.name = 'Plate Analysis';
|
|
509
|
-
return grok.shell.addView(view);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/** Adds data from the other plate to this plate. Typically, you would apply plate layout */
|
|
513
|
-
merge(plate: Plate) {
|
|
514
|
-
for (const col of plate.data.columns)
|
|
515
|
-
this.data.columns.add(col.clone());
|
|
516
|
-
|
|
517
|
-
return this;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/** Deep cloning */
|
|
521
|
-
clone(): Plate {
|
|
522
|
-
const cloned = new Plate(this.rows, this.cols);
|
|
523
|
-
cloned.data = this.data.clone();
|
|
524
|
-
return cloned;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
print() {
|
|
528
|
-
for (const fieldCol of this.data.columns) {
|
|
529
|
-
console.log();
|
|
530
|
-
console.log(fieldCol.name);
|
|
531
|
-
console.log(DG.range(this.cols + 1).map((col) => col == 0 ? '' : `${col}`).toArray().join('\t'));
|
|
532
|
-
for (let row = 0; row < this.rows; row++) {
|
|
533
|
-
console.log(numToExcel(row) + '\t' +
|
|
534
|
-
DG.range(this.cols).map((col) => fieldCol.getString(this._idx(row, col))).toArray().join(',\t'));
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
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
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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,42 +0,0 @@
|
|
|
1
|
-
import {Plate} from '../plate';
|
|
2
|
-
import {IPlateReader} from '../plate-reader';
|
|
3
|
-
import {parseExcelPosition} from '../utils';
|
|
4
|
-
|
|
5
|
-
export class BmgPherastar96PlateReader implements IPlateReader {
|
|
6
|
-
isApplicable(s: string): boolean {
|
|
7
|
-
return s.includes('No. of Channels / Multichromatics:') && s.includes('No. of Cycles:');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
read(s: string): Plate {
|
|
11
|
-
// Find the data section starting with "A01;"
|
|
12
|
-
const dataStart = s.indexOf('A01;');
|
|
13
|
-
if (dataStart === -1) throw new Error('Data section not found');
|
|
14
|
-
|
|
15
|
-
// Split into lines and process each line
|
|
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()));
|
|
20
|
-
|
|
21
|
-
const plate = Plate.autoSize(lines.map((line) => parseExcelPosition(line[0])));
|
|
22
|
-
|
|
23
|
-
// Create columns for both channels
|
|
24
|
-
const channelA = plate.data.columns.addNewFloat('Channel A');
|
|
25
|
-
const channelB = plate.data.columns.addNewFloat('Channel B');
|
|
26
|
-
|
|
27
|
-
// Process each line
|
|
28
|
-
for (const line of lines) {
|
|
29
|
-
const [pos, valA, valB] = line;
|
|
30
|
-
if (!pos || pos.length !== 3) continue;
|
|
31
|
-
|
|
32
|
-
const [row, col] = parseExcelPosition(pos);
|
|
33
|
-
|
|
34
|
-
// Set values in the plate
|
|
35
|
-
const idx = plate._idx(row, col);
|
|
36
|
-
channelA.set(idx, parseFloat(valA), false);
|
|
37
|
-
channelB.set(idx, parseFloat(valB), false);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return plate;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import {Plate} from '../plate';
|
|
3
|
-
import {IPlateReader} from '../plate-reader';
|
|
4
|
-
|
|
5
|
-
export class DelfiaEnvision96MaxRluPlateReader implements IPlateReader {
|
|
6
|
-
isApplicable(s: string): boolean {
|
|
7
|
-
return s.startsWith('Plate information') && s.includes('DELFIA') && s.includes('Number of the wells in the plate,,,,96');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
read(s: string): Plate {
|
|
11
|
-
const start = s.indexOf(',01,02,03,04,05,06,07,08,09,10,11,12,');
|
|
12
|
-
let end = s.indexOf('\n\n', start + 1);
|
|
13
|
-
end = end != -1 ? end : s.indexOf('\r\n\r\n', start + 1);
|
|
14
|
-
return Plate.fromCsv(s.substring(start, end));
|
|
15
|
-
}
|
|
16
|
-
}
|