@datagrok/curves 1.12.1 → 1.13.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/CLAUDE.md +118 -15
  3. package/README.md +51 -4
  4. package/dist/package-test.js +7963 -4867
  5. package/dist/package-test.js.map +1 -1
  6. package/dist/package.js +3411 -2024
  7. package/dist/package.js.map +1 -1
  8. package/files/demo/Assay_Curves.csv +43 -43
  9. package/package.json +5 -4
  10. package/scripts/calculateMSR.py +16 -7
  11. package/src/fit/curve-converter.ts +8 -1
  12. package/src/fit/data-to-curves.ts +10 -5
  13. package/src/fit/fit-chart-data.ts +323 -0
  14. package/src/fit/fit-grid-cell-handler.ts +98 -231
  15. package/src/fit/fit-inspection.ts +3 -3
  16. package/src/fit/fit-interaction.ts +181 -0
  17. package/src/fit/fit-layout.ts +64 -0
  18. package/src/fit/fit-legend.ts +292 -0
  19. package/src/fit/fit-options.ts +222 -0
  20. package/src/fit/fit-parser.ts +16 -5
  21. package/src/fit/fit-renderer.ts +180 -469
  22. package/src/fit/fit-statistics.ts +154 -0
  23. package/src/fit/multi-curve-viewer.ts +46 -20
  24. package/src/fit/render-utils.ts +208 -150
  25. package/src/package-api.ts +92 -14
  26. package/src/package-test.ts +6 -0
  27. package/src/package.g.ts +70 -15
  28. package/src/package.ts +121 -15
  29. package/src/tests/calculated-columns-tests.ts +299 -0
  30. package/src/tests/converter-tests.ts +29 -0
  31. package/src/tests/curve-data.ts +82 -0
  32. package/src/tests/fit-cache-tests.ts +128 -0
  33. package/src/tests/fit-tests.ts +310 -3
  34. package/src/tests/legend-tests.ts +243 -0
  35. package/src/tests/multi-curve-viewer-tests.ts +100 -0
  36. package/src/tests/panel-renderer-tests.ts +502 -0
  37. package/src/tests/project-tests.ts +99 -0
  38. package/src/tests/transform-tests.ts +3 -2
  39. package/test-console-output-1.log +357 -110
  40. package/test-record-1.mp4 +0 -0
@@ -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,22 +22,22 @@ 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
38
  /**
39
- Dashboard with curves for multiple compounds, assays and targets
40
- */
39
+ * Dashboard with curves for multiple compounds, assays and targets
40
+ */
41
41
  export async function assayCurveFitDemo(): Promise<void> {
42
42
  return await grok.functions.call('Curves:AssayCurveFitDemo', {});
43
43
  }
@@ -46,6 +46,17 @@ export namespace funcs {
46
46
  return await grok.functions.call('Curves:InitCurves', {});
47
47
  }
48
48
 
49
+ /**
50
+ * Group well-level assay data by compound, assay, target, and run, then fit a dose-response curve per group.
51
+ * @param {DG.Column} concentrationCol - Concentration (dose) column
52
+ * @param {DG.Column} readoutCol - Readout (response) column
53
+ * @param {DG.Column} batchIDCol - Batch identifier column
54
+ * @param {DG.Column} assayCol - Assay name column
55
+ * @param {DG.Column} runIDCol - Run identifier column
56
+ * @param {DG.Column} compoundIDCol - Compound identifier column
57
+ * @param {DG.Column} targetEntityCol - Target entity column
58
+ * @param {DG.Column} excludeOutliersCol - Boolean column marking points to exclude as outliers
59
+ */
49
60
  export async function dataToCurves(df: DG.DataFrame , concentrationCol: DG.Column , readoutCol: DG.Column , batchIDCol: DG.Column , assayCol: DG.Column , runIDCol: DG.Column , compoundIDCol: DG.Column , targetEntityCol: DG.Column , excludeOutliersCol: DG.Column | null, parentTable: DG.DataFrame | null, fitParamColumns: any | null, reportedIC50Column: string | null, reportedQualifiedIC50Column: string | null, experimentIDColumn: string | null, qualifierColumn: string | null, additionalColumns: any | null, wellLevelJoinCol: string | null, parentLevelJoinCol: string | null, wellLevelAdditionalColumns?: any | null): Promise<DG.DataFrame> {
50
61
  return await grok.functions.call('Curves:DataToCurves', { df, concentrationCol, readoutCol, batchIDCol, assayCol, runIDCol, compoundIDCol, targetEntityCol, excludeOutliersCol, parentTable, fitParamColumns, reportedIC50Column, reportedQualifiedIC50Column, experimentIDColumn, qualifierColumn, additionalColumns, wellLevelJoinCol, parentLevelJoinCol, wellLevelAdditionalColumns });
51
62
  }
