@datagrok/curves 1.6.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +39 -0
- package/.vscode/launch.json +10 -9
- package/.vscode/tasks.json +14 -0
- package/CHANGELOG.md +33 -0
- package/README.md +36 -8
- package/databases/plates/0000_init.sql +167 -0
- package/detectors.js +2 -2
- package/dist/package-test.js +15930 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +13750 -1
- package/dist/package.js.map +1 -1
- package/img/plate-dose-response-series.gif +0 -0
- package/img/plate-readers.gif +0 -0
- package/package.json +17 -11
- package/queries/plates-crud.sql +148 -0
- package/src/fit/const.ts +60 -59
- package/src/fit/data-to-curves.ts +220 -0
- package/src/fit/fit-demo.ts +6 -6
- package/src/fit/fit-grid-cell-handler.ts +94 -85
- package/src/fit/fit-renderer.ts +162 -98
- package/src/fit/multi-curve-viewer.ts +69 -28
- package/src/fit/render-utils.ts +346 -288
- package/src/package-api.ts +167 -0
- package/src/package-test.ts +7 -1
- package/src/package.g.ts +140 -2
- package/src/package.ts +221 -79
- package/src/plate/excel-plates.ts +112 -0
- package/src/plate/plate-cell-renderer.ts +48 -0
- package/src/plate/plate-drc-analysis.ts +262 -0
- package/src/plate/plate-reader.ts +28 -0
- package/src/plate/plate-well-validators.ts +41 -0
- package/src/plate/plate-widget.ts +242 -0
- package/src/plate/plate.ts +557 -0
- package/src/plate/plates-folder-preview.ts +63 -0
- package/src/plate/readers/bmg-pherastar-96.ts +42 -0
- package/src/plate/readers/delfia-envision-96-max-rlu.ts +16 -0
- package/src/plate/readers/delfia-envision-by-row.ts +18 -0
- package/src/plate/readers/spectramax.ts +42 -0
- package/src/plate/utils.ts +141 -0
- package/src/plates/numeric_matcher.ts +191 -0
- package/src/plates/objects/plate-template-handler.ts +48 -0
- package/src/plates/plates-app.ts +64 -0
- package/src/plates/plates-crud.ts +502 -0
- package/src/plates/plates-demo.ts +107 -0
- package/src/plates/plates.sql +169 -0
- package/src/plates/views/plates-create-view.ts +123 -0
- package/src/plates/views/plates-schema-view.ts +58 -0
- package/src/plates/views/plates-search-view.ts +137 -0
- package/src/plates/views/plates-templates-view.ts +38 -0
- package/src/tests/curves-cell-renderer-tests.ts +95 -75
- package/src/tests/detector-tests.ts +3 -2
- package/src/tests/fit-tests.ts +199 -163
- package/src/tests/plate-tests.ts +153 -0
- package/src/tests/transform-tests.ts +6 -6
- package/test-console-output-1.log +435 -0
- package/test-record-1.mp4 +0 -0
- package/tsconfig.json +1 -1
- package/src/fit/cell-render-viewer.ts +0 -54
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/curves",
|
|
3
3
|
"friendlyName": "Curves",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.9.0",
|
|
5
5
|
"description": "Curves provides support for fitted curves (such as dose-response curves), including in-grid rendering, storing charts in cells, interactivity, and automatic fitting.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Dmytro Kovalyov",
|
|
8
8
|
"email": "dkovalyov@datagrok.ai"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@datagrok-libraries/statistics": "^1.
|
|
12
|
-
"@datagrok-libraries/utils": "^4.
|
|
11
|
+
"@datagrok-libraries/statistics": "^1.7.0",
|
|
12
|
+
"@datagrok-libraries/utils": "^4.6.0",
|
|
13
13
|
"@types/wu": "^2.1.42",
|
|
14
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
15
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
14
16
|
"cash-dom": "^8.0.0",
|
|
15
|
-
"datagrok-api": "^1.
|
|
17
|
+
"datagrok-api": "^1.26.0",
|
|
16
18
|
"dayjs": "^1.11.7",
|
|
19
|
+
"eslint": "^8.1.0",
|
|
20
|
+
"eslint-config-google": "^0.14.0",
|
|
21
|
+
"exceljs": "^4.3.0",
|
|
22
|
+
"jstat": "^1.9.6",
|
|
17
23
|
"rxjs": "^6.5.5"
|
|
18
24
|
},
|
|
19
25
|
"devDependencies": {
|
|
20
|
-
"datagrok-tools": "latest",
|
|
21
26
|
"css-loader": "^5.0.0",
|
|
27
|
+
"datagrok-tools": "^4.14.20",
|
|
22
28
|
"source-map-loader": "^4.0.1",
|
|
23
29
|
"style-loader": "^2.0.0",
|
|
24
|
-
"ts-loader": "
|
|
25
|
-
"typescript": "
|
|
26
|
-
"webpack": "
|
|
27
|
-
"webpack-cli": "
|
|
30
|
+
"ts-loader": "^9.5.1",
|
|
31
|
+
"typescript": "^5.6.3",
|
|
32
|
+
"webpack": "^5.95.0",
|
|
33
|
+
"webpack-cli": "^5.1.4"
|
|
28
34
|
},
|
|
29
35
|
"scripts": {
|
|
30
36
|
"link-all": "npm link datagrok-api @datagrok-libraries/utils @datagrok-libraries/statistics",
|
|
31
37
|
"debug-curves": "webpack && grok publish",
|
|
32
38
|
"release-curves": "webpack && grok publish --release",
|
|
33
39
|
"build-curves": "webpack",
|
|
34
|
-
"build": "webpack",
|
|
40
|
+
"build": "grok api && grok check --soft && webpack",
|
|
35
41
|
"debug-curves-dev": "webpack && grok publish dev",
|
|
36
42
|
"release-curves-dev": "webpack && grok publish dev --release",
|
|
37
43
|
"debug-curves-public": "webpack && grok publish public",
|
|
@@ -41,7 +47,7 @@
|
|
|
41
47
|
"build-all": "npm --prefix ./../../js-api run build && npm --prefix ./../../libraries/utils run build && npm --prefix ./../../libraries/statistics run build && npm run build"
|
|
42
48
|
},
|
|
43
49
|
"canEdit": [
|
|
44
|
-
"
|
|
50
|
+
"Administrators"
|
|
45
51
|
],
|
|
46
52
|
"canView": [
|
|
47
53
|
"All users"
|
|
@@ -0,0 +1,148 @@
|
|
|
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
CHANGED
|
@@ -1,72 +1,73 @@
|
|
|
1
1
|
import {IFitSeries} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
2
2
|
|
|
3
3
|
export class FitConstants {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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;
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
static LINE_STYLES: {[key: string]: number[]} = {
|
|
50
|
+
'solid': [],
|
|
51
|
+
'dotted': [1, 1],
|
|
52
|
+
'dashed': [5, 5],
|
|
53
|
+
'dashdotted': [5, 5, 2, 5],
|
|
54
|
+
};
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
static CURVE_CONFIDENCE_INTERVAL_BOUNDS = {
|
|
57
|
+
TOP: 'top',
|
|
58
|
+
BOTTOM: 'bottom',
|
|
59
|
+
};
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
static CONFIDENCE_INTERVAL_STROKE_COLOR = 'rgba(255,191,63,0.4)';
|
|
62
|
+
static CONFIDENCE_INTERVAL_FILL_COLOR = 'rgba(255,238,204,0.3)';
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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) =>
|
|
66
67
|
series!.some((series) => series.points?.length === 0),
|
|
67
|
-
|
|
68
|
+
'There were series with all x zeroes': (series) =>
|
|
68
69
|
series!.some((series) => series.points?.every((point) => point.x === 0)),
|
|
69
|
-
|
|
70
|
+
'There were series with all y zeroes': (series) =>
|
|
70
71
|
series!.some((series) => series.points?.every((point) => point.y === 0)),
|
|
71
|
-
|
|
72
|
+
};
|
|
72
73
|
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
|
|
3
|
+
import {FIT_FUNCTION_4PL_REGRESSION, FitChartData, FitMarkerType, IFitSeries} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
4
|
+
import * as DG from 'datagrok-api/dg';
|
|
5
|
+
import * as grok from 'datagrok-api/grok';
|
|
6
|
+
import * as ui from 'datagrok-api/ui';
|
|
7
|
+
import wu from 'wu';
|
|
8
|
+
|
|
9
|
+
export function dataToCurvesUI() {
|
|
10
|
+
const tv = grok.shell.tv;
|
|
11
|
+
if (!tv || !tv.dataFrame) {
|
|
12
|
+
grok.shell.warning('No open tableview');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const df = tv.dataFrame;
|
|
17
|
+
|
|
18
|
+
const assayColInput = ui.input.column('Assay Column', {table: df, nullable: true, filter: (c) => c.isCategorical, tooltipText: 'Column with assay names'});
|
|
19
|
+
const concentrationColInput = ui.input.column('Concentration Column', {table: df, nullable: false, filter: (c) => c.isNumerical, tooltipText: 'Column with concentration values'});
|
|
20
|
+
const readoutColInput = ui.input.column('Readout Column', {table: df, nullable: false, filter: (c) => c.isNumerical, tooltipText: 'Column with readout values'});
|
|
21
|
+
const excludeOutliersInput = ui.input.column('Outliers Column', {table: df, nullable: true, filter: (c) => (c.isCategorical || c.type === DG.TYPE.BOOL) && c.categories.length === 2, tooltipText: 'Column with outliers to exclude from the analysis'});
|
|
22
|
+
const compoundIDColInput = ui.input.column('Compound ID Column', {table: df, nullable: true, tooltipText: 'Column with compound IDs'});
|
|
23
|
+
const batchIDColInput = ui.input.column('Batch ID Column', {table: df, nullable: false, tooltipText: 'Column with batch IDs. this column along with the Assay column will be used to group the data into curves'});
|
|
24
|
+
const runIDColInput = ui.input.column('Run ID Column', {table: df, nullable: true, tooltipText: 'Column with run IDs. this column along with the Assay column will be used to group the data into curves'});
|
|
25
|
+
|
|
26
|
+
assayColInput.value = wu(df.columns.categorical).find((c) => c.name.toLowerCase().includes('assay')) ?? null;
|
|
27
|
+
concentrationColInput.value = df.columns.firstWhere((c) => c.isNumerical && c.type !== DG.COLUMN_TYPE.DATE_TIME && c.name.toLowerCase().includes('concentration')) ?? null;
|
|
28
|
+
readoutColInput.value = df.columns.firstWhere((c) => c.isNumerical && c.type !== DG.COLUMN_TYPE.DATE_TIME && (c.name.toLowerCase().includes('inhibition'))) ?? null;
|
|
29
|
+
excludeOutliersInput.value = df.columns.firstWhere((c) => (c.isCategorical || c.type === DG.TYPE.BOOL) && c.categories.length === 2 && (c.name.toLowerCase().includes('outlier') || (c.name.toLowerCase().includes('include') && c.name.toLowerCase().includes('exclude')))) ?? null;
|
|
30
|
+
compoundIDColInput.value = df.columns.firstWhere((c) => c.isCategorical && c.name.toLowerCase().includes('compound') && c.name.toLowerCase().includes('id')) ?? null;
|
|
31
|
+
batchIDColInput.value = df.columns.firstWhere((c) => c.name.toLowerCase().includes('batch') && c.name.toLowerCase().includes('id')) ?? null;
|
|
32
|
+
runIDColInput.value = df.columns.firstWhere((c) => (c.name.toLowerCase().includes('run') || c.name.toLowerCase().includes('set')) && c.name.toLowerCase().includes('id')) ?? null;
|
|
33
|
+
|
|
34
|
+
const onOK = async () => {
|
|
35
|
+
if (!concentrationColInput.value || !readoutColInput.value || !batchIDColInput.value) {
|
|
36
|
+
grok.shell.warning('Please fill all required fields');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const resultObj: {[assay: string]: {[batchID: string]: {[runID: string]: {x: number[], y: number[], outliers: boolean[], compoundId: any}}}} = {};
|
|
41
|
+
|
|
42
|
+
const assayCol = assayColInput.value;
|
|
43
|
+
const concentrationCol = concentrationColInput.value!;
|
|
44
|
+
const readoutCol = readoutColInput.value!;
|
|
45
|
+
const excludeOutliersCol = excludeOutliersInput.value;
|
|
46
|
+
const compoundIDCol = compoundIDColInput.value;
|
|
47
|
+
const batchIDCol = batchIDColInput.value!;
|
|
48
|
+
const runIDCol = runIDColInput.value;
|
|
49
|
+
|
|
50
|
+
const getAssay = assayCol ? (row: number) => assayCol.get(row) : () => 'All';
|
|
51
|
+
const otlierIndexes = excludeOutliersCol ? excludeOutliersCol.getRawData() : null;
|
|
52
|
+
const isOutlier = excludeOutliersCol ? (excludeOutliersCol.type == DG.COLUMN_TYPE.BOOL ? (row: number) => !!otlierIndexes![row] : (row: number) => !otlierIndexes![row] ) : (_row: number) => false;
|
|
53
|
+
const getConcentration = (row: number) => concentrationCol.get(row);
|
|
54
|
+
const getReadout = (row: number) => readoutCol.get(row);
|
|
55
|
+
const getBatchID = (row: number) => batchIDCol.get(row);
|
|
56
|
+
const getCompoundID = compoundIDCol ? (row: number) => compoundIDCol.get(row) : () => null;
|
|
57
|
+
const getRunID = runIDCol ? (row: number) => runIDCol.get(row) : () => null;
|
|
58
|
+
const markerTypes: FitMarkerType[] = ['circle', 'triangle bottom', 'star', 'cross border', 'diamond', 'square', 'triangle left', 'triangle right', 'triangle top', 'asterisk'];
|
|
59
|
+
let markerTypeIndex = 0; // will keep track of the markers
|
|
60
|
+
const runIdToMarkerType: {[runID: string]: FitMarkerType} = {};
|
|
61
|
+
const getMarkerType = (runID: string) => {
|
|
62
|
+
if (runID in runIdToMarkerType) { return runIdToMarkerType[runID]; } else {
|
|
63
|
+
const markerType = markerTypes[markerTypeIndex];
|
|
64
|
+
runIdToMarkerType[runID] = markerType;
|
|
65
|
+
markerTypeIndex = (markerTypeIndex + 1) % markerTypes.length;
|
|
66
|
+
return markerType;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < df.rowCount; i++) {
|
|
71
|
+
const assay = getAssay(i);
|
|
72
|
+
const batchID = getBatchID(i);
|
|
73
|
+
|
|
74
|
+
const concentration = getConcentration(i);
|
|
75
|
+
const readout = getReadout(i);
|
|
76
|
+
const outlier = isOutlier(i);
|
|
77
|
+
if (!resultObj[assay])
|
|
78
|
+
resultObj[assay] = {};
|
|
79
|
+
|
|
80
|
+
const assayObj = resultObj[assay];
|
|
81
|
+
if (!assayObj[batchID])
|
|
82
|
+
assayObj[batchID] = {};
|
|
83
|
+
|
|
84
|
+
const assayBatchObj = assayObj[batchID];
|
|
85
|
+
// {x: [], y: [], outliers: [], compoundId: compoundID};
|
|
86
|
+
// use batchID as a key if runID is not provided
|
|
87
|
+
const runID = getRunID(i) ?? batchID;
|
|
88
|
+
if (!assayBatchObj[runID]) {
|
|
89
|
+
const compoundID = getCompoundID(i);
|
|
90
|
+
assayBatchObj[runID] = {x: [], y: [], outliers: [], compoundId: compoundID};
|
|
91
|
+
}
|
|
92
|
+
const assayBatchRunObj = assayBatchObj[runID];
|
|
93
|
+
assayBatchRunObj.x.push(concentration);
|
|
94
|
+
assayBatchRunObj.y.push(readout);
|
|
95
|
+
assayBatchRunObj.outliers.push(outlier);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// create fit series
|
|
99
|
+
|
|
100
|
+
const assays: string[] = [];
|
|
101
|
+
const batchIDs: string[] = [];
|
|
102
|
+
const compoundIDs: string[] = [];
|
|
103
|
+
const seriesData: Omit<FitChartData, 'seriesOptions'>[] = [];
|
|
104
|
+
|
|
105
|
+
for (const assay in resultObj) {
|
|
106
|
+
for (const batchID in resultObj[assay]) {
|
|
107
|
+
const assayBatchObj = resultObj[assay][batchID];
|
|
108
|
+
for (const runID in assayBatchObj) {
|
|
109
|
+
assays.push(assay);
|
|
110
|
+
batchIDs.push(batchID);
|
|
111
|
+
const compoundID = Object.values(assayBatchObj)[0]?.compoundId;
|
|
112
|
+
compoundIDs.push(compoundID);
|
|
113
|
+
const x = assayBatchObj[runID].x;
|
|
114
|
+
const y = assayBatchObj[runID].y;
|
|
115
|
+
const outliers = assayBatchObj[runID].outliers;
|
|
116
|
+
const markerType = getMarkerType(runID);
|
|
117
|
+
const s: IFitSeries = {
|
|
118
|
+
fit: undefined, fitFunction: FIT_FUNCTION_4PL_REGRESSION, clickToToggle: true, droplines: ['IC50'], name: `${runID}`,
|
|
119
|
+
points: x.map((xv, i) => ({x: xv, y: y[i], outlier: outliers[i], marker: markerType, size: 6})).sort((a, b) => a.x - b.x),
|
|
120
|
+
};
|
|
121
|
+
const fitData: Omit<FitChartData, 'seriesOptions'> = {
|
|
122
|
+
chartOptions: {
|
|
123
|
+
xAxisName: concentrationCol.name,
|
|
124
|
+
yAxisName: readoutCol.name,
|
|
125
|
+
logX: true,
|
|
126
|
+
title: `${assay} - ${batchID} - ${runID}`,
|
|
127
|
+
},
|
|
128
|
+
series: [s],
|
|
129
|
+
};
|
|
130
|
+
seriesData.push(fitData);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const assaysColumn = DG.Column.fromStrings('Assay', assays);
|
|
136
|
+
const batchIDsColumn = DG.Column.fromStrings('Batch ID', batchIDs);
|
|
137
|
+
const compoundIDsColumn = DG.Column.fromStrings('Compound ID', compoundIDs);
|
|
138
|
+
const seriesColumn = DG.Column.fromStrings('Series', seriesData.map((s) => JSON.stringify(s)));
|
|
139
|
+
const allResultsColumn = DG.Column.fromStrings('All Results', seriesData.map((s) => s.series[0]?.points.map((p) => `(${p.x}, ${p.y})`).join(', ')));
|
|
140
|
+
const runIdColumn = DG.Column.fromStrings('Run ID', seriesData.map((s) => s.series[0]!.name ?? ''));
|
|
141
|
+
seriesColumn.semType = 'fit';
|
|
142
|
+
seriesColumn.setTag('cell.renderer', 'fit');
|
|
143
|
+
|
|
144
|
+
const resDF = DG.DataFrame.fromColumns([seriesColumn, assaysColumn, batchIDsColumn, compoundIDsColumn, runIdColumn, allResultsColumn]);
|
|
145
|
+
resDF.name = 'Fitted Curves';
|
|
146
|
+
|
|
147
|
+
const actualStatNames = {
|
|
148
|
+
'interceptX': 'IC50',
|
|
149
|
+
'top': 'Max',
|
|
150
|
+
'bottom': 'Min',
|
|
151
|
+
'slope': 'Hill',
|
|
152
|
+
'auc': 'AUC',
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
Object.entries(actualStatNames).forEach(([statName, alias]) => {
|
|
156
|
+
const params = {table: resDF, colName: seriesColumn.name, propName: statName, seriesNumber: 0};
|
|
157
|
+
DG.Func.find({name: 'addStatisticsColumn'})[0].prepare(params).callSync({processed: false}).getOutputParamValue().name = alias;
|
|
158
|
+
});
|
|
159
|
+
if (actualStatNames['interceptX'])
|
|
160
|
+
resDF.col(actualStatNames['interceptX']) && (resDF.col(actualStatNames['interceptX'])!.meta.format = 'scientific');
|
|
161
|
+
|
|
162
|
+
return resDF;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
ui.dialog('Data to Curves')
|
|
166
|
+
.add(assayColInput)
|
|
167
|
+
.add(batchIDColInput)
|
|
168
|
+
.add(runIDColInput)
|
|
169
|
+
.add(concentrationColInput)
|
|
170
|
+
.add(readoutColInput)
|
|
171
|
+
.add(compoundIDColInput)
|
|
172
|
+
.add(excludeOutliersInput)
|
|
173
|
+
.onOK(async () => {
|
|
174
|
+
const df = await onOK();
|
|
175
|
+
if (df) {
|
|
176
|
+
const tv = grok.shell.addTableView(df);
|
|
177
|
+
const trellis = tv.trellisPlot({yColumnNames: ['Batch ID'], xColumnNames: [], viewerType: 'MultiCurveViewer',
|
|
178
|
+
showControlPanel: false, showXLabels: false, showYLabels: false, showXSelectors: false, showYSelectors: true, packCategories: true,
|
|
179
|
+
onClick: 'Select'
|
|
180
|
+
});
|
|
181
|
+
tv.dockManager.dock(trellis, DG.DOCK_TYPE.TOP, null, 'Fitted Curves', 0.5);
|
|
182
|
+
const selectionGrid = tv.addViewer(DG.VIEWER.GRID, {rowSource: 'Selected', selectedRowsColor: DG.Color.white});
|
|
183
|
+
tv.dockManager.dock(selectionGrid, DG.DOCK_TYPE.FILL, tv.dockManager.findNode(tv.grid.root), 'Selected Curves');
|
|
184
|
+
selectionGrid.props.title = 'Selected Curves';
|
|
185
|
+
tv.dockManager.dock(tv.grid, DG.DOCK_TYPE.FILL, tv.dockManager.findNode(selectionGrid.root));
|
|
186
|
+
tv.grid.props.title = 'Fitted Curves';
|
|
187
|
+
|
|
188
|
+
// add the pivot table
|
|
189
|
+
|
|
190
|
+
const pivot = tv.addViewer(DG.VIEWER.PIVOT_TABLE, {
|
|
191
|
+
rowSource: 'Selected', pivotColumnNames: [],
|
|
192
|
+
groupByColumnNames: ['Assay'], aggregateColumnNames: ['IC50', 'AUC', 'Hill', 'Min', 'Max'],
|
|
193
|
+
aggregateAggTypes: ['geomean', 'avg', 'geomean', 'avg', 'avg'], showHeader: false
|
|
194
|
+
});
|
|
195
|
+
pivot.props.title = 'Selected Statistics';
|
|
196
|
+
tv.dockManager.dock(pivot, DG.DOCK_TYPE.TOP, tv.dockManager.findNode(trellis.root), 'Selected Statistics', 0.1);
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
.show()
|
|
200
|
+
.history(() => {
|
|
201
|
+
const obj = {
|
|
202
|
+
assayCol: assayColInput.value?.name,
|
|
203
|
+
batchIDCol: batchIDColInput.value?.name,
|
|
204
|
+
concentrationCol: concentrationColInput.value?.name,
|
|
205
|
+
readoutCol: readoutColInput.value?.name,
|
|
206
|
+
compoundIDCol: compoundIDColInput.value?.name,
|
|
207
|
+
excludeOutliersCol: excludeOutliersInput.value?.name,
|
|
208
|
+
runIDCol: runIDColInput.value?.name,
|
|
209
|
+
};
|
|
210
|
+
return Object.fromEntries(Object.entries(obj).filter(([_, v]) => !!v));
|
|
211
|
+
}, (v) => {
|
|
212
|
+
assayColInput.value = v.assayCol ? df.columns.byName(v.assayCol) : null;
|
|
213
|
+
batchIDColInput.value = v.batchIDCol ? df.columns.byName(v.batchIDCol) : null;
|
|
214
|
+
concentrationColInput.value = df.columns.byName(v.concentrationCol);
|
|
215
|
+
readoutColInput.value = df.columns.byName(v.readoutCol);
|
|
216
|
+
compoundIDColInput.value = v.compoundIDCol ? df.columns.byName(v.compoundIDCol) : null;
|
|
217
|
+
excludeOutliersInput.value = v.excludeOutliersCol ? df.columns.byName(v.excludeOutliersCol) : null;
|
|
218
|
+
runIDColInput.value = v.runIDCol ? df.columns.byName(v.runIDCol) : null;
|
|
219
|
+
});
|
|
220
|
+
}
|
package/src/fit/fit-demo.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {_package} from '../package';
|
|
|
7
7
|
import {IFitChartData, sigmoid} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
8
8
|
|
|
9
9
|
import wu from 'wu';
|
|
10
|
-
import {FitConstants} from
|
|
10
|
+
import {FitConstants} from './const';
|
|
11
11
|
|
|
12
12
|
/** Returns random number from the interval */
|
|
13
13
|
function rnd(min: number, max: number): number {
|
|
@@ -36,9 +36,9 @@ export function createSigmoidPoints(length: number, step: number, pointsPerX: nu
|
|
|
36
36
|
// adding 20% noise
|
|
37
37
|
const range = (pointsPerX === 1 ? 0.2 : 0.4) * (Math.max(...y) - Math.min(...y));
|
|
38
38
|
const minY = Math.min(...y);
|
|
39
|
-
for (let i = 0; i < x.length; i++)
|
|
39
|
+
for (let i = 0; i < x.length; i++)
|
|
40
40
|
y[i] = -minY + y[i] + rnd(0, range);
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
|
|
43
43
|
return {x: x, y: y, params: params};
|
|
44
44
|
}
|
|
@@ -65,7 +65,7 @@ export function createDemoDataFrame(rowCount: number, chartsCount: number, chart
|
|
|
65
65
|
|
|
66
66
|
const jsonColumn = df.columns.addNewString(`json chart ${colIdx}`); // charts as json
|
|
67
67
|
jsonColumn.semType = FitConstants.FIT_SEM_TYPE;
|
|
68
|
-
|
|
68
|
+
const charts = colIdx % 2 === 0 ? chartsPerCell : 1;
|
|
69
69
|
|
|
70
70
|
for (let i = 0; i < rowCount; i++) {
|
|
71
71
|
const chartData: IFitChartData = {
|
|
@@ -81,7 +81,7 @@ export function createDemoDataFrame(rowCount: number, chartsCount: number, chart
|
|
|
81
81
|
|
|
82
82
|
for (let j = 0; j < charts; j++) {
|
|
83
83
|
const points = createSigmoidPoints(seriesLength, step, pointsPerX);
|
|
84
|
-
|
|
84
|
+
const color = DG.Color.toHtml(DG.Color.getCategoricalColor(colIdx * chartsPerCell + j));
|
|
85
85
|
chartData.series?.push({
|
|
86
86
|
parameters: undefined,
|
|
87
87
|
// TODO: make better parameter generating
|
|
@@ -105,6 +105,6 @@ export async function curveDemo(): Promise<void> {
|
|
|
105
105
|
grok.shell.windows.showContextPanel = true;
|
|
106
106
|
// const df = createDemoDataFrame(30, 5, 2);
|
|
107
107
|
const df = await grok.data.loadTable(`${_package.webRoot}files/curves-demo.csv`);
|
|
108
|
-
const
|
|
108
|
+
const _tableView = grok.shell.addTableView(df);
|
|
109
109
|
// tableView.addViewer('MultiCurveViewer');
|
|
110
110
|
}
|