@datagrok/curves 1.10.11 → 1.10.13

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 (49) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/package-test.js +470 -4268
  3. package/dist/package-test.js.map +1 -1
  4. package/dist/package.js +254 -3893
  5. package/dist/package.js.map +1 -1
  6. package/package.json +4 -4
  7. package/scripts/calculateMSR.py +65 -65
  8. package/src/fit/fit-demo.ts +1 -1
  9. package/src/fit/fit-grid-cell-handler.ts +385 -385
  10. package/src/fit/fit-inspection.ts +39 -0
  11. package/src/fit/fit-renderer.ts +1 -8
  12. package/src/fit/multi-curve-viewer.ts +1 -3
  13. package/src/fit/render-utils.ts +4 -2
  14. package/src/package-api.ts +3 -126
  15. package/src/package-test.ts +2 -3
  16. package/src/package.g.ts +0 -82
  17. package/src/package.ts +21 -128
  18. package/src/tests/curves-cell-renderer-tests.ts +15 -15
  19. package/src/tests/detector-tests.ts +1 -1
  20. package/src/tests/transform-tests.ts +1 -1
  21. package/test-console-output-1.log +21 -241
  22. package/test-record-1.mp4 +0 -0
  23. package/databases/plates/0000_init.sql +0 -167
  24. package/queries/plates-crud.sql +0 -148
  25. package/src/fit/const.ts +0 -73
  26. package/src/plate/excel-plates.ts +0 -112
  27. package/src/plate/plate-cell-renderer.ts +0 -48
  28. package/src/plate/plate-drc-analysis.ts +0 -262
  29. package/src/plate/plate-reader.ts +0 -28
  30. package/src/plate/plate-well-validators.ts +0 -41
  31. package/src/plate/plate-widget.ts +0 -242
  32. package/src/plate/plate.ts +0 -557
  33. package/src/plate/plates-folder-preview.ts +0 -63
  34. package/src/plate/readers/bmg-pherastar-96.ts +0 -42
  35. package/src/plate/readers/delfia-envision-96-max-rlu.ts +0 -16
  36. package/src/plate/readers/delfia-envision-by-row.ts +0 -18
  37. package/src/plate/readers/spectramax.ts +0 -42
  38. package/src/plate/utils.ts +0 -141
  39. package/src/plates/numeric_matcher.ts +0 -191
  40. package/src/plates/objects/plate-template-handler.ts +0 -48
  41. package/src/plates/plates-app.ts +0 -64
  42. package/src/plates/plates-crud.ts +0 -502
  43. package/src/plates/plates-demo.ts +0 -107
  44. package/src/plates/plates.sql +0 -169
  45. package/src/plates/views/plates-create-view.ts +0 -123
  46. package/src/plates/views/plates-schema-view.ts +0 -58
  47. package/src/plates/views/plates-search-view.ts +0 -137
  48. package/src/plates/views/plates-templates-view.ts +0 -37
  49. package/src/tests/plate-tests.ts +0 -153
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@datagrok/curves",
3
3
  "friendlyName": "Curves",
4
- "version": "1.10.11",
4
+ "version": "1.10.13",
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.2",
12
- "@datagrok-libraries/utils": "^4.6.3",
11
+ "@datagrok-libraries/statistics": "^1.10.0",
12
+ "@datagrok-libraries/utils": "^4.6.5",
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.48",
27
+ "datagrok-tools": "^4.14.55",
28
28
  "source-map-loader": "^4.0.1",
29
29
  "style-loader": "^2.0.0",
30
30
  "ts-loader": "^9.5.1",
@@ -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)
@@ -7,7 +7,7 @@ import {_package} from '../package';
7
7
  import {IFitChartData, sigmoid} from '@datagrok-libraries/statistics/src/fit/fit-curve';
8
8
 
9
9
  import wu from 'wu';
10
- import {FitConstants} from './const';
10
+ import {FitConstants} from '@datagrok-libraries/statistics/src/fit/const';
11
11
 
12
12
  /** Returns random number from the interval */
13
13
  function rnd(min: number, max: number): number {