@@ -54,31 +65,94 @@ export namespace funcs {
54
65
  return await grok.functions.call('Curves:DataToCurvesTopMenu', {});
55
66
  }
56
67
 
68
+ /**
69
+ * Extract a fit statistic (e.g. IC50, AUC, R²) from a curve series into a calculated column.
70
+ * @param {DG.Column} curveColumn - Curve column to read
71
+ * semType: fit
72
+ * @param {string} propName - Fit statistic to extract (e.g. ic50, auc, rSquared)
73
+ * @param {number} seriesNumber - Zero-based index of the curve series
74
+ */
75
+ export async function curveStatistic(table: DG.DataFrame , curveColumn: DG.Column , propName: string , seriesNumber: number ): Promise<DG.Column> {
76
+ return await grok.functions.call('Curves:CurveStatistic', { table, curveColumn, propName, seriesNumber });
77
+ }
78
+
79
+ /**
80
+ * Aggregate a fit statistic across all series of a curve into a calculated column.
81
+ * @param {DG.Column} curveColumn - Curve column to read
82
+ * semType: fit
83
+ * @param {string} propName - Fit statistic to aggregate
84
+ * @param {string} aggrType - Aggregation applied across the series of each curve
85
+ * choices: ["avg","med","min","max","q1","q2","q3"]
86
+ */
87
+ export async function curveAggrStatistic(table: DG.DataFrame , curveColumn: DG.Column , propName: string , aggrType: string ): Promise<DG.Column> {
88
+ return await grok.functions.call('Curves:CurveAggrStatistic', { table, curveColumn, propName, aggrType });
89
+ }
90
+
91
+ /**
92
+ * Extract a fit statistic (e.g. IC50, AUC, R²) from a specific curve series into a new column.
93
+ * @param {string} colName - Name of the curve column to read
94
+ * @param {string} propName - Fit statistic to extract. interceptX is IC50, top and bottom are max/min Y
95
+ * choices: ["rSquared","auc","interceptX","interceptY","slope","top","bottom"]
96
+ * @param {number} seriesNumber - Zero-based index of the curve series
97
+ */
57
98
  export async function addStatisticsColumn(table: DG.DataFrame , colName: string , propName: string , seriesNumber: number ): Promise<DG.Column> {
58
99
  return await grok.functions.call('Curves:AddStatisticsColumn', { table, colName, propName, seriesNumber });
59
100
  }
60
101
 
102
+ /**
103
+ * Aggregate a fit statistic across all series of a curve into a new column.
104
+ * @param {string} colName - Name of the curve column to read
105
+ * @param {string} propName - Fit statistic to aggregate. interceptX is IC50, top and bottom are max/min Y
106
+ * choices: ["rSquared","auc","interceptX","interceptY","slope","top","bottom"]
107
+ * @param {string} aggrType - Aggregation applied across the series of each curve
108
+ * choices: ["min","max","avg","med","q1","q2","q3"]
109
+ */
61
110
  export async function addAggrStatisticsColumn(table: DG.DataFrame , colName: string , propName: string , aggrType: string ): Promise<DG.Column> {
62
111
  return await grok.functions.call('Curves:AddAggrStatisticsColumn', { table, colName, propName, aggrType });
63
112
  }
64
113
 
