@datagrok/compute 1.15.1 → 1.17.0
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/CHANGELOG.md +28 -0
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +5 -5
- package/scripts/default-get-real-data.js +1 -1
- package/scripts/lorenz-attractor.js +0 -1
- package/scripts/lotka-volterra.js +1 -2
- package/scripts/maximal-volume.R +0 -1
- package/scripts/{demo-rfv-simple.js → object-cooling.js} +5 -5
- package/src/css/model-card.css +1 -1
- package/src/model-handler.ts +104 -8
- package/src/package.ts +79 -0
- package/files/cars.csv +0 -6
- package/scripts/cars.js +0 -16
- package/scripts/pkpd.R +0 -71
- package/scripts/pop-pk.R +0 -85
- package/scripts/trig.js +0 -15
- package/scripts/vmax.js +0 -179
- package/scripts/wrapper.js +0 -8
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/compute",
|
|
3
3
|
"friendlyName": "Compute",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.17.0",
|
|
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.
|
|
16
|
+
"@datagrok-libraries/compute-utils": "^1.17.0",
|
|
17
17
|
"cash-dom": "latest",
|
|
18
|
-
"datagrok-api": "^1.
|
|
19
|
-
"dayjs": "
|
|
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
|
+
}
|
|
@@ -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
|
package/scripts/maximal-volume.R
CHANGED
|
@@ -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/css/model-card.css
CHANGED
package/src/model-handler.ts
CHANGED
|
@@ -4,7 +4,58 @@ import * as DG from 'datagrok-api/dg';
|
|
|
4
4
|
import wu from "wu";
|
|
5
5
|
import {ModelCatalogView} from "./model-catalog-view";
|
|
6
6
|
|
|
7
|
+
function addPopover(popover: HTMLElement) {
|
|
8
|
+
stylePopover(popover);
|
|
9
|
+
document.body.append(popover);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function displayPopover(icon: HTMLElement, popover: HTMLElement) {
|
|
13
|
+
alignPopover(icon, popover);
|
|
14
|
+
popover.showPopover();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function alignPopover(target: HTMLElement, popover: HTMLElement): void {
|
|
18
|
+
const bounds = target.getBoundingClientRect().toJSON();
|
|
19
|
+
popover.style.inset = 'unset';
|
|
20
|
+
popover.style.top = bounds.y + 'px';
|
|
21
|
+
popover.style.left = (bounds.x + 20) + 'px';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function stylePopover(popover: HTMLElement): void {
|
|
25
|
+
popover.popover = 'auto';
|
|
26
|
+
popover.style.cursor = 'default';
|
|
27
|
+
popover.style.padding = '10px';
|
|
28
|
+
popover.style.background = '#fdffe5';
|
|
29
|
+
popover.style.border = '1px solid #E4E6CE';
|
|
30
|
+
popover.style.borderRadius = '2px';
|
|
31
|
+
popover.style.boxShadow = '0 0 5px #E4E6CE';
|
|
32
|
+
popover.style.maxWidth = '500px';
|
|
33
|
+
popover.style.color = 'var(--gray-6)';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function requestMembership(groupName: string) {
|
|
37
|
+
return async () => {
|
|
38
|
+
try {
|
|
39
|
+
const groups = await grok.dapi.groups.filter(`friendlyName="${groupName}"`).list();
|
|
40
|
+
if (groups.length === 0) {
|
|
41
|
+
throw new Error(`group with specified name is not found`);
|
|
42
|
+
}
|
|
43
|
+
if (groups.length > 1) {
|
|
44
|
+
throw new Error(`found more than one group with specified name`);
|
|
45
|
+
}
|
|
46
|
+
const group = groups[0];
|
|
47
|
+
|
|
48
|
+
// Workaround till JS API is not ready: https://reddata.atlassian.net/browse/GROK-14160
|
|
49
|
+
fetch(`${window.location.origin}/api/groups/${group.id}/requests/${grok.shell.user.group.id}`, {method: "POST"})
|
|
50
|
+
} catch (e: any) {
|
|
51
|
+
grok.shell.error(e.toString());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
7
56
|
export class ModelHandler extends DG.ObjectHandler {
|
|
57
|
+
userGroups = [] as DG.Group[];
|
|
58
|
+
|
|
8
59
|
get type() {
|
|
9
60
|
return 'Model';
|
|
10
61
|
}
|
|
@@ -47,9 +98,54 @@ export class ModelHandler extends DG.ObjectHandler {
|
|
|
47
98
|
}
|
|
48
99
|
|
|
49
100
|
renderMarkup(x: DG.Func): HTMLElement {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
101
|
+
const mandatoryUserGroups = JSON.parse(x.options['mandatoryUserGroups'] ? `${x.options['mandatoryUserGroups']}` : '[]') as {name: string, help?: string}[];
|
|
102
|
+
const hasMissingMandatoryGroups = mandatoryUserGroups.filter((group) => !this.userGroups.map((userGroup) => userGroup.friendlyName).includes(group.name)).length > 0;
|
|
103
|
+
const mandatoryGroupsIcon = ui.iconFA('exclamation-triangle', null);
|
|
104
|
+
mandatoryGroupsIcon.classList.remove('grok-icon');
|
|
105
|
+
|
|
106
|
+
const getBulletIcon = () => {
|
|
107
|
+
const bulletIcon = ui.iconFA('times');
|
|
108
|
+
bulletIcon.style.marginRight = '6px';
|
|
109
|
+
bulletIcon.classList.remove('grok-icon');
|
|
110
|
+
return bulletIcon;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const mandatoryGroupsInfo = ui.div(ui.divV([
|
|
114
|
+
ui.label('You should be a member of the following group(s):', {style: {marginLeft: '0px'}}),
|
|
115
|
+
...mandatoryUserGroups.map((group) => ui.divV([
|
|
116
|
+
ui.span([getBulletIcon(), group.name], {style: {'font-weight': 600}}),
|
|
117
|
+
...group.help ? [ui.span([group.help], {style: {marginLeft: '16px'}})]: [],
|
|
118
|
+
ui.link(`Request group membership`, requestMembership(group.name), undefined, {style: {marginLeft: '16px'}})
|
|
119
|
+
])),
|
|
120
|
+
], {style: {gap: '10px'}})) as HTMLElement;
|
|
121
|
+
|
|
122
|
+
if (hasMissingMandatoryGroups) {
|
|
123
|
+
addPopover(mandatoryGroupsInfo);
|
|
124
|
+
|
|
125
|
+
mandatoryGroupsIcon.addEventListener('click', () => {
|
|
126
|
+
displayPopover(mandatoryGroupsIcon, mandatoryGroupsInfo)
|
|
127
|
+
})
|
|
128
|
+
mandatoryGroupsIcon.addEventListener('mouseover', (e) => {
|
|
129
|
+
e.stopPropagation();
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const label = ui.span([
|
|
134
|
+
this.renderIcon(x),
|
|
135
|
+
ui.label(x.friendlyName)
|
|
136
|
+
]);
|
|
137
|
+
const markup = ui.divH([
|
|
138
|
+
label,
|
|
139
|
+
...hasMissingMandatoryGroups ? [ui.span([mandatoryGroupsIcon])]: [],
|
|
140
|
+
], {style: {'justify-content': 'space-between', 'width': '100%'}})
|
|
141
|
+
|
|
142
|
+
if (!hasMissingMandatoryGroups) {
|
|
143
|
+
markup.ondblclick = () => { ModelHandler.openModel(x); }
|
|
144
|
+
markup.onclick = () => { ModelHandler.openHelp(x); }
|
|
145
|
+
} else {
|
|
146
|
+
label.classList.add('d4-disabled');
|
|
147
|
+
}
|
|
148
|
+
|
|
53
149
|
return markup;
|
|
54
150
|
}
|
|
55
151
|
|
|
@@ -85,13 +181,12 @@ export class ModelHandler extends DG.ObjectHandler {
|
|
|
85
181
|
}
|
|
86
182
|
|
|
87
183
|
renderTooltip(x: DG.Func) {
|
|
88
|
-
let h = this.
|
|
184
|
+
let h = ui.span([this.renderIcon(x), ui.label(x.friendlyName)]);
|
|
89
185
|
h.classList.add('d4-link-label');
|
|
90
186
|
let card = ui.bind(x, ui.divV([
|
|
91
187
|
ui.h2(h),
|
|
92
188
|
ui.divV([ui.divText(x.description, 'ui-description')], {style: {lineHeight: '150%'}})
|
|
93
189
|
]));
|
|
94
|
-
card.ondblclick = (e) => { ModelHandler.openModel(x); }
|
|
95
190
|
return card;
|
|
96
191
|
}
|
|
97
192
|
|
|
@@ -99,8 +194,6 @@ export class ModelHandler extends DG.ObjectHandler {
|
|
|
99
194
|
let h = this.renderMarkup(x);
|
|
100
195
|
h.classList.add('d4-link-label');
|
|
101
196
|
let card = ui.bind(x, ui.h2(h));
|
|
102
|
-
card.ondblclick = (e) => { ModelHandler.openModel(x); }
|
|
103
|
-
card.onclick = (e) => { ModelHandler.openHelp(x); }
|
|
104
197
|
return card;
|
|
105
198
|
}
|
|
106
199
|
|
|
@@ -154,7 +247,10 @@ export class ModelHandler extends DG.ObjectHandler {
|
|
|
154
247
|
}
|
|
155
248
|
|
|
156
249
|
init() {
|
|
157
|
-
setTimeout(() => {
|
|
250
|
+
setTimeout(async () => {
|
|
251
|
+
// Workaround till JS API is not ready: https://reddata.atlassian.net/browse/GROK-14159
|
|
252
|
+
this.userGroups = (await (await fetch(`${window.location.origin}/api/groups/all_parents`)).json() as DG.Group[]);
|
|
253
|
+
|
|
158
254
|
grok.functions.onBeforeRunAction.subscribe((fc) => {
|
|
159
255
|
if (fc.func.hasTag('model') || fc.func.hasTag('model-editor')) {
|
|
160
256
|
ModelHandler.bindModel(fc);
|
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
|
package/scripts/trig.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//name: trig
|
|
2
|
-
//description: Returns sin, cos, and tan
|
|
3
|
-
//language: javascript
|
|
4
|
-
//input: double x
|
|
5
|
-
//output: double sin
|
|
6
|
-
//output: double cos
|
|
7
|
-
//output: double tan
|
|
8
|
-
//meta.domain: math
|
|
9
|
-
//meta.runOnOpen: true
|
|
10
|
-
//meta.runOnInput: true
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
sin = Math.sin(x);
|
|
14
|
-
cos = Math.cos(x);
|
|
15
|
-
tan = Math.tan(x);
|