@datagrok/compute 1.15.1 → 1.16.1

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/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "1.15.1",
4
+ "version": "1.16.1",
5
5
  "author": {
6
6
  "name": "Aufar Zakiev",
7
7
  "email": "aufar.zakiev@softwarecountry.com"
@@ -13,10 +13,10 @@
13
13
  "directory": "packages/Compute"
14
14
  },
15
15
  "dependencies": {
16
- "@datagrok-libraries/compute-utils": "^1.15.1",
16
+ "@datagrok-libraries/compute-utils": "^1.16.1",
17
17
  "cash-dom": "latest",
18
- "datagrok-api": "^1.16.3",
19
- "dayjs": "=1.11.7",
18
+ "datagrok-api": "^1.17.0",
19
+ "dayjs": "^1.11.10",
20
20
  "rxjs": "^6.5.5",
21
21
  "source-map-loader": "^4.0.1",
22
22
  "ts-loader": "latest",
@@ -64,4 +64,4 @@
64
64
  "All users"
65
65
  ],
66
66
  "category": "Machine Learning"
67
- }
67
+ }
@@ -2,5 +2,5 @@
2
2
  //description: Shows that default view works (or not)
3
3
  //language: javascript
4
4
  //tags: bioreactor
5
- //input: string db_name = 50 {caption: DB name}
5
+ //input: string db_name = "My DB name" {caption: DB name}
6
6
  //editor: Compute:RichFunctionViewEditor
@@ -1,5 +1,4 @@
1
1
  //name: Lorenz Attractor
2
- //tags: model, demo
3
2
  //meta.domain: Nonlinear dynamics
4
3
  //description: Set of chaotic solutions of the system for weather prediction. It illustrates the phenomenon known as the Butterfly effect or (more technically) sensitive dependence on initial conditions
5
4
  //language: javascript
@@ -1,5 +1,4 @@
1
- //name: Lotka-Volterra
2
- //tags: model
1
+ //name: LotkaVolterra
3
2
  //meta.domain: Nonlinear dynamics
4
3
  //description: Model describes the dynamics of biological systems in which two species interact, one as a predator and the other as prey.
5
4
  //language: javascript
@@ -1,5 +1,4 @@
1
1
  #name: Vmax
2
- #tags: model
3
2
  #description: Predict the minimum filter size required for the separation of effluent from bioreactors, given the constraints of batch size and total batch time based on a training dataset of time vs filtrate volume for a given filter type, filter area and pressure
4
3
  #language: r
5
4
  #input: dataframe test_data {editor: Compute:manualOutlierSelectionDialog; editor-button: Outliers...}
@@ -2,13 +2,13 @@
2
2
  //description: Uses Newton's law of cooling to simulate object cooling process. Default values are for cube of boiling water in air.
3
3
  //language: javascript
4
4
  //tags: simulation, demo
5
- //input: double ambTemp = 22 {caption: Ambient temperature; units: C; category: Environment; block: 50}
6
- //input: double initTemp = 100 {caption: Initial temperature; units: C; category: Environment; block: 50}
7
- //input: double desiredTemp = 30 {caption: Desired temperature; units: C; category: Environment}
5
+ //input: double ambTemp = 22 {caption: Ambient temperature; units: C; category: Environment; block: 50; validator: Compute:AmbTempValidator; }
6
+ //input: double initTemp = 100 {caption: Initial temperature; units: C; category: Environment; block: 50; validator: Compute:InitialTempValidator; }
7
+ //input: double desiredTemp = 30 {caption: Desired temperature; units: C; category: Environment; validator: Compute:DesiredTempValidator; }
8
8
  //input: double area = 0.06 {caption: Surface area; units: m²; category: Object properties}
9
- //input: double heatCap = 4200 {caption: Heat capacity; units: J/C; category: Object properties}
9
+ //input: double heatCap = 4200 {caption: Heat capacity; units: J/C; category: Object properties; validator: Compute:HeatCapValidator; }
10
10
  //input: double heatTransferCoeff = 8.3 {caption: Heat transfer coefficient; units: W/(m² * C); category: Object properties}
11
- //input: int simTime = 21600 {caption: Simulation time; units: sec; category: Simulation}
11
+ //input: int simTime = 21600 {caption: Simulation time; units: sec; category: Simulation; validator: Compute:SimTimeValidator; validatorOptions: { "reasonableMin": 10800, "reasonableMax": 100000} }
12
12
  //output: dataframe simulation {caption: Temp. vs time; category: Output; viewer: Line chart(block: 75) | Grid(block: 25)}