65
114
  /**
66
- Returns XML 3DX curve converter function
67
- */
115
+ * Extracts a fit statistic from one series of a curve column into a new column.
116
+ * @param {DG.Column} curvesCol - Column of fitted curves
117
+ * semType: fit
118
+ * @param {string} statistic - interceptX is IC50, top and bottom are max/min Y
119
+ * choices: ["rSquared","auc","interceptX","interceptY","slope","top","bottom"]
120
+ * @param {number} seriesNumber - Zero-based index of the curve series
121
+ */
122
+ export async function addCurveStatistic(table: DG.DataFrame , curvesCol: DG.Column , statistic: string , seriesNumber: number ): Promise<DG.Column> {
123
+ return await grok.functions.call('Curves:AddCurveStatistic', { table, curvesCol, statistic, seriesNumber });
124
+ }
125
+
126
+ /**
127
+ * Aggregates a fit statistic across all series of a curve column into a new column.
128
+ * @param {DG.Column} curvesCol - Column of fitted curves
129
+ * semType: fit
130
+ * @param {string} statistic - interceptX is IC50, top and bottom are max/min Y
131
+ * choices: ["rSquared","auc","interceptX","interceptY","slope","top","bottom"]
132
+ * @param {string} aggregation - Applied across the series of each curve
133
+ * choices: ["med","avg","min","max","q1","q2","q3"]
134
+ */
135
+ export async function addAggrCurveStatistic(table: DG.DataFrame , curvesCol: DG.Column , statistic: string , aggregation: string ): Promise<DG.Column> {
136
+ return await grok.functions.call('Curves:AddAggrCurveStatistic', { table, curvesCol, statistic, aggregation });
137
+ }
138
+
139
+ /**
140
+ * Returns XML 3DX curve converter function
141
+ */
68
142
  export async function convertXmlCurveToJsonFunc(): Promise<any> {
69
143
  return await grok.functions.call('Curves:ConvertXmlCurveToJsonFunc', {});
70
144
  }
71
145
 
72
146
  /**
73
- Returns compact dose-response JSON converter function
74
- */
147
+ * Returns compact dose-response JSON converter function
148
+ */
75
149
  export async function convertCompactDrToJsonFunc(): Promise<any> {
76
150
  return await grok.functions.call('Curves:ConvertCompactDrToJsonFunc', {});
77
151
  }
78
152
 
79
153
  /**
80
- Returns PZFX curve converter function
81
- */
154
+ * Returns PZFX curve converter function
155
+ */
82
156
  export async function convertPzfxToJsonFunc(): Promise<any> {
83
157
  return await grok.functions.call('Curves:ConvertPzfxToJsonFunc', {});
84
158
  }
@@ -87,6 +161,10 @@ export namespace funcs {
87
161
  return await grok.functions.call('Curves:PreviewPzfx', { file });
88
162
  }
89
163
 
164
+ /**
165
+ * Open a GraphPad Prism (.pzfx) file as data tables, fitting XY curve tables.
166
+ * @param {any} bytes - Raw bytes of the .pzfx file
167
+ */
90
168
  export async function pzfxFileHandler(bytes: any ): Promise<any> {
91
169
  return await grok.functions.call('Curves:PzfxFileHandler', { bytes });
92
170
  }
@@ -8,6 +8,12 @@ import './tests/curves-cell-renderer-tests';
8
8
  import './tests/transform-tests';
9
9
  import './tests/fit-tests';
10
10
  import './tests/pzfx-tests';
11
+ import './tests/calculated-columns-tests';
12
+ import './tests/panel-renderer-tests';
13
+ import './tests/multi-curve-viewer-tests';
14
+ import './tests/legend-tests';
15
+ import './tests/fit-cache-tests';
16
+ import './tests/project-tests';
11
17
 
12
18
  export const _package = new DG.Package();
13
19
  export {tests};
package/src/package.g.ts CHANGED
@@ -42,15 +42,17 @@ export async function _initCurves() : Promise<void> {
42
42
  await PackageFunctions._initCurves();
43
43
  }
44
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.
45
47
  //input: dataframe df
46
- //input: column concentrationCol
47
- //input: column readoutCol
48
- //input: column batchIDCol
49
- //input: column assayCol
50
- //input: column runIDCol
51
- //input: column compoundIDCol
52
- //input: column targetEntityCol
53
- //input: column excludeOutliersCol { nullable: true }
48
+ //input: column concentrationCol { type: numerical; nullable: false; description: Concentration (dose) column }
49
+ //input: column readoutCol { type: numerical; nullable: false; description: Readout (response) column }
50
+ //input: column batchIDCol { type: categorical; nullable: false; description: Batch identifier column }
51
+ //input: column assayCol { type: categorical; nullable: false; description: Assay name column }
52
+ //input: column runIDCol { type: categorical; nullable: false; description: Run identifier column }
53
+ //input: column compoundIDCol { type: categorical; nullable: false; description: Compound identifier column }
54
+ //input: column targetEntityCol { type: categorical; nullable: false; description: Target entity column }
55
+ //input: column excludeOutliersCol { nullable: true; description: Boolean column marking points to exclude as outliers }
54
56
  //input: dataframe parentTable { nullable: true }
55
57
  //input: list<string> fitParamColumns { nullable: true }
56
58
  //input: string reportedIC50Column { nullable: true }
