Skip to content

Commit 6a5d2d7

Browse files
authored
Merge pull request #31 from PumasAI-Labs/dw/updates
Updates for SA workshop
2 parents d9949ec + 6c61235 commit 6a5d2d7

28 files changed

+226
-241
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.DS_Store
2+
*.jls
3+
*.png

Exercises/01-pkpd_simulations_exercises.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# =============================================================================
44

55
# Import the previous code that returns the fitted Pumas model
6-
include(joinpath(@__DIR__, "..","01-TeachingMaterial","02-population_pkpd","03-pkpd_model_fitting.jl") ) # to get warfarin_model and warfarin_model_fit
6+
include(joinpath(@__DIR__, "..","TeachingMaterial","population_pkpd","03-pkpd_model_fitting.jl")) # to get warfarin_model and warfarin_model_fit
77

88
# -----------------------------------------------------------------------------
99
# 1. PACKAGES
@@ -29,7 +29,7 @@ Using the warfarin PK-PD model:
2929
2. Explore the effect on PK and PCA
3030
"""
3131

32-
# Create DosagRegimen object for single dose levels of 50 and 150 at time 0
32+
# Create DosagRegimen objects for single dose levels of 50 and 150 at time 0
3333
# your code here
3434

3535
# Create a population of 100 subjects for each new dosing regimen:
@@ -54,7 +54,7 @@ Using the warfarin PK-PD model:
5454
2. Explore the effect on PK and PCA
5555
"""
5656

57-
# Create DosagRegimen object for daily doses of 50 and 150 for a week:
57+
# Create DosagRegimen objects for daily doses of 50 and 150 for a week:
5858
# your code here
5959

6060
# Create a population for each new dosing regimen:
@@ -79,7 +79,7 @@ Using the warfarin PK-PD model:
7979
2. Explore the effect on PK and PCA
8080
"""
8181

82-
# Create DosagRegimen object for a loading dose of 400 followed by daily doses of 150 for a week:
82+
# Create a DosagRegimen object for a loading dose of 400 followed by daily doses of 150 for a week:
8383
# your code here
8484

8585
# Create a population with the new dosing regimen:

Exercises/01-variables_exercise.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ using Test
44
Exercise 1: Variable Declaration and Types
55
----------------------------------------
66
Declare variables for the following pharmacometric parameters:
7-
1. Create a variable 'dose' with value 100 (mg)
8-
2. Create a variable 'volume_of_distribution' with value 48.2 (L)
9-
3. Create a variable 'half_life' with value 12.5 (hours)
10-
4. Create a variable 'is_fasted' as a boolean indicating fasting state
11-
5. Create a variable 'patient_id' as a string "SUBJ-001"
7+
1. Create a variable `dose` with value 100 (mg)
8+
2. Create a variable `volume_of_distribution` with value 48.2 (L)
9+
3. Create a variable `half_life` with value 12.5 (hours)
10+
4. Create a variable `is_fasted` as a boolean indicating fasting state
11+
5. Create a variable `patient_id` as a string "SUBJ-001"
1212
1313
Use the most appropriate type for each variable!
1414
"""
@@ -20,8 +20,8 @@ Use the most appropriate type for each variable!
2020
Exercise 2: Basic Calculations
2121
----------------------------
2222
Using the variables you created above:
23-
1. Calculate the elimination rate constant (k) using the formula: k = ln(2)/half_life
24-
2. Calculate the initial concentration (C0) using: C0 = dose/volume_of_distribution
23+
1. Calculate the elimination rate constant (k) using the formula: `k` = ln(2)/`half_life`
24+
2. Calculate the initial concentration (C0) using: `C0` = `dose`/`volume_of_distribution`
2525
3. Store both results in new variables
2626
"""
2727

Exercises/02-syntax_exercise.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Test
44
Exercise 1: Conditional Statements
55
--------------------------------
66
Write conditional statements to:
7-
1. Check if a drug concentration (conc = 15.5 μg/mL) is within therapeutic range (10-20 μg/mL)
7+
1. Check if a drug concentration (`conc` = 15.5 μg/mL) is within therapeutic range (10-20 μg/mL)
88
2. Wriate a function that classifies the drug exposure as:
99
- "Low" if < 10 μg/mL
1010
- "Therapeutic" if between 10-20 μg/mL
@@ -18,9 +18,9 @@ Write conditional statements to:
1818
Exercise 2: Loops
1919
----------------
2020
1. Create an array of hourly time points from 0 to 24 hours
21-
2. Calculate drug concentrations at each time point using the formula:
22-
C(t) = C0 * exp(-k * t)
23-
where C0 = 100 μg/mL and k = 0.1 /hour
21+
2. Calculate drug concentrations at each time point in a loop using the formula:
22+
C(t) = `C0` * exp(-`k` * t)
23+
where `C0` = 100 μg/mL and `k` = 0.1 /hour
2424
3. Store results in a new array
2525
"""
2626

