@datagrok/curves 1.12.0 → 1.12.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/curves",
3
3
  "friendlyName": "Curves",
4
- "version": "1.12.0",
4
+ "version": "1.12.2",
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",
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@datagrok-libraries/statistics": "^1.12.3",
12
- "@datagrok-libraries/utils": "^4.6.5",
13
12
  "@datagrok-libraries/test": "^1.2.0",
13
+ "@datagrok-libraries/utils": "^4.6.5",
14
14
  "@types/wu": "^2.1.42",
15
15
  "@typescript-eslint/eslint-plugin": "^5.62.0",
16
16
  "@typescript-eslint/parser": "^5.62.0",
@@ -34,7 +34,8 @@
34
34
  "webpack-cli": "^5.1.4"
35
35
  },
36
36
  "overrides": {
37
- "datagrok-api": "$datagrok-api"
37
+ "datagrok-api": "$datagrok-api",
38
+ "uuid": "^11.1.1"
38
39
  },
39
40
  "scripts": {
40
41
  "link-all": "npm link datagrok-api @datagrok-libraries/utils @datagrok-libraries/statistics",
@@ -69,7 +69,14 @@ export function parseCellValue(cellValue: string, column?: DG.Column | null): IF
69
69
  return {series: []};
70
70
 
71
71
  const jsonStr = column ? convertCellValue(cellValue, column) : cellValue;
72
- return JSON.parse(jsonStr ?? '{}') ?? {};
72
+ try {
73
+ return JSON.parse(jsonStr ?? '{}') ?? {};
74
+ } catch (_e) {
75
+ // Cell value is not valid fit JSON (e.g. a column mis-detected as 'fit' via a substring match).
76
+ // Degrade to an empty chart so the renderer hits the existing 'No series to show' path and draws the
77
+ // incorrect-fit marker, instead of throwing a SyntaxError on every grid redraw.
78
+ return {series: []};
79
+ }
73
80
  }
74
81
 
75
82
  /** Returns true if the column uses a non-native format (has a converter). */
@@ -109,3 +109,16 @@ export async function curveDemo(): Promise<void> {
109
109
  const _tableView = grok.shell.addTableView(df);
110
110
  // tableView.addViewer('MultiCurveViewer');
111
111
  }
112
+
113
+ export async function assayCurvesDemo(): Promise<void> {
114
+ const df = await grok.data.loadTable(`${_package.webRoot}files/demo/Assay_Curves.csv`);
115
+ await df.meta.detectSemanticTypes();
116
+ const layoutTXT = await _package.files.readAsText('demo/Assay_Curves.layout');
117
+ const layout = DG.ViewLayout.fromJson(layoutTXT);
118
+ df.selection.set(13, true);
119
+ df.selection.set(14, true); // two curves for multicurve viewer
120
+ const tv = grok.shell.addTableView(df);
121
+ await DG.delay(100);
122
+ tv.loadLayout(layout, true);
123
+ grok.shell.info('Select cells in Trellis plot to see corresponding curves in Multi Curve Viewer.', {timeout: 10});
124
+ }
@@ -9,8 +9,8 @@ import * as DG from 'datagrok-api/dg';
9
9
 