@@ -72,10 +74,34 @@ export async function dataToCurvesTopMenu() {
72
74
  return await PackageFunctions.dataToCurvesTopMenu();
73
75
  }
74
76
 
77
+ //description: Extract a fit statistic (e.g. IC50, AUC, R²) from a curve series into a calculated column.
75
78
  //input: dataframe table
76
- //input: string colName
77
- //input: string propName
78
- //input: int seriesNumber
79
+ //input: column curveColumn { semType: fit; nullable: false; description: Curve column to read }
80
+ //input: string propName { nullable: false; description: Fit statistic to extract (e.g. ic50, auc, rSquared) }
81
+ //input: int seriesNumber { nullable: false; description: Zero-based index of the curve series }
82
+ //output: column result { action: join(table) }
83
+ //meta.vectorFunc: true
84
+ export function curveStatistic(table: DG.DataFrame, curveColumn: DG.Column, propName: string, seriesNumber: number) : any {
85
+ return PackageFunctions.curveStatistic(table, curveColumn, propName, seriesNumber);
86
+ }
87
+
88
+ //description: Aggregate a fit statistic across all series of a curve into a calculated column.
89
+ //input: dataframe table
90
+ //input: column curveColumn { semType: fit; nullable: false; description: Curve column to read }
91
+ //input: string propName { nullable: false; description: Fit statistic to aggregate }
92
+ //input: string aggrType = 'med' { choices: ["avg","med","min","max","q1","q2","q3"]; nullable: false; description: Aggregation applied across the series of each curve }
93
+ //output: column result { action: join(table) }
94
+ //meta.vectorFunc: true
95
+ export function curveAggrStatistic(table: DG.DataFrame, curveColumn: DG.Column, propName: string, aggrType: string) : any {
96
+ return PackageFunctions.curveAggrStatistic(table, curveColumn, propName, aggrType);
97
+ }
98
+
99
+ //name: Add Curve Statistic Column
100
+ //description: Extract a fit statistic (e.g. IC50, AUC, R²) from a specific curve series into a new column.
101
+ //input: dataframe table
102
+ //input: string colName { description: Name of the curve column to read }
103
+ //input: string propName = 'interceptX' { choices: ["rSquared","auc","interceptX","interceptY","slope","top","bottom"]; description: Fit statistic to extract. interceptX is IC50, top and bottom are max/min Y }
104
+ //input: int seriesNumber = 0 { description: Zero-based index of the curve series }
79
105
  //output: column result
80
106
  //meta.vectorFunc: true
81
107
  //meta.role: transform
@@ -83,10 +109,12 @@ export function addStatisticsColumn(table: DG.DataFrame, colName: string, propNa
83
109
  return PackageFunctions.addStatisticsColumn(table, colName, propName, seriesNumber);
84
110
  }
85
111
 
112
+ //name: Add Aggregated Curve Statistic Column
113
+ //description: Aggregate a fit statistic across all series of a curve into a new column.
86
114
  //input: dataframe table
87
- //input: string colName
88
- //input: string propName
89
- //input: string aggrType
115
+ //input: string colName { description: Name of the curve column to read }
116
+ //input: string propName = 'interceptX' { choices: ["rSquared","auc","interceptX","interceptY","slope","top","bottom"]; description: Fit statistic to aggregate. interceptX is IC50, top and bottom are max/min Y }
117
+ //input: string aggrType = 'med' { choices: ["min","max","avg","med","q1","q2","q3"]; description: Aggregation applied across the series of each curve }
90
118
  //output: column result
91
119
  //meta.vectorFunc: true
92
120
  //meta.role: transform
@@ -94,6 +122,32 @@ export function addAggrStatisticsColumn(table: DG.DataFrame, colName: string, pr
94
122
  return PackageFunctions.addAggrStatisticsColumn(table, colName, propName, aggrType);
95
123
  }
96
124
 
