@datagrok/curves 1.10.3 → 1.10.5

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,15 +1,15 @@
1
1
  {
2
2
  "name": "@datagrok/curves",
3
3
  "friendlyName": "Curves",
4
- "version": "1.10.3",
4
+ "version": "1.10.5",
5
5
  "description": "Curves provides support for fitted curves (such as dose-response curves), including in-grid rendering, storing charts in cells, interactivity, and automatic fitting.",
6
6
  "author": {
7
7
  "name": "Dmytro Kovalyov",
8
8
  "email": "dkovalyov@datagrok.ai"
9
9
  },
10
10
  "dependencies": {
11
- "@datagrok-libraries/statistics": "^1.9.0",
12
- "@datagrok-libraries/utils": "^4.6.0",
11
+ "@datagrok-libraries/statistics": "^1.9.1",
12
+ "@datagrok-libraries/utils": "^4.6.3",
13
13
  "@types/wu": "^2.1.42",
14
14
  "@typescript-eslint/eslint-plugin": "^5.62.0",
15
15
  "@typescript-eslint/parser": "^5.62.0",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "css-loader": "^5.0.0",
27
- "datagrok-tools": "^4.14.20",
27
+ "datagrok-tools": "^4.14.45",
28
28
  "source-map-loader": "^4.0.1",
29
29
  "style-loader": "^2.0.0",
30
30
  "ts-loader": "^9.5.1",
@@ -0,0 +1,353 @@
1
+ #name: calculateMSR
2
+ #description: Calculates Minimum Significant Ratio (MSR) for compounds based on IC50 values, run dates, assay names, and target entities.
3
+ #environment: channels: [Conda-forge], dependencies: [python=3.12, {pip: [statsmodels]}]
4
+ #language: python
5
+ #tags: Transform
6
+ #top-menu: Curves | Calculate MSR
7
+ #input: dataframe table [Input data table]
8
+ #input: column ic50Column [IC50 column]
9
+ #input: column compoundIdColumn [Compound ID column]
10
+ #input: column runDateColumn [Run date column]
11
+ #input: column assayNameColumn [Assay name column]
12
+ #input: column targetEntityColumn [Target entity column]
13
+ #output: dataframe res {action:join(table)}
14
+
15
+ import pandas as pd
16
+ import numpy as np
17
+ import warnings
18
+ from statsmodels.regression.mixed_linear_model import MixedLM
19
+ from typing import Dict, Tuple, Optional
20
+ from scipy import stats
21
+
22
+
23
+ def prepare_data(df, ic50_col, compound_col,
24
+ run_date_col, assay_col, target_col):
25
+ """Prepare and clean the data for MSR calculation."""
26
+
27
+ # Make a copy and select relevant columns
28
+ df_work = df[[ic50_col, compound_col, run_date_col, assay_col, target_col]].copy()
29
+
30
+ # Remove rows with missing values
31
+ df_work = df_work.dropna()
32
+ # remove rows where reported_ic50 is not a valid float or is zero
33
+ df_work = df_work[df[ic50_col].apply(lambda x: isinstance(x, (int, float)) and x > 0)]
34
+ # Remove non-positive IC50 values
35
+ df_work = df_work[df_work[ic50_col] > 0]
36
+
37
+ # Calculate log10 IC50
38
+ df_work['log10_ic50'] = np.log10(df_work[ic50_col])
39
+
40
+ # Convert run_date to datetime if it's not already
41
+ if not pd.api.types.is_datetime64_any_dtype(df_work[run_date_col]):
42
+ df_work[run_date_col] = pd.to_datetime(df_work[run_date_col])
43
+
44
+ # Create numeric run_date for modeling (days since first run per group)
45
+ min_date = df_work[run_date_col].min()
46
+ df_work['run_date_numeric'] = (df_work[run_date_col] - min_date).dt.days
47
+
48
+ return df_work
49
+
50
+ def calculate_msr_mixed_model(group, compound, assay, target,
51
+ n_runs, n_measurements):
52
+ """Calculate MSR using mixed effects model for compounds with sufficient runs."""
53
+
54
+ try:
55
+ with warnings.catch_warnings():
56
+ warnings.simplefilter("ignore")
57
+
58
+ # For a single compound, we don't need fixed effects for compound
59
+ # We just need to model the variance components
60
+ # Random effect: run_date, Fixed effectercept only
61
+
62
+ # Create design matrix (just intercept)
63
+ exog = np.ones((len(group), 1))
64
+
65
+ model = MixedLM(
66
+ endog=group['log10_ic50'].values,
67
+ exog=exog,
68
+ groups=group['run_date_numeric'].values
69
+ )
70
+
71
+ result = model.fit(method='lbfgs', maxiter=1000)
72
+ # Extract variance components
73
+ residual_variance = result.scale # Within-run variance
74
+ random_effect_variance = float(result.cov_re[0][0]) if len(result.cov_re) > 0 and len(result.cov_re[0]) > 0 else 0 # Between-run variance
75
+
76
+ # Calculate s as square root of sum of variance components
77
+ s = np.sqrt(random_effect_variance + residual_variance)
78
+
79
+ # Calculate MSR = 10^(2*sqrt(2)*s)
80
+ msr = 10**(2 * np.sqrt(2) * s)
81
+
82
+ return {
83
+ 'compound_id': compound,
84
+ 'assay_name': assay,
85
+ 'target_entity': target,
86
+ 'database_msr': msr,
87
+ 'residual_variance': residual_variance,
88
+ 'run_date_variance': random_effect_variance,
89
+ 'total_variance': random_effect_variance + residual_variance,
90
+ 's_value': s,
91
+ 'n_runs': n_runs,
92
+ 'n_measurements': n_measurements,
93
+ 'method': 'mixed_model',
94
+ 'mean_log10_ic50': group['log10_ic50'].mean(),
95
+ 'geometric_mean_ic50': 10**group['log10_ic50'].mean()
96
+ }
97
+
98
+ except Exception as e:
99
+ print(e)
100
+ # Fallback to simple method if mixed model fails
101
+ return calculate_msr_simple(group, compound, assay, target, n_runs, n_measurements)
102
+
103
+ def calculate_msr_simple(group, compound, assay, target,
104
+ n_runs, n_measurements):
105
+ """Calculate MSR using simple variance decomposition for compounds with fewer runs."""
106
+
107
+ # Calculate run means
108
+ run_means = group.groupby('run_date_numeric')['log10_ic50'].agg(['mean', 'count']).reset_index()
109
+ run_means.columns = ['run_date_numeric', 'run_mean', 'n_per_run']
110
+
111
+ # Calculate overall mean
112
+ overall_mean = group['log10_ic50'].mean()
113
+
114
+ # Calculate between-run variance (if multiple runs)
115
+ if len(run_means) > 1:
116
+ between_run_variance = np.var(run_means['run_mean'], ddof=1)
117
+ else:
118
+ between_run_variance = 0
119
+
120
+ # Calculate within-run variance
121
+ within_run_variances = []
122
+ for run_date in group['run_date_numeric'].unique():
123
+ run_data = group[group['run_date_numeric'] == run_date]['log10_ic50']
124
+ if len(run_data) > 1:
125
+ within_run_variances.append(np.var(run_data, ddof=1))
126
+
127
+ if within_run_variances:
128
+ within_run_variance = np.mean(within_run_variances)
129
+ else:
130
+ # If no within-run replicates, estimate from total variance
131
+ total_variance = np.var(group['log10_ic50'], ddof=1)
132
+ within_run_variance = max(0, total_variance - between_run_variance)
133
+
134
+ # Calculate s as square root of sum of variance components
135
+ s = np.sqrt(between_run_variance + within_run_variance)
136
+
137
+ # Calculate MSR = 10^(2*sqrt(2)*s)
138
+ msr = 10**(2 * np.sqrt(2) * s)
139
+
140
+ return {
141
+ 'compound_id': compound,
142
+ 'assay_name': assay,
143
+ 'target_entity': target,
144
+ 'database_msr': msr,
145
+ 'residual_variance': within_run_variance,
146
+ 'run_date_variance': between_run_variance,
147
+ 'total_variance': between_run_variance + within_run_variance,
148
+ 's_value': s,
149
+ 'n_runs': n_runs,
150
+ 'n_measurements': n_measurements,
151
+ 'method': 'simple_variance',
152
+ 'mean_log10_ic50': overall_mean,
153
+ 'geometric_mean_ic50': 10**overall_mean
154
+ }
155
+
156
+ def calculate_msr_for_compound(group, ic50_col, compound_col,
157
+ run_date_col, min_runs, min_measurements,
158
+ compound, assay, target):
159
+ """Calculate MSR for a specific compound/assay/target combination."""
160
+
161
+ # Check minimum requirements
162
+ n_runs = group['run_date_numeric'].nunique()
163
+ n_measurements = len(group)
164
+
165
+ if n_measurements < min_measurements:
166
+ return None
167
+
168
+ if n_runs < 2: # Need at least 2 different runs to estimate between-run variance
169
+ return None
170
+
171
+ try:
172
+ # Method 1: Use mixed effects model if we have enough runs
173
+ if n_runs >= min_runs:
174
+ return calculate_msr_mixed_model(group, compound, assay, target, n_runs, n_measurements)
175
+ else:
176
+ # Method 2: Simple variance decomposition for fewer runs
177
+ return calculate_msr_simple(group, compound, assay, target, n_runs, n_measurements)
178
+
179
+ except Exception as e:
180
+ print("Model fitting failed for {compound}/{assay}/{target}: {ee}".format(
181
+ compound=compound, assay=assay, target=target, ee=str(e)
182
+ ))
183
+ # If both methods fail, return None
184
+ return None
185
+
186
+ def calculate_compound_database_msr(df,
187
+ ic50_col = 'reported_ic50',
188
+ compound_col = 'compound_id',
189
+ run_date_col = 'run_date',
190
+ assay_col = 'assay_name',
191
+ target_col = 'target_entity',
192
+ min_runs = 6,
193
+ min_measurements = 2):
194
+ """
195
+ Calculate Database MSR for each unique combination of compound_id, assay_name, and target_entity.
196
+ Each compound must have multiple measurements across different runs.
197
+
198
+ Parameters:
199
+ -----------
200
+ df
201
+ Input dataframe with assay data
202
+ ic50_col
203
+ Column name for IC50 values
204
+ compound_col
205
+ Column name for compound identifiers
206
+ run_date_col
207
+ Column name for run dates
208
+ assay_col
209
+ Column name for assay names
210
+ target_col
211
+ Column name for target entities
212
+ min_runs
213
+ Minimum number of different runs required for a compound
214
+ min_measurements
215
+ Minimum number of measurements required for a compound
216
+
217
+ Returns:
218
+ --------
219
+ pd.DataFrame
220
+ DataFrame with MSR values for each compound/assay/target combination
221
+ """
222
+
223
+ # Prepare the data
224
+ df_clean = prepare_data(df, ic50_col, compound_col, run_date_col, assay_col, target_col)
225
+
226
+ # Group by compound, assay, and target
227
+ results = []
228
+
229
+ for (compound, assay, target), group in df_clean.groupby([compound_col, assay_col, target_col]):
230
+ try:
231
+ msr_result = calculate_msr_for_compound(
232
+ group, ic50_col, compound_col, run_date_col,
233
+ min_runs, min_measurements, compound, assay, target
234
+ )
235
+ if msr_result is not None:
236
+ results.append(msr_result)
237
+ except Exception as e:
238
+ print("Error calculating MSR for {compound}/{assay}/{target}: {ee}".format(
239
+ compound=compound, assay=assay, target=target, ee=str(e)
240
+ ))
241
+ # Continue to next group if there's an error
242
+ continue
243
+
244
+ if not results:
245
+ return pd.DataFrame()
246
+
247
+ return pd.DataFrame(results)
248
+
249
+ def calculate_control_compound_msr(df, control_compounds,
250
+ ic50_col = 'reported_ic50',
251
+ compound_col = 'compound_id',
252
+ run_date_col = 'run_date',
253
+ assay_col = 'assay_name',
254
+ target_col = 'target_entity'):
255
+ """
256
+ Calculate Control Compound MSR for specified control compounds.
257
+ This is useful for assay performance monitoring.
258
+ """
259
+
260
+ control_df = df[df[compound_col].isin(control_compounds)]
261
+ return calculate_compound_database_msr(
262
+ control_df, ic50_col, compound_col, run_date_col, assay_col, target_col,
263
+ min_runs=6, min_measurements=6
264
+ )
265
+
266
+ def generate_msr_summary(msr_results):
267
+ """Generate a summary of MSR results with additional statistics."""
268
+
269
+ if msr_results.empty:
270
+ return msr_results
271
+
272
+ summary = msr_results.copy()
273
+
274
+ # Add interpretation categories
275
+ summary['msr_category'] = pd.cut(
276
+ summary['database_msr'],
277
+ bins=[0, 3, 5, 10, float('inf')],
278
+ labels=['Excellent (<3)', 'Good (3-5)', 'Fair (5-10)', 'Poor (>10)']
279
+ )
280
+
281
+ # Add percentage of variance from each source
282
+ summary['pct_run_date_variance'] = (
283
+ summary['run_date_variance'] / summary['total_variance'] * 100
284
+ ).fillna(0)
285
+ summary['pct_residual_variance'] = (
286
+ summary['residual_variance'] / summary['total_variance'] * 100
287
+ ).fillna(0)
288
+
289
+ # Add 95% confidence interval for the compound potency
290
+ # CI width = MSR gives the range where we expect 95% of measurements
291
+ summary['ic50_lower_95ci'] = summary['geometric_mean_ic50'] / summary['database_msr']
292
+ summary['ic50_upper_95ci'] = summary['geometric_mean_ic50'] * summary['database_msr']
293
+
294
+ return summary
295
+
296
+ def get_compounds_for_msr(df,
297
+ compound_col = 'compound_id',
298
+ run_date_col = 'run_date',
299
+ assay_col = 'assay_name',
300
+ target_col = 'target_entity',
301
+ min_measurements = 2):
302
+ """
303
+ Identify which compounds have sufficient data for MSR calculation.
304
+ """
305
+
306
+ # Count measurements per compound/assay/target combination
307
+ compound_counts = (df.groupby([compound_col, assay_col, target_col])
308
+ .agg({
309
+ run_date_col: 'nunique',
310
+ compound_col: 'count' # total measurements
311
+ })
312
+ .rename(columns={
313
+ run_date_col: 'n_runs',
314
+ compound_col: 'n_measurements'
315
+ })
316
+ .reset_index())
317
+
318
+ # Filter compounds with sufficient data
319
+ sufficient_data = compound_counts[
320
+ (compound_counts['n_measurements'] >= min_measurements) &
321
+ (compound_counts['n_runs'] >= 2)
322
+ ]
323
+
324
+ return sufficient_data.sort_values('n_measurements', ascending=False)
325
+
326
+
327
+ np.random.seed(42)
328
+ odf = table
329
+ # odf = pd.read_csv("assay.csv")
330
+ # compoundIdColumn = 'compound_id'
331
+ # runDateColumn = 'run_date'
332
+ # assayNameColumn = 'assay_name'
333
+ # targetEntityColumn = 'cell_line'
334
+ # ic50Column = 'reported_ic50'
335
+ sufficient_compounds = get_compounds_for_msr(odf, compound_col=compoundIdColumn, run_date_col=runDateColumn, assay_col=assayNameColumn, target_col=targetEntityColumn)
336
+ msr_results = calculate_compound_database_msr(odf, min_runs=2, min_measurements=2, ic50_col=ic50Column, compound_col=compoundIdColumn, run_date_col=runDateColumn, assay_col=assayNameColumn, target_col=targetEntityColumn)
337
+
338
+ # generate a dataset which is the same length as the input data, and for each corresponding row, have the results from the msr_results dataset except the compound_id, assay_name and target_entity. use these three for matching between the two
339
+ # res = msr_results
340
+
341
+ msr_results = msr_results.rename(columns=lambda x: f"{x} (msr)" if x not in ['compound_id', 'assay_name', 'target_entity'] else x) # give postfix
342
+ # Merge the results back to the original dataframe
343
+ res = odf.merge(
344
+ msr_results,
345
+ left_on=[compoundIdColumn, assayNameColumn, targetEntityColumn],
346
+ right_on=['compound_id', 'assay_name', 'target_entity'],
347
+ how='left',
348
+ suffixes=('', ' (msr)')
349
+ )
350
+
351
+ orig_columns_names = odf.columns.tolist()
352
+
353
+ res = res.drop(columns=orig_columns_names)
@@ -367,7 +367,6 @@ export function dataToCurvesUI() {
367
367
  wellLevelJoinCol: joinValues?.wellLevelCol?.name,
368
368
  parentLevelJoinCol: joinValues?.parentLevelCol?.name,
369
369
  });
370
- console.log(fc.toString());
371
370
  const needsCreationScript = table.tags[DG.Tags.CreationScript] && (!parentLevelData?.table || parentLevelData.table.tags[DG.Tags.CreationScript]);
372
371
  await fc.call(undefined, undefined, {processed: !needsCreationScript});
373
372
  //console.log(fc.getResultViews());
@@ -437,7 +437,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
437
437
  for (let i = 0; i < data.series?.length!; i++) {
438
438
  const series = data.series![i];
439
439
  const containsParams = series.parameters && series.parameters.length > 0;
440
- if (series.points.some((point) => point.x === undefined || point.y === undefined))
440
+ if (series.points.some((point) => point.x === undefined || point.y === undefined) || series.points.length <= 1)
441
441
  continue;
442
442
  series.points.sort((a, b) => a.x - b.x);
443
443
 
@@ -25,7 +25,8 @@ export class MultiCurveViewer extends DG.JsViewer {
25
25
  canvas: HTMLCanvasElement;
26
26
  gridCellWidget: DG.GridCellWidget;
27
27
  curvesColumnNames?: string[] = [];
28
- showSelectedRowsCurves: boolean = false;
28
+ legendColumnName?: string;
29
+ showSelectedRowsCurves: boolean = true;
29
30
  showCurrentRowCurve: boolean = true;
30
31
  showMouseOverRowCurve: boolean = true;
31
32
  mergeColumnSeries: boolean = false;
@@ -63,14 +64,15 @@ export class MultiCurveViewer extends DG.JsViewer {
63
64
  });
64
65
 
65
66
  this.curvesColumnNames = this.addProperty('curvesColumnNames', DG.TYPE.COLUMN_LIST, [], {semType: FitConstants.FIT_SEM_TYPE});
67
+ this.legendColumnName = this.addProperty('legendColumnName', DG.TYPE.STRING, '', {description: 'Column to be used for curves names'});
66
68
 
67
- this.showSelectedRowsCurves = this.bool('showSelectedRowsCurves', false, {description: 'Adds curves from the selected rows'});
69
+ this.showSelectedRowsCurves = this.bool('showSelectedRowsCurves', true, {description: 'Adds curves from the selected rows'});
68
70
  this.showCurrentRowCurve = this.bool('showCurrentRowCurve', true);
69
71
  this.showMouseOverRowCurve = this.bool('showMouseOverRowCurve', true);
70
72
  this.mergeColumnSeries = this.bool('mergeColumnSeries', false);
71
73
 
72
74
  for (const p of fitChartDataProperties)
73
- this.addProperty(p.name === 'mergeSeries' ? 'mergeCellSeries' : p.name, p.propertyType, p.defaultValue, p.options);
75
+ this.addProperty(p.name === 'mergeSeries' ? 'mergeCellSeries' : p.name, p.propertyType, p.defaultValue, {...p.options, showSlider: false});
74
76
  }
75
77
 
76
78
  static fromChartData(chartData: IFitChartData): MultiCurveViewer {
@@ -133,9 +135,17 @@ export class MultiCurveViewer extends DG.JsViewer {
133
135
  if (!tableCell || !tableCell.value)
134
136
  continue;
135
137
  const cellCurves = getOrCreateParsedChartData(tableCell);
136
- cellCurves.series?.forEach((series) => series.columnName = tableCell.column.name);
138
+ if (!cellCurves.series || cellCurves.series.length === 0)
139
+ continue;
140
+ cellCurves.series.forEach((series) => series.columnName = tableCell.column.name);
141
+ const legendCol = !this.legendColumnName || !this.dataFrame.col(this.legendColumnName) ? null : this.dataFrame.col(this.legendColumnName);
142
+ for (let j = 0; j < cellCurves.series.length; j++) {
143
+ const series = cellCurves.series[j];
144
+ if (legendCol)
145
+ series.auxLegendName = cellCurves.series.length > 1 ? `${legendCol.get(i)} ${series.name}` : `${legendCol.get(i)}`;
146
+ }
137
147
  const currentChartOptions = cellCurves.chartOptions;
138
- if (currentChartOptions !== undefined && currentChartOptions !== null)
148
+ if (currentChartOptions != null)
139
149
  chartOptions[chartOptions.length] = currentChartOptions;
140
150
  if (mergeCellSeries) {
141
151
  const mergedSeries = mergeSeries(cellCurves.series!)!;
@@ -151,6 +161,7 @@ export class MultiCurveViewer extends DG.JsViewer {
151
161
  this.data.series?.push(...JSON.parse(JSON.stringify(series)));
152
162
  }
153
163
  this.data.chartOptions = mergeChartOptions(chartOptions);
164
+ this.data.chartOptions.useAuxLegendNames = true;
154
165
  this.mergeViewerChartOptions();
155
166
  this.data.series?.forEach((series, i) => {
156
167
  if (!series.fitLineColor && !series.pointColor) {
@@ -196,8 +207,9 @@ export class MultiCurveViewer extends DG.JsViewer {
196
207
  this.render();
197
208
  }
198
209
  });
199
- if (this.isInTrellis())
200
- this.createChartData();
210
+ this.createChartData();
211
+ if (!this.isInTrellis())
212
+ this.render();
201
213
  }
202
214
 
203
215
  _showErrorMessage(msg: string) {
@@ -96,6 +96,7 @@ interface FitLegendColumnlabelSeriesRenderOptions extends FitLegendRenderOptions
96
96
  drawnCurvesInLegend: number;
97
97
  showColumnLabel?: boolean;
98
98
  seriesIdx?: number;
99
+ useAuxLegendNames?: boolean;
99
100
  }
100
101
 
101
102
 
@@ -437,7 +438,7 @@ export function renderLegend(g: CanvasRenderingContext2D, data: IFitChartData, r
437
438
  const currentSeries = series![j];
438
439
  if (currentSeries.name === '' || currentSeries.name === null || currentSeries.name === undefined)
439
440
  continue;
440
- renderLegendSeries(g, currentSeries, {dataBox: dataBox, ratio: ratio,
441
+ renderLegendSeries(g, currentSeries, {dataBox: dataBox, ratio: ratio, useAuxLegendNames: data.chartOptions?.useAuxLegendNames,
441
442
  columnIdx: i, drawnCurvesInLegend, showColumnLabel: data.chartOptions?.showColumnLabel, seriesIdx: j});
442
443
  drawnCurvesInLegend++;
443
444
  }
@@ -466,7 +467,8 @@ function renderLegendSeries(g: CanvasRenderingContext2D, series: IFitSeries, ren
466
467
  g.beginPath();
467
468
  g.strokeStyle = fitLineColor;
468
469
  g.lineWidth = 2 * ratio;
469
- const textWidth = g.measureText(series.name!).width;
470
+ const nameToRender = renderOptions.useAuxLegendNames ? series.auxLegendName ?? series.name! : series.name!;
471
+ const textWidth = g.measureText(nameToRender).width;
470
472
  g.moveTo(dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_PX_WIDTH - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
471
473
  dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
472
474
  (showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) +
@@ -482,8 +484,7 @@ function renderLegendSeries(g: CanvasRenderingContext2D, series: IFitSeries, ren
482
484
  (columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend,
483
485
  pointColor, FitConstants.POINT_PX_SIZE * ratio);
484
486
  g.fillStyle = fitLineColor;
485
- g.fillText(series.name!, dataBox.maxX - textWidth,
486
- dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN + (showColumnLabel ?
487
- FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
487
+ g.fillText(nameToRender, dataBox.maxX - textWidth, dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN + (showColumnLabel ?
488
+ FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
488
489
  g.stroke();
489
490
  }
@@ -7,6 +7,15 @@ import * as grok from 'datagrok-api/grok';
7
7
  import * as DG from 'datagrok-api/dg';
8
8
 
9
9
 
10
+ export namespace scripts {
11
+ /**
12
+ Calculates Minimum Significant Ratio (MSR) for compounds based on IC50 values, run dates, assay names, and target entities.
13
+ */
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
+ return await grok.functions.call('Curves:CalculateMSR', { table, ic50Column, compoundIdColumn, runDateColumn, assayNameColumn, targetEntityColumn });
16
+ }
17
+ }
18
+
10
19
  export namespace queries {
11
20
  export async function getPlates(): Promise<DG.DataFrame> {
12
21
  return await grok.data.query('Curves:GetPlates', {});
@@ -80,8 +89,8 @@ export namespace queries {
80
89
  }
81
90
 
82
91
  export namespace funcs {
83
- export async function platesAppTreeBrowserTempDisabled(treeNode: any , browseView: DG.View ): Promise<void> {
84
- return await grok.functions.call('Curves:PlatesAppTreeBrowserTempDisabled', { treeNode, browseView });
92
+ export async function platesAppTreeBrowserTempDisabled(treeNode: any ): Promise<void> {
93
+ return await grok.functions.call('Curves:PlatesAppTreeBrowserTempDisabled', { treeNode });
85
94
  }
86
95
 
87
96
  export async function fitChartCellRenderer(): Promise<any> {
@@ -113,8 +122,8 @@ export namespace funcs {
113
122
  return await grok.functions.call('Curves:InitCurves', {});
114
123
  }
115
124
 
116
- 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): Promise<DG.DataFrame> {
117
- return await grok.functions.call('Curves:DataToCurves', { df, concentrationCol, readoutCol, batchIDCol, assayCol, runIDCol, compoundIDCol, targetEntityCol, excludeOutliersCol, parentTable, fitParamColumns, reportedIC50Column, reportedQualifiedIC50Column, experimentIDColumn, qualifierColumn, additionalColumns });
125
+ 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): Promise<DG.DataFrame> {
126
+ 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 });
118
127
  }
119
128
 
120
129
  export async function dataToCurvesTopMenu(): Promise<any> {
@@ -157,10 +166,6 @@ export namespace funcs {
157
166
  return await grok.functions.call('Curves:CheckFileIsPlate', { content });
158
167
  }
159
168
 
160
- export async function platesApp(): Promise<DG.View> {
161
- return await grok.functions.call('Curves:PlatesApp', {});
162
- }
163
-
164
169
  export async function getPlateByBarcode(barcode: string ): Promise<any> {
165
170
  return await grok.functions.call('Curves:GetPlateByBarcode', { barcode });
166
171
  }