10
10
  export namespace scripts {
11
11
  /**
12
- Calculates Minimum Significant Ratio (MSR) for compounds based on IC50 values, run dates, assay names, and target entities.
13
- */
12
+ * Calculates Minimum Significant Ratio (MSR) for compounds based on IC50 values, run dates, assay names, and target entities.
13
+ */
14
14
  export async function calculateMSR(table: DG.DataFrame , ic50Column: DG.Column , compoundIdColumn: DG.Column , runDateColumn: DG.Column , assayNameColumn: DG.Column , targetEntityColumn: DG.Column ): Promise<DG.DataFrame> {
15
15
  return await grok.functions.call('Curves:CalculateMSR', { table, ic50Column, compoundIdColumn, runDateColumn, assayNameColumn, targetEntityColumn });
16
16
  }
@@ -22,19 +22,26 @@ export namespace funcs {
22
22
  }
23
23
 
24
24
  /**
25
- A viewer that superimposes multiple in-cell curves on one chart
26
- */
25
+ * A viewer that superimposes multiple in-cell curves on one chart
26
+ */
27
27
  export async function multiCurveViewer(): Promise<any> {
28
28
  return await grok.functions.call('Curves:MultiCurveViewer', {});
29
29
  }
30
30
 
31
31
  /**
32
- Curve fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of data points
33
- */
32
+ * Curve fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of data points
33
+ */
34
34
  export async function curveFitDemo(): Promise<void> {
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
  }
@@ -56,22 +63,22 @@ export namespace funcs {
56
63
  }
57
64
 
58
65
  /**
59
- Returns XML 3DX curve converter function
60
- */
66
+ * Returns XML 3DX curve converter function
67
+ */
61
68
  export async function convertXmlCurveToJsonFunc(): Promise<any> {
62
69
  return await grok.functions.call('Curves:ConvertXmlCurveToJsonFunc', {});
63
70
  }
64
71
 
65
72
  /**
66
- Returns compact dose-response JSON converter function
67
- */
73
+ * Returns compact dose-response JSON converter function
74
+ */
68
75
  export async function convertCompactDrToJsonFunc(): Promise<any> {
69
76
  return await grok.functions.call('Curves:ConvertCompactDrToJsonFunc', {});
70
77
  }
71
78
 
72
79
  /**
73
- Returns PZFX curve converter function
74
- */
80
+ * Returns PZFX curve converter function
81
+ */
75
82
  export async function convertPzfxToJsonFunc(): Promise<any> {
76
83
  return await grok.functions.call('Curves:ConvertPzfxToJsonFunc', {});
77
84
  }
package/src/package.g.ts CHANGED
@@ -30,20 +30,29 @@ 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
41
  export async function _initCurves() : Promise<void> {
35
42
  await PackageFunctions._initCurves();
36
43
  }
37
44
 
45
+ //name: Fit Dose-Response Curves
46
+ //description: Group well-level assay data by compound, assay, target, and run, then fit a dose-response curve per group.
38
47
  //input: dataframe df
39
- //input: column concentrationCol
40
- //input: column readoutCol
41
- //input: column batchIDCol
42
- //input: column assayCol
43
- //input: column runIDCol
44
- //input: column compoundIDCol
45
- //input: column targetEntityCol
46
- //input: column excludeOutliersCol { nullable: true }
48
+ //input: column concentrationCol { description: Concentration (dose) column }
49
+ //input: column readoutCol { description: Readout (response) column }
50
+ //input: column batchIDCol { description: Batch identifier column }
51
+ //input: column assayCol { description: Assay name column }
52
+ //input: column runIDCol { description: Run identifier column }
53
+ //input: column compoundIDCol { description: Compound identifier column }
54
+ //input: column targetEntityCol { description: Target entity column }
55
+ //input: column excludeOutliersCol { nullable: true; description: Boolean column marking points to exclude as outliers }
47
56
  //input: dataframe parentTable { nullable: true }
48
57
  //input: list<string> fitParamColumns { nullable: true }
49
58
  //input: string reportedIC50Column { nullable: true }
@@ -65,10 +74,12 @@ export async function dataToCurvesTopMenu() {
65
74
  return await PackageFunctions.dataToCurvesTopMenu();
66
75
  }
67
76
 
77
+ //name: Add Curve Statistic Column
78
+ //description: Extract a fit statistic (e.g. IC50, AUC, R²) from a specific curve series into a new column.
68
79
  //input: dataframe table
69
- //input: string colName
70
- //input: string propName
71
- //input: int seriesNumber
80
+ //input: string colName { description: Name of the curve column to read }
81
+ //input: string propName { description: Fit statistic to extract (e.g. IC50, AUC, R²) }
82
+ //input: int seriesNumber { description: Zero-based index of the curve series }
72
83
  //output: column result
73
84
  //meta.vectorFunc: true
74
85
  //meta.role: transform
@@ -76,10 +87,12 @@ export function addStatisticsColumn(table: DG.DataFrame, colName: string, propNa
76
87
  return PackageFunctions.addStatisticsColumn(table, colName, propName, seriesNumber);
77
88
  }
78
89
 
90
+ //name: Add Aggregated Curve Statistic Column
91
+ //description: Aggregate a fit statistic across all series of a curve into a new column.
79
92
  //input: dataframe table
80
- //input: string colName
81
- //input: string propName
82
- //input: string aggrType
93
+ //input: string colName { description: Name of the curve column to read }
94
+ //input: string propName { description: Fit statistic to aggregate (e.g. IC50, AUC, R²) }
95
+ //input: string aggrType { description: Aggregation type applied across series (e.g. avg, min, max) }
83
96
  //output: column result
84
97
  //meta.vectorFunc: true
85
98
  //meta.role: transform
@@ -119,7 +132,8 @@ export async function previewPzfx(file: DG.FileInfo) : Promise<any> {
119
132
  return await PackageFunctions.previewPzfx(file);
120
133
  }
121
134
 
122
- //input: list bytes
135
+ //description: Open a GraphPad Prism (.pzfx) file as data tables, fitting XY curve tables.
136
+ //input: list bytes { description: Raw bytes of the .pzfx file }
123
137
  //output: list<dataframe> result
124
138
  //meta.role: fileHandler
125
139
  //meta.ext: pzfx
package/src/package.ts CHANGED
@@ -9,7 +9,7 @@ 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';
12
+ import {assayCurvesDemo, curveDemo} from './fit/fit-demo';
13
13
  import {convertXmlCurveToJson} from './fit/converters/xml-converter';
14
14
  import {convertCompactDrToJson} from './fit/converters/compact-dr-converter';
15
15
  import {convertPzfxToJson} from './fit/converters/pzfx-converter';
@@ -52,6 +52,15 @@ export class PackageFunctions {
52
52
  await curveDemo();
53
53
  }
54
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
+
55
64
  // @grok.decorators.func({
56
65
  // name: 'Assay Plates',
57
66
  // description: 'Assasy plates with concentration, layout and readout data',
@@ -73,9 +82,19 @@ export class PackageFunctions {
73
82
  await initExternalConverters();
74
83
  }
75
84
 
76
- @grok.decorators.func()
77
- static async dataToCurves(df: DG.DataFrame, concentrationCol: DG.Column, readoutCol: DG.Column, batchIDCol: DG.Column, assayCol: DG.Column,
78
- runIDCol: DG.Column, compoundIDCol: DG.Column, targetEntityCol: DG.Column, @grok.decorators.param({options: {nullable: true}})excludeOutliersCol?: DG.Column,
85
+ @grok.decorators.func({
86
+ name: 'Fit Dose-Response Curves',
87
+ description: 'Group well-level assay data by compound, assay, target, and run, then fit a dose-response curve per group.',
88
+ })
89
+ static async dataToCurves(df: DG.DataFrame,
90
+ @grok.decorators.param({options: {description: 'Concentration (dose) column'}}) concentrationCol: DG.Column,
91
+ @grok.decorators.param({options: {description: 'Readout (response) column'}}) readoutCol: DG.Column,
92
+ @grok.decorators.param({options: {description: 'Batch identifier column'}}) batchIDCol: DG.Column,
93
+ @grok.decorators.param({options: {description: 'Assay name column'}}) assayCol: DG.Column,
94
+ @grok.decorators.param({options: {description: 'Run identifier column'}}) runIDCol: DG.Column,
95
+ @grok.decorators.param({options: {description: 'Compound identifier column'}}) compoundIDCol: DG.Column,
96
+ @grok.decorators.param({options: {description: 'Target entity column'}}) targetEntityCol: DG.Column,
97
+ @grok.decorators.param({options: {nullable: true, description: 'Boolean column marking points to exclude as outliers'}})excludeOutliersCol?: DG.Column,
79
98
  // rest is parent level data
80
99
  @grok.decorators.param({options: {nullable: true}})parentTable?: DG.DataFrame, // these inputs need to be string and resolved here bellow, because this function is used in datasync, otherwise context is lost
81
100
  @grok.decorators.param({options: {nullable: true}})fitParamColumns?: string[],
@@ -112,8 +131,15 @@ export class PackageFunctions {
112
131
  dataToCurvesUI();
113
132
  }
114
133
 
115
- @grok.decorators.func({meta: {vectorFunc: 'true', role: 'transform'}})
116
- static addStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, @grok.decorators.param({type: 'int'}) seriesNumber: number): DG.Column {
134
+ @grok.decorators.func({
135
+ name: 'Add Curve Statistic Column',
136
+ description: 'Extract a fit statistic (e.g. IC50, AUC, R²) from a specific curve series into a new column.',
137
+ meta: {vectorFunc: 'true', role: 'transform'},
138
+ })
139
+ static addStatisticsColumn(table: DG.DataFrame,
140
+ @grok.decorators.param({options: {description: 'Name of the curve column to read'}}) colName: string,
141
+ @grok.decorators.param({options: {description: 'Fit statistic to extract (e.g. IC50, AUC, R²)'}}) propName: string,
142
+ @grok.decorators.param({type: 'int', options: {description: 'Zero-based index of the curve series'}}) seriesNumber: number): DG.Column {
117
143
  const df = table;
118
144
  const col = df.col(colName)!;
119
145
  const sourceColName = col.name;
@@ -147,8 +173,15 @@ export class PackageFunctions {
147
173
  return column;
148
174
  }
149
175
 
150
- @grok.decorators.func({meta: {vectorFunc: 'true', role: 'transform'}})
151
- static addAggrStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, aggrType: string): DG.Column {
176
+ @grok.decorators.func({
177
+ name: 'Add Aggregated Curve Statistic Column',
178
+ description: 'Aggregate a fit statistic across all series of a curve into a new column.',
179
+ meta: {vectorFunc: 'true', role: 'transform'},
180
+ })
181
+ static addAggrStatisticsColumn(table: DG.DataFrame,
182
+ @grok.decorators.param({options: {description: 'Name of the curve column to read'}}) colName: string,
183
+ @grok.decorators.param({options: {description: 'Fit statistic to aggregate (e.g. IC50, AUC, R²)'}}) propName: string,
184
+ @grok.decorators.param({options: {description: 'Aggregation type applied across series (e.g. avg, min, max)'}}) aggrType: string): DG.Column {
152
185
  const df = table;
153
186
  const col = df.col(colName)!;
154
187
  const nName = `${colName} ${aggrType} ${propName}`;
@@ -215,8 +248,11 @@ export class PackageFunctions {
215
248
  return view;
216
249
  }
217
250
 
218
- @grok.decorators.fileHandler({ext: 'pzfx'})
219
- static pzfxFileHandler(@grok.decorators.param({type: 'list'}) bytes: Uint8Array): DG.DataFrame[] {
251
+ @grok.decorators.fileHandler({
252
+ ext: 'pzfx',
253
+ description: 'Open a GraphPad Prism (.pzfx) file as data tables, fitting XY curve tables.',
254
+ })
255
+ static pzfxFileHandler(@grok.decorators.param({type: 'list', options: {description: 'Raw bytes of the .pzfx file'}}) bytes: Uint8Array): DG.DataFrame[] {
220
256
  const text = new TextDecoder().decode(new Uint8Array(bytes));
221
257
  const tables = parsePzfxXml(text);
222
258
  const results: DG.DataFrame[] = [];
@@ -181,6 +181,12 @@ category('converters', () => {
181
181
  expect(chartData.series !== undefined && chartData.series.length === 0, true);
182
182
  });
183
183
 
184
+ test('parseCellValue.malformedJson', async () => {
185
+ // Unquoted-key value that passes the substring-based fit detection but is not valid JSON.
186
+ const chartData = parseCellValue('{series: [{name: "A", points: [{x:0,y:50}]}]}', null);
187
+ expect(chartData.series !== undefined && chartData.series.length === 0, true);
188
+ });
189
+
184
190
  test('converterCaching', async () => {
185
191
  registerCurveConverter('compact-dr', convertCompactDrToJson);
186
192