125
+ //name: Add Curve Statistic
126
+ //description: Extracts a fit statistic from one series of a curve column into a new column.
127
+ //input: dataframe table { caption: Table; nullable: false }
128
+ //input: column curvesCol { semType: fit; caption: Curves; nullable: false; description: Column of fitted curves }
129
+ //input: string statistic = 'interceptX' { caption: Statistic; nullable: false; choices: ["rSquared","auc","interceptX","interceptY","slope","top","bottom"]; description: interceptX is IC50, top and bottom are max/min Y }
130
+ //input: int seriesNumber = 0 { caption: Series; nullable: false; description: Zero-based index of the curve series }
131
+ //output: column result
132
+ //meta.vectorFunc: true
133
+ //meta.role: transform
134
+ export function addCurveStatistic(table: DG.DataFrame, curvesCol: DG.Column, statistic: string, seriesNumber: number) : any {
135
+ return PackageFunctions.addCurveStatistic(table, curvesCol, statistic, seriesNumber);
136
+ }
137
+
138
+ //name: Add Aggregated Curve Statistic
139
+ //description: Aggregates a fit statistic across all series of a curve column into a new column.
140
+ //input: dataframe table { caption: Table; nullable: false }
141
+ //input: column curvesCol { semType: fit; caption: Curves; nullable: false; description: Column of fitted curves }
142
+ //input: string statistic = 'interceptX' { caption: Statistic; nullable: false; choices: ["rSquared","auc","interceptX","interceptY","slope","top","bottom"]; description: interceptX is IC50, top and bottom are max/min Y }
143
+ //input: string aggregation = 'med' { caption: Aggregation; nullable: false; choices: ["med","avg","min","max","q1","q2","q3"]; description: Applied across the series of each curve }
144
+ //output: column result
145
+ //meta.vectorFunc: true
146
+ //meta.role: transform
147
+ export function addAggrCurveStatistic(table: DG.DataFrame, curvesCol: DG.Column, statistic: string, aggregation: string) : any {
148
+ return PackageFunctions.addAggrCurveStatistic(table, curvesCol, statistic, aggregation);
149
+ }
150
+
97
151
  //description: Returns XML 3DX curve converter function
98
152
  //output: dynamic result
99
153
  //meta.role: curveConverter
@@ -126,7 +180,8 @@ export async function previewPzfx(file: DG.FileInfo) : Promise<any> {
126
180
  return await PackageFunctions.previewPzfx(file);
127
181
  }
128
182
 
129
- //input: list bytes
183
+ //description: Open a GraphPad Prism (.pzfx) file as data tables, fitting XY curve tables.
184
+ //input: list bytes { description: Raw bytes of the .pzfx file }
130
185
  //output: list<dataframe> result
131
186
  //meta.role: fileHandler
132
187
  //meta.ext: pzfx
package/src/package.ts CHANGED
@@ -7,15 +7,16 @@ import * as DG from 'datagrok-api/dg';
7
7
  import * as grok from 'datagrok-api/grok';
8
8
  import * as ui from 'datagrok-api/ui';
9
9
 
10
- import {FitGridCellHandler, calculateSeriesStats, getChartDataAggrStats} from './fit/fit-grid-cell-handler';
11
- import {getOrCreateParsedChartData, substituteZeroes} from './fit/fit-renderer';
10
+ import {FitGridCellHandler} from './fit/fit-grid-cell-handler';
11
+ import {calculateSeriesFit, getChartDataAggrStats, curveStatisticAt, curveAggrStatisticAt} from './fit/fit-statistics';
12
+ import {getOrCreateParsedChartData, substituteZeroes} from './fit/fit-chart-data';
12
13
  import {assayCurvesDemo, curveDemo} from './fit/fit-demo';
13
14
  import {convertXmlCurveToJson} from './fit/converters/xml-converter';
14
15
  import {convertCompactDrToJson} from './fit/converters/compact-dr-converter';
15
16
  import {convertPzfxToJson} from './fit/converters/pzfx-converter';
16
17
  import {registerCurveConverter, initExternalConverters} from './fit/curve-converter';
17
- import {LogOptions} from '@datagrok-libraries/statistics/src/fit/fit-data';
18
- import {FitStatistics} from '@datagrok-libraries/statistics/src/fit/fit-curve';
18
+ import {FitStatistics, LogOptions} from '@datagrok-libraries/statistics/src/fit/fit-curve';
19
+ import {getStatistic} from '@datagrok-libraries/statistics/src/fit/fit-engine';
19
20
 
20
21
  // import {PlateWidget} from './plate/plate-widget';
21
22
 
@@ -82,9 +83,27 @@ export class PackageFunctions {
82
83
  await initExternalConverters();
83
84
  }
84
85
 
