@datagrok/curves 1.11.0 → 1.12.1
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 +11 -0
- package/CLAUDE.md +123 -103
- package/CREDITS.md +79 -0
- package/agents/package-knowledge.yaml +29 -0
- package/detectors.js +37 -0
- package/dist/package-test.js +1200 -109
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +674 -101
- package/dist/package.js.map +1 -1
- package/files/demo/Assay_Curves.csv +44 -0
- package/files/demo/Assay_Curves.layout +981 -0
- package/files/dose-response-4pl.pzfx +178 -0
- package/files/exponential-decay.pzfx +81 -0
- package/files/mixed-tables.pzfx +64 -0
- package/package.json +4 -4
- package/src/fit/converters/compact-dr-converter.ts +73 -0
- package/src/fit/converters/pzfx-converter.ts +13 -0
- package/src/fit/converters/xml-converter.ts +9 -0
- package/src/fit/curve-converter.ts +83 -0
- package/src/fit/data-to-curves.ts +1 -0
- package/src/fit/fit-demo.ts +14 -0
- package/src/fit/fit-grid-cell-handler.ts +7 -14
- package/src/fit/fit-inspection.ts +1 -1
- package/src/fit/fit-parser.ts +1 -1
- package/src/fit/fit-renderer.ts +8 -15
- package/src/formats/pzfx/pzfx-parser.ts +251 -0
- package/src/package-api.ts +36 -0
- package/src/package-test.ts +2 -0
- package/src/package.g.ts +49 -2
- package/src/package.ts +80 -9
- package/src/tests/converter-tests.ts +305 -0
- package/src/tests/detector-tests.ts +38 -0
- package/src/tests/pzfx-tests.ts +178 -0
- package/test-console-output-1.log +190 -30
- package/test-record-1.mp4 +0 -0
package/src/fit/fit-renderer.ts
CHANGED
|
@@ -20,8 +20,8 @@ import {
|
|
|
20
20
|
LogOptions, getDataPoints,
|
|
21
21
|
} from '@datagrok-libraries/statistics/src/fit/fit-data';
|
|
22
22
|
|
|
23
|
-
import {convertXMLToIFitChartData} from './fit-parser';
|
|
24
23
|
import {FitConstants} from '@datagrok-libraries/statistics/src/fit/const';
|
|
24
|
+
import {parseCellValue, isNativeFormat} from './curve-converter';
|
|
25
25
|
import {
|
|
26
26
|
renderAxesLabels,
|
|
27
27
|
renderConfidenceIntervals, renderConnectDots,
|
|
@@ -155,8 +155,7 @@ function getChartData(tableCell: DG.Cell): IFitChartData {
|
|
|
155
155
|
cellValue = cellValue.replaceAll('|', '');
|
|
156
156
|
const column = tableCell.column;
|
|
157
157
|
const cellChartData: IFitChartData = column ? (column.type === DG.TYPE.STRING ?
|
|
158
|
-
(column
|
|
159
|
-
convertXMLToIFitChartData(cellValue) : JSON.parse(cellValue ?? '{}') ?? {}) :
|
|
158
|
+
parseCellValue(cellValue, column) :
|
|
160
159
|
createDefaultChartData()) : JSON.parse(cellValue ?? '{}') ?? {};
|
|
161
160
|
|
|
162
161
|
const columnChartOptions = tableCell.column ? getColumnChartOptions(tableCell.column) : {};
|
|
@@ -260,8 +259,8 @@ export function substituteZeroes(data: IFitChartData): void {
|
|
|
260
259
|
|
|
261
260
|
export function setOutlier(gridCell: DG.GridCell, p: IFitPoint, seriesIdx: number, pointIdx: number, _data?: IFitChartData) {
|
|
262
261
|
p.outlier = !p.outlier;
|
|
263
|
-
//
|
|
264
|
-
if (gridCell.cell.column
|
|
262
|
+
// outlier toggling works only for native JSON format (no converter)
|
|
263
|
+
if (isNativeFormat(gridCell.cell.column)) {
|
|
265
264
|
const gridCellValue = JSON.parse(gridCell.cell.value) as IFitChartData;
|
|
266
265
|
gridCellValue.series![seriesIdx].points[pointIdx].outlier = p.outlier;
|
|
267
266
|
gridCell.cell.column.set(gridCell.cell.rowIndex, JSON.stringify(gridCellValue), true);
|
|
@@ -276,8 +275,7 @@ export function setOutlier(gridCell: DG.GridCell, p: IFitPoint, seriesIdx: numbe
|
|
|
276
275
|
}
|
|
277
276
|
const columns = gridCell.grid.dataFrame.columns.byTags({'.sourceColumn': gridCell.cell.column.name});
|
|
278
277
|
if (columns) {
|
|
279
|
-
_data ??= gridCell.cell
|
|
280
|
-
convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell);
|
|
278
|
+
_data ??= getOrCreateParsedChartData(gridCell.cell);
|
|
281
279
|
for (const column of columns) {
|
|
282
280
|
const chartLogOptions: LogOptions = {logX: _data.chartOptions?.logX, logY: _data.chartOptions?.logY};
|
|
283
281
|
const stats = column.tags['.seriesAggregation'] !== null ?
|
|
@@ -341,8 +339,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
341
339
|
if (!gridCell.cell.value || !gridCell.cell.column)
|
|
342
340
|
return;
|
|
343
341
|
|
|
344
|
-
const data = gridCell.cell
|
|
345
|
-
convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell, false);
|
|
342
|
+
const data = getOrCreateParsedChartData(gridCell.cell, false);
|
|
346
343
|
|
|
347
344
|
for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
|
|
348
345
|
if (condition(data.series)) {
|
|
@@ -496,8 +493,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
496
493
|
return;
|
|
497
494
|
|
|
498
495
|
const isRenderedOnGrid = gridCell?.grid && gridCell?.grid.dart && g.canvas === gridCell?.grid?.canvas; // only use cache for grid, because there is no guarantee that rowIdx will be correct for other places
|
|
499
|
-
const data = gridCell.cell
|
|
500
|
-
convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell, isRenderedOnGrid);
|
|
496
|
+
const data = getOrCreateParsedChartData(gridCell.cell, isRenderedOnGrid);
|
|
501
497
|
const screenBounds = FitChartCellRenderer.inflateScreenBounds(new DG.Rect(x, y, w, h));
|
|
502
498
|
|
|
503
499
|
for (const [_message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
|
|
@@ -538,10 +534,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
538
534
|
ui.tooltip.show(content, e.x, e.y);
|
|
539
535
|
}
|
|
540
536
|
|
|
541
|
-
|
|
542
|
-
const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
543
|
-
convertXMLToIFitChartData(gridCell.cell.value) :
|
|
544
|
-
getOrCreateParsedChartData(gridCell?.cell);
|
|
537
|
+
const data = getOrCreateParsedChartData(gridCell?.cell);
|
|
545
538
|
|
|
546
539
|
if (screenBounds.width >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH &&
|
|
547
540
|
screenBounds.height >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import * as DG from 'datagrok-api/dg';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
IFitChartData,
|
|
5
|
+
IFitChartOptions,
|
|
6
|
+
IFitSeries,
|
|
7
|
+
IFitPoint,
|
|
8
|
+
FIT_FUNCTION_SIGMOID,
|
|
9
|
+
} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const PZFX_NS = 'http://graphpad.com/prism/Prism.htm';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export interface PzfxSubcolumn {
|
|
16
|
+
values: (number | null)[];
|
|
17
|
+
excluded: boolean[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PzfxYColumn {
|
|
21
|
+
title: string;
|
|
22
|
+
subcolumns: PzfxSubcolumn[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PzfxTable {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
tableType: string;
|
|
29
|
+
xFormat: string;
|
|
30
|
+
xTitle: string;
|
|
31
|
+
xValues: (number | null)[];
|
|
32
|
+
yColumns: PzfxYColumn[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/** Returns child elements matching a local name, handling XML namespaces. */
|
|
37
|
+
function getChildren(parent: Element, localName: string): Element[] {
|
|
38
|
+
const results: Element[] = [];
|
|
39
|
+
for (let i = 0; i < parent.children.length; i++) {
|
|
40
|
+
const child = parent.children[i];
|
|
41
|
+
if (child.localName === localName)
|
|
42
|
+
results.push(child);
|
|
43
|
+
}
|
|
44
|
+
return results;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Returns the first child element matching a local name. */
|
|
48
|
+
function getChild(parent: Element, localName: string): Element | null {
|
|
49
|
+
for (let i = 0; i < parent.children.length; i++) {
|
|
50
|
+
if (parent.children[i].localName === localName)
|
|
51
|
+
return parent.children[i];
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Returns the text content of the first child element matching a local name. */
|
|
57
|
+
function getChildText(parent: Element, localName: string): string {
|
|
58
|
+
const el = getChild(parent, localName);
|
|
59
|
+
return el?.textContent?.trim() ?? '';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Parses `<d>` elements from a `<Subcolumn>` element. */
|
|
63
|
+
function parseSubcolumn(subcolEl: Element): PzfxSubcolumn {
|
|
64
|
+
const dElements = getChildren(subcolEl, 'd');
|
|
65
|
+
const values: (number | null)[] = [];
|
|
66
|
+
const excluded: boolean[] = [];
|
|
67
|
+
|
|
68
|
+
for (const d of dElements) {
|
|
69
|
+
const text = d.textContent?.trim() ?? '';
|
|
70
|
+
if (text === '') {
|
|
71
|
+
values.push(null);
|
|
72
|
+
excluded.push(false);
|
|
73
|
+
} else {
|
|
74
|
+
values.push(parseFloat(text));
|
|
75
|
+
excluded.push(d.getAttribute('Excluded') === '1');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {values, excluded};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Parses a `<YColumn>` element. */
|
|
83
|
+
function parseYColumn(yColEl: Element): PzfxYColumn {
|
|
84
|
+
const title = getChildText(yColEl, 'Title');
|
|
85
|
+
const subcolumns = getChildren(yColEl, 'Subcolumn').map(parseSubcolumn);
|
|
86
|
+
return {title, subcolumns};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Parses a `<Table>` or `<HugeTable>` element. */
|
|
90
|
+
function parseTable(tableEl: Element): PzfxTable {
|
|
91
|
+
const id = tableEl.getAttribute('ID') ?? '';
|
|
92
|
+
const tableType = tableEl.getAttribute('TableType') ?? '';
|
|
93
|
+
const xFormat = tableEl.getAttribute('XFormat') ?? '';
|
|
94
|
+
const title = getChildText(tableEl, 'Title');
|
|
95
|
+
|
|
96
|
+
let xTitle = '';
|
|
97
|
+
let xValues: (number | null)[] = [];
|
|
98
|
+
|
|
99
|
+
const xCol = getChild(tableEl, 'XColumn');
|
|
100
|
+
if (xCol) {
|
|
101
|
+
xTitle = getChildText(xCol, 'Title');
|
|
102
|
+
const xSubcol = getChild(xCol, 'Subcolumn');
|
|
103
|
+
if (xSubcol)
|
|
104
|
+
xValues = parseSubcolumn(xSubcol).values;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const yColumns = getChildren(tableEl, 'YColumn').map(parseYColumn);
|
|
108
|
+
|
|
109
|
+
return {id, title, tableType, xFormat, xTitle, xValues, yColumns};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
/** Parses a PZFX XML string and returns an array of tables.
|
|
114
|
+
* Truncates at the closing root tag to handle trailing binary data. */
|
|
115
|
+
export function parsePzfxXml(xmlText: string): PzfxTable[] {
|
|
116
|
+
const closingTag = '</GraphPadPrismFile>';
|
|
117
|
+
const closingIdx = xmlText.indexOf(closingTag);
|
|
118
|
+
if (closingIdx !== -1)
|
|
119
|
+
xmlText = xmlText.substring(0, closingIdx + closingTag.length);
|
|
120
|
+
|
|
121
|
+
const parser = new DOMParser();
|
|
122
|
+
const doc = parser.parseFromString(xmlText, 'text/xml');
|
|
123
|
+
|
|
124
|
+
const root = doc.documentElement;
|
|
125
|
+
if (root.nodeName === 'parsererror')
|
|
126
|
+
return [];
|
|
127
|
+
|
|
128
|
+
const tables: PzfxTable[] = [];
|
|
129
|
+
for (let i = 0; i < root.children.length; i++) {
|
|
130
|
+
const el = root.children[i];
|
|
131
|
+
if (el.localName === 'Table' || el.localName === 'HugeTable')
|
|
132
|
+
tables.push(parseTable(el));
|
|
133
|
+
}
|
|
134
|
+
return tables;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
/** Converts a PZFX XY table to an IFitChartData object.
|
|
139
|
+
* Returns null for non-XY tables or tables without numeric X data. */
|
|
140
|
+
export function pzfxTableToFitChartData(table: PzfxTable): IFitChartData | null {
|
|
141
|
+
if (table.tableType !== 'XY' || table.xValues.length === 0)
|
|
142
|
+
return null;
|
|
143
|
+
|
|
144
|
+
const series: IFitSeries[] = [];
|
|
145
|
+
|
|
146
|
+
for (const yCol of table.yColumns) {
|
|
147
|
+
const points: IFitPoint[] = [];
|
|
148
|
+
|
|
149
|
+
for (const subcol of yCol.subcolumns) {
|
|
150
|
+
for (let i = 0; i < table.xValues.length; i++) {
|
|
151
|
+
const x = table.xValues[i];
|
|
152
|
+
if (x == null || i >= subcol.values.length)
|
|
153
|
+
continue;
|
|
154
|
+
const y = subcol.values[i];
|
|
155
|
+
if (y == null)
|
|
156
|
+
continue;
|
|
157
|
+
points.push({
|
|
158
|
+
x,
|
|
159
|
+
y,
|
|
160
|
+
outlier: subcol.excluded[i] || false,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (points.length === 0)
|
|
166
|
+
continue;
|
|
167
|
+
|
|
168
|
+
series.push({
|
|
169
|
+
name: yCol.title,
|
|
170
|
+
fitFunction: FIT_FUNCTION_SIGMOID,
|
|
171
|
+
showFitLine: true,
|
|
172
|
+
showPoints: 'points',
|
|
173
|
+
clickToToggle: true,
|
|
174
|
+
droplines: ['IC50'],
|
|
175
|
+
points,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (series.length === 0)
|
|
180
|
+
return null;
|
|
181
|
+
|
|
182
|
+
const chartOptions: IFitChartOptions = {
|
|
183
|
+
logX: true,
|
|
184
|
+
xAxisName: table.xTitle || 'Concentration',
|
|
185
|
+
yAxisName: 'Response',
|
|
186
|
+
title: table.title,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return {chartOptions, series};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
/** Converts PZFX XY tables into a DataFrame with a fit column. Each row is one XY table. */
|
|
194
|
+
export function pzfxToFitDataFrame(tables: PzfxTable[]): DG.DataFrame {
|
|
195
|
+
const xyTables = tables.filter((t) => t.tableType === 'XY');
|
|
196
|
+
const names: string[] = [];
|
|
197
|
+
const curves: string[] = [];
|
|
198
|
+
|
|
199
|
+
for (const table of xyTables) {
|
|
200
|
+
const chartData = pzfxTableToFitChartData(table);
|
|
201
|
+
if (!chartData)
|
|
202
|
+
continue;
|
|
203
|
+
names.push(table.title || table.id);
|
|
204
|
+
curves.push(JSON.stringify(chartData));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const df = DG.DataFrame.create(names.length);
|
|
208
|
+
df.setTag(DG.Tags.Id, crypto.randomUUID());
|
|
209
|
+
df.name = 'PZFX Curves';
|
|
210
|
+
|
|
211
|
+
const nameCol = df.columns.addNewString('Table');
|
|
212
|
+
for (let i = 0; i < names.length; i++)
|
|
213
|
+
nameCol.set(i, names[i]);
|
|
214
|
+
|
|
215
|
+
const curveCol = df.columns.addNewString('Fitted Curve');
|
|
216
|
+
curveCol.semType = 'fit';
|
|
217
|
+
curveCol.meta.cellRenderer = 'fit';
|
|
218
|
+
for (let i = 0; i < curves.length; i++)
|
|
219
|
+
curveCol.set(i, curves[i]);
|
|
220
|
+
|
|
221
|
+
return df;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
/** Converts a non-XY PZFX table into a plain DataFrame. */
|
|
226
|
+
export function pzfxTableToDataFrame(table: PzfxTable): DG.DataFrame {
|
|
227
|
+
const maxRows = Math.max(...table.yColumns.map((yc) =>
|
|
228
|
+
Math.max(...yc.subcolumns.map((sc) => sc.values.length), 0)), 0);
|
|
229
|
+
|
|
230
|
+
const df = DG.DataFrame.create(maxRows);
|
|
231
|
+
df.setTag(DG.Tags.Id, crypto.randomUUID());
|
|
232
|
+
df.name = table.title || table.id;
|
|
233
|
+
|
|
234
|
+
for (const yCol of table.yColumns) {
|
|
235
|
+
if (yCol.subcolumns.length === 1) {
|
|
236
|
+
const col = df.columns.addNewFloat(yCol.title || 'Values');
|
|
237
|
+
const sc = yCol.subcolumns[0];
|
|
238
|
+
for (let i = 0; i < sc.values.length; i++)
|
|
239
|
+
col.set(i, sc.values[i] ?? DG.FLOAT_NULL);
|
|
240
|
+
} else {
|
|
241
|
+
for (let si = 0; si < yCol.subcolumns.length; si++) {
|
|
242
|
+
const col = df.columns.addNewFloat(`${yCol.title}_${si + 1}`);
|
|
243
|
+
const sc = yCol.subcolumns[si];
|
|
244
|
+
for (let i = 0; i < sc.values.length; i++)
|
|
245
|
+
col.set(i, sc.values[i] ?? DG.FLOAT_NULL);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return df;
|
|
251
|
+
}
|
package/src/package-api.ts
CHANGED
|
@@ -35,6 +35,13 @@ export namespace funcs {
|
|
|
35
35
|
return await grok.functions.call('Curves:CurveFitDemo', {});
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
Dashboard with curves for multiple compounds, assays and targets
|
|
40
|
+
*/
|
|
41
|
+
export async function assayCurveFitDemo(): Promise<void> {
|
|
42
|
+
return await grok.functions.call('Curves:AssayCurveFitDemo', {});
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
export async function initCurves(): Promise<void> {
|
|
39
46
|
return await grok.functions.call('Curves:InitCurves', {});
|
|
40
47
|
}
|
|
@@ -54,4 +61,33 @@ export namespace funcs {
|
|
|
54
61
|
export async function addAggrStatisticsColumn(table: DG.DataFrame , colName: string , propName: string , aggrType: string ): Promise<DG.Column> {
|
|
55
62
|
return await grok.functions.call('Curves:AddAggrStatisticsColumn', { table, colName, propName, aggrType });
|
|
56
63
|
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Returns XML 3DX curve converter function
|
|
67
|
+
*/
|
|
68
|
+
export async function convertXmlCurveToJsonFunc(): Promise<any> {
|
|
69
|
+
return await grok.functions.call('Curves:ConvertXmlCurveToJsonFunc', {});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
Returns compact dose-response JSON converter function
|
|
74
|
+
*/
|
|
75
|
+
export async function convertCompactDrToJsonFunc(): Promise<any> {
|
|
76
|
+
return await grok.functions.call('Curves:ConvertCompactDrToJsonFunc', {});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
Returns PZFX curve converter function
|
|
81
|
+
*/
|
|
82
|
+
export async function convertPzfxToJsonFunc(): Promise<any> {
|
|
83
|
+
return await grok.functions.call('Curves:ConvertPzfxToJsonFunc', {});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function previewPzfx(file: DG.FileInfo ): Promise<DG.View> {
|
|
87
|
+
return await grok.functions.call('Curves:PreviewPzfx', { file });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function pzfxFileHandler(bytes: any ): Promise<any> {
|
|
91
|
+
return await grok.functions.call('Curves:PzfxFileHandler', { bytes });
|
|
92
|
+
}
|
|
57
93
|
}
|
package/src/package-test.ts
CHANGED
|
@@ -3,9 +3,11 @@ import * as DG from 'datagrok-api/dg';
|
|
|
3
3
|
import {runTests, tests, TestContext, initAutoTests as initTests} from '@datagrok-libraries/test/src/test';
|
|
4
4
|
|
|
5
5
|
import './tests/detector-tests';
|
|
6
|
+
import './tests/converter-tests';
|
|
6
7
|
import './tests/curves-cell-renderer-tests';
|
|
7
8
|
import './tests/transform-tests';
|
|
8
9
|
import './tests/fit-tests';
|
|
10
|
+
import './tests/pzfx-tests';
|
|
9
11
|
|
|
10
12
|
export const _package = new DG.Package();
|
|
11
13
|
export {tests};
|
package/src/package.g.ts
CHANGED
|
@@ -30,9 +30,16 @@ export async function curveFitDemo() : Promise<void> {
|
|
|
30
30
|
await PackageFunctions.curveFitDemo();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
//name: Assay Curves
|
|
34
|
+
//description: Dashboard with curves for multiple compounds, assays and targets
|
|
35
|
+
//meta.demoPath: Curves | Assay Curves
|
|
36
|
+
export async function assayCurveFitDemo() : Promise<void> {
|
|
37
|
+
await PackageFunctions.assayCurveFitDemo();
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
//meta.role: init
|
|
34
|
-
export function _initCurves() : void {
|
|
35
|
-
PackageFunctions._initCurves();
|
|
41
|
+
export async function _initCurves() : Promise<void> {
|
|
42
|
+
await PackageFunctions._initCurves();
|
|
36
43
|
}
|
|
37
44
|
|
|
38
45
|
//input: dataframe df
|
|
@@ -86,3 +93,43 @@ export function addStatisticsColumn(table: DG.DataFrame, colName: string, propNa
|
|
|
86
93
|
export function addAggrStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, aggrType: string) : any {
|
|
87
94
|
return PackageFunctions.addAggrStatisticsColumn(table, colName, propName, aggrType);
|
|
88
95
|
}
|
|
96
|
+
|
|
97
|
+
//description: Returns XML 3DX curve converter function
|
|
98
|
+
//output: dynamic result
|
|
99
|
+
//meta.role: curveConverter
|
|
100
|
+
//meta.curveFormat: 3dx
|
|
101
|
+
export function convertXmlCurveToJsonFunc() : any {
|
|
102
|
+
return PackageFunctions.convertXmlCurveToJsonFunc();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//description: Returns compact dose-response JSON converter function
|
|
106
|
+
//output: dynamic result
|
|
107
|
+
//meta.role: curveConverter
|
|
108
|
+
//meta.curveFormat: compact-dr
|
|
109
|
+
export function convertCompactDrToJsonFunc() : any {
|
|
110
|
+
return PackageFunctions.convertCompactDrToJsonFunc();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//description: Returns PZFX curve converter function
|
|
114
|
+
//output: dynamic result
|
|
115
|
+
//meta.role: curveConverter
|
|
116
|
+
//meta.curveFormat: pzfx
|
|
117
|
+
export function convertPzfxToJsonFunc() : any {
|
|
118
|
+
return PackageFunctions.convertPzfxToJsonFunc();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//input: file file
|
|
122
|
+
//output: view result
|
|
123
|
+
//meta.role: fileViewer
|
|
124
|
+
//meta.fileViewer: pzfx
|
|
125
|
+
export async function previewPzfx(file: DG.FileInfo) : Promise<any> {
|
|
126
|
+
return await PackageFunctions.previewPzfx(file);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//input: list bytes
|
|
130
|
+
//output: list<dataframe> result
|
|
131
|
+
//meta.role: fileHandler
|
|
132
|
+
//meta.ext: pzfx
|
|
133
|
+
export function pzfxFileHandler(bytes: Uint8Array) : any {
|
|
134
|
+
return PackageFunctions.pzfxFileHandler(bytes);
|
|
135
|
+
}
|
package/src/package.ts
CHANGED
|
@@ -9,16 +9,19 @@ import * as ui from 'datagrok-api/ui';
|
|
|
9
9
|
|
|
10
10
|
import {FitGridCellHandler, calculateSeriesStats, getChartDataAggrStats} from './fit/fit-grid-cell-handler';
|
|
11
11
|
import {getOrCreateParsedChartData, substituteZeroes} from './fit/fit-renderer';
|
|
12
|
-
import {curveDemo} from './fit/fit-demo';
|
|
13
|
-
import {
|
|
12
|
+
import {assayCurvesDemo, curveDemo} from './fit/fit-demo';
|
|
13
|
+
import {convertXmlCurveToJson} from './fit/converters/xml-converter';
|
|
14
|
+
import {convertCompactDrToJson} from './fit/converters/compact-dr-converter';
|
|
15
|
+
import {convertPzfxToJson} from './fit/converters/pzfx-converter';
|
|
16
|
+
import {registerCurveConverter, initExternalConverters} from './fit/curve-converter';
|
|
14
17
|
import {LogOptions} from '@datagrok-libraries/statistics/src/fit/fit-data';
|
|
15
18
|
import {FitStatistics} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
16
|
-
import {FitConstants} from '@datagrok-libraries/statistics/src/fit/const';
|
|
17
19
|
|
|
18
20
|
// import {PlateWidget} from './plate/plate-widget';
|
|
19
21
|
|
|
20
22
|
import * as api from './package-api';
|
|
21
23
|
import {convertDataToCurves, dataToCurvesUI} from './fit/data-to-curves';
|
|
24
|
+
import {parsePzfxXml, pzfxTableToFitChartData, pzfxToFitDataFrame, pzfxTableToDataFrame} from './formats/pzfx/pzfx-parser';
|
|
22
25
|
|
|
23
26
|
export const _package = new DG.Package();
|
|
24
27
|
|
|
@@ -49,6 +52,15 @@ export class PackageFunctions {
|
|
|
49
52
|
await curveDemo();
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
@grok.decorators.demo({
|
|
56
|
+
name: 'Assay Curves',
|
|
57
|
+
description: 'Dashboard with curves for multiple compounds, assays and targets',
|
|
58
|
+
meta: {demoPath: 'Curves | Assay Curves'},
|
|
59
|
+
})
|
|
60
|
+
static async assayCurveFitDemo(): Promise<void> {
|
|
61
|
+
await assayCurvesDemo();
|
|
62
|
+
}
|
|
63
|
+
|
|
52
64
|
// @grok.decorators.func({
|
|
53
65
|
// name: 'Assay Plates',
|
|
54
66
|
// description: 'Assasy plates with concentration, layout and readout data',
|
|
@@ -60,8 +72,14 @@ export class PackageFunctions {
|
|
|
60
72
|
// }
|
|
61
73
|
|
|
62
74
|
@grok.decorators.init()
|
|
63
|
-
static _initCurves(): void {
|
|
75
|
+
static async _initCurves(): Promise<void> {
|
|
64
76
|
DG.ObjectHandler.register(new FitGridCellHandler());
|
|
77
|
+
// Register local converters by format name (avoids circular dependency with DG.Func.find)
|
|
78
|
+
registerCurveConverter('3dx', convertXmlCurveToJson);
|
|
79
|
+
registerCurveConverter('compact-dr', convertCompactDrToJson);
|
|
80
|
+
registerCurveConverter('pzfx', convertPzfxToJson);
|
|
81
|
+
// Discover converters from external packages (skips already-registered local ones)
|
|
82
|
+
await initExternalConverters();
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
@grok.decorators.func()
|
|
@@ -123,8 +141,7 @@ export class PackageFunctions {
|
|
|
123
141
|
const cell = df.cell(i, sourceColName);
|
|
124
142
|
if (!cell || !cell.value)
|
|
125
143
|
return null;
|
|
126
|
-
const chartData = cell
|
|
127
|
-
convertXMLToIFitChartData(cell.value) : getOrCreateParsedChartData(cell, true); // false because there is no dataframe
|
|
144
|
+
const chartData = getOrCreateParsedChartData(cell, true);
|
|
128
145
|
if (chartData.series![seriesNumber] === undefined || chartData.series![seriesNumber].points.every((p) => p.outlier))
|
|
129
146
|
return null;
|
|
130
147
|
if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
|
|
@@ -154,9 +171,7 @@ export class PackageFunctions {
|
|
|
154
171
|
const cell = df.cell(i, colName);
|
|
155
172
|
if (!cell || !cell.value)
|
|
156
173
|
return null;
|
|
157
|
-
const chartData =
|
|
158
|
-
cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
159
|
-
convertXMLToIFitChartData(cell.value) : getOrCreateParsedChartData(cell);
|
|
174
|
+
const chartData = getOrCreateParsedChartData(cell);
|
|
160
175
|
if (chartData.series?.every((series) => series.points.every((p) => p.outlier)))
|
|
161
176
|
return null;
|
|
162
177
|
if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
|
|
@@ -168,4 +183,60 @@ export class PackageFunctions {
|
|
|
168
183
|
df.columns.insert(column, df.columns.names().indexOf(colName) + 1);
|
|
169
184
|
return column;
|
|
170
185
|
}
|
|
186
|
+
|
|
187
|
+
@grok.decorators.func({description: 'Returns XML 3DX curve converter function', meta: {role: 'curveConverter', curveFormat: '3dx'}})
|
|
188
|
+
static convertXmlCurveToJsonFunc(): (value: string) => string {
|
|
189
|
+
return convertXmlCurveToJson;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@grok.decorators.func({description: 'Returns compact dose-response JSON converter function', meta: {role: 'curveConverter', curveFormat: 'compact-dr'}})
|
|
193
|
+
static convertCompactDrToJsonFunc(): (value: string) => string {
|
|
194
|
+
return convertCompactDrToJson;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@grok.decorators.func({description: 'Returns PZFX curve converter function', meta: {role: 'curveConverter', curveFormat: 'pzfx'}})
|
|
198
|
+
static convertPzfxToJsonFunc(): (value: string) => string {
|
|
199
|
+
return convertPzfxToJson;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@grok.decorators.fileViewer({fileViewer: 'pzfx'})
|
|
203
|
+
static async previewPzfx(file: DG.FileInfo): Promise<DG.View> {
|
|
204
|
+
const view = DG.View.create();
|
|
205
|
+
view.name = file.name;
|
|
206
|
+
|
|
207
|
+
const text = await file.readAsString();
|
|
208
|
+
const tables = parsePzfxXml(text);
|
|
209
|
+
const xyTables = tables.filter((t) => t.tableType === 'XY');
|
|
210
|
+
|
|
211
|
+
if (xyTables.length === 0) {
|
|
212
|
+
const nonXyDfs = tables.map(pzfxTableToDataFrame);
|
|
213
|
+
for (const df of nonXyDfs)
|
|
214
|
+
view.append(DG.Viewer.grid(df).root);
|
|
215
|
+
return view;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const df = pzfxToFitDataFrame(xyTables);
|
|
219
|
+
const grid = DG.Viewer.grid(df);
|
|
220
|
+
grid.root.style.width = '100%';
|
|
221
|
+
grid.root.style.height = '100%';
|
|
222
|
+
view.append(grid.root);
|
|
223
|
+
|
|
224
|
+
return view;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@grok.decorators.fileHandler({ext: 'pzfx'})
|
|
228
|
+
static pzfxFileHandler(@grok.decorators.param({type: 'list'}) bytes: Uint8Array): DG.DataFrame[] {
|
|
229
|
+
const text = new TextDecoder().decode(new Uint8Array(bytes));
|
|
230
|
+
const tables = parsePzfxXml(text);
|
|
231
|
+
const results: DG.DataFrame[] = [];
|
|
232
|
+
|
|
233
|
+
const xyTables = tables.filter((t) => t.tableType === 'XY');
|
|
234
|
+
if (xyTables.length > 0)
|
|
235
|
+
results.push(pzfxToFitDataFrame(xyTables));
|
|
236
|
+
|
|
237
|
+
for (const table of tables.filter((t) => t.tableType !== 'XY'))
|
|
238
|
+
results.push(pzfxTableToDataFrame(table));
|
|
239
|
+
|
|
240
|
+
return results;
|
|
241
|
+
}
|
|
171
242
|
}
|