Exercises/03-functions_exercise.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ using Test
33
@info """
44
Exercise 1: Basic Function Definition
55
----------------------------------
6-
1. Create a function calculate_clearance that takes volume (L) and elimination_rate (/hr) as arguments
6+
1. Create a function `calculate_clearance` that takes `volume` (L) and `elimination_rate` (/hr) as arguments
77
and returns clearance (L/hr)
8-
2. Create a function calculate_half_life that takes elimination_rate (/hr) as argument
8+
2. Create a function `calculate_half_life` that takes `elimination_rate` (/hr) as argument
99
and returns the half-life (hr)
10-
3. Create a function calculate_auc that takes dose (mg) and clearance (L/hr) as arguments
10+
3. Create a function `calculate_auc` that takes `dose` (mg) and `clearance` (L/hr) as arguments
1111
and returns the AUC (mg*hr/L)
1212
"""
1313

@@ -17,11 +17,16 @@ Exercise 1: Basic Function Definition
1717
@info """
1818
Exercise 2: Multiple Dispatch
1919
---------------------------
20-
1. Create a function calculate_dose that works with different units:
21-
- One method that takes weight (kg) and dose_per_kg (mg/kg)
22-
- Another method that takes BSA (m²) and dose_per_m2 (mg/m²)
23-
Both should return the total dose in mg
24-
2. Add type annotations to make the function more robust
20+
1. Create a function `calculate_dose` that works with both
21+
weight of a single subject and weights of a population of multiple subjects:
22+
- One method that takes `weight` (kg) of a single subject and `dose_per_kg` (mg/kg),
23+
and returns the total dose of that subject in mg.
24+
- Another method that takes a vector of `weights` (kg) of multiple subjects and
25+
`dose_per_kg` (mg/kg), and returns a vector of total doses in mg for each subject.
26+
Reuse the method for a single subject in the method for multiple subjects.
27+
2. In this case, it is actually not necessary to define two different methods.
28+
Define a single method `calculate_dose_alt` that works for both cases,
29+
without using `if`/`else` statements on the input type.
2530
"""
2631

2732
# Your code here
@@ -43,7 +48,7 @@ Exercise 3: Anonymous Functions
4348
@info """
4449
Bonus Challenge: Higher Order Functions
4550
-----------------------------------
46-
1. Create a higher-order function simulate_pk that takes:
51+
1. Create a higher-order function `simulate_pk` that takes:
4752
- A dosing function (that calculates concentration vs time)
4853
- Time points array
4954
- PK parameters dictionary

Exercises/HCV_model/02-HCV_model_exercise.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# https://pmc.ncbi.nlm.nih.gov/articles/PMC4294071/
55
# ==============================================================
66

7-
using Pumas, CairoMakie, DataFrames, Random, PumasUtilities, Logging
7+
using Pumas, CairoMakie, DataFrames, Random, PumasUtilities
88

99

1010
# Model set up
@@ -15,7 +15,7 @@ model_hcv = @model begin
1515
# fixed effects
1616
logθKa RealDomain()
1717

18-
# random effects variance parameters, must be posisitive
18+
# random effects variance parameters, must be positive
1919
ω²Ka RealDomain(lower = 0.0)
2020

2121
# variance parameter in error models

Exercises/TGI_model/01-TGI_model_exercise.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# https://pubmed.ncbi.nlm.nih.gov/19636014/
55
# ==============================================================
66

7-
using Pumas, CairoMakie, DataFrames, Random, PumasUtilities, Logging
7+
using Pumas, CairoMakie, DataFrames, Random, PumasUtilities
88

99
# Reproduce the model for FU Phase III
1010

Solutions/01-pkpd_simulations_solutions.jl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# =============================================================================
44

55
# Import the previous code that returns the fitted Pumas model
6-
include(joinpath(@__DIR__, "..","01-TeachingMaterial","02-population_pkpd","03-pkpd_model_fitting.jl") ) # to get warfarin_model and warfarin_model_fit
6+
include(joinpath(@__DIR__, "..","TeachingMaterial","population_pkpd","03-pkpd_model_fitting.jl")) # to get warfarin_model and warfarin_model_fit
77

88
# -----------------------------------------------------------------------------
99
# 1. PACKAGES
@@ -51,11 +51,11 @@ sim_150 = simobs(
5151
)
5252

5353
# Plot:
54-
sim_plot(warfarin_model, sim_50; observations = [:conc], axis = (; limits = (nothing, (0, 30))))
55-
sim_plot(warfarin_model, sim_150; observations = [:conc], axis = (; limits = (nothing, (0, 30))))
54+
sim_plot(warfarin_model, sim_50; observations = [:conc])
55+
sim_plot(warfarin_model, sim_150; observations = [:conc])
5656

57-
sim_plot(warfarin_model, sim_50; observations = [:pca], axis = (; limits = (nothing, (0, 150))))
58-
sim_plot(warfarin_model, sim_150; observations = [:pca], axis = (; limits = (nothing, (0, 150))))
57+
sim_plot(warfarin_model, sim_50; observations = [:pca])
58+
sim_plot(warfarin_model, sim_150; observations = [:pca])
5959

6060

6161
# -----------------------------------------------------------------------------
@@ -70,7 +70,7 @@ Using the warfarin PK-PD model:
7070
2. Explore the effect on PK and PCA
7171
"""
7272