85
- @grok.decorators.func()
86
- static async dataToCurves(df: DG.DataFrame, concentrationCol: DG.Column, readoutCol: DG.Column, batchIDCol: DG.Column, assayCol: DG.Column,
87
- runIDCol: DG.Column, compoundIDCol: DG.Column, targetEntityCol: DG.Column, @grok.decorators.param({options: {nullable: true}})excludeOutliersCol?: DG.Column,
86
+ @grok.decorators.func({
87
+ name: 'Fit Dose-Response Curves',
88
+ description: 'Group well-level assay data by compound, assay, target, and run, then fit a dose-response curve per group.',
89
+ })
90
+ static async dataToCurves(df: DG.DataFrame,
91
+ /* The declared `type` must stay `column`: an `options.type` on its own
92
+ * becomes the parameter's OWN type in the generated annotation, turning the
93
+ * column slot into a plain numerical/categorical value. (And never spell an
94
+ * `input:` annotation out inside a comment — the server scans package.ts for
95
+ * those lines and would try to parse it as a real parameter.) */
96
+ // All seven are dereferenced unconditionally, so they are `nullable: false`
97
+ // — a column parameter defaults to nullable, which read as "optional" and
98
+ // let a half-configured node run.
99
+ @grok.decorators.param({type: 'column', options: {type: 'numerical', nullable: false, description: 'Concentration (dose) column'}}) concentrationCol: DG.Column,
100
+ @grok.decorators.param({type: 'column', options: {type: 'numerical', nullable: false, description: 'Readout (response) column'}}) readoutCol: DG.Column,
101
+ @grok.decorators.param({type: 'column', options: {type: 'categorical', nullable: false, description: 'Batch identifier column'}}) batchIDCol: DG.Column,
102
+ @grok.decorators.param({type: 'column', options: {type: 'categorical', nullable: false, description: 'Assay name column'}}) assayCol: DG.Column,
103
+ @grok.decorators.param({type: 'column', options: {type: 'categorical', nullable: false, description: 'Run identifier column'}}) runIDCol: DG.Column,
104
+ @grok.decorators.param({type: 'column', options: {type: 'categorical', nullable: false, description: 'Compound identifier column'}}) compoundIDCol: DG.Column,
105
+ @grok.decorators.param({type: 'column', options: {type: 'categorical', nullable: false, description: 'Target entity column'}}) targetEntityCol: DG.Column,
106
+ @grok.decorators.param({type: 'column', options: {nullable: true, description: 'Boolean column marking points to exclude as outliers'}})excludeOutliersCol?: DG.Column,
88
107
  // rest is parent level data
89
108
  @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
90
109
  @grok.decorators.param({options: {nullable: true}})fitParamColumns?: string[],
@@ -121,8 +140,49 @@ export class PackageFunctions {
121
140
  dataToCurvesUI();
122
141
  }
123
142
 
124
- @grok.decorators.func({meta: {vectorFunc: 'true', role: 'transform'}})
125
- static addStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, @grok.decorators.param({type: 'int'}) seriesNumber: number): DG.Column {
143
+ @grok.decorators.func({
144
+ name: 'curveStatistic',
145
+ description: 'Extract a fit statistic (e.g. IC50, AUC, R²) from a curve series into a calculated column.',
146
+ meta: {vectorFunc: 'true'},
147
+ outputs: [{name: 'result', type: 'column', options: {action: 'join(table)'}}],
148
+ })
149
+ static curveStatistic(table: DG.DataFrame,
150
+ @grok.decorators.param({type: 'column', options: {semType: 'fit', nullable: false, description: 'Curve column to read'}}) curveColumn: DG.Column,
151
+ @grok.decorators.param({options: {nullable: false, description: 'Fit statistic to extract (e.g. ic50, auc, rSquared)'}}) propName: string,
152
+ @grok.decorators.param({type: 'int', options: {nullable: false, description: 'Zero-based index of the curve series'}}) seriesNumber: number): DG.Column {
153
+ // stable name: recalculation matches the result back by name, and AddNewColumn makes it unique on insert
154
+ const result = DG.Column.float(`${curveColumn.name} ${seriesNumber + 1} ${propName}`, curveColumn.length);
155
+ result.init((i) => curveStatisticAt(curveColumn, i, propName, seriesNumber, table));
156
+ return result;
157
+ }
158
+
159
+ @grok.decorators.func({
160
+ name: 'curveAggrStatistic',
161
+ description: 'Aggregate a fit statistic across all series of a curve into a calculated column.',
162
+ meta: {vectorFunc: 'true'},
163
+ outputs: [{name: 'result', type: 'column', options: {action: 'join(table)'}}],
164
+ })
165
+ static curveAggrStatistic(table: DG.DataFrame,
166
+ @grok.decorators.param({type: 'column', options: {semType: 'fit', nullable: false, description: 'Curve column to read'}}) curveColumn: DG.Column,
167
+ @grok.decorators.param({options: {nullable: false, description: 'Fit statistic to aggregate'}}) propName: string,
168
+ @grok.decorators.param({options: {choices: ['avg', 'med', 'min', 'max', 'q1', 'q2', 'q3'], initialValue: 'med', nullable: false, description: 'Aggregation applied across the series of each curve'}}) aggrType: string): DG.Column {
169
+ // stable name: recalculation matches the result back by name, and AddNewColumn makes it unique on insert
170
+ const result = DG.Column.float(`${curveColumn.name} ${aggrType} ${propName}`, curveColumn.length);
171
+ result.init((i) => curveAggrStatisticAt(curveColumn, i, propName, aggrType, table));
172
+ return result;
173
+ }
174
+
175
+ @grok.decorators.func({
176
+ name: 'Add Curve Statistic Column',
177
+ description: 'Extract a fit statistic (e.g. IC50, AUC, R²) from a specific curve series into a new column.',
178
+ meta: {vectorFunc: 'true', role: 'transform'},
179
+ })
180
+ static addStatisticsColumn(table: DG.DataFrame,
181
+ @grok.decorators.param({options: {description: 'Name of the curve column to read'}}) colName: string,
182
+ // Literal strings, not `statisticsProperties.map(...)` — the func generator
183
+ // only reads literal arrays and emits nothing for a computed one.
184
+ @grok.decorators.param({options: {choices: ['rSquared', 'auc', 'interceptX', 'interceptY', 'slope', 'top', 'bottom'], initialValue: 'interceptX', description: 'Fit statistic to extract. interceptX is IC50, top and bottom are max/min Y'}}) propName: string,
185
+ @grok.decorators.param({type: 'int', options: {initialValue: '0', description: 'Zero-based index of the curve series'}}) seriesNumber: number): DG.Column {
126
186
  const df = table;
127
187
  const col = df.col(colName)!;
128
188
  const sourceColName = col.name;
@@ -148,16 +208,24 @@ export class PackageFunctions {
148
208
  chartData.series?.some((series) => series.points.some((p) => p.x === 0)))
149
209
  substituteZeroes(chartData);
150
210
  const chartLogOptions: LogOptions = {logX: chartData.chartOptions?.logX, logY: chartData.chartOptions?.logY};
151
- const fitResult = calculateSeriesStats(chartData.series![seriesNumber], seriesNumber, chartLogOptions, cell, true);
152
- return fitResult[propName as keyof FitStatistics];
211
+ // resolve by name so both current statistic names and legacy ones from saved projects work
212
+ const fitResult = calculateSeriesFit(chartData.series![seriesNumber], seriesNumber, chartLogOptions, cell, true);
213
+ return getStatistic(fitResult, propName) ?? null;
153
214
  });
154
215
 
155
216
  df.columns.insert(column, df.columns.names().indexOf(colName) + 1);
156
217
  return column;
157
218
  }
