@datagrok/curves 1.10.15 → 1.12.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/CHANGELOG.md +11 -1
- package/CLAUDE.md +265 -0
- package/detectors.js +39 -2
- package/dist/package-test.js +1719 -572
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +778 -237
- package/dist/package.js.map +1 -1
- 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 +8 -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 +1 -0
- package/src/fit/fit-grid-cell-handler.ts +10 -16
- package/src/fit/fit-inspection.ts +1 -1
- package/src/fit/fit-parser.ts +1 -1
- package/src/fit/fit-renderer.ts +13 -17
- package/src/formats/pzfx/pzfx-parser.ts +251 -0
- package/src/package-api.ts +27 -2
- package/src/package-test.ts +3 -1
- package/src/package.g.ts +47 -7
- package/src/package.ts +72 -15
- package/src/tests/converter-tests.ts +305 -0
- package/src/tests/curves-cell-renderer-tests.ts +1 -1
- package/src/tests/detector-tests.ts +39 -1
- package/src/tests/fit-tests.ts +1 -1
- package/src/tests/pzfx-tests.ts +178 -0
- package/src/tests/transform-tests.ts +1 -1
- package/test-console-output-1.log +152 -169
- 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 ?
|
|
@@ -305,6 +303,7 @@ export function inspectCurve(gridCell: DG.GridCell, size?: Partial<DG.Size>, rer
|
|
|
305
303
|
const dlg = ui.dialog({title: 'Edit chart'})
|
|
306
304
|
.add(gridCellWidget.root)
|
|
307
305
|
.show({resizable: true, width: size?.width ?? 500, height: size?.height ?? 430});
|
|
306
|
+
dlg.getButton('CANCEL').textContent = 'Close';
|
|
308
307
|
if (rerenderOnChange)
|
|
309
308
|
dlg.sub(merge(gridCell.grid.dataFrame.onDataChanged, gridCell.grid.dataFrame.onMetadataChanged).subscribe(() => gridCellWidget.render()));
|
|
310
309
|
}
|
|
@@ -337,11 +336,10 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
337
336
|
}
|
|
338
337
|
|
|
339
338
|
onClick(gridCell: DG.GridCell, e: MouseEvent): void {
|
|
340
|
-
if (!gridCell.cell.value)
|
|
339
|
+
if (!gridCell.cell.value || !gridCell.cell.column)
|
|
341
340
|
return;
|
|
342
341
|
|
|
343
|
-
const data = gridCell.cell
|
|
344
|
-
convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell, false);
|
|
342
|
+
const data = getOrCreateParsedChartData(gridCell.cell, false);
|
|
345
343
|
|
|
346
344
|
for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
|
|
347
345
|
if (condition(data.series)) {
|
|
@@ -375,7 +373,9 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
375
373
|
}
|
|
376
374
|
|
|
377
375
|
onDoubleClick(gridCell: DG.GridCell, _e: MouseEvent): void {
|
|
378
|
-
inspectCurve(gridCell);
|
|
376
|
+
inspectCurve(gridCell, undefined, true);
|
|
377
|
+
_e.preventDefault();
|
|
378
|
+
_e.stopPropagation();
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
areAxesShown(screenBounds: DG.Rect): boolean {
|
|
@@ -493,8 +493,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
493
493
|
return;
|
|
494
494
|
|
|
495
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
|
|
496
|
-
const data = gridCell.cell
|
|
497
|
-
convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell, isRenderedOnGrid);
|
|
496
|
+
const data = getOrCreateParsedChartData(gridCell.cell, isRenderedOnGrid);
|
|
498
497
|
const screenBounds = FitChartCellRenderer.inflateScreenBounds(new DG.Rect(x, y, w, h));
|
|
499
498
|
|
|
500
499
|
for (const [_message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
|
|
@@ -535,10 +534,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
535
534
|
ui.tooltip.show(content, e.x, e.y);
|
|
536
535
|
}
|
|
537
536
|
|
|
538
|
-
|
|
539
|
-
const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
540
|
-
convertXMLToIFitChartData(gridCell.cell.value) :
|
|
541
|
-
getOrCreateParsedChartData(gridCell?.cell);
|
|
537
|
+
const data = getOrCreateParsedChartData(gridCell?.cell);
|
|
542
538
|
|
|
543
539
|
if (screenBounds.width >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH &&
|
|
544
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
|
@@ -55,7 +55,32 @@ export namespace funcs {
|
|
|
55
55
|
return await grok.functions.call('Curves:AddAggrStatisticsColumn', { table, colName, propName, aggrType });
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
/**
|
|
59
|
+
Returns XML 3DX curve converter function
|
|
60
|
+
*/
|
|
61
|
+
export async function convertXmlCurveToJsonFunc(): Promise<any> {
|
|
62
|
+
return await grok.functions.call('Curves:ConvertXmlCurveToJsonFunc', {});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Returns compact dose-response JSON converter function
|
|
67
|
+
*/
|
|
68
|
+
export async function convertCompactDrToJsonFunc(): Promise<any> {
|
|
69
|
+
return await grok.functions.call('Curves:ConvertCompactDrToJsonFunc', {});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
Returns PZFX curve converter function
|
|
74
|
+
*/
|
|
75
|
+
export async function convertPzfxToJsonFunc(): Promise<any> {
|
|
76
|
+
return await grok.functions.call('Curves:ConvertPzfxToJsonFunc', {});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function previewPzfx(file: DG.FileInfo ): Promise<DG.View> {
|
|
80
|
+
return await grok.functions.call('Curves:PreviewPzfx', { file });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function pzfxFileHandler(bytes: any ): Promise<any> {
|
|
84
|
+
return await grok.functions.call('Curves:PzfxFileHandler', { bytes });
|
|
60
85
|
}
|
|
61
86
|
}
|
package/src/package-test.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as DG from 'datagrok-api/dg';
|
|
2
2
|
|
|
3
|
-
import {runTests, tests, TestContext, initAutoTests as initTests} from '@datagrok-libraries/
|
|
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
|
@@ -3,8 +3,8 @@ import {MultiCurveViewer} from './fit/multi-curve-viewer';
|
|
|
3
3
|
import {FitChartCellRenderer} from './fit/fit-renderer';
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
5
|
//name: Fit
|
|
6
|
-
//tags: cellRenderer
|
|
7
6
|
//output: grid_cell_renderer renderer
|
|
7
|
+
//meta.role: cellRenderer
|
|
8
8
|
//meta.cellType: fit
|
|
9
9
|
//meta.virtual: true
|
|
10
10
|
export function _FitChartCellRenderer() {
|
|
@@ -13,8 +13,8 @@ export function _FitChartCellRenderer() {
|
|
|
13
13
|
|
|
14
14
|
//name: MultiCurveViewer
|
|
15
15
|
//description: A viewer that superimposes multiple in-cell curves on one chart
|
|
16
|
-
//tags: viewer
|
|
17
16
|
//output: viewer result
|
|
17
|
+
//meta.role: viewer
|
|
18
18
|
//meta.icon: icons/multi-curve-viewer.png
|
|
19
19
|
//meta.trellisable: true
|
|
20
20
|
export function _MultiCurveViewer() {
|
|
@@ -30,9 +30,9 @@ export async function curveFitDemo() : Promise<void> {
|
|
|
30
30
|
await PackageFunctions.curveFitDemo();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
//
|
|
34
|
-
export function _initCurves() : void {
|
|
35
|
-
PackageFunctions._initCurves();
|
|
33
|
+
//meta.role: init
|
|
34
|
+
export async function _initCurves() : Promise<void> {
|
|
35
|
+
await PackageFunctions._initCurves();
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
//input: dataframe df
|
|
@@ -65,24 +65,64 @@ export async function dataToCurvesTopMenu() {
|
|
|
65
65
|
return await PackageFunctions.dataToCurvesTopMenu();
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
//tags: Transform
|
|
69
68
|
//input: dataframe table
|
|
70
69
|
//input: string colName
|
|
71
70
|
//input: string propName
|
|
72
71
|
//input: int seriesNumber
|
|
73
72
|
//output: column result
|
|
74
73
|
//meta.vectorFunc: true
|
|
74
|
+
//meta.role: transform
|
|
75
75
|
export function addStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, seriesNumber: number) : any {
|
|
76
76
|
return PackageFunctions.addStatisticsColumn(table, colName, propName, seriesNumber);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
//tags: Transform
|
|
80
79
|
//input: dataframe table
|
|
81
80
|
//input: string colName
|
|
82
81
|
//input: string propName
|
|
83
82
|
//input: string aggrType
|
|
84
83
|
//output: column result
|
|
85
84
|
//meta.vectorFunc: true
|
|
85
|
+
//meta.role: transform
|
|
86
86
|
export function addAggrStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, aggrType: string) : any {
|
|
87
87
|
return PackageFunctions.addAggrStatisticsColumn(table, colName, propName, aggrType);
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
//description: Returns XML 3DX curve converter function
|
|
91
|
+
//output: dynamic result
|
|
92
|
+
//meta.role: curveConverter
|
|
93
|
+
//meta.curveFormat: 3dx
|
|
94
|
+
export function convertXmlCurveToJsonFunc() : any {
|
|
95
|
+
return PackageFunctions.convertXmlCurveToJsonFunc();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//description: Returns compact dose-response JSON converter function
|
|
99
|
+
//output: dynamic result
|
|
100
|
+
//meta.role: curveConverter
|
|
101
|
+
//meta.curveFormat: compact-dr
|
|
102
|
+
export function convertCompactDrToJsonFunc() : any {
|
|
103
|
+
return PackageFunctions.convertCompactDrToJsonFunc();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//description: Returns PZFX curve converter function
|
|
107
|
+
//output: dynamic result
|
|
108
|
+
//meta.role: curveConverter
|
|
109
|
+
//meta.curveFormat: pzfx
|
|
110
|
+
export function convertPzfxToJsonFunc() : any {
|
|
111
|
+
return PackageFunctions.convertPzfxToJsonFunc();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//input: file file
|
|
115
|
+
//output: view result
|
|
116
|
+
//meta.role: fileViewer
|
|
117
|
+
//meta.fileViewer: pzfx
|
|
118
|
+
export async function previewPzfx(file: DG.FileInfo) : Promise<any> {
|
|
119
|
+
return await PackageFunctions.previewPzfx(file);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//input: list bytes
|
|
123
|
+
//output: list<dataframe> result
|
|
124
|
+
//meta.role: fileHandler
|
|
125
|
+
//meta.ext: pzfx
|
|
126
|
+
export function pzfxFileHandler(bytes: Uint8Array) : any {
|
|
127
|
+
return PackageFunctions.pzfxFileHandler(bytes);
|
|
128
|
+
}
|
package/src/package.ts
CHANGED
|
@@ -10,24 +10,22 @@ import * as ui from 'datagrok-api/ui';
|
|
|
10
10
|
import {FitGridCellHandler, calculateSeriesStats, getChartDataAggrStats} from './fit/fit-grid-cell-handler';
|
|
11
11
|
import {getOrCreateParsedChartData, substituteZeroes} from './fit/fit-renderer';
|
|
12
12
|
import {curveDemo} from './fit/fit-demo';
|
|
13
|
-
import {
|
|
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
|
|
|
25
28
|
|
|
26
|
-
// //tags: autostart
|
|
27
|
-
// export async function autostart(): Promise<void> {
|
|
28
|
-
// }
|
|
29
|
-
|
|
30
|
-
|
|
31
29
|
const SOURCE_COLUMN_TAG = '.sourceColumn';
|
|
32
30
|
const SERIES_NUMBER_TAG = '.seriesNumber';
|
|
33
31
|
const SERIES_AGGREGATION_TAG = '.seriesAggregation';
|
|
@@ -65,8 +63,14 @@ export class PackageFunctions {
|
|
|
65
63
|
// }
|
|
66
64
|
|
|
67
65
|
@grok.decorators.init()
|
|
68
|
-
static _initCurves(): void {
|
|
66
|
+
static async _initCurves(): Promise<void> {
|
|
69
67
|
DG.ObjectHandler.register(new FitGridCellHandler());
|
|
68
|
+
// Register local converters by format name (avoids circular dependency with DG.Func.find)
|
|
69
|
+
registerCurveConverter('3dx', convertXmlCurveToJson);
|
|
70
|
+
registerCurveConverter('compact-dr', convertCompactDrToJson);
|
|
71
|
+
registerCurveConverter('pzfx', convertPzfxToJson);
|
|
72
|
+
// Discover converters from external packages (skips already-registered local ones)
|
|
73
|
+
await initExternalConverters();
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
@grok.decorators.func()
|
|
@@ -108,7 +112,7 @@ export class PackageFunctions {
|
|
|
108
112
|
dataToCurvesUI();
|
|
109
113
|
}
|
|
110
114
|
|
|
111
|
-
@grok.decorators.func({meta: {vectorFunc: 'true'
|
|
115
|
+
@grok.decorators.func({meta: {vectorFunc: 'true', role: 'transform'}})
|
|
112
116
|
static addStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, @grok.decorators.param({type: 'int'}) seriesNumber: number): DG.Column {
|
|
113
117
|
const df = table;
|
|
114
118
|
const col = df.col(colName)!;
|
|
@@ -128,8 +132,7 @@ export class PackageFunctions {
|
|
|
128
132
|
const cell = df.cell(i, sourceColName);
|
|
129
133
|
if (!cell || !cell.value)
|
|
130
134
|
return null;
|
|
131
|
-
const chartData = cell
|
|
132
|
-
convertXMLToIFitChartData(cell.value) : getOrCreateParsedChartData(cell, true); // false because there is no dataframe
|
|
135
|
+
const chartData = getOrCreateParsedChartData(cell, true);
|
|
133
136
|
if (chartData.series![seriesNumber] === undefined || chartData.series![seriesNumber].points.every((p) => p.outlier))
|
|
134
137
|
return null;
|
|
135
138
|
if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
|
|
@@ -144,7 +147,7 @@ export class PackageFunctions {
|
|
|
144
147
|
return column;
|
|
145
148
|
}
|
|
146
149
|
|
|
147
|
-
@grok.decorators.func({meta: {vectorFunc: 'true'
|
|
150
|
+
@grok.decorators.func({meta: {vectorFunc: 'true', role: 'transform'}})
|
|
148
151
|
static addAggrStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, aggrType: string): DG.Column {
|
|
149
152
|
const df = table;
|
|
150
153
|
const col = df.col(colName)!;
|
|
@@ -159,9 +162,7 @@ export class PackageFunctions {
|
|
|
159
162
|
const cell = df.cell(i, colName);
|
|
160
163
|
if (!cell || !cell.value)
|
|
161
164
|
return null;
|
|
162
|
-
const chartData =
|
|
163
|
-
cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
164
|
-
convertXMLToIFitChartData(cell.value) : getOrCreateParsedChartData(cell);
|
|
165
|
+
const chartData = getOrCreateParsedChartData(cell);
|
|
165
166
|
if (chartData.series?.every((series) => series.points.every((p) => p.outlier)))
|
|
166
167
|
return null;
|
|
167
168
|
if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
|
|
@@ -173,4 +174,60 @@ export class PackageFunctions {
|
|
|
173
174
|
df.columns.insert(column, df.columns.names().indexOf(colName) + 1);
|
|
174
175
|
return column;
|
|
175
176
|
}
|
|
177
|
+
|
|
178
|
+
@grok.decorators.func({description: 'Returns XML 3DX curve converter function', meta: {role: 'curveConverter', curveFormat: '3dx'}})
|
|
179
|
+
static convertXmlCurveToJsonFunc(): (value: string) => string {
|
|
180
|
+
return convertXmlCurveToJson;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
@grok.decorators.func({description: 'Returns compact dose-response JSON converter function', meta: {role: 'curveConverter', curveFormat: 'compact-dr'}})
|
|
184
|
+
static convertCompactDrToJsonFunc(): (value: string) => string {
|
|
185
|
+
return convertCompactDrToJson;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@grok.decorators.func({description: 'Returns PZFX curve converter function', meta: {role: 'curveConverter', curveFormat: 'pzfx'}})
|
|
189
|
+
static convertPzfxToJsonFunc(): (value: string) => string {
|
|
190
|
+
return convertPzfxToJson;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@grok.decorators.fileViewer({fileViewer: 'pzfx'})
|
|
194
|
+
static async previewPzfx(file: DG.FileInfo): Promise<DG.View> {
|
|
195
|
+
const view = DG.View.create();
|
|
196
|
+
view.name = file.name;
|
|
197
|
+
|
|
198
|
+
const text = await file.readAsString();
|
|
199
|
+
const tables = parsePzfxXml(text);
|
|
200
|
+
const xyTables = tables.filter((t) => t.tableType === 'XY');
|
|
201
|
+
|
|
202
|
+
if (xyTables.length === 0) {
|
|
203
|
+
const nonXyDfs = tables.map(pzfxTableToDataFrame);
|
|
204
|
+
for (const df of nonXyDfs)
|
|
205
|
+
view.append(DG.Viewer.grid(df).root);
|
|
206
|
+
return view;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const df = pzfxToFitDataFrame(xyTables);
|
|
210
|
+
const grid = DG.Viewer.grid(df);
|
|
211
|
+
grid.root.style.width = '100%';
|
|
212
|
+
grid.root.style.height = '100%';
|
|
213
|
+
view.append(grid.root);
|
|
214
|
+
|
|
215
|
+
return view;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@grok.decorators.fileHandler({ext: 'pzfx'})
|
|
219
|
+
static pzfxFileHandler(@grok.decorators.param({type: 'list'}) bytes: Uint8Array): DG.DataFrame[] {
|
|
220
|
+
const text = new TextDecoder().decode(new Uint8Array(bytes));
|
|
221
|
+
const tables = parsePzfxXml(text);
|
|
222
|
+
const results: DG.DataFrame[] = [];
|
|
223
|
+
|
|
224
|
+
const xyTables = tables.filter((t) => t.tableType === 'XY');
|
|
225
|
+
if (xyTables.length > 0)
|
|
226
|
+
results.push(pzfxToFitDataFrame(xyTables));
|
|
227
|
+
|
|
228
|
+
for (const table of tables.filter((t) => t.tableType !== 'XY'))
|
|
229
|
+
results.push(pzfxTableToDataFrame(table));
|
|
230
|
+
|
|
231
|
+
return results;
|
|
232
|
+
}
|
|
176
233
|
}
|