@datagrok/curves 1.10.10 → 1.10.12

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.10.10",
4
+ "version": "1.10.12",
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",
@@ -1,9 +1,9 @@
1
- #name: calculateMSR
2
- #description: Calculates Minimum Significant Ratio (MSR) for compounds based on IC50 values, run dates, assay names, and target entities.
1
+ #name: Calculate MSR
2
+ #description: Calculates Minimum Significant Ratio (MSR) for compounds based on IC50 values, run dates, assay names, and target entities.
3
3
  #environment: channels: [Conda-forge], dependencies: [python=3.12, pip, {pip: [statsmodels]}]
4
4
  #language: python
5
5
  #tags: Transform
6
- #top-menu: Data | Curves | Calculate MSR
6
+ #top-menu: Data | Curves | Calculate MSR...
7
7
  #input: dataframe table [Input data table]
8
8
  #input: column ic50Column [IC50 column]
9
9
  #input: column compoundIdColumn [Compound ID column]
@@ -20,65 +20,65 @@ from typing import Dict, Tuple, Optional
20
20
  from scipy import stats
21
21
 
22
22
 
23
- def prepare_data(df, ic50_col, compound_col,
23
+ def prepare_data(df, ic50_col, compound_col,
24
24
  run_date_col, assay_col, target_col):
25
25
  """Prepare and clean the data for MSR calculation."""
26
-
26
+
27
27
  # Make a copy and select relevant columns
28
28
  df_work = df[[ic50_col, compound_col, run_date_col, assay_col, target_col]].copy()
29
-
29
+
30
30
  # Remove rows with missing values
31
31
  df_work = df_work.dropna()
32
32
  # remove rows where reported_ic50 is not a valid float or is zero
33
33
  df_work = df_work[df[ic50_col].apply(lambda x: isinstance(x, (int, float)) and x > 0)]
34
34
  # Remove non-positive IC50 values
35
35
  df_work = df_work[df_work[ic50_col] > 0]
36
-
36
+
37
37
  # Calculate log10 IC50
38
38
  df_work['log10_ic50'] = np.log10(df_work[ic50_col])
39
-
39
+
40
40
  # Convert run_date to datetime if it's not already
41
41
  if not pd.api.types.is_datetime64_any_dtype(df_work[run_date_col]):
42
42
  df_work[run_date_col] = pd.to_datetime(df_work[run_date_col])
43
-
43
+
44
44
  # Create numeric run_date for modeling (days since first run per group)
45
45
  min_date = df_work[run_date_col].min()
46
46
  df_work['run_date_numeric'] = (df_work[run_date_col] - min_date).dt.days
47
-
47
+
48
48
  return df_work
49
49
 
50
50
  def calculate_msr_mixed_model(group, compound, assay, target,
51
51
  n_runs, n_measurements):
52
52
  """Calculate MSR using mixed effects model for compounds with sufficient runs."""
53
-
53
+
54
54
  try:
55
55
  with warnings.catch_warnings():
56
56
  warnings.simplefilter("ignore")
57
-
57
+
58
58
  # For a single compound, we don't need fixed effects for compound
59
59
  # We just need to model the variance components
60
60
  # Random effect: run_date, Fixed effectercept only
61
-
61
+
62
62
  # Create design matrix (just intercept)
63
63
  exog = np.ones((len(group), 1))
64
-
64
+
65
65
  model = MixedLM(
66
66
  endog=group['log10_ic50'].values,
67
67
  exog=exog,
68
68
  groups=group['run_date_numeric'].values
69
69
  )
70
-
70
+
71
71
  result = model.fit(method='lbfgs', maxiter=1000)
72
72
  # Extract variance components
73
73
  residual_variance = result.scale # Within-run variance
74
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
-
75
+
76
76
  # Calculate s as square root of sum of variance components
77
77
  s = np.sqrt(random_effect_variance + residual_variance)
78
-
78
+
79
79
  # Calculate MSR = 10^(2*sqrt(2)*s)
80
80
  msr = 10**(2 * np.sqrt(2) * s)
81
-
81
+
82
82
  return {
83
83
  'compound_id': compound,
84
84
  'assay_name': assay,
@@ -94,7 +94,7 @@ def calculate_msr_mixed_model(group, compound, assay, target,
94
94
  'mean_log10_ic50': group['log10_ic50'].mean(),
95
95
  'geometric_mean_ic50': 10**group['log10_ic50'].mean()
96
96
  }
97
-
97
+
98
98
  except Exception as e:
99
99
  print(e)
100
100
  # Fallback to simple method if mixed model fails
@@ -103,40 +103,40 @@ def calculate_msr_mixed_model(group, compound, assay, target,
103
103
  def calculate_msr_simple(group, compound, assay, target,
104
104
  n_runs, n_measurements):
105
105
  """Calculate MSR using simple variance decomposition for compounds with fewer runs."""
106
-
106
+
107
107
  # Calculate run means
108
108
  run_means = group.groupby('run_date_numeric')['log10_ic50'].agg(['mean', 'count']).reset_index()
109
109
  run_means.columns = ['run_date_numeric', 'run_mean', 'n_per_run']
110
-
110
+
111
111
  # Calculate overall mean
112
112
  overall_mean = group['log10_ic50'].mean()
113
-
113
+
114
114
  # Calculate between-run variance (if multiple runs)
115
115
  if len(run_means) > 1:
116
116
  between_run_variance = np.var(run_means['run_mean'], ddof=1)
117
117
  else:
118
118
  between_run_variance = 0
119
-
119
+
120
120
  # Calculate within-run variance
121
121
  within_run_variances = []
122
122
  for run_date in group['run_date_numeric'].unique():
123
123
  run_data = group[group['run_date_numeric'] == run_date]['log10_ic50']
124
124
  if len(run_data) > 1:
125
125
  within_run_variances.append(np.var(run_data, ddof=1))
126
-
126
+
127
127
  if within_run_variances:
128
128
  within_run_variance = np.mean(within_run_variances)
129
129
  else:
130
130
  # If no within-run replicates, estimate from total variance
131
131
  total_variance = np.var(group['log10_ic50'], ddof=1)
132
132
  within_run_variance = max(0, total_variance - between_run_variance)
133
-
133
+
134
134
  # Calculate s as square root of sum of variance components
135
135
  s = np.sqrt(between_run_variance + within_run_variance)
136
-
136
+
137
137
  # Calculate MSR = 10^(2*sqrt(2)*s)
138
138
  msr = 10**(2 * np.sqrt(2) * s)
139
-
139
+
140
140
  return {
141
141
  'compound_id': compound,
142
142
  'assay_name': assay,
@@ -153,21 +153,21 @@ def calculate_msr_simple(group, compound, assay, target,
153
153
  'geometric_mean_ic50': 10**overall_mean
154
154
  }
155
155
 
156
- def calculate_msr_for_compound(group, ic50_col, compound_col,
156
+ def calculate_msr_for_compound(group, ic50_col, compound_col,
157
157
  run_date_col, min_runs, min_measurements,
158
158
  compound, assay, target):
159
159
  """Calculate MSR for a specific compound/assay/target combination."""
160
-
160
+
161
161
  # Check minimum requirements
162
162
  n_runs = group['run_date_numeric'].nunique()
163
163
  n_measurements = len(group)
164
-
164
+
165
165
  if n_measurements < min_measurements:
166
166
  return None
167
-
167
+
168
168
  if n_runs < 2: # Need at least 2 different runs to estimate between-run variance
169
169
  return None
170
-
170
+
171
171
  try:
172
172
  # Method 1: Use mixed effects model if we have enough runs
173
173
  if n_runs >= min_runs:
@@ -175,7 +175,7 @@ def calculate_msr_for_compound(group, ic50_col, compound_col,
175
175
  else:
176
176
  # Method 2: Simple variance decomposition for fewer runs
177
177
  return calculate_msr_simple(group, compound, assay, target, n_runs, n_measurements)
178
-
178
+
179
179
  except Exception as e:
180
180
  print("Model fitting failed for {compound}/{assay}/{target}: {ee}".format(
181
181
  compound=compound, assay=assay, target=target, ee=str(e)
@@ -183,7 +183,7 @@ def calculate_msr_for_compound(group, ic50_col, compound_col,
183
183
  # If both methods fail, return None
184
184
  return None
185
185
 
186
- def calculate_compound_database_msr(df,
186
+ def calculate_compound_database_msr(df,
187
187
  ic50_col = 'reported_ic50',
188
188
  compound_col = 'compound_id',
189
189
  run_date_col = 'run_date',
@@ -194,42 +194,42 @@ def calculate_compound_database_msr(df,
194
194
  """
195
195
  Calculate Database MSR for each unique combination of compound_id, assay_name, and target_entity.
196
196
  Each compound must have multiple measurements across different runs.
197
-
197
+
198
198
  Parameters:
199
199
  -----------
200
- df
200
+ df
201
201
  Input dataframe with assay data
202
- ic50_col
202
+ ic50_col
203
203
  Column name for IC50 values
204
- compound_col
204
+ compound_col
205
205
  Column name for compound identifiers
206
- run_date_col
206
+ run_date_col
207
207
  Column name for run dates
208
- assay_col
208
+ assay_col
209
209
  Column name for assay names
210
- target_col
210
+ target_col
211
211
  Column name for target entities
212
- min_runs
212
+ min_runs
213
213
  Minimum number of different runs required for a compound
214
- min_measurements
214
+ min_measurements
215
215
  Minimum number of measurements required for a compound
216
-
216
+
217
217
  Returns:
218
218
  --------
219
219
  pd.DataFrame
220
220
  DataFrame with MSR values for each compound/assay/target combination
221
221
  """
222
-
222
+
223
223
  # Prepare the data
224
224
  df_clean = prepare_data(df, ic50_col, compound_col, run_date_col, assay_col, target_col)
225
-
225
+
226
226
  # Group by compound, assay, and target
227
227
  results = []
228
-
228
+
229
229
  for (compound, assay, target), group in df_clean.groupby([compound_col, assay_col, target_col]):
230
230
  try:
231
231
  msr_result = calculate_msr_for_compound(
232
- group, ic50_col, compound_col, run_date_col,
232
+ group, ic50_col, compound_col, run_date_col,
233
233
  min_runs, min_measurements, compound, assay, target
234
234
  )
235
235
  if msr_result is not None:
@@ -240,10 +240,10 @@ def calculate_compound_database_msr(df,
240
240
  ))
241
241
  # Continue to next group if there's an error
242
242
  continue
243
-
243
+
244
244
  if not results:
245
245
  return pd.DataFrame()
246
-
246
+
247
247
  return pd.DataFrame(results)
248
248
 
249
249
  def calculate_control_compound_msr(df, control_compounds,
@@ -256,7 +256,7 @@ def calculate_control_compound_msr(df, control_compounds,
256
256
  Calculate Control Compound MSR for specified control compounds.
257
257
  This is useful for assay performance monitoring.
258
258
  """
259
-
259
+
260
260
  control_df = df[df[compound_col].isin(control_compounds)]
261
261
  return calculate_compound_database_msr(
262
262
  control_df, ic50_col, compound_col, run_date_col, assay_col, target_col,
@@ -265,19 +265,19 @@ def calculate_control_compound_msr(df, control_compounds,
265
265
 
266
266
  def generate_msr_summary(msr_results):
267
267
  """Generate a summary of MSR results with additional statistics."""
268
-
268
+
269
269
  if msr_results.empty:
270
270
  return msr_results
271
-
271
+
272
272
  summary = msr_results.copy()
273
-
273
+
274
274
  # Add interpretation categories
275
275
  summary['msr_category'] = pd.cut(
276
- summary['database_msr'],
277
- bins=[0, 3, 5, 10, float('inf')],
276
+ summary['database_msr'],
277
+ bins=[0, 3, 5, 10, float('inf')],
278
278
  labels=['Excellent (<3)', 'Good (3-5)', 'Fair (5-10)', 'Poor (>10)']
279
279
  )
280
-
280
+
281
281
  # Add percentage of variance from each source
282
282
  summary['pct_run_date_variance'] = (
283
283
  summary['run_date_variance'] / summary['total_variance'] * 100
@@ -285,15 +285,15 @@ def generate_msr_summary(msr_results):
285
285
  summary['pct_residual_variance'] = (
286
286
  summary['residual_variance'] / summary['total_variance'] * 100
287
287
  ).fillna(0)
288
-
288
+
289
289
  # Add 95% confidence interval for the compound potency
290
290
  # CI width = MSR gives the range where we expect 95% of measurements
291
291
  summary['ic50_lower_95ci'] = summary['geometric_mean_ic50'] / summary['database_msr']
292
292
  summary['ic50_upper_95ci'] = summary['geometric_mean_ic50'] * summary['database_msr']
293
-
293
+
294
294
  return summary
295
295
 
296
- def get_compounds_for_msr(df,
296
+ def get_compounds_for_msr(df,
297
297
  compound_col = 'compound_id',
298
298
  run_date_col = 'run_date',
299
299
  assay_col = 'assay_name',
@@ -302,7 +302,7 @@ def get_compounds_for_msr(df,
302
302
  """
303
303
  Identify which compounds have sufficient data for MSR calculation.
304
304
  """
305
-
305
+
306
306
  # Count measurements per compound/assay/target combination
307
307
  compound_counts = (df.groupby([compound_col, assay_col, target_col])
308
308
  .agg({
@@ -314,13 +314,13 @@ def get_compounds_for_msr(df,
314
314
  compound_col: 'n_measurements'
315
315
  })
316
316
  .reset_index())
317
-
317
+
318
318
  # Filter compounds with sufficient data
319
319
  sufficient_data = compound_counts[
320
- (compound_counts['n_measurements'] >= min_measurements) &
320
+ (compound_counts['n_measurements'] >= min_measurements) &
321
321
  (compound_counts['n_runs'] >= 2)
322
322
  ]
323
-
323
+
324
324
  return sufficient_data.sort_values('n_measurements', ascending=False)
325
325
 
326
326
 
@@ -350,4 +350,4 @@ res = odf.merge(
350
350
 
351
351
  orig_columns_names = odf.columns.tolist()
352
352
 
353
- res = res.drop(columns=orig_columns_names)
353
+ res = res.drop(columns=orig_columns_names)
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-len */
2
2
 
3
- import {FIT_FUNCTION_4PL_DOSE_RESPONSE, FIT_FUNCTION_4PL_REGRESSION, FitChartData, FitMarkerType, IFitSeries} from '@datagrok-libraries/statistics/src/fit/fit-curve';
3
+ import {FIT_FUNCTION_4PL_DOSE_RESPONSE, FitChartData, FitMarkerType, IFitSeries} from '@datagrok-libraries/statistics/src/fit/fit-curve';
4
4
  import * as DG from 'datagrok-api/dg';
5
5
  import * as grok from 'datagrok-api/grok';
6
6
  import * as ui from 'datagrok-api/ui';
@@ -188,6 +188,7 @@ function createWellTableForm(onTableChange: (t: DG.DataFrame | null) => void) {
188
188
  let batchIDColInput: DG.InputBase<DG.Column | null>;
189
189
  let runIDColInput: DG.InputBase<DG.Column | null>;
190
190
  let targetEntityColInput: DG.InputBase<DG.Column | null>;
191
+ let wellLevelAdditionalColumnsInput: DG.InputBase<DG.Column[] | null>;
191
192
  const form = ui.form([]);
192
193
 
193
194
  const onTableInputChange = () => {
@@ -202,6 +203,7 @@ function createWellTableForm(onTableChange: (t: DG.DataFrame | null) => void) {
202
203
  batchIDColInput = ui.input.column('Batch ID', {table: df, nullable: false, tooltipText: 'Column with batch IDs. this column along with the Assay column will be used to group the data into curves'});
203
204
  runIDColInput = ui.input.column('Run ID', {table: df, nullable: true, tooltipText: 'Column with run IDs. this column along with the Assay column will be used to group the data into curves'});
204
205
  targetEntityColInput = ui.input.column('Target Entity', {table: df, nullable: false, filter: (c) => c.isCategorical, tooltipText: 'Column with target entity names. This column will be used to group the data into curves'});
206
+ wellLevelAdditionalColumnsInput = ui.input.columns('Additional Columns', {table: df, nullable: true, tooltipText: 'Additional columns to include in the curves data'});
205
207
 
206
208
  assayColInput.value = wu(df.columns.categorical).find((c) => c.name.toLowerCase().includes('assay') && c.name.toLowerCase().includes('name')) ?? null;
207
209
  concentrationColInput.value = df.columns.firstWhere((c) => c.isNumerical && c.type !== DG.COLUMN_TYPE.DATE_TIME && c.name.toLowerCase().includes('concentration')) ?? null;
@@ -211,7 +213,8 @@ function createWellTableForm(onTableChange: (t: DG.DataFrame | null) => void) {
211
213
  batchIDColInput.value = df.columns.firstWhere((c) => c.name.toLowerCase().includes('batch') && c.name.toLowerCase().includes('id')) ?? null;
212
214
  runIDColInput.value = df.columns.firstWhere((c) => (c.name.toLowerCase().includes('run') || c.name.toLowerCase().includes('set')) && c.name.toLowerCase().includes('id')) ?? null;
213
215
  targetEntityColInput.value = df.columns.firstWhere((c) => c.isCategorical && (c.name.toLowerCase().includes('target') && c.name.toLowerCase().includes('entity'))) ?? null;
214
- ui.appendAll(form, [tableInput.root, assayColInput.root, batchIDColInput.root, runIDColInput.root, concentrationColInput.root, readoutColInput.root, compoundIDColInput.root, targetEntityColInput.root, excludeOutliersInput.root]);
216
+ wellLevelAdditionalColumnsInput.value = [];
217
+ ui.appendAll(form, [tableInput.root, assayColInput.root, batchIDColInput.root, runIDColInput.root, concentrationColInput.root, readoutColInput.root, compoundIDColInput.root, targetEntityColInput.root, excludeOutliersInput.root, wellLevelAdditionalColumnsInput.root]);
215
218
  };
216
219
  onTableInputChange();
217
220
  tableInput.onChanged.subscribe(() => onTableInputChange());
@@ -225,8 +228,9 @@ function createWellTableForm(onTableChange: (t: DG.DataFrame | null) => void) {
225
228
  excludeOutliersCol: excludeOutliersInput.value,
226
229
  targetEntityCol: targetEntityColInput.value,
227
230
  runIDCol: runIDColInput.value,
231
+ additionalColumns: wellLevelAdditionalColumnsInput.value ?? [],
228
232
  }), applyHistory: (v: {[key in 'assayCol' | 'batchIDCol' | 'concentrationCol' | 'readoutCol' | 'compoundIDCol' | 'excludeOutliersCol' | 'runIDCol' | 'targetEntityCol'
229
- ]: string | null}
233
+ ]: string | null} & {additionalColumns: string[] | null}
230
234
  ) => {
231
235
  const df = tableInput.value!;
232
236
  assayColInput.value = v.assayCol ? df.col(v.assayCol) : null;
@@ -237,6 +241,7 @@ function createWellTableForm(onTableChange: (t: DG.DataFrame | null) => void) {
237
241
  excludeOutliersInput.value = v.excludeOutliersCol ? df.col(v.excludeOutliersCol) : null;
238
242
  runIDColInput.value = v.runIDCol ? df.col(v.runIDCol) : null;
239
243
  targetEntityColInput.value = v.targetEntityCol ? df.col(v.targetEntityCol) : null;
244
+ wellLevelAdditionalColumnsInput.value = v.additionalColumns?.map((c) => df.col(c)).filter((c) => c != null) as DG.Column[];
240
245
  }
241
246
  };
242
247
  }
@@ -337,7 +342,7 @@ export function dataToCurvesUI() {
337
342
  };
338
343
  }
339
344
  const joinValues = joinEditor.getValues();
340
- const {table, assayCol, batchIDCol, concentrationCol, readoutCol, compoundIDCol, excludeOutliersCol, runIDCol, targetEntityCol} = formRes;
345
+ const {table, assayCol, batchIDCol, concentrationCol, readoutCol, compoundIDCol, excludeOutliersCol, runIDCol, targetEntityCol, additionalColumns} = formRes;
341
346
  const func = DG.Func.find({name: 'dataToCurves'})[0];
342
347
  if (!func) {
343
348
  grok.shell.error('Function dataToCurves not found');
@@ -355,6 +360,7 @@ export function dataToCurvesUI() {
355
360
  compoundIDCol: compoundIDCol,
356
361
  targetEntityCol: targetEntityCol,
357
362
  excludeOutliersCol: excludeOutliersCol,
363
+ wellLevelAdditionalColumns: (additionalColumns ?? []).map((c) => c?.name).filter((c) => !!c),
358
364
  // parentData:
359
365
  parentTable: parentLevelData?.table,
360
366
  fitParamColumns: parentLevelData?.fitParamColumns?.map((c) => c.name) ?? [],
@@ -366,6 +372,7 @@ export function dataToCurvesUI() {
366
372
  // joinInfo
367
373
  wellLevelJoinCol: joinValues?.wellLevelCol?.name,
368
374
  parentLevelJoinCol: joinValues?.parentLevelCol?.name,
375
+
369
376
  });
370
377
  const needsCreationScript = table.tags[DG.Tags.CreationScript] && (!parentLevelData?.table || parentLevelData.table.tags[DG.Tags.CreationScript]);
371
378
  await fc.call(undefined, undefined, {processed: !needsCreationScript});
@@ -395,7 +402,7 @@ export function dataToCurvesUI() {
395
402
  .show()
396
403
  .history(() => {
397
404
  const formRes = wellLevelForm.getValues();
398
- const {assayCol, batchIDCol, concentrationCol, readoutCol, compoundIDCol, excludeOutliersCol, runIDCol, targetEntityCol} = formRes;
405
+ const {assayCol, batchIDCol, concentrationCol, readoutCol, compoundIDCol, excludeOutliersCol, runIDCol, targetEntityCol, additionalColumns} = formRes;
399
406
  const obj = {
400
407
  assayCol: assayCol?.name,
401
408
  batchIDCol: batchIDCol?.name,
@@ -405,6 +412,7 @@ export function dataToCurvesUI() {
405
412
  excludeOutliersCol: excludeOutliersCol?.name,
406
413
  runIDCol: runIDCol?.name,
407
414
  targetEntityCol: targetEntityCol?.name,
415
+ additionalColumns: additionalColumns?.map((c) => c.name) ?? [],
408
416
  };
409
417
  return {wells: JSON.stringify(Object.fromEntries(Object.entries(obj).filter(([_, v]) => !!v)) ?? {}), parent: JSON.stringify(parentTableForm.getHistory() ?? {}), join: JSON.stringify(joinEditor.getHistory() ?? {})};
410
418
  }, (v) => {
@@ -424,7 +432,7 @@ export type WellTableParentData = {
424
432
  export async function convertDataToCurves(df: DG.DataFrame,
425
433
  concentrationCol: DG.Column, readoutCol: DG.Column, batchIDCol: DG.Column,
426
434
  assayCol: DG.Column, runIDCol: DG.Column, compoundIDCol: DG.Column, targetEntityCol: DG.Column, excludeOutliersCol?: DG.Column, parentData?: WellTableParentData,
427
- joinInfo?: {wellLevelCol: DG.Column, parentLevelCol: DG.Column}
435
+ joinInfo?: {wellLevelCol: DG.Column, parentLevelCol: DG.Column}, wellLevelAdditionalColumns?: DG.Column[]
428
436
  ): Promise<DG.DataFrame> {
429
437
  if (!concentrationCol || !readoutCol || !batchIDCol) {
430
438
  grok.shell.warning('Please fill all required fields');
@@ -522,6 +530,14 @@ export async function convertDataToCurves(df: DG.DataFrame,
522
530
  'Run ID': runID,
523
531
  'Max Percent Inhibition': null, // will be calculated later
524
532
  }};
533
+ if (wellLevelAdditionalColumns) {
534
+ for (const col of wellLevelAdditionalColumns) {
535
+ let name = col.name;
536
+ while (name in curvesObj[curveKey].info)
537
+ name = `${name} (1)`;
538
+ curvesObj[curveKey].info[name] = col.get(i);
539
+ }
540
+ }
525
541
  if (parentData && parentObj[curveKey]) {
526
542
  curvesObj[curveKey].info['Reported IC50'] = parentObj[curveKey].reportedIC50;
527
543
  curvesObj[curveKey].info['Qualified Reported IC50'] = parentObj[curveKey].reportedQualifiedIC50;
@@ -9,7 +9,7 @@ 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.
12
+ Calculates Minimum Significant Ratio (MSR) for compounds based on IC50 values, run dates, assay names, and target entities.
13
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 });
package/src/package.g.ts CHANGED
@@ -62,9 +62,10 @@ export function _initCurves() : void {
62
62
  //input: list<string> additionalColumns { nullable: true }
63
63
  //input: string wellLevelJoinCol { nullable: true }
64
64
  //input: string parentLevelJoinCol { nullable: true }
65
+ //input: list<string> wellLevelAdditionalColumns { nullable: true; optional: true }
65
66
  //output: dataframe result
66
- 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, parentTable?: DG.DataFrame, fitParamColumns?: string[], reportedIC50Column?: string, reportedQualifiedIC50Column?: string, experimentIDColumn?: string, qualifierColumn?: string, additionalColumns?: string[], wellLevelJoinCol?: string, parentLevelJoinCol?: string) : Promise<any> {
67
- return await PackageFunctions.dataToCurves(df, concentrationCol, readoutCol, batchIDCol, assayCol, runIDCol, compoundIDCol, targetEntityCol, excludeOutliersCol, parentTable, fitParamColumns, reportedIC50Column, reportedQualifiedIC50Column, experimentIDColumn, qualifierColumn, additionalColumns, wellLevelJoinCol, parentLevelJoinCol);
67
+ 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, parentTable?: DG.DataFrame, fitParamColumns?: string[], reportedIC50Column?: string, reportedQualifiedIC50Column?: string, experimentIDColumn?: string, qualifierColumn?: string, additionalColumns?: string[], wellLevelJoinCol?: string, parentLevelJoinCol?: string, wellLevelAdditionalColumns?: string[]) : Promise<any> {
68
+ return await PackageFunctions.dataToCurves(df, concentrationCol, readoutCol, batchIDCol, assayCol, runIDCol, compoundIDCol, targetEntityCol, excludeOutliersCol, parentTable, fitParamColumns, reportedIC50Column, reportedQualifiedIC50Column, experimentIDColumn, qualifierColumn, additionalColumns, wellLevelJoinCol, parentLevelJoinCol, wellLevelAdditionalColumns);
68
69
  }
69
70
 
70
71
  //output: dynamic result
package/src/package.ts CHANGED
@@ -83,13 +83,15 @@ export class PackageFunctions {
83
83
  @grok.decorators.param({options: {nullable: true}})experimentIDColumn?: string, @grok.decorators.param({options: {nullable: true}})qualifierColumn?: string,
84
84
  @grok.decorators.param({options: {nullable: true}})additionalColumns?: string[],
85
85
  @grok.decorators.param({options: {nullable: true}})wellLevelJoinCol?: string,
86
- @grok.decorators.param({options: {nullable: true}})parentLevelJoinCol?: string
86
+ @grok.decorators.param({options: {nullable: true}})parentLevelJoinCol?: string,
87
+ @grok.decorators.param({options: {nullable: true, optional: true}})wellLevelAdditionalColumns?: string[]
87
88
  ): Promise<DG.DataFrame> {
88
89
  const pt = parentTable;
89
90
  const joinInfo = pt && wellLevelJoinCol && parentLevelJoinCol && df.col(wellLevelJoinCol) && pt.col(parentLevelJoinCol) ? {
90
91
  wellLevelCol: df.col(wellLevelJoinCol)!,
91
92
  parentLevelCol: pt.col(parentLevelJoinCol)!,
92
93
  } : undefined;
94
+ const wellLevelAdditionalColumnsAct = (wellLevelAdditionalColumns ?? []).map((c) => df.col(c)).filter((c) => c != null) as DG.Column[];
93
95
  // this needs to work with datasync so we use wide format
94
96
  return convertDataToCurves(df, concentrationCol, readoutCol, batchIDCol, assayCol, runIDCol, compoundIDCol, targetEntityCol, excludeOutliersCol, {
95
97
  table: pt,
@@ -100,7 +102,7 @@ export class PackageFunctions {
100
102
  qualifierColumn: qualifierColumn ? pt?.col(qualifierColumn) ?? undefined : undefined,
101
103
  additionalColumns: (additionalColumns ?? []).map((c) => pt?.col(c)).filter((c) => c != null) as DG.Column[],
102
104
  },
103
- joinInfo
105
+ joinInfo, wellLevelAdditionalColumnsAct
104
106
  );
105
107
  }
106
108
 
@@ -34,6 +34,8 @@ export class PlateGridCellRenderer extends DG.GridCellRenderer {
34
34
  g.fillRect(x, y, w, h);
35
35
  return;
36
36
  }
37
+ if (w < 35 || h < 35)
38
+ return;
37
39
 
38
40
  this.plateWidget.plate = Plate.fromTableByRow(gridCell.value!);
39
41
  this.plateWidget.grid.props.colHeaderHeight = h > 120 ? 16 : 0;