@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.
Files changed (48) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/package-test.js +470 -4270
  3. package/dist/package-test.js.map +1 -1
  4. package/dist/package.js +254 -3895
  5. package/dist/package.js.map +1 -1
  6. package/package.json +4 -4
  7. package/src/fit/fit-demo.ts +1 -1
  8. package/src/fit/fit-grid-cell-handler.ts +385 -385
  9. package/src/fit/fit-inspection.ts +39 -0
  10. package/src/fit/fit-renderer.ts +1 -8
  11. package/src/fit/multi-curve-viewer.ts +1 -3
  12. package/src/fit/render-utils.ts +4 -2
  13. package/src/package-api.ts +2 -125
  14. package/src/package-test.ts +2 -3
  15. package/src/package.g.ts +0 -82
  16. package/src/package.ts +21 -128
  17. package/src/tests/curves-cell-renderer-tests.ts +15 -15
  18. package/src/tests/detector-tests.ts +1 -1
  19. package/src/tests/transform-tests.ts +1 -1
  20. package/test-console-output-1.log +22 -242
  21. package/test-record-1.mp4 +0 -0
  22. package/databases/plates/0000_init.sql +0 -167
  23. package/queries/plates-crud.sql +0 -148
  24. package/src/fit/const.ts +0 -73
  25. package/src/plate/excel-plates.ts +0 -112
  26. package/src/plate/plate-cell-renderer.ts +0 -50
  27. package/src/plate/plate-drc-analysis.ts +0 -262
  28. package/src/plate/plate-reader.ts +0 -28
  29. package/src/plate/plate-well-validators.ts +0 -41
  30. package/src/plate/plate-widget.ts +0 -242
  31. package/src/plate/plate.ts +0 -557
  32. package/src/plate/plates-folder-preview.ts +0 -63
  33. package/src/plate/readers/bmg-pherastar-96.ts +0 -42
  34. package/src/plate/readers/delfia-envision-96-max-rlu.ts +0 -16
  35. package/src/plate/readers/delfia-envision-by-row.ts +0 -18
  36. package/src/plate/readers/spectramax.ts +0 -42
  37. package/src/plate/utils.ts +0 -141
  38. package/src/plates/numeric_matcher.ts +0 -191
  39. package/src/plates/objects/plate-template-handler.ts +0 -48
  40. package/src/plates/plates-app.ts +0 -64
  41. package/src/plates/plates-crud.ts +0 -502
  42. package/src/plates/plates-demo.ts +0 -107
  43. package/src/plates/plates.sql +0 -169
  44. package/src/plates/views/plates-create-view.ts +0 -123
  45. package/src/plates/views/plates-schema-view.ts +0 -58
  46. package/src/plates/views/plates-search-view.ts +0 -137
  47. package/src/plates/views/plates-templates-view.ts +0 -37
  48. package/src/tests/plate-tests.ts +0 -153