13
13
  //output: double timeToCool {caption: Time to cool; units: sec.; category: Output}
14
14
  //output: double coolingFactor {caption: Cooling factor; units: 1 / sec.; category: Calculations}
package/src/package.ts CHANGED
@@ -9,6 +9,7 @@ import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-v
9
9
  import {RichFunctionView} from "@datagrok-libraries/compute-utils";
10
10
  import './css/model-card.css';
11
11
  import { ImportScriptGeneratorApp } from './import-script-generator/view';
12
+ import { ValidationInfo, makeAdvice, makeValidationResult } from '@datagrok-libraries/compute-utils/shared-utils/validation';
12
13
 
13
14
  let initCompleted: boolean = false;
14
15
  export const _package = new DG.Package();
@@ -227,3 +228,81 @@ export function modelCatalog() {
227
228
  }
228
229
  } else grok.shell.v = modelsView;
229
230
  }
231
+
232
+
233
+ //name: SimTimeValidator
234
+ //input: object params
235
+ //output: object validator
236
+ export function SimTimeValidator(params: any) {
237
+ const {reasonableMin, reasonableMax} = params;
238
+ return (val: number) => {
239
+ return makeValidationResult({
240
+ warnings: val < reasonableMin || val > reasonableMax ? [`Minimum reasonable time is ${reasonableMin}. Maximum reasonable time is ${reasonableMax}`]: undefined,
241
+ errors: val < 0 ? [`Time should be strictly positive`]: undefined,
242
+ });
243
+ };
244
+ }
245
+
246
+ //name: DesiredTempValidator
247
+ //input: object params
248
+ //output: object validator
249
+ export function DesiredTempValidator(params: any) {
250
+ return (val: number, info: ValidationInfo) => {
251
+ const ambTemp = info.funcCall.inputs['ambTemp'];
252
+ const initTemp = info.funcCall.inputs['initTemp'];
253
+ return makeValidationResult({
254
+ errors: [
255
+ ...(val < ambTemp) ? [makeAdvice(`Desired temperature cannot be less than ambient temperature (${ambTemp}). \n`, [
256
+ {actionName: 'Set desired equal to ambient', action: () => info.funcCall.inputs['desiredTemp'] = ambTemp }
257
+ ])]: [],
258
+ ...(val > initTemp) ? [`Desired temperature cannot be higher than initial temperature (${initTemp})`]: [],
259
+ ]
260
+ });
261
+ };
262
+ }
263
+
264
+ //name: InitialTempValidator
265
+ //input: object params
266
+ //output: object validator
267
+ export function InitialTempValidator(params: any) {
268
+ return (val: number, info: ValidationInfo) => {
269
+ const ambTemp = info.funcCall.inputs['ambTemp'];
270
+ return makeValidationResult({
271
+ errors: [
272
+ ...(val < ambTemp) ? [`Initial temperature cannot be less than ambient temperature (${ambTemp}).`]: [],
273
+ ]
274
+ });
275
+ };
276
+ }
277
+
278
+ //name: AmbTempValidator
279
+ //input: object params
280
+ //output: object validator
281
+ export function AmbTempValidator(params: any) {
282
+ return (val: number, info: ValidationInfo) => {
283
+ const initTemp = info.funcCall.inputs['initTemp'];
284
+ return makeValidationResult({
285
+ errors: [
286
+ ...(val > initTemp) ? [`Ambient temperature cannot be higher than initial temperature (${initTemp})`]: [],
287
+ ]
288
+ });
289
+ };
290
+ }
291
+
292
+ //name: HeatCapValidator
293
+ //input: object params
294
+ //output: object validator
295
+ export function HeatCapValidator(params: any) {
296
+ return (val: number, info: ValidationInfo) => {
297
+ return makeValidationResult({
298
+ errors: [
299
+ ...val <= 0 ? ['Heat capacity must be greater than zero.']: []
300
+ ],
301
+ notifications: [
302
+ makeAdvice(`Heat capacity is only dependent on the object material.`, [
303
+ {actionName: 'Google it', action: () => { window.open(`http://google.com`)}}
304
+ ]),
305
+ ]
306
+ });
307
+ };
308
+ }
package/files/cars.csv DELETED
@@ -1,6 +0,0 @@
1
- model,mpg,cyl,disp,hp,drat,wt,qsec,vs,am,gear,carb
2
- Mazda RX4,21.0,6,160,110,3.90,2.620,16.46,0,1,4,4
3
- Mazda RX4 Wag,21.0,6,160,110,3.90,2.875,17.02,0,1,4,4
4
- Datsun 710,22.8,4,108,93,3.85,2.320,18.61,1,1,4,1
5
- Hornet 4 Drive,21.4,6,258,110,3.08,3.215,19.44,1,0,3,1
6
- Hornet Sportabout,18.7,8,360,175,3.15,3.440,17.02,0,0,3,2
package/scripts/cars.js DELETED
@@ -1,16 +0,0 @@
1
- //name: cars
2
- //description: Demonstrates value lookup
3
- //language: javascript
4
- //input: string model { choices: OpenFile("System:AppData/Compute/cars.csv"); propagateChoice: all }
5
- //input: double mpg
6
- //input: int cyl
7
- //input: int disp
8
- //input: int hp
9
- //input: double drat
10
- //input: double wt
11
- //input: double qsec
12
- //output: double mpgPerCylinder
13
- //output: double acc
14
-
15
- mpgPerCylinder = mpg / cyl;
16
- acc = hp / wt;
package/scripts/pkpd.R DELETED
@@ -1,71 +0,0 @@
1
- #name: pkpd
2
- #language: r
3
- #tags: model
4
- #input: double dosage = 1000 {category: Dosing options}
5
- #input: double doseInterval = 12 {category: Dosing options}
6
- #input: string compartments {category: PK model; choices: ['2 compartment PK', '1 compartment PK']}
7
- #input: double clearance = 2 {category: PK parameters}
8
- #input: double rateConstant = 0.3 {category: PK parameters} [rate constant]
9
- #input: double centralV = 4 {category: PK parameters} [central compartment volume]
10
- #input: double perV = 30 {category: PK parameters} [peripheral compartment volume]
11
- #input: double interRate = 1 {category: PK parameters} [intercompartmental rate]
12
- #input: double effRate = 0.2 {category: PD parameters} [effective compartment rate]
13
- #input: double effect = 8 {category: PD parameters} [EC50]
14
- #output: graphics PKPD
15
- #output: double Cmax {units: nM}
16
- #meta.domain: PKPD
17
- #editor: Compute:RichFunctionViewEditor
18
- #meta.runOnOpen: true
19
- #meta.runOnInput: true
20
-
21
- require("ggplot2")
22
- require("RxODE")
23
-
24
- rxCreateCache()
25
-
26
- params <-
27
- c(KA = rateConstant, CL = clearance, # central
28
- V2 = centralV, Q = interRate, V3 = perV, # peripheral
29
- Kin = effRate, Kout = effRate, EC50 = effect) # effects
30
- inits <- c(0, 0, 0, 1)
31
-
32
- ev <- eventTable()
33
- ev$add.dosing(dose = dosage, nbr.doses = floor(120/doseInterval), dosing.interval = doseInterval)
34
-
35
- if(compartments == "1 compartment PK"){
36
- mod <-RxODE({
37
- C2 = centr/V2;
38
- C3 = peri/V3;
39
- d/dt(depot) =-KA*depot;
40
- d/dt(centr) = KA*depot - CL*C2;
41
- d/dt(peri) = Q*C2 - Q*C3;
42
- d/dt(eff) = Kin - Kout*(1-C2/(EC50+C2))*eff;
43
- })
44
- } else {
45
- mod <-RxODE({
46
- C2 = centr/V2;
47
- C3 = peri/V3;
48
- d/dt(depot) =-KA*depot;
49
- d/dt(centr) = KA*depot - CL*C2 - Q*C2 + Q*C3;
50
- d/dt(peri) = Q*C2 - Q*C3;
51
- d/dt(eff) = Kin - Kout*(1-C2/(EC50+C2))*eff;
52
- })
53
- }
54
-
55
- Sims <- as.data.frame(mod$run(params, ev, inits))
56
-
57
- cMax <- max(Sims$centr)
58
- effMax <- max(Sims$eff)
59
-
60
- ggplot() +
61
- geom_line(data = Sims, aes(x = time, y = centr), col = "Red", alpha = 0.7) + theme_bw()+
62
- geom_line(data = Sims, aes(x = time, y = eff*0.5*cMax/effMax), col = "Blue", alpha = 0.7) + theme_bw() +
63
- scale_y_continuous(name = "Drug concentration, nM",
64
- sec.axis = sec_axis( trans=~.*effMax*2/cMax, name="Drug effect")) +
65
- scale_x_continuous(name = "Time, hours", breaks = seq(0, 120, 12)) +
66
- theme(axis.text.x = element_text(size = 24, angle = 0,vjust =.5, family="serif"),
67
- axis.text.y = element_text(size = 24, family = "serif"),
68
- axis.title.x = element_text(vjust = 1, size = 24, family = "serif"),
69
- axis.title.y = element_text(vjust = 1, size = 24, family = "serif"))
70
-
71
- Cmax <- max(Sims$centr)
package/scripts/pop-pk.R DELETED
@@ -1,85 +0,0 @@
1
- #name: popPK
2
- #language: r
3
- #tags: model
4
- #input: double dosage = 1000 {category: Dosing options}
5
- #input: double doseInterval = 12 {category: Dosing options}
6
- #input: string compartments {category: PK model; choices: ['2 compartment PK', '1 compartment PK']}
7
- #input: double clearance = 2 {category: PK parameters}
8
- #input: double omegaClearance = 0.3 {category: Random effects} [omega clearance]
9
- #input: double rateConstant = 0.3 {category: PK parameters} [rate constant]
10
- #input: double centralV = 4 {category: PK parameters} [central compartment volume]
11
- #input: double perV = 30 {category: PK parameters} [peripheral compartment volume]
12
- #input: double interRate = 1 {category: PK parameters} [intercompartmental rate]
13
- #output: graphics popPK
14
- #meta.domain: PKPD
15
- #editor: Compute:RichFunctionViewEditor
16
-
17
- require("ggplot2")
18
- require("RxODE")
19
- require("dplyr")
20
- rxCreateCache()
21
-
22
- params <-
23
- c(KA = rateConstant, CL = clearance, # central
24
- V2 = centralV, Q = interRate, V3 = perV, # peripheral
25
- Kin = effRate, Kout = effRate, EC50 = effect) # effects
26
- inits <- c(0, 0, 0, 1)
27
-
28
- # Initialize event table
29
- ev <- eventTable()
30
- # Specify dose
31
- ev$add.dosing(dose = 1000, nbr.doses = 1)
32
-
33
- if(compartments == "1 compartment PK"){
34
- mod <-RxODE({
35
- C2 = centr/V2;
36
- C3 = peri/V3;
37
- d/dt(depot) =-KA*depot;
38
- d/dt(centr) = KA*depot - CL*C2;
39
- d/dt(peri) = Q*C2 - Q*C3;
40
- d/dt(eff) = Kin - Kout*(1-C2/(EC50+C2))*eff;
41
- })
42
- } else {
43
- mod <-RxODE({
44
- C2 = centr/V2;
45
- C3 = peri/V3;
46
- d/dt(depot) =-KA*depot;
47
- d/dt(centr) = KA*depot - CL*C2 - Q*C2 + Q*C3;
48
- d/dt(peri) = Q*C2 - Q*C3;
49
- d/dt(eff) = Kin - Kout*(1-C2/(EC50+C2))*eff;
50
- })
51
- }
52
-
53
-
54
- SimsAll <- data.frame()
55
-
56
- for(i in seq(1, 20)){
57
- a <- params
58
- a["CL"] <- params["CL"] + rlnorm(1, 0, omegaClearance)
59
-
60
- Sims <- data.frame(mod$run(a, ev, inits)) %>% mutate(ID = i)
61
- SimsAll <- SimsAll %>% bind_rows(Sims)
62
- }
63
-
64
-
65
- DataSet <- SimsAll %>% select(time, centr, ID)
66
-
67
- DataSet <- DataSet %>%
68
- group_by(time) %>%
69
- summarise(mean = mean(centr),
70
- q95 = quantile(centr, probs = 0.95),
71
- q05 = quantile(centr, probs = 0.05),
72
- n = n()) %>% ungroup()
73
-
74
- # Plot results
75
- ggplot() +
76
- geom_line(data = DataSet, aes(x = time, y = mean), col = "#483D8B", size =1) + theme_bw()+
77
- geom_ribbon(data = DataSet, aes(x = time, ymin = q05, ymax = q95), col = "#ADFF2F", fill = "#ADFF2F", alpha = 0.5) +
78
- scale_y_continuous(name = "Drug concentration, uM")+
79
- scale_x_continuous(name = "Time, hours", breaks = seq(0, 4, 24), limits = c(0, 24))+
80
- theme(axis.text.x = element_text(size = 24, angle = 0,vjust =.5, family="serif"),
81
- axis.text.y = element_text(size = 24, family = "serif"),
82
- axis.title.x = element_text(vjust = 1, size = 24, family = "serif"),
83
- axis.title.y = element_text(vjust = 1, size = 24, family = "serif"))
84
-
85
- omega <- omegaClearance