@datagrok/compute 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,102 +1,13 @@
1
1
  # Compute
2
2
 
3
- Provides support for scientific computations.
4
-
5
- Scientific model is an arbitrary [function](https://datagrok.ai/help/overview/functions/function)
6
- with typed inputs and outputs:
7
-
8
- * Inputs and outputs can be scalars, vectors, matrices
9
- * Typically written in R, Python or Matlab/Octave and run on the server
10
- * Other languages are possible, including compiled to WebAssembly and run in the browser
11
- * Automatic scaling
12
- * Evaluated in multiple contexts of experiment design, such as variability analysis
13
- of output values with respect to input values
14
- * Composable (an output of one function becomes an input to the other)
15
- * Could be connected to any data source (db, web service, file, etc)
16
- * Logging, audit, traceability
17
- * Privileges and visibility
18
-
19
- `Compute` package:
20
-
21
- * Allows using arbitrary functions in R, Python and any other language as full-fledged
22
- scientific models
23
- * Enables a full lifecycle of models: create, tune, share, use, validate
24
- * Provides for easy to use and highly automated evaluation and computation environment
25
- * Enables contextual process for the Design of Experiment (sensitivity analysis and more)
26
-
27
- In addition, Datagrok platform supports a UI layout markup, so that the model function becomes
28
- a GUI-rich application with no manual coding.
29
-
30
- Project planning board: [link](https://github.com/datagrok-ai/public/projects/8).
31
-
32
- ## Roadmap
33
-
34
- 1. **UI markup**
35
-
36
- Annotate function inputs and outputs to produce highly interactive, visually reach GUI:
37
-
38
- * arrange inputs and outputs in blocks and tabs
39
- * add captions, units of measure and other information to inputs and outputs
40
- * automatically produce additional plots with Datagrok
41
- [viewers](https://datagrok.ai/help/visualize/viewers)
42
-
43
- 2. **Input providers**
44
-
45
- Produce inputs to functions in-place as outputs of other functions (aka input providers),
46
- including:
47
-
48
- * queries to databases
49
- * dialog-based functions (outlier detection, data annotation)
50
- * queries to OpenAPI and REST endpoints
51
- * other computing functions with or without GUI
52
-
53
- These may include UI parts as well. The input provider is specified as part of the Universal UI
54
- markup.
55
-
56
- 3. **Persistent, sharable historical runs**
57
-
58
- It is already possible to provide a link to a function (with specified input parameters in
59
- the URI), which will open a function view and run it.
60
-
61
- Once a certain version of a specific function is run with specific inputs, the result should
62
- be stored in the immutable database log along with the inputs. Later it will be used to verify
63
- the grounds for decisions made from these calculations.
64
-
65
- 4. **Sensitivity analysis**
66
-
67
- * Sample inputs:
68
- * by specified number of samples
69
- * by a specified distribution or within a range
70
- * for a specified set of scalar inputs and/or columns of the matrix input
71
- * Produce variability analysis for outputs based on the sampled inputs
72
- * Visualize the results of analysis with Datagrok viewers
73
-
74
- 5. **Modeling input parameters**
75
-
76
- Solve an inversion problem: identify input conditions leading to specified output constraints.
77
-
78
- 6. **Outlier detection and annotation**
79
-
80
- * Automatic outliers detection
81
- * Manual outliers markup and annotation
82
- * Used as an input provider in other functions
83
-
84
- 7. **Model Repository and discoverability**
85
-
86
- 8. **Scaling on demand**
87
-
88
- 9. **Asynchronous computation**
89
-
90
- 10. **Export and reporting**
91
-
92
- 11. **REST endpoints**
93
-
94
- 12. **Data annotation**
95
-
96
- 13. **Test data for functions**
97
-
98
- 14. **Functions versioning**
99
-
100
- 15. **Audit**
101
-
102
- Most of the features are implemented in this package, some of them are part of the platform.
3
+ Provides additional analytical and UI blocks for
4
+ [Datagrok scientific computing](../../help/compute/compute.md)
5
+
6
+ * Model browser
7
+ * Outlier selector tool
8
+ * Universal export tool
9
+ * Step-by-step wizard for onboarding new models
10
+ * Model renderers
11
+ * Function views
12
+ * Function parameter grid
13
+ * A set of examples
@@ -0,0 +1,27 @@
1
+ [
2
+ {
3
+ "name": "Bioreactor simulation",
4
+ "props": [
5
+ {
6
+ "name": "reactorType",
7
+ "type": "string",
8
+ "choices": ["Experimental", "Production"]
9
+ },
10
+ {
11
+ "name": "department",
12
+ "type": "string",
13
+ "choices": ["", "Production"]
14
+ }
15
+ ]
16
+ },
17
+ {
18
+ "name": "Biosensors",
19
+ "props": [
20
+ {
21
+ "name": "sensor",
22
+ "type": "string",
23
+ "choices": ["Accelerometer", "GSR", "EEG", "ECG", "Eye Tracker"]
24
+ }
25
+ ]
26
+ }
27
+ ]
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "0.1.0",
4
+ "version": "0.2.5",
5
5
  "description": "",
6
6
  "dependencies": {
7
7
  "cash-dom": "latest",
8
- "datagrok-api": "../../js-api",
8
+ "datagrok-api": ">=0.95.8",
9
9
  "dayjs": "latest",
10
10
  "exceljs": "^4.3.0",
11
11
  "file-saver": "^2.0.5",
12
12
  "ts-loader": "latest",
13
- "typescript": "latest"
13
+ "typescript": "latest",
14
+ "wu": "latest"
14
15
  },
15
16
  "devDependencies": {
17
+ "@types/wu": "latest",
16
18
  "@types/file-saver": "^2.0.3",
17
19
  "@typescript-eslint/eslint-plugin": "^5.1.0",
18
20
  "@typescript-eslint/parser": "^5.1.0",
@@ -22,12 +24,13 @@
22
24
  "webpack-cli": "latest"
23
25
  },
24
26
  "scripts": {
25
- "debug-compute": "webpack & grok publish",
27
+ "link-api": "npm link datagrok-api",
28
+ "debug-compute": "webpack & grok publish dev --release",
26
29
  "release-compute": "grok publish --rebuild --release",
27
30
  "build-compute": "webpack",
28
31
  "build": "webpack",
29
- "debug-compute-dev": "grok publish dev --rebuild",
30
- "release-compute-dev": "grok publish dev --rebuild --release",
32
+ "debug-compute-dev": "webpack && grok publish dev --rebuild",
33
+ "release-compute-dev": "grok publish dev --release",
31
34
  "debug-compute-local": "grok publish local --rebuild",
32
35
  "release-compute-local": "grok publish local --rebuild --release",
33
36
  "debug-compute-localhost": "grok publish localhost --rebuild",
@@ -1,6 +1,8 @@
1
1
  #name: Fab Arm Exchange
2
2
  #language: python
3
- #tags: model
3
+ #tags: model, simulation
4
+ #meta.modality: Antibody
5
+ #meta.domain: Manufacturing
4
6
  #input: double meaConcentration = 60 {category:FAE Reaction Parameters; units:mM; caption:2-MEA Concentration} [2-MEA Concentration]
5
7
  #input: double phOfFaeReaction = 7.5 {category:FAE Reaction Parameters; caption:pH of FAE Reaction} [pH of FAE Reaction]
6
8
  #input: double faeReactionTime = 3 {category:FAE Reaction Parameters; units:hr; caption:FAE Reaction Time} [FAE Reaction Time]
@@ -1,12 +1,14 @@
1
1
  //name: Heat Exchange
2
2
  //language: javascript
3
- //tags: model
3
+ //tags: model, simulation
4
+ //meta.modality: Small molecule
4
5
  //input: int len = 1000
5
6
  //input: double k = 1.2
6
7
  //output: dataframe simulation {viewer: Line Chart(multiAxis: "true")}
7
8
  //output: double finalTemperature
8
9
  //output: double finalSaturation
9
10
  //output: double finalConcentration
11
+ //meta.domain: Manufacturing
10
12
 
11
13
  function sigmoid(z) {
12
14
  return 1 / (1 + Math.exp(-z));
@@ -0,0 +1,24 @@
1
+ #name: IntervalsFromECG
2
+ #description: Identify the beats in an ECG signal and compute the IBIs
3
+ #language: python
4
+ #tags: model
5
+ #input: double samplingFrequency = 2048
6
+ #input: int bpmMax = 120 [Maximal expected heart rate (in beats per minute): (1 < bpm_max <= 400)]
7
+ #input: double delta = 0 [Threshold for the peak detection. By default it is computed from the signal (adaptive thresholding)]
8
+ #input: double k = 0.7 [Ratio at which the signal range is multiplied (when delta = 0), (0 < k < 1)]
9
+ #output: graphics Intervals
10
+
11
+ import pyphysio as ph
12
+ import matplotlib.pyplot as plt
13
+ from pyphysio.tests import TestData
14
+
15
+ ecg_data = TestData.ecg()
16
+
17
+ ecg = ph.EvenlySignal(values=ecg_data, sampling_freq=samplingFrequency, signal_type = 'ecg')
18
+
19
+ extracted = ph.BeatFromECG(bpm_max=bpmMax, delta=delta, k=k)(ecg)
20
+
21
+ Intervals = plt.plot(extracted)
22
+ plt.title('RR intervals')
23
+ plt.xlabel('Interval index')
24
+ plt.ylabel('Seconds')
@@ -1,5 +1,5 @@
1
- //name: Logistic map
2
- //tags: model, NonlinearDynamics
1
+ //name: Logistic Map
2
+ //tags: model, simulation
3
3
  //description: Archetypal example of how complex, chaotic behaviour can arise from very simple non-linear dynamical equations.
4
4
  //language: javascript
5
5
  //input: int iterations = 1000 [Number of iterations per point]
@@ -7,6 +7,7 @@
7
7
  //input: double spacing = 0.001 [Spacing between points on domain (r-axis)]
8
8
  //input: double res = 8 [Largest n-cycle visible]
9
9
  //output: dataframe df {viewer: Scatter plot(title: "Logistic map")}
10
+ //meta.domain: Nonlinear dynamics
10
11
 
11
12
  function getRandomNumberInRange(min, max) {
12
13
  return Math.random() * (max - min) + min;
@@ -1,5 +1,6 @@
1
- //name: Lorenz attractor
2
- //tags: model, NonlinearDynamics
1
+ //name: Lorenz Attractor
2
+ //tags: model, simulation
3
+ //meta.domain: Nonlinear dynamics
3
4
  //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
4
5
  //language: javascript
5
6
  //input: int iterations = 1000
@@ -1,5 +1,6 @@
1
- //name: Lotka-Volterra Model
2
- //tags: model, NonlinearDynamics
1
+ //name: Lotka-Volterra
2
+ //tags: model, simulation
3
+ //meta.domain: Nonlinear dynamics
3
4
  //description: Model describes the dynamics of biological systems in which two species interact, one as a predator and the other as prey.
4
5
  //language: javascript
5
6
  //input: double x0 = 0.5 [Initial conditions for prey population]
@@ -1,11 +1,13 @@
1
- #name: Maximal Volume
1
+ #name: Vmax
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
2
3
  #language: r
3
4
  #tags: model
4
5
  #input: dataframe test_data {editor: Compute:manualOutlierSelectionDialog; editor-button: Outliers...}
5
- #input: double test_area = 2.5 {caption: Filter Area; units: cm²} [Filter area]
6
- #input: double test_pressure = 21 {caption: Pressure; units: psi} [Pressure]
7
- #input: double vbatch = 11 {caption: VBatch; units: L} [Desired batch size to process]
8
- #input: double tbatch = 0.8 {caption: TBatch; units: hr} [Desired process time]
6
+ #input: double test_area = 3.5 {caption: Filter Area; units: cm²} [Filter area]
7
+ #input: double vbatch = 25 {caption: VBatch; units: L} [Desired batch size to process]
8
+ #input: double tbatch = 0.5 {caption: TBatch; units: hr} [Desired process time]
9
+ #input: double sf = 1.5 {caption: Safety Factor} [Safety Factor]
10
+ #output: dataframe processedData {viewer: Scatter Plot(x: "time (hr)", y: "t/V (hr/(L/m2))", showRegressionLine: "true"); category: Raw Plot}
9
11
  #output: double vmax { category: Lin Reg Param }
10
12
  #output: double q0 { category: Lin Reg Param }
11
13
  #output: double slope_est { category: Lin Reg Param }
@@ -19,19 +21,33 @@
19
21
  #output: double resid_ss { category: Lin Reg Param }
20
22
  #output: double expl_ss { category: Lin Reg Param }
21
23
  #output: double ss_tot { category: Lin Reg Param }
22
- #output: double amin { category: Min Filter Area }
24
+ #output: double amin { category: Recommendation }
23
25
 
24
- vmax <- 3
25
- q0 <- 6
26
- slope_est <- vbatch / test_area
27
- slope_err <- 3
28
- icept_est <- slope_err / test_area
29
- icept_err <- 2
30
- rsq <- 2
31
- f_stat <- test_pressure * test_area
32
- df <- 5
33
- sigma <- 4
34
- resid_ss <- 2
35
- expl_ss <- 7
36
- ss_tot <- 5
37
- amin <- vbatch / tbatch
26
+ a <- as.data.frame(test_data)
27
+ a <- a[!a$isOutlier=='true',]
28
+ processedData <- a
29
+ processedData$time..min. <- processedData$time..min. / 60
30
+ names(processedData)[names(processedData) == "time..min."] <- "time (hr)"
31
+ processedData$filtrate.volume..mL. <- (processedData$filtrate.volume..mL./1000)/(test_area/10000)
32
+ names(processedData)[names(processedData) == "filtrate.volume..mL."] <- "V (L/m2)"
33
+ processedData["t/V (hr/(L/m2))"] <- processedData$`time (hr)` / processedData$`V (L/m2)`
34
+
35
+ lin_mod <- lm(`t/V (hr/(L/m2))` ~ `time (hr)`, data=processedData)
36
+ lin_mod_sum <- summary(lin_mod)
37
+ coeff <- lin_mod_sum$coefficients
38
+ slope_est <- coeff["`time (hr)`", "Estimate"]
39
+ slope_err <- coeff["`time (hr)`", "Std. Error"]
40
+ icept_est <- coeff["(Intercept)", "Estimate"]
41
+ icept_err <- coeff["(Intercept)", "Std. Error"]
42
+ rsq <- lin_mod_sum$r.squared
43
+ ad_rsq <- lin_mod_sum$adj.r.squared
44
+ f_stat <- lin_mod_sum$fstatistic[1]
45
+ df <- lin_mod_sum$df[2]
46
+ sigma <- lin_mod_sum$sigma
47
+ resid_ss <- sum(lin_mod_sum$residuals^2)
48
+ expl_ss <- sum((fitted(lin_mod) - mean(processedData$`t/V (hr/(L/m2))`))^2)
49
+ vmax <- round(1 / slope_est)
50
+ q0 <- round(1 / icept_est)
51
+ amin <- (vbatch / vmax) + (vbatch / tbatch / q0)
52
+ amin <- round(amin, digits = 1)
53
+ ss_tot <- resid_ss + expl_ss
@@ -0,0 +1,163 @@
1
+ //name: PmaxScript
2
+ //description: pMax Filtration Model
3
+ //language: javascript
4
+ //tags: model
5
+ //input: dataframe inputTable [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
6
+ //input: double batchVolume = 100 {units: L} [Batch Volume]
7
+ //input: double batchTime = 2 {units: hours} [Batch Time]
8
+ //input: double targetPressure = 20 {units: psi} [Target Pressure]
9
+ //input: double aMinFilter1Guessed = 0.153 {units: m²; caption:Amin Filter 1 guessed} [Amin Filter 1 guessed]
10
+ //input: double aMinFilter2Guessed = 0.153 {units: m²; caption:Amin Filter 2 guessed} [Amin Filter 2 guessed]
11
+ //input: double filterArea1 = 23 {units: m²} [Filter Area 1]
12
+ //input: double filterArea2 = 23 {units: m²} [Filter Area 2]
13
+ //input: double sf1 = 1.5 {caption: SF1}
14
+ //input: double sf2 = 1.5 {caption: SF2}
15
+ //input: int orderOfPolynomialRegression = 3 {caption: Order Of Polynomial Regression} [Order Of Polynomial Regression]
16
+ //output: dataframe Filter1 {viewer: Scatter Plot(x: "TP 1 (L/m2)", y: "Res. 1 (psi/LMH)", showRegressionLine: "true"); category: PRIMARY FILTER}
17
+ //output: dataframe Filter2 {viewer: Scatter Plot(x: "TP 2 (L/m2)", y: "Res. 2 (psi/LMH)", showRegressionLine: "true"); category: SECONDARY FILTER}
18
+ //output: double amin1 {units: m²; caption: Amin; category: PRIMARY FILTER}
19
+ //output: double amin2 {units: m²; caption: Amin; category: SECONDARY FILTER}
20
+ //output: double aminSF1 {units: m²; caption: Amin SF; category: PRIMARY FILTER}
21
+ //output: double aminSF2 {units: m²; caption: Amin SF; category: SECONDARY FILTER}
22
+ //output: double trialLoading1 {units: L/m²; caption: Trial Loading; category: PRIMARY FILTER}
23
+ //output: double trialLoading2 {units: L/m²; caption: Trial Loading; category: SECONDARY FILTER}
24
+ //output: double processLoading1 {units: L/m²; caption: Process Loading; category: PRIMARY FILTER}
25
+ //output: double processLoading2 {units: L/m²; caption: Process Loading; category: SECONDARY FILTER}
26
+ //output: double maxP1 {units: psi; caption: Max P; category: PRIMARY FILTER}
27
+ //output: double maxP2 {units: psi; caption: Max P; category: SECONDARY FILTER}
28
+ //output: double trialFlux1 {units: LMH; caption: Trial Flux; category: PRIMARY FILTER}
29
+ //output: double trialFlux2 {units: LMH; caption: Trial Flux; category: SECONDARY FILTER}
30
+ //output: double processFlux1 {units: LMH; caption: Process Flux; category: PRIMARY FILTER}
31
+ //output: double processFlux2 {units: LMH; caption: Process Flux; category: SECONDARY FILTER}
32
+ //output: double processFlow1 {units: L/hr; caption: Process Flow; category: PRIMARY FILTER}
33
+ //output: double processFlow2 {units: L/hr; caption: Process Flow; category: SECONDARY FILTER}
34
+ //output: double guessedAmin1 {units: m²; caption: Guessed Amin; category: PRIMARY FILTER}
35
+ //output: double guessedAmin2 {units: m²; caption: Guessed Amin; category: SECONDARY FILTER}
36
+ //output: double guessedProcessLoading1 {units: L/m²; caption: Guessed Process Loading; category: PRIMARY FILTER}
37
+ //output: double guessedProcessLoading2 {units: L/m²; caption: Guessed Process Loading; category: SECONDARY FILTER}
38
+ //output: double guessedMaxP1 {units: psi; caption: Guessed Max P; category: PRIMARY FILTER}
39
+ //output: double guessedMaxP2 {units: psi; caption: Guessed Max P; category: SECONDARY FILTER}
40
+ //output: double guessedProcessFlux1 {units: LMH; caption: Guessed Process Flux; category: PRIMARY FILTER}
41
+ //output: double guessedProcessFlux2 {units: LMH; caption: Guessed Process Flux; category: SECONDARY FILTER}
42
+
43
+ function gaussianElimination(input, orderOfPolynomialRegression) {
44
+ const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
45
+ for (let i = 0; i < n; i++) {
46
+ let maxrow = i;
47
+ for (let j = i + 1; j < n; j++)
48
+ if (Math.abs(input[i][j]) > Math.abs(input[i][maxrow]))
49
+ maxrow = j;
50
+ for (let k = i; k < n + 1; k++) {
51
+ const tmp = input[k][i];
52
+ input[k][i] = input[k][maxrow];
53
+ input[k][maxrow] = tmp;
54
+ }
55
+ for (let j = i + 1; j < n; j++)
56
+ for (let k = n; k >= i; k--)
57
+ input[k][j] -= (input[k][i] * input[i][j]) / input[i][i];
58
+ }
59
+ for (let j = n - 1; j >= 0; j--) {
60
+ let total = 0;
61
+ for (let k = j + 1; k < n; k++)
62
+ total += input[k][j] * coefficients[k];
63
+ coefficients[j] = (input[n][j] - total) / input[j][j];
64
+ }
65
+ return coefficients;
66
+ }
67
+
68
+ function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression) {
69
+ const lhs = [], rhs = [], len = xCol.length, k = orderOfPolynomialRegression + 1;
70
+ let a = 0, b = 0;
71
+ for (let i = 0; i < k; i++) {
72
+ for (let l = 0; l < len; l++)
73
+ a += (xCol.get(l) ** i) * yCol.get(l);
74
+ lhs.push(a);
75
+ a = 0;
76
+ const c = [];
77
+ for (let j = 0; j < k; j++) {
78
+ for (let l = 0; l < len; l++)
79
+ b += xCol.get(l) ** (i + j);
80
+ c.push(b);
81
+ b = 0;
82
+ }
83
+ rhs.push(c);
84
+ }
85
+ rhs.push(lhs);
86
+ return gaussianElimination(rhs, k);
87
+ }
88
+
89
+ function predictPolynomialRegression(coefficients, x) {
90
+ let result = coefficients[0];
91
+ for (let i = coefficients.length - 1; i > 0; i--)
92
+ result += coefficients[i] * Math.pow(x, i);
93
+ return result;
94
+ }
95
+
96
+ const lengthOfSecondTable = 2985;
97
+ const colNames1 = {
98
+ 'time': 'Time (min)',
99
+ 'volume': 'Vol (mL)',
100
+ 'pressure1': 'P1 (psi)',
101
+ 'pressure2': 'P2 (psi)',
102
+ 'tp1': 'TP 1 (L/m2)', 'flux1': 'Flux 1 (LMH)', 'res1': 'Res. 1 (psi/LMH)',
103
+ 'tp2': 'TP 2 (L/m2)', 'flux2': 'Flux 2 (LMH)', 'res2': 'Res. 2 (psi/LMH)',
104
+ 'deltaP': 'Delta P (psi)'
105
+ };
106
+ const colNames2 = {
107
+ 'area': 'Guess Area (m2)',
108
+ 'javg': 'Javg (LMH)',
109
+ 'R': 'R calc (psi/LMH)',
110
+ 'Y1': 'Y1', 'd1': 'Delta1',
111
+ 'Y2': 'Y2', 'd2': 'Delta2'
112
+ };
113
+
114
+ const t = inputTable.col(colNames1['time']);
115
+ const v = inputTable.col(colNames1['volume']);
116
+ const p1 = inputTable.col(colNames1['pressure1']);
117
+ const p2 = inputTable.col(colNames1['pressure2']);
118
+ const df1 = DG.DataFrame.fromColumns([t, v, p1, p2]);
119
+ df1.columns.addNewFloat(colNames1['tp1']).init((i) => (i > 0) ? 10 * v.get(i) / filterArea1 : 0);
120
+ df1.columns.addNewFloat(colNames1['tp2']).init((i) => (i > 0) ? 10 * v.get(i) / filterArea2 : 0);
121
+ df1.columns.addNewFloat(colNames1['flux1']).init((i) => (i > 0) ? 600 * (v.get(i) - v.get(i-1)) / (t.get(i) - t.get(i-1)) / filterArea1 : 0);
122
+ df1.columns.addNewFloat(colNames1['flux2']).init((i) => (i > 0) ? 600 * (v.get(i) - v.get(i-1)) / (t.get(i) - t.get(i-1)) / filterArea2 : 0);
123
+ df1.columns.addNewFloat(colNames1['deltaP']).init((i) => p1.get(i) - p2.get(i));
124
+ const deltaP = df1.col(colNames1['deltaP']), flux1 = df1.col(colNames1['flux1']), flux2 = df1.col(colNames1['flux2']);
125
+ df1.columns.addNewFloat(colNames1['res1']).init((i) => (i > 0) ? deltaP.get(i) / flux1.get(i) : 0);
126
+ df1.columns.addNewFloat(colNames1['res2']).init((i) => (i > 0) ? p2.get(i) / flux2.get(i) : 0);
127
+ Filter1 = DG.DataFrame.fromColumns([df1.col(colNames1['tp1']), df1.col(colNames1['res1'])]);
128
+ Filter2 = DG.DataFrame.fromColumns([df1.col(colNames1['tp2']), df1.col(colNames1['res2'])]);
129
+ const coefficients1 = polynomialRegressionCoefficients(df1.col(colNames1['tp1']), df1.col(colNames1['res1']), orderOfPolynomialRegression);
130
+ const coefficients2 = polynomialRegressionCoefficients(df1.col(colNames1['tp2']), df1.col(colNames1['res2']), orderOfPolynomialRegression);
131
+
132
+
133
+ const df2 = DG.DataFrame.create(lengthOfSecondTable);
134
+ df2.columns.addNewFloat(colNames2['area']).init((i) => (i > 0) ? batchVolume / i : 0);
135
+ const area = df2.col(colNames2['area']);
136
+ df2.columns.addNewFloat(colNames2['javg']).init((i) => (i > 0) ? batchVolume / area.get(i) / batchTime : 0);
137
+ const javg = df2.col(colNames2['javg']);
138
+ df2.columns.addNewFloat(colNames2['R']).init((i) => (i > 0) ? targetPressure / javg.get(i) : 0);
139
+ df2.columns.addNewFloat(colNames2['Y1']).init((i) => predictPolynomialRegression(coefficients1, i));
140
+ df2.columns.addNewFloat(colNames2['Y2']).init((i) => predictPolynomialRegression(coefficients2, i));
141
+ const rCalc = df2.col(colNames2['R']), y1 = df2.col(colNames2['Y1']), y2 = df2.col(colNames2['Y2']);
142
+ df2.columns.addNewFloat(colNames2['d1']).init((i) => Math.abs(rCalc.get(i) - y1.get(i)));
143
+ df2.columns.addNewFloat(colNames2['d2']).init((i) => Math.abs(rCalc.get(i) - y2.get(i)));
144
+
145
+
146
+ amin1 = df2.col(colNames2['area']).get(df2.col(colNames2['d1']).toList().indexOf(df2.col(colNames2['d1']).min));
147
+ amin2 = df2.col(colNames2['area']).get(df2.col(colNames2['d2']).toList().indexOf(df2.col(colNames2['d2']).min));
148
+ processFlow1 = batchVolume / batchTime, processFlow2 = batchVolume / batchTime;
149
+ processFlux1 = processFlow1 / amin1, processFlux2 = processFlow2 / amin2;
150
+ trialFlux1 = 600 * v.max / t.max / filterArea1, trialFlux2 = 600 * v.max / t.max / filterArea2;
151
+ aminSF1 = sf1 * amin1, aminSF2 = sf2 * amin2;
152
+ trialLoading1 = df1.col(colNames1['tp1']).max, trialLoading2 = df1.col(colNames1['tp2']).max;
153
+ processLoading1 = batchVolume / amin1, processLoading2 = batchVolume / amin2;
154
+ maxP1 = predictPolynomialRegression(coefficients1, processLoading1) * processFlux1;
155
+ maxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
156
+
157
+
158
+ guessedAmin1 = aMinFilter1Guessed, guessedAmin2 = aMinFilter2Guessed;
159
+ guessedProcessLoading1 = batchVolume / aMinFilter1Guessed, guessedProcessLoading2 = batchVolume / aMinFilter2Guessed;
160
+ guessedMaxP1 = predictPolynomialRegression(coefficients1, processLoading1) * processFlux1;
161
+ guessedMaxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
162
+ guessedProcessFlux1 = processFlow1 / aMinFilter1Guessed, guessedProcessFlux2 = processFlow2 / aMinFilter2Guessed;
163
+
package/scripts/pkpd.R CHANGED
@@ -13,6 +13,7 @@
13
13
  #output: graphics PKPD
14
14
  #output: double Cmax {units: nM}
15
15
  #tags: model
16
+ #meta.domain: PKPD
16
17
 
17
18
  require("ggplot2")
18
19
  require("RxODE")
package/scripts/popPK.R CHANGED
@@ -4,18 +4,18 @@
4
4
  #input: double doseInterval = 12 {category: Dosing options}
5
5
  #input: string compartments {category: PK model; choices: ['2 compartment PK', '1 compartment PK']}
6
6
  #input: double clearance = 2 {category: PK parameters}
7
- #input: double omegaClearance {category: Random effects} [omega clearance]
7
+ #input: double omegaClearance = 0.3 {category: Random effects} [omega clearance]
8
8
  #input: double rateConstant = 0.3 {category: PK parameters} [rate constant]
9
9
  #input: double centralV = 4 {category: PK parameters} [central compartment volume]
10
10
  #input: double perV = 30 {category: PK parameters} [peripheral compartment volume]
11
11
  #input: double interRate = 1 {category: PK parameters} [intercompartmental rate]
12
12
  #output: graphics popPK
13
- #output: double omega
14
13
  #tags: model
14
+ #meta.domain: PKPD
15
15
 
16
16
  require("ggplot2")
17
17
  require("RxODE")
18
- require("tidyverse")
18
+ require("dplyr")
19
19
  rxCreateCache()
20
20
 
21
21
  params <-
@@ -56,14 +56,14 @@ for(i in seq(1, 20)){
56
56
  a <- params
57
57
  a["CL"] <- params["CL"] + rlnorm(1, 0, omegaClearance)
58
58
 
59
- Sims <- data.frame(mod1$run(a, ev, inits)) %>% mutate(ID = i)
59
+ Sims <- data.frame(mod$run(a, ev, inits)) %>% mutate(ID = i)
60
60
  SimsAll <- SimsAll %>% bind_rows(Sims)
61
61
  }
62
62
 
63
63
 
64
64
  DataSet <- SimsAll %>% select(time, centr, ID)
65
65
 
66
- DataSet <- DartaSet %>%
66
+ DataSet <- DataSet %>%
67
67
  group_by(time) %>%
68
68
  summarise(mean = mean(centr),
69
69
  q95 = quantile(centr, probs = 0.95),
@@ -75,6 +75,10 @@ ggplot() +
75
75
  geom_line(data = DataSet, aes(x = time, y = mean), col = "#483D8B", size =1) + theme_bw()+
76
76
  geom_ribbon(data = DataSet, aes(x = time, ymin = q05, ymax = q95), col = "#ADFF2F", fill = "#ADFF2F", alpha = 0.5) +
77
77
  scale_y_continuous(name = "Drug concentration, uM")+
78
- scale_x_continuous(name = "Time, hours", breaks = seq(0,1200, 24), limits = c(0, 240))
78
+ scale_x_continuous(name = "Time, hours", breaks = seq(0, 4, 24), limits = c(0, 24))+
79
+ theme(axis.text.x = element_text(size = 24, angle = 0,vjust =.5, family="serif"),
80
+ axis.text.y = element_text(size = 24, family = "serif"),
81
+ axis.title.x = element_text(vjust = 1, size = 24, family = "serif"),
82
+ axis.title.y = element_text(vjust = 1, size = 24, family = "serif"))
79
83
 
80
84
  omega <- omegaClearance
package/scripts/trig.js CHANGED
@@ -6,6 +6,7 @@
6
6
  //output: double sin
7
7
  //output: double cos
8
8
  //output: double tan
9
+ //meta.domain: math
9
10
 
10
11
  sin = Math.sin(x);
11
12
  cos = Math.cos(x);