73-
# Create DosagRegimen object for daily doses of 50 for a week:
73+
# Create DosagRegimen objects for daily doses of 50 and 150 for a week:
7474
dose_50qd = DosageRegimen(50; time = 0, ii = 24 , addl = 6)
7575
dose_150qd = DosageRegimen(150; time = 0, ii = 24 , addl = 6)
7676
# Create a population for each new dosing regimen:
@@ -91,11 +91,11 @@ sim_150qd = simobs(
9191
obstimes = 0.0:1:150.0, # Fine time grid
9292
)
9393
# Plot:
94-
sim_plot(warfarin_model, sim_50qd; observations = [:conc], axis = (; limits = (nothing, (0, 80))))
95-
sim_plot(warfarin_model, sim_150qd; observations = [:conc], axis = (; limits = (nothing, (0, 80))))
94+
sim_plot(warfarin_model, sim_50qd; observations = [:conc])
95+
sim_plot(warfarin_model, sim_150qd; observations = [:conc])
9696

97-
sim_plot(warfarin_model, sim_50qd; observations = [:pca], axis = (; limits = (nothing, (0, 80))))
98-
sim_plot(warfarin_model, sim_150qd; observations = [:pca], axis = (; limits = (nothing, (0, 80))))
97+
sim_plot(warfarin_model, sim_50qd; observations = [:pca])
98+
sim_plot(warfarin_model, sim_150qd; observations = [:pca])
9999

100100

101101
# -----------------------------------------------------------------------------
@@ -128,7 +128,3 @@ new_sim = simobs(
128128
# Plot:
129129
sim_plot(warfarin_model, new_sim; observations = [:conc])
130130
sim_plot(warfarin_model, new_sim; observations = [:pca])
131-
132-
133-
134-

Solutions/01-variables_solution.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ k = log(2)/half_life
1919
C0 = dose/volume_of_distribution
2020

2121
# Test Exercise 2
22-
@test isapprox(k, 0.0554, atol=0.001)
23-
@test isapprox(C0, 2.0747, atol=0.001)
22+
@test k 0.0554 atol=0.001
23+
@test C0 2.0747 atol=0.001
2424

2525
# Exercise 3: String Manipulation
2626
patient_info = "Patient $patient_id received $dose mg"
@@ -47,4 +47,4 @@ patient_params["clearance"] = volume_of_distribution * k
4747
# Test Bonus Challenge
4848
@test dose_in_grams == 0.1
4949
@test haskey(patient_params, "clearance")
50-
@test isapprox(patient_params["clearance"], 2.67, atol=0.01)
50+
@test patient_params["clearance"] 2.67 atol=0.01

Solutions/02-syntax_solution.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ end
6868
# Test Bonus Challenge
6969
@test haskey(dosing_recommendations, 60)
7070
@test dosing_recommendations[60][1] == 60
71-
@test dosing_recommendations[90][3] == 270 # This should trigger warning
71+
@test dosing_recommendations[90][3] == 270

0 commit comments

Comments
 (0)