@@ -1,148 +0,0 @@
1
- -- name: getPlates
2
- -- connection: Plates
3
- SELECT * FROM plates.plates;
4
- -- end
5
-
6
-
7
- -- name: getWellLevelProperties
8
- -- description: Get all well level properties (either used in a well or specified in a template)
9
- -- connection: Plates
10
- SELECT DISTINCT p.*
11
- FROM plates.properties p
12
- JOIN plates.plate_well_values pd ON p.id = pd.property_id
13
-
14
- UNION
15
-
16
- SELECT DISTINCT p.*
17
- FROM plates.properties p
18
- JOIN plates.template_well_properties twp ON p.id = twp.property_id
19
-
20
- ORDER BY name;
21
- -- end
22
-
23
-
24
- -- name: getPlateLevelProperties
25
- -- description: Get all plate level properties (either used in a plate or specified in a template)
26
- -- connection: Plates
27
- SELECT DISTINCT p.*
28
- FROM plates.properties p
29
- JOIN plates.plate_details pd ON p.id = pd.property_id
30
-
31
- UNION
32
-
33
- SELECT DISTINCT p.*
34
- FROM plates.properties p
35
- JOIN plates.template_plate_properties twp ON p.id = twp.property_id
36
-
37
- ORDER BY name;
38
- -- end
39
-
40
-
41
- -- name: getPropertyNames
42
- -- connection: Plates
43
- SELECT name FROM plates.properties;
44
- -- end
45
-
46
-
47
- -- name: getPlateTypes
48
- -- connection: Plates
49
- SELECT * FROM plates.plate_types;
50
- -- end
51
-
52
-
53
- -- name: getPlateTemplates
54
- -- connection: Plates
55
- SELECT * FROM plates.templates;
56
- -- end
57
-
58
-
59
- -- name: getWellRoles
60
- -- connection: Plates
61
- SELECT pav.id, pav.value_string AS name
62
- FROM plates.property_allowed_values pav
63
- JOIN plates.properties p ON pav.property_id = p.id
64
- WHERE p.name = 'Well Role';
65
- -- end
66
-
67
-
68
- -- name: getWellValuesByBarcode
69
- -- connection: Plates
70
- -- input: string barcode
71
- select v.row, v.col, v.value_num, v.value_string, v.value_bool, v.property_id from plates.plate_well_values v
72
- join plates.plates p on v.plate_id = p.id
73
- where p.barcode = @barcode
74
- order by property_id, row, col
75
- -- end
76
-
77
-
78
- -- name: getWellValuesById
79
- -- connection: Plates
80
- -- input: int id
81
- select v.row, v.col, v.value_num, v.value_string, v.value_bool, v.property_id from plates.plate_well_values v
82
- join plates.plates p on v.plate_id = p.id
83
- where p.id = @id
84
- order by property_id, row, col
85
- -- end
86
-
87
-
88
- -- name: getAllowedValues
89
- -- connection: Plates
90
- -- input: string propertyName { choices: getPropertyNames() }
91
- SELECT pav.id, pav.value_string AS name
92
- FROM plates.property_allowed_values pav
93
- JOIN plates.properties p ON pav.property_id = p.id
94
- WHERE p.name = @propertyName;
95
- -- end
96
-
97
-
98
- -- name: getUniquePlatePropertyValues
99
- -- connection: Plates
100
- SELECT DISTINCT p.name, pd.value_string
101
- FROM plates.plate_details pd
102
- JOIN plates.properties p ON pd.property_id = p.id
103
- WHERE p.type = 'string';
104
- -- end
105
-
106
-
107
- -- name: getUniqueWellPropertyValues
108
- -- connection: Plates
109
- SELECT DISTINCT p.name, pwv.value_string
110
- FROM plates.plate_well_values pwv
111
- JOIN plates.properties p ON pwv.property_id = p.id
112
- WHERE p.type = 'string';
113
- -- end
114
-
115
-
116
- -- name: createProperty
117
- -- connection: Plates
118
- -- input: string propertyName
119
- -- input: string valueType
120
- -- output: int propertyId
121
- INSERT INTO plates.properties(name, type)
122
- VALUES(@propertyName, @valueType)
123
- RETURNING id;
124
- -- end
125
-
126
-
127
- -- name: createTemplate
128
- -- connection: Plates
129
- -- input: string name
130
- -- input: string description
131
- -- output: int templateId
132
- INSERT INTO plates.templates(name, description)
133
- VALUES(@name, @description)
134
- RETURNING id;
135
- -- end
136
-
137
- -- name: getTemplateWellProperties
138
- -- connection: Plates
139
- SELECT template_id, property_id
140
- FROM plates.template_well_properties
141
- -- end
142
-
143
-
144
- -- name: getTemplatePlateProperties
145
- -- connection: Plates
146
- SELECT template_id, property_id
147
- FROM plates.template_plate_properties
148
- -- end
package/src/fit/const.ts DELETED
@@ -1,73 +0,0 @@
1
- import {IFitSeries} from '@datagrok-libraries/statistics/src/fit/fit-curve';
2
-
3
- export class FitConstants {
4
- static TAG_FIT_CHART_FORMAT = '.fitChartFormat';
5
- static TAG_FIT_CHART_FORMAT_3DX = '3dx';
6
- static FIT_SEM_TYPE = 'fit';
7
- static FIT_CELL_TYPE = 'fit';
8
- static TAG_FIT = '.fit';
9
-
10
- static CELL_DEFAULT_WIDTH = 230;
11
- static CELL_DEFAULT_HEIGHT = 160;
12
- static MIN_CELL_RENDERER_PX_WIDTH = 10;
13
- static MIN_CELL_RENDERER_PX_HEIGHT = 5;
14
- static MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH = 70;
15
- static MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT = 45;
16
- static MIN_AXES_CELL_PX_WIDTH = 100;
17
- static MIN_AXES_CELL_PX_HEIGHT = 55;
18
- static MIN_TITLE_PX_WIDTH = 275;
19
- static MIN_TITLE_PX_HEIGHT = 225;
20
- static MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH = 180;
21
- static MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT = 140;
22
- static MIN_LEGEND_PX_WIDTH = 325;
23
- static MIN_LEGEND_PX_HEIGHT = 275;
24
- static MIN_DROPLINES_VISIBILITY_PX_WIDTH = 120;
25
- static MIN_DROPLINES_VISIBILITY_PX_HEIGHT = 110;
26
- static AXES_LEFT_PX_MARGIN = 38;
27
- static AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS = 45;
28
- static AXES_TOP_PX_MARGIN = 5;
29
- static AXES_TOP_PX_MARGIN_WITH_TITLE = 25;
30
- static AXES_RIGHT_PX_MARGIN = 18;
31
- static AXES_BOTTOM_PX_MARGIN = 15;
32
- static AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS = 30;
33
- static X_AXIS_LABEL_BOTTOM_PX_MARGIN = 4;
34
- static LEGEND_TOP_PX_MARGIN = 10;
35
-
36
- static OUTLIER_PX_SIZE = 12;
37
- static POINT_PX_SIZE = 4;
38
- static OUTLIER_HITBOX_RADIUS = 2;
39
- static CANDLESTICK_BORDER_PX_SIZE = 4;
40
- static CANDLESTICK_MEDIAN_PX_SIZE = 3.5;
41
- static CANDLESTICK_OUTLIER_PX_SIZE = 6;
42
- static INFLATE_SIZE = -12 / 2;
43
- static MIN_INFLATE_SIZE = -4 / 2;
44
- static LEGEND_RECORD_PX_HEIGHT = 18;
45
- static LEGEND_RECORD_LINE_PX_WIDTH = 20;
46
- static LEGEND_RECORD_LINE_RIGHT_PX_MARGIN = 5;
47
- static LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN = 4;
48
-
49
- static LINE_STYLES: {[key: string]: number[]} = {
50
- 'solid': [],
51
- 'dotted': [1, 1],
52
- 'dashed': [5, 5],
53
- 'dashdotted': [5, 5, 2, 5],
54
- };
55
-
56
- static CURVE_CONFIDENCE_INTERVAL_BOUNDS = {
57
- TOP: 'top',
58
- BOTTOM: 'bottom',
59
- };
60
-
61
- static CONFIDENCE_INTERVAL_STROKE_COLOR = 'rgba(255,191,63,0.4)';
62
- static CONFIDENCE_INTERVAL_FILL_COLOR = 'rgba(255,238,204,0.3)';
63
-
64
- static CONDITION_MAP: {[key: string]: ((series?: IFitSeries[]) => boolean)} = {
65
- 'No series to show': (series) => series === undefined || series?.length === 0,
66
- 'There were series with no points': (series) =>
67
- series!.some((series) => series.points?.length === 0),
68
- 'There were series with all x zeroes': (series) =>
69
- series!.some((series) => series.points?.every((point) => point.x === 0)),
70
- 'There were series with all y zeroes': (series) =>
71
- series!.some((series) => series.points?.every((point) => point.y === 0)),
72
- };
73
- }
@@ -1,112 +0,0 @@
1
- import * as DG from 'datagrok-api/dg';
2
- import * as ExcelJS from 'exceljs';
3
- import wu from 'wu';
4
- import {Plate} from "./plate";
5
- import {DataFrame} from "datagrok-api/dg";
6
-
7
- interface ExcelPlatePosition {
8
- sheet: ExcelJS.Worksheet;
9
- startRow: number;
10
- startCol: number;
11
- rows: number;
12
- cols: number;
13
- }
14
-
15
-
16
- /** Finds plate positions in the Excel workbook by iterating over sheets
17
- * and finding row/column label patterns such as (1-24, A-P). */
18
- export function findPlatePositions(workbook: ExcelJS.Workbook): ExcelPlatePosition[] {
19
- const results: ExcelPlatePosition[] = [];
20
- const ACharCode = 'A'.charCodeAt(0);
21
- workbook.eachSheet((worksheet) => {
22
- // TODO: Hack for current things, remove later
23
- if (worksheet.name?.toLowerCase() === 'desired outputs')
24
- return;
25
- // Create a grid representation of the worksheet
26
- const grid: any[][] = [];
27
- worksheet.eachRow((row, rowIndex) => {
28
- grid[rowIndex] = [];
29
- row.eachCell((cell, colIndex) => {
30
- grid[rowIndex][colIndex] = cell.value;
31
- });
32
- });
33
-
34
- // Find numeric column headers (1, 2, 3, ...)
35
- let headerRow = -1, startCol = -1, numColumns = 0;
36
- for (let i = 1; i < grid.length; i++) {
37
- const row = grid[i] || [];
38
- let numSequence = 0, seqStart = -1;
39
-
40
- for (let j = 1; j < row.length; j++) {
41
- if (typeof row[j] === 'number' && Number.isInteger(row[j]) && row[j] === numSequence + 1) {
42
- if (numSequence === 0) seqStart = j;
43
- numSequence++;
44
- }
45
- else if (numSequence > 0)
46
- break;
47
- }
48
-
49
- if (numSequence >= 12) { // Minimum 12 columns
50
- headerRow = i;
51
- startCol = seqStart;
52
- numColumns = numSequence;
53
- break;
54
- }
55
- }
56
-
57
- // Find alphabetic row headers (A, B, C, ...)
58
- let headerCol = -1, startRow = -1, numRows = 0;
59
- if (headerRow !== -1) {
60
- for (let j = 1; j < startCol; j++) {
61
- let letterSequence = 0, seqStart = -1;
62
-
63
- for (let i = headerRow + 1; i < grid.length; i++) {
64
- if (!grid[i]) continue;
65
- const val = grid[i][j];
66
-
67
- if (typeof val === 'string' && /^[A-Za-z]{1,2}$/.test(val)) {
68
- const prefix = letterSequence > 25 ? 'A' : '';
69
- const expected = prefix + String.fromCharCode(ACharCode + letterSequence % 26);
70
- if (val?.toLowerCase() === expected?.toLowerCase()) {
71
- if (letterSequence === 0) seqStart = i;
72
- letterSequence++;
73
- }
74
- else break;
75
- }
76
- else if (letterSequence > 0)
77
- break;
78
- }
79
-
80
- if (letterSequence >= 8) { // Minimum 8 rows
81
- headerCol = j;
82
- startRow = seqStart;
83
- numRows = letterSequence;
84
- break;
85
- }
86
- }
87
- }
88
-
89
- if (headerRow !== -1 && headerCol !== -1) {
90
- results.push({
91
- sheet: worksheet,
92
- startRow: headerRow,
93
- startCol: headerCol,
94
- rows: numRows,
95
- cols: numColumns
96
- });
97
- }
98
- });
99
-
100
- return results;
101
- }
102
-
103
-
104
- /** Constructs a plate from the specified position in the Excel sheet. */
105
- export function getPlateFromSheet(p: ExcelPlatePosition): Plate {
106
- const df = DataFrame.create(p.rows);
107
- for (let col = p.startCol + 1; col <= p.startCol + p.cols; col++) {
108
- const strings = DG.range(p.rows).map(i => p.sheet.getCell(p.startRow + i + 1, col).toString()).toArray();
109
- df.columns.add(DG.Column.fromStrings(`${col - p.startCol + 1}`, strings));
110
- }
111
- return Plate.fromGridDataFrame(df, p.sheet.name);
112
- }
@@ -1,50 +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
- import {PlateWidget} from './plate-widget';
5
- import {GridColumn, x} from 'datagrok-api/dg';
6
- import {Plate} from "./plate";
7
-
8
- export class PlateCellHandler extends DG.ObjectHandler {
9
- get type(): string { return 'Plate'; }
10
-
11
- isApplicable(x: any): boolean {
12
- return x instanceof DG.GridCell && x.cellType === 'Plate';
13
- }
14
-
15
- getGridCellRenderer(): DG.GridCellRenderer | null {
16
- return new PlateGridCellRenderer();
17
- }
18
- }
19
-
20
-
21
- @grok.decorators.cellRenderer({cellType: 'Plate', name: 'PlateGridCellRenderer'})
22
- export class PlateGridCellRenderer extends DG.GridCellRenderer {
23
- plateWidget = new PlateWidget();
24
-
25
- get name(): string { return 'Plate'; }
26
- get cellType(): string { return 'Plate'; }
27
-
28
- getDefaultSize(_gridColumn: GridColumn) { return {width: 240, height: 160}; }
29
-
30
- // eslint-disable-next-line max-len
31
- render(g: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, gridCell: DG.GridCell<DG.DataFrame | null>, _cellStyle: DG.GridCellStyle) {
32
- if (gridCell.value == null) {
33
- g.fillStyle = 'white';
34
- g.fillRect(x, y, w, h);
35
- return;
36
- }
37
- if (w < 35 || h < 35)
38
- return;
39
-
40
- this.plateWidget.plate = Plate.fromTableByRow(gridCell.value!);
41
- this.plateWidget.grid.props.colHeaderHeight = h > 120 ? 16 : 0;
42
- this.plateWidget.grid.props.showRowHeader = w > 100;
43
-
44
- this.plateWidget.grid.render(g, new DG.Rect(x, y, w, h).cutTop(Math.min(h / 20, 5)).cutRight(Math.min(w / 20, 5)));
45
- }
46
-
47
- onClick(gridCell: DG.GridCell, _e: MouseEvent) {
48
- grok.shell.o = PlateWidget.detailedView(Plate.fromTableByRow(gridCell.value!)).root;
49
- }
50
- }
@@ -1,262 +0,0 @@
1
- /* eslint-disable max-len */
2
- import {AnalysisOptions} from './plate-widget';
3
-
4
- import * as DG from 'datagrok-api/dg';
5
- import * as ui from 'datagrok-api/ui';
6
- import * as grok from 'datagrok-api/grok';
7
- import {mapFromRow} from './utils';
8
- import {IPlateWellFilter, Plate, randomizeTableId} from './plate';
9
- import {FIT_FUNCTION_4PL_REGRESSION, FIT_FUNCTION_SIGMOID, FitMarkerType, IFitPoint} from '@datagrok-libraries/statistics/src/fit/fit-curve';
10
- import {FitConstants} from '../fit/const';
11
- import {FitCellOutlierToggleArgs, setOutlier} from '../fit/fit-renderer';
12
- import {_package} from '../package';
13
- import {savePlate} from '../plates/plates-crud';
14
- import {PlateWidget} from './plate-widget';
15
-
16
-
17
- export class PlateDrcAnalysis {
18
- static analysisView(plate: Plate, options?: Partial<AnalysisOptions>): PlateWidget {
19
- const pw = PlateWidget.detailedView(plate);
20
- const gridRoot = pw.grid.root;
21
- const detailsRoot = pw.detailsDiv;
22
- pw.plateActionsDiv = ui.div();
23
- pw.plateDetailsDiv = ui.div();
24
- detailsRoot!.prepend(pw.plateDetailsDiv);
25
- detailsRoot!.append(pw.plateActionsDiv);
26
- const defaultOptions: AnalysisOptions = {
27
- roleName: 'layout', concentrationName: 'concentration', valueName: 'readout',
28
- normalize: true, controlColumns: ['High Control', 'Low Control'], autoFilterOutliers: true,
29
- categorizeFormula: '${rSquared} > 0.8 && ${Hill} > 0.25 && ${Max} > 80 && ${Max} < 120', statisticsColumns: ['Min', 'Max', 'rSquared', 'Hill', 'IC50', 'AUC'],
30
- };
31
-
32
- // system of aliases for the column names
33
- const aliases = {
34
- concentrationName: ['conc', 'dose', 'conc.', 'dilution', 'concentrations'],
35
- valueName: ['response', 'value', 'signal', 'raw data', 'raw signal', 'raw', 'response', 'values'],
36
- roleName: ['role', 'plate layout', 'plate positions', 'group', 'compound', 'well']
37
- };
38
- Object.entries(aliases).forEach(([key, value]) => {
39
- const colName = defaultOptions[key as keyof typeof defaultOptions] as string;
40
- if (plate.data.columns.contains(colName))
41
- return;
42
- const alias = value.find((v) => plate.data.columns.contains(v));
43
- if (alias)
44
- (defaultOptions[key as keyof typeof defaultOptions] as string) = alias;
45
- });
46
-
47
- // find control columns
48
- if (plate.data.columns.contains(defaultOptions.roleName) && !defaultOptions.controlColumns.every((cc) => plate.data.col(defaultOptions.roleName)!.categories.includes(cc))) {
49
- // if control columns are not provided, try to find them in the data
50
- const controlCols = plate.data.col(defaultOptions.roleName)!.categories.filter((cat) => cat.toLowerCase().includes('control'));
51
- // take maximum of 2 control columns
52
- defaultOptions.controlColumns = controlCols.slice(0, 2);
53
- }
54
-
55
- const actOptions: AnalysisOptions & {normalizedColName?: string} = {...defaultOptions, ...options};
56
-
57
- const statisticsAliases = {
58
- 'rSquared': ['rsquared', 'r2', 'r squared', 'r^2'],
59
- 'slope': ['slope', 'hill', 'steepness', 'hill slope'],
60
- 'bottom': ['bottom', 'min', 'minimum', 'miny', 'min y'],
61
- 'top': ['top', 'max', 'maximum', 'maxy', 'max y'],
62
- 'interceptX': ['interceptx', 'intercept x', 'ic50', 'ic 50', 'ic-50', 'ic_50', 'ic 50 value', 'ic50 value', 'ic50value', 'ec50', 'ec 50', 'ec-50', 'ec_50', 'ec 50 value', 'ec50 value', 'ec50value'],
63
- 'auc': ['auc', 'area under the curve', 'area under curve', 'area'],
64
- };
65
-
66
- const actualStatNames: Record<string, string> = {}; // will hold actual statistic name to its alias column name
67
- actOptions.statisticsColumns.forEach((stat) => {
68
- const alias = Object.entries(statisticsAliases).find(([_, aliases]) => aliases.includes(stat.toLowerCase()));
69
- if (alias)
70
- actualStatNames[alias[0]] = stat;
71
- });
72
-
73
-
74
- if (!gridRoot || !detailsRoot)
75
- return pw;
76
- // place them horizontally
77
- const container = ui.divH([gridRoot, detailsRoot]);
78
- pw.tabsContainer.appendChild(container);
79
- detailsRoot.style.flex = '0 0 min(250px, 25%)';
80
- gridRoot.style.flexGrow = '1';
81
- gridRoot.style.removeProperty('width');
82
-
83
- const drFilterOptions: IPlateWellFilter = {exclude: {[actOptions.roleName]: actOptions.controlColumns}};
84
- let normed = false;
85
- if (actOptions.normalize && actOptions.controlColumns.length === 2) {
86
- const [lStats, hStats] = actOptions.controlColumns.map((colName) => {
87
- return plate.getStatistics(actOptions.valueName, ['mean', 'std'], {match: {[actOptions.roleName]: colName}});
88
- }).sort((a, b) => a.mean - b.mean);
89
-
90
- defaultOptions.plateStatistics = {
91
- 'Z Prime': (_plate) => 1 - (3 * (hStats.std + lStats.std) / Math.abs(hStats.mean - lStats.mean)),
92
- 'Signal to background': (_plate) => hStats.mean / lStats.mean,
93
- };
94
- if (!actOptions.plateStatistics)
95
- actOptions.plateStatistics = defaultOptions.plateStatistics;
96
- actOptions.normalizedColName = plate.normalize(actOptions.valueName, (v) => (hStats.mean - v) / (hStats.mean - lStats.mean) * 100).name;
97
- normed = true;
98
- const plateStatMap: Record<string, string> = {};
99
- Object.entries(actOptions.plateStatistics).forEach(([statName, statFunc]) => {
100
- const value = statFunc(plate);
101
- plateStatMap[statName] = typeof value === 'number' ? DG.format(value, '#0.0000') : value;
102
- });
103
- const statTable = ui.tableFromMap(plateStatMap);
104
- pw.plateDetailsDiv!.appendChild(statTable);
105
- // mark outliers that go outside the bounds
106
-
107
- if (actOptions.autoFilterOutliers)
108
- plate.markOutliersWhere(actOptions.normalizedColName!, (v) => v > 106 || v < -6, drFilterOptions);
109
- }
110
-
111
- const series = plate.doseResponseSeries({...drFilterOptions, value: normed ? actOptions.normalizedColName! : actOptions.valueName, concentration: actOptions.concentrationName, groupBy: actOptions.roleName});
112
- const seriesVals = Object.entries(series);
113
- const minMax = normed ? {minY: -10, maxY: 110} : 0;
114
- const roleCol = DG.Column.string(actOptions.roleName, seriesVals.length);
115
- const curveCol = DG.Column.string('Curve', seriesVals.length);
116
- curveCol.init((i) => JSON.stringify(
117
- {
118
- 'chartOptions': {
119
- 'xAxisName': actOptions.concentrationName,
120
- 'yAxisName': normed ? `norm(${actOptions.valueName})` : actOptions.valueName,
121
- 'logX': true,
122
- 'title': `${seriesVals[i][0]}`,
123
- ...minMax
124
- },
125
- // TODO: change to 4PL regression once fixed for normed data
126
- 'series': [{...seriesVals[i][1], fit: undefined, fitFunction: FIT_FUNCTION_4PL_REGRESSION, clickToToggle: true, droplines: ['IC50'], name: seriesVals[i][0]}]
127
- }
128
-
129
- ));
130
- roleCol.init((i) => seriesVals[i][0]);
131
-
132
- const df = DG.DataFrame.fromColumns([roleCol, curveCol]);
133
- df.name = pw.plate.data.name;
134
- df.id = randomizeTableId();
135
-
136
- curveCol.semType ='fit';
137
- const curvesGrid = df.plot.grid();
138
-
139
- // add statistics columns
140
- Object.entries(actualStatNames).forEach(([statName, alias]) => {
141
- const params = {table: df, colName: curveCol.name, propName: statName, seriesNumber: 0};
142
- const col: DG.Column = ( DG.Func.find({name: 'addStatisticsColumn'})[0].prepare(params).callSync({processed: false})).getOutputParamValue();
143
- col.name = alias;
144
- });
145
- if (actualStatNames['interceptX'])
146
- df.col(actualStatNames['interceptX']) && (df.col(actualStatNames['interceptX'])!.meta.format = 'scientific');
147
-
148
- //categorize the curves
149
-
150
- const criteriaCol = df.columns.addNewString(df.columns.getUnusedName('Criteria'));
151
- criteriaCol.applyFormula(`if(${actOptions.categorizeFormula}, "Qualified", "Fails Criteria")`, DG.COLUMN_TYPE.STRING);
152
- criteriaCol.meta.colors.setCategorical({'Fails Criteria': 4294922560, 'Qualified': 4283477800});
153
-
154
- curvesGrid.root.style.width = '100%';
155
- pw.root.style.display = 'flex';
156
- pw.root.style.flexDirection = 'column';
157
- pw.root.style.height = '100%';
158
-
159
- pw.root.appendChild(curvesGrid.root);
160
-
161
- // when selecting a cell on plate, go to appropriate curve and mark the corresponding point with different marker
162
- // remember the previous change, so that we can revert it
163
- let prevSelection: {seriesIndex: number, pointIndex: number, markerType: FitMarkerType, markerSize: number, markerColor: string, curvesGridCell?: DG.GridCell} | null = null;
164
-
165
- pw.mapFromRowFunc = (row) => mapFromRow(row, (rowIdx, checkBoxState) => {
166
- plate._markOutlier(rowIdx, checkBoxState);
167
- if (prevSelection && prevSelection.curvesGridCell)
168
- setOutlier(prevSelection.curvesGridCell, {x: 0, y: 0, outlier: !checkBoxState}, 0, prevSelection.pointIndex);
169
- pw.grid.invalidate();
170
- });
171
-
172
- function clearPreviousSelection() {
173
- try {
174
- if (!prevSelection || (prevSelection.seriesIndex ?? -1) < 0)
175
- return;
176
-
177
- const series = curveCol.get(prevSelection.seriesIndex);
178
- if (!series)
179
- return;
180
- const parsed = JSON.parse(series);
181
- const points: IFitPoint[] = parsed.series[0]?.points;
182
- if (points && points.length && points.length > prevSelection.pointIndex) {
183
- points[prevSelection.pointIndex].marker = prevSelection.markerType;
184
- points[prevSelection.pointIndex].size = prevSelection.markerSize;
185
- points[prevSelection.pointIndex].color = prevSelection.markerColor;
186
- curveCol.set(prevSelection.seriesIndex, JSON.stringify(parsed));
187
- }
188
- } catch (e) {
189
- console.error(e);
190
- } finally {
191
- prevSelection = null;
192
- }
193
- }
194
-
195
- // highlight selected point in the curve
196
- pw.subs.push(pw.grid.onCurrentCellChanged.subscribe((gc) => {
197
- clearPreviousSelection();
198
- if (gc?.gridRow == null || gc?.gridRow == -1 || !gc?.gridColumn || gc?.gridColumn.idx == 0)
199
- return;
200
- const row = pw.plate._idx(gc.gridRow, gc.gridColumn.idx - 1);
201
- if (row == undefined || row < 0)
202
- return;
203
- const catValue = pw.plate.data.get(actOptions.roleName, row)?.toLowerCase();
204
- if (!catValue)
205
- return;
206
- const seriesIndex = seriesVals.findIndex(([serName, _]) => serName?.toLowerCase() === catValue);
207
- if (seriesIndex < 0)
208
- return;
209
- const conscentration: number = pw.plate.data.get(actOptions.concentrationName, row);
210
- const value: number = pw.plate.data.get(normed ? actOptions.normalizedColName! : actOptions.valueName, row);
211
-
212
- const pointInSeriesIndex: number = seriesVals[seriesIndex][1].points.findIndex((p) => p.x === conscentration && p.y === value);
213
- if (pointInSeriesIndex < 0)
214
- return;
215
-
216
- prevSelection = {seriesIndex, pointIndex: pointInSeriesIndex, markerType: seriesVals[seriesIndex][1].points[pointInSeriesIndex].marker ?? DG.MARKER_TYPE.CIRCLE,
217
- markerSize: seriesVals[seriesIndex][1].points[pointInSeriesIndex].size ?? FitConstants.POINT_PX_SIZE, markerColor: seriesVals[seriesIndex][1].points[pointInSeriesIndex].color ?? DG.Color.toHtml(DG.Color.getCategoricalColor(0))};
218
-
219
- const curveJSON = JSON.parse(curveCol.get(seriesIndex)!);
220
- const points: IFitPoint[] = curveJSON.series[0]?.points;
221
- if (points && points.length && points.length > pointInSeriesIndex) {
222
- points[pointInSeriesIndex].marker = DG.MARKER_TYPE.SQUARE;
223
- points[pointInSeriesIndex].size = FitConstants.POINT_PX_SIZE * 2;
224
- points[pointInSeriesIndex].color = DG.Color.toHtml(DG.Color.green);
225
- curveCol.set(seriesIndex, JSON.stringify(curveJSON));
226
- }
227
-
228
- // scroll in grid
229
- const curveGridRow = curvesGrid.tableRowToGrid(seriesIndex);
230
- prevSelection.curvesGridCell = curvesGrid.cell(curveCol.name, curveGridRow);
231
- prevSelection.curvesGridCell && curvesGrid.scrollToCell(curveCol.name, curveGridRow);
232
- }));
233
-
234
- // mark outliers in the original plate if it is switched from curve manually
235
-
236
- pw.subs.push(grok.events.onCustomEvent('fit-cell-outlier-toggle').subscribe((args: FitCellOutlierToggleArgs) => {
237
- if (!args || !args.gridCell || !args.series || args.pointIdx == null || args.gridCell.cell.column !== curveCol)
238
- return;
239
- const point: IFitPoint = args.series.points[args.pointIdx];
240
- if (point.meta !== null) {
241
- plate._markOutlier(point.meta, !!point.outlier);
242
- pw.grid.invalidate();
243
- }
244
- }));
245
-
246
-
247
- const s = DG.debounce(curvesGrid.onAfterDrawContent, 300).subscribe(() => {
248
- s.unsubscribe();
249
- curvesGrid.col(curveCol.name) && (curvesGrid.col(curveCol.name)!.width = 400);
250
- curvesGrid.props.rowHeight = 200;
251
- });
252
-
253
- if (actOptions.submitAction) {
254
- const btn = ui.button('Save to ELN', () => {
255
- savePlate(plate).then((_) => grok.shell.info('Plate saved'));
256
- //actOptions.submitAction!(plate, df);
257
- });
258
- pw.plateActionsDiv!.appendChild(btn);
259
- }
260
- return pw;
261
- }
262
- }
@@ -1,28 +0,0 @@
1
- import {Plate} from './plate';
2
- import {BmgPherastar96PlateReader} from './readers/bmg-pherastar-96';
3
- import {DelfiaEnvision96MaxRluPlateReader} from './readers/delfia-envision-96-max-rlu';
4
- import {SpectramaxPlateReader} from './readers/spectramax';
5
- import {DelfiaEnvisionByRowPlateReader} from './readers/delfia-envision-by-row';
6
-
7
- export interface IPlateReader {
8
- isApplicable(s: string): boolean;
9
- read(s: string): Plate;
10
- }
11
-
12
-
13
- export abstract class PlateReader {
14
- static readers: IPlateReader[] = [
15
- new DelfiaEnvision96MaxRluPlateReader(),
16
- new DelfiaEnvisionByRowPlateReader(),
17
- new BmgPherastar96PlateReader(),
18
- new SpectramaxPlateReader(),
19
- ];
20
-
21
- static getReader(s: string): IPlateReader | null {
22
- return this.readers.find((r) => r.isApplicable(s)) ?? null;
23
- }
24
-
25
- static read(s: string): Plate | null {
26
- return this.getReader(s)?.read(s) ?? null;
27
- }
28
- }