158
219
 
159
- @grok.decorators.func({meta: {vectorFunc: 'true', role: 'transform'}})
160
- static addAggrStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, aggrType: string): DG.Column {
220
+ @grok.decorators.func({
221
+ name: 'Add Aggregated Curve Statistic Column',
222
+ description: 'Aggregate a fit statistic across all series of a curve into a new column.',
223
+ meta: {vectorFunc: 'true', role: 'transform'},
224
+ })
225
+ static addAggrStatisticsColumn(table: DG.DataFrame,
226
+ @grok.decorators.param({options: {description: 'Name of the curve column to read'}}) colName: string,
227
+ @grok.decorators.param({options: {choices: ['rSquared', 'auc', 'interceptX', 'interceptY', 'slope', 'top', 'bottom'], initialValue: 'interceptX', description: 'Fit statistic to aggregate. interceptX is IC50, top and bottom are max/min Y'}}) propName: string,
228
+ @grok.decorators.param({options: {choices: ['min', 'max', 'avg', 'med', 'q1', 'q2', 'q3'], initialValue: 'med', description: 'Aggregation applied across the series of each curve'}}) aggrType: string): DG.Column {
161
229
  const df = table;
162
230
  const col = df.col(colName)!;
163
231
  const nName = `${colName} ${aggrType} ${propName}`;
@@ -184,6 +252,41 @@ export class PackageFunctions {
184
252
  return column;
185
253
  }
186
254
 
255
+ /* The two functions above address the curve column by NAME, because their
256
+ * `colName` string is what the "+" buttons in the Fit pane and the Data to
257
+ * Curves pipeline pass, and both are recorded as `role: transform` steps that
258
+ * must keep replaying. On a pipeline canvas a name string means no column
259
+ * picker and no `fit` filter, so these twins take a real column slot and
260
+ * delegate to the same implementation. */
261
+
262
+ @grok.decorators.func({
263
+ name: 'Add Curve Statistic',
264
+ description: 'Extracts a fit statistic from one series of a curve column into a new column.',
265
+ outputs: [{name: 'result', type: 'column'}],
266
+ meta: {vectorFunc: 'true', role: 'transform'},
267
+ })
268
+ static addCurveStatistic(
269
+ @grok.decorators.param({options: {caption: 'Table', nullable: false}}) table: DG.DataFrame,
270
+ @grok.decorators.param({type: 'column', options: {semType: 'fit', caption: 'Curves', nullable: false, description: 'Column of fitted curves'}}) curvesCol: DG.Column,
271
+ @grok.decorators.param({type: 'string', options: {caption: 'Statistic', nullable: false, choices: ['rSquared', 'auc', 'interceptX', 'interceptY', 'slope', 'top', 'bottom'], initialValue: 'interceptX', description: 'interceptX is IC50, top and bottom are max/min Y'}}) statistic: string = 'interceptX',
272
+ @grok.decorators.param({type: 'int', options: {caption: 'Series', nullable: false, initialValue: '0', description: 'Zero-based index of the curve series'}}) seriesNumber: number = 0): DG.Column {
273
+ return PackageFunctions.addStatisticsColumn(table, curvesCol.name, statistic, seriesNumber);
274
+ }
275
+
276
+ @grok.decorators.func({
277
+ name: 'Add Aggregated Curve Statistic',
278
+ description: 'Aggregates a fit statistic across all series of a curve column into a new column.',
279
+ outputs: [{name: 'result', type: 'column'}],
280
+ meta: {vectorFunc: 'true', role: 'transform'},
281
+ })
282
+ static addAggrCurveStatistic(
283
+ @grok.decorators.param({options: {caption: 'Table', nullable: false}}) table: DG.DataFrame,
284
+ @grok.decorators.param({type: 'column', options: {semType: 'fit', caption: 'Curves', nullable: false, description: 'Column of fitted curves'}}) curvesCol: DG.Column,
285
+ @grok.decorators.param({type: 'string', options: {caption: 'Statistic', nullable: false, choices: ['rSquared', 'auc', 'interceptX', 'interceptY', 'slope', 'top', 'bottom'], initialValue: 'interceptX', description: 'interceptX is IC50, top and bottom are max/min Y'}}) statistic: string = 'interceptX',
286
+ @grok.decorators.param({type: 'string', options: {caption: 'Aggregation', nullable: false, choices: ['med', 'avg', 'min', 'max', 'q1', 'q2', 'q3'], initialValue: 'med', description: 'Applied across the series of each curve'}}) aggregation: string = 'med'): DG.Column {
287
+ return PackageFunctions.addAggrStatisticsColumn(table, curvesCol.name, statistic, aggregation);
288
+ }
289
+
187
290
  @grok.decorators.func({description: 'Returns XML 3DX curve converter function', meta: {role: 'curveConverter', curveFormat: '3dx'}})
188
291
  static convertXmlCurveToJsonFunc(): (value: string) => string {
189
292
  return convertXmlCurveToJson;
@@ -224,8 +327,11 @@ export class PackageFunctions {
224
327
  return view;
225
328
  }
226
329
 
227
- @grok.decorators.fileHandler({ext: 'pzfx'})
228
- static pzfxFileHandler(@grok.decorators.param({type: 'list'}) bytes: Uint8Array): DG.DataFrame[] {
330
+ @grok.decorators.fileHandler({
331
+ ext: 'pzfx',
332
+ description: 'Open a GraphPad Prism (.pzfx) file as data tables, fitting XY curve tables.',
333
+ })
334
+ static pzfxFileHandler(@grok.decorators.param({type: 'list', options: {description: 'Raw bytes of the .pzfx file'}}) bytes: Uint8Array): DG.DataFrame[] {
229
335
  const text = new TextDecoder().decode(new Uint8Array(bytes));
230
336
  const tables = parsePzfxXml(text);
231
337
  const results: DG.DataFrame[] = [];