Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/spraying #308

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
fd58ea6
Specify timesteps in create process
pwinskill Jul 12, 2023
7fa7ea3
Merge pull request #258 from mrc-ide/bug/progress_bar_timesteps
giovannic Jul 19, 2023
a7c7dd1
Fix competing hazards for mass and EPI pev:
giovannic Sep 18, 2023
efd3dfc
Merge pull request #265 from mrc-ide/bug/competing_vaccination
giovannic Sep 22, 2023
e7b5c4d
Fix bug with pev min_wait:
giovannic Sep 15, 2023
8e0e76e
Merge pull request #264 from mrc-ide/bug/min_wait
giovannic Nov 3, 2023
5f174c4
Custom carrying capacity is set as a relative scaler, not absolute value
pwinskill Nov 23, 2023
a109246
Document and make suggested changes to carrying capacity vignette for…
pwinskill Dec 4, 2023
dc922d7
Merge pull request #272 from mrc-ide/carrying_capacity_relative
giovannic Dec 6, 2023
73cbfb4
Implement time varying coverage for PEV boosters:
giovannic Nov 16, 2023
d49c8dd
Fix PEV EPI parameterisation bug
giovannic Dec 6, 2023
91247b4
Implement simplified pev booster interface:
giovannic Jan 4, 2024
45486ad
Check that booster_spacing is monotonically increasing
giovannic Jan 9, 2024
f1039ea
Changed the calculation of birth_ivm in sample_maternal_immunity(). T…
tbreweric Jan 15, 2024
b0ad081
Merge pull request #270 from mrc-ide/feat/time_boosters
giovannic Jan 16, 2024
01a0a1e
Merge branch 'dev' into bug/maternal_immunity_sampling
giovannic Jan 18, 2024
0359cec
Merge pull request #279 from mrc-ide/bug/maternal_immunity_sampling
giovannic Jan 22, 2024
d8930d8
Opened sub-branch of feat/antimalarial_resistance for developing the …
Jun 6, 2023
8efb863
Added first iteration of the set_antimalarial_resistance() function d…
tbreweric Jul 6, 2023
74a2a3b
Updated the set_antimalarial_resistance() function to allow for multi…
Jul 11, 2023
acf145e
Removed the else{} arguments on the checks, condensed the first check…
Jul 13, 2023
856ec1e
Added additional section for testing different versions of ETF versio…
Jul 13, 2023
da94206
removed the extra versions of calculate_treated() from human_infectio…
Jul 13, 2023
571a20c
removed all but resistance first, efficacy second version of calculat…
tbreweric Jul 14, 2023
bfb6aa0
Deleting the development script from the branch (will store developme…
tbreweric Jul 14, 2023
02e4916
Amended the calculate_treated() function to remove the loop when assi…
tbreweric Jul 17, 2023
7be84ee
Added check to number of clinical_infections in calculate_treated() a…
tbreweric Jul 22, 2023
fea9da2
Removed typos/spaces from antimalarial_resistance.R. Added check for …
Aug 1, 2023
0b1adb6
removed comments from calculate_treated() function
tbreweric Aug 4, 2023
731899e
removed unnecessary spacing and comments from the calculate_treated()…
tbreweric Aug 17, 2023
578c9e5
Create test-antimalarial-resistance.R and added six tests for the set…
tbreweric Aug 17, 2023
ded0251
Added test file for new antimalarial resistance functions and added n…
tbreweric Aug 17, 2023
d4db8f9
Commiting all changes recommended by Pete/Giovanni except those that …
tbreweric Sep 20, 2023
11e61e1
Commiting the final set of changes and corrections in response to com…
tbreweric Oct 10, 2023
de29495
Implemented the second round of changes requested in the pull request
Feb 8, 2024
4d75b2e
Implented the second round of changes requested in the pull request
Feb 8, 2024
d51bbf7
Re-adding the changes recommended by Pete following a reversion to 4d…
tbreweric Feb 12, 2024
2adf823
Corrected drugs documentation for get_antimalarial_resistance_paramet…
tbreweric Feb 13, 2024
3ea8ee3
Merge pull request #263 from mrc-ide/antimalarial_resistance/etf
tbreweric Feb 14, 2024
d16978e
Added check for undeveloped antimalarial resistance features (SPC/LPF…
Feb 15, 2024
1a5f00a
Merge pull request #282 from mrc-ide/feat/resistance_unused_feature_e…
tbreweric Feb 15, 2024
c42e2c5
Add initial support for saving and restoring simulation state. (#280)
plietar Feb 27, 2024
b3376d3
Rewrite the exponential decay process in C++. (#285)
plietar Mar 21, 2024
2c9932b
Combined ETF and SPC. Need to fix testthat files before PR
tbreweric Mar 26, 2024
2a3d4cc
Improve correlation tests. (#287)
plietar Apr 3, 2024
952108c
Fixed errors in unit tests which included amending the create_mortali…
Apr 3, 2024
0cef273
Added section modelling early treatment failure and slow parasite cle…
tbreweric Apr 4, 2024
5123d6e
Made clearer the antimalarial resistance parameter names in set_antim…
tbreweric Apr 4, 2024
54456df
Merge branch 'dev' into feat/spc
tbreweric Apr 8, 2024
d9ce4a6
Implemented the changes recommended by in first round of PR comments
tbreweric Apr 11, 2024
086956a
Merge branch 'feat/spc' of https://github.com/mrc-ide/malariasimulati…
tbreweric Apr 11, 2024
5077d4b
Moved mortality to the end of processes to resolve order of competing…
RJSheppard Apr 15, 2024
f58d48f
Altered check for rate data type in create_disease_progression() func…
tbreweric Apr 18, 2024
e9d46e7
Update description of the dt parameter. (#288)
plietar Apr 25, 2024
5900751
Merge branch 'dev' into feat/spc
tbreweric Apr 26, 2024
380d113
Merge pull request #289 from mrc-ide/feat/spc
tbreweric Apr 26, 2024
9debd7f
Clarify some intervention parametrization documentation. (#291)
plietar Apr 26, 2024
e534db7
Allow simulation to be restored with new interventions. (#286)
plietar Feb 13, 2024
1111500
Allow correlations to be extended when resuming. (#293)
plietar Apr 30, 2024
a9b495c
Merging dev branch back before merging into main dev branch.
RJSheppard May 1, 2024
7e62cc9
Merge pull request #292 from mrc-ide/competing_hazards_mortality_order
RJSheppard May 2, 2024
b8f3c27
I think the calculation for initial EIR values isn't quite right. I d…
RJSheppard May 8, 2024
69fc17f
Improved robustness of calculate initial EIR test.
RJSheppard May 9, 2024
6804095
Merge pull request #296 from mrc-ide/initial_eir_calculation_correction
RJSheppard May 20, 2024
254bce2
Depend on dqrng from CRAN again.
plietar May 15, 2024
75a0332
Fix warnings and deprecations.
plietar May 15, 2024
25c0956
Merge pull request #305 from mrc-ide/dqrng-release
plietar May 21, 2024
6008a8a
adding in n_spray output
htopazian May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: malariasimulation
Title: An individual based model for malaria
Version: 1.6.0
Version: 1.6.1
Authors@R: c(
person(
given = "Giovanni",
Expand Down Expand Up @@ -70,12 +70,12 @@ Remotes:
mrc-ide/malariaEquilibrium,
mrc-ide/individual
Imports:
individual (>= 0.1.7),
individual (>= 0.1.16),
malariaEquilibrium (>= 1.0.1),
Rcpp,
statmod,
MASS,
dqrng,
dqrng (>= 0.4),
sitmo,
BH,
R6,
Expand All @@ -91,7 +91,7 @@ Suggests:
ggplot2,
covr,
mgcv
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
LinkingTo:
Rcpp,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export(rtss_profile)
export(run_metapop_simulation)
export(run_simulation)
export(run_simulation_with_repetitions)
export(set_antimalarial_resistance)
export(set_bednets)
export(set_carrying_capacity)
export(set_clinical_treatment)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# malariasimulation 1.6.1 (wip)

* Fix bug in competing hazards between mass and EPI vaccines. Where individuals
can be enrolled onto both strategies if applied on the same timestep.
* Fix bug with min_wait. Min wait was working off of the final primary dose. It
now works of of the first dose.

# malariasimulation 1.6.0

* Fix MDA bug where undetectable asymptomatics are treated
Expand Down
32 changes: 32 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ adult_mosquito_model_update <- function(model, mu, foim, susceptible, f) {
invisible(.Call(`_malariasimulation_adult_mosquito_model_update`, model, mu, foim, susceptible, f))
}

adult_mosquito_model_save_state <- function(model) {
.Call(`_malariasimulation_adult_mosquito_model_save_state`, model)
}

adult_mosquito_model_restore_state <- function(model, state) {
invisible(.Call(`_malariasimulation_adult_mosquito_model_restore_state`, model, state))
}

create_adult_solver <- function(model, init, r_tol, a_tol, max_steps) {
.Call(`_malariasimulation_create_adult_solver`, model, init, r_tol, a_tol, max_steps)
}
Expand Down Expand Up @@ -37,10 +45,18 @@ rainfall <- function(t, g0, g, h, floor) {
.Call(`_malariasimulation_rainfall`, t, g0, g, h, floor)
}

exponential_process_cpp <- function(variable, rate) {
.Call(`_malariasimulation_exponential_process_cpp`, variable, rate)
}

solver_get_states <- function(solver) {
.Call(`_malariasimulation_solver_get_states`, solver)
}

solver_set_states <- function(solver, t, state) {
invisible(.Call(`_malariasimulation_solver_set_states`, solver, t, state))
}

solver_step <- function(solver) {
invisible(.Call(`_malariasimulation_solver_step`, solver))
}
Expand All @@ -57,10 +73,26 @@ timeseries_push <- function(timeseries, value, timestep) {
invisible(.Call(`_malariasimulation_timeseries_push`, timeseries, value, timestep))
}

timeseries_save_state <- function(timeseries) {
.Call(`_malariasimulation_timeseries_save_state`, timeseries)
}

timeseries_restore_state <- function(timeseries, state) {
invisible(.Call(`_malariasimulation_timeseries_restore_state`, timeseries, state))
}

random_seed <- function(seed) {
invisible(.Call(`_malariasimulation_random_seed`, seed))
}

random_save_state <- function() {
.Call(`_malariasimulation_random_save_state`)
}

random_restore_state <- function(state) {
invisible(.Call(`_malariasimulation_random_restore_state`, state))
}

bernoulli_multi_p_cpp <- function(p) {
.Call(`_malariasimulation_bernoulli_multi_p_cpp`, p)
}
Expand Down
146 changes: 146 additions & 0 deletions R/antimalarial_resistance.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#' @title Parameterise antimalarial resistance
#' @description
#' Parameterise antimalarial resistance
#'
#' @param parameters the model parameters
#' @param drug the index of the drug which resistance is being set, as set by the set_drugs() function, in the parameter list
#' @param timesteps vector of time steps for each update to resistance proportion and resistance outcome probability
#' @param artemisinin_resistance_proportion vector of updates to the proportions of infections that are artemisinin resistant at time t
#' @param partner_drug_resistance_proportion vector of updates to the proportions of infections that are partner-drug resistant at time t
#' @param slow_parasite_clearance_probability vector of updates to the proportion of artemisinin-resistant infections that result in early treatment failure
#' @param early_treatment_failure_probability vector of updates to the proportion of artemisinin-resistant infections that result in slow parasite clearance
#' @param late_clinical_failure_probability vector of updates to the proportion of partner-drug-resistant infections that result in late clinical failure
#' @param late_parasitological_failure_probability vector of updates to the proportion of partner-drug-resistant infections that result in late parasitological failure
#' @param reinfection_during_prophylaxis_probability vector of updates to the proportion of partner-drug-resistant infections that result in reinfection during prophylaxis
#' @param slow_parasite_clearance_time single value representing the mean time individual's experiencing slow parasite clearance reside in the treated state
#' @export
set_antimalarial_resistance <- function(parameters,
drug,
timesteps,
artemisinin_resistance_proportion,
partner_drug_resistance_proportion,
slow_parasite_clearance_probability,
early_treatment_failure_probability,
late_clinical_failure_probability,
late_parasitological_failure_probability,
reinfection_during_prophylaxis_probability,
slow_parasite_clearance_time) {

if(any(partner_drug_resistance_proportion > 0,
late_clinical_failure_probability > 0,
late_parasitological_failure_probability > 0,
reinfection_during_prophylaxis_probability > 0)) {
stop("Parameters set for unimplemented feature - late clinical failure, late parasitological failure, or reinfection during prophylaxis")
}

if(any(c(length(artemisinin_resistance_proportion),
length(partner_drug_resistance_proportion),
length(slow_parasite_clearance_probability),
length(early_treatment_failure_probability),
length(late_clinical_failure_probability),
length(late_parasitological_failure_probability),
length(reinfection_during_prophylaxis_probability)) != length(timesteps))) {
stop("Length of one or more resistance parameter vectors does not match time steps specified for update")
}

if(any(artemisinin_resistance_proportion < 0 | artemisinin_resistance_proportion > 1 |
partner_drug_resistance_proportion < 0 | partner_drug_resistance_proportion > 1)) {
stop("Artemisinin and partner-drug resistance proportions must fall between 0 and 1")
}

if(any(slow_parasite_clearance_probability < 0 | slow_parasite_clearance_probability > 1 |
early_treatment_failure_probability < 0 | early_treatment_failure_probability > 1 |
late_clinical_failure_probability < 0 | late_clinical_failure_probability > 1 |
late_parasitological_failure_probability < 0 | late_parasitological_failure_probability > 1 |
reinfection_during_prophylaxis_probability < 0 | reinfection_during_prophylaxis_probability > 1)) {
stop("Resistance outcome probabilities must fall between 0 and 1")
}

if(length(slow_parasite_clearance_time) != 1) {
stop("Error: length of slow_parasite_clearance_time not equal to 1")
}

if(slow_parasite_clearance_time <= 0) {
stop("Error: slow_parasite_clearance_time is non-positive")
}

parameters$antimalarial_resistance <- TRUE

n_drugs <- length(parameters$drug_efficacy)

if (drug < 1 | drug > n_drugs) {
stop('Drug index is invalid, please set drugs using set_drugs')
}

drug_index <- which(parameters$antimalarial_resistance_drug == drug)

if (length(drug_index) == 0) {
drug_index <- length(parameters$antimalarial_resistance_drug) + 1
}

parameters$antimalarial_resistance_drug[[drug_index]] <- drug
parameters$antimalarial_resistance_timesteps[[drug_index]] <- timesteps
parameters$artemisinin_resistance_proportion[[drug_index]] <- artemisinin_resistance_proportion
parameters$partner_drug_resistance_proportion[[drug_index]] <- partner_drug_resistance_proportion
parameters$slow_parasite_clearance_probability[[drug_index]] <- slow_parasite_clearance_probability
parameters$early_treatment_failure_probability[[drug_index]] <- early_treatment_failure_probability
parameters$late_clinical_failure_probability[[drug_index]] <- late_clinical_failure_probability
parameters$late_parasitological_failure_probability[[drug_index]] <- late_parasitological_failure_probability
parameters$reinfection_during_prophylaxis_probability[[drug_index]] <- reinfection_during_prophylaxis_probability
parameters$dt_slow_parasite_clearance[[drug_index]] <- slow_parasite_clearance_time

return(parameters)

}

#' @title Retrieve resistance parameters
#' @description
#' Retrieve the resistance parameters associated with the drug each individual receiving clinical
#' treatment has been administered in the current time step.
#'
#' @param parameters the model parameters
#' @param drugs vector of integers representing the drugs administered to each individual receiving treatment
#' @param timestep the current time step
get_antimalarial_resistance_parameters <- function(parameters, drugs, timestep) {

if(!parameters$antimalarial_resistance) {
stop("Error: Antimalarial resistance has not been parameterised; antimalarial_resistance = FALSE")
}

blank_vector <- numeric(length = length(drugs))
artemisinin_resistance_proportion <- blank_vector
partner_drug_resistance_proportion <- blank_vector
slow_parasite_clearance_probability <- blank_vector
early_treatment_failure_probability <- blank_vector
late_clinical_failure_probability <- blank_vector
late_parasitological_failure_probability <- blank_vector
reinfection_during_prophylaxis_probability <- blank_vector
dt_slow_parasite_clearance <- rep(parameters$dt, length = length(drugs))

for(i in seq_along(parameters$antimalarial_resistance_drug)) {
drug <- parameters$antimalarial_resistance_drug[[i]]
treated_with_drug <- which(drugs == drug)
resistance_timestep <- match_timestep(ts = parameters$antimalarial_resistance_timesteps[[i]], t = timestep)
artemisinin_resistance_proportion[treated_with_drug] <- parameters$artemisinin_resistance_proportion[[i]][resistance_timestep]
partner_drug_resistance_proportion[treated_with_drug] <- parameters$partner_drug_resistance_proportion[[i]][resistance_timestep]
slow_parasite_clearance_probability[treated_with_drug] <- parameters$slow_parasite_clearance_probability[[i]][resistance_timestep]
early_treatment_failure_probability[treated_with_drug] <- parameters$early_treatment_failure_probability[[i]][resistance_timestep]
late_clinical_failure_probability[treated_with_drug] <- parameters$late_clinical_failure_probability[[i]][resistance_timestep]
late_parasitological_failure_probability[treated_with_drug] <- parameters$late_parasitological_failure_probability[[i]][resistance_timestep]
reinfection_during_prophylaxis_probability[treated_with_drug] <- parameters$reinfection_during_prophylaxis_probability[[i]][resistance_timestep]
dt_slow_parasite_clearance[treated_with_drug] <- parameters$dt_slow_parasite_clearance[[i]]
}

resistance_parameters <- list()
resistance_parameters$artemisinin_resistance_proportion <- artemisinin_resistance_proportion
resistance_parameters$partner_drug_resistance_proportion <- partner_drug_resistance_proportion
resistance_parameters$slow_parasite_clearance_probability <- slow_parasite_clearance_probability
resistance_parameters$early_treatment_failure_probability <- early_treatment_failure_probability
resistance_parameters$late_clinical_failure_probability <- late_clinical_failure_probability
resistance_parameters$late_parasitological_failure_probability <- late_parasitological_failure_probability
resistance_parameters$reinfection_during_prophylaxis_probability <- reinfection_during_prophylaxis_probability
resistance_parameters$dt_slow_parasite_clearance <- dt_slow_parasite_clearance

return(resistance_parameters)

}
12 changes: 5 additions & 7 deletions R/biting_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ simulate_bites <- function(

for (s_i in seq_along(parameters$species)) {
species_name <- parameters$species[[s_i]]
solver_states <- solver_get_states(solvers[[s_i]])
solver_states <- solvers[[s_i]]$get_states()
p_bitten <- prob_bitten(timestep, variables, s_i, parameters)
Q0 <- parameters$Q0[[s_i]]
W <- average_p_successful(p_bitten$prob_bitten_survives, .pi, Q0)
Expand Down Expand Up @@ -167,7 +167,7 @@ simulate_bites <- function(
if (parameters$individual_mosquitoes) {
# update the ODE with stats for ovoposition calculations
aquatic_mosquito_model_update(
models[[s_i]],
models[[s_i]]$.model,
species_index$size(),
f,
mu
Expand All @@ -189,7 +189,7 @@ simulate_bites <- function(
)
} else {
adult_mosquito_model_update(
models[[s_i]],
models[[s_i]]$.model,
mu,
foim,
solver_states[[ADULT_ODE_INDICES['Sm']]],
Expand All @@ -210,9 +210,7 @@ simulate_bites <- function(
calculate_eir <- function(species, solvers, variables, parameters, timestep) {
a <- human_blood_meal_rate(species, variables, parameters, timestep)
infectious <- calculate_infectious(species, solvers, variables, parameters)
age <- get_age(variables$birth$get_values(), timestep)
psi <- unique_biting_rate(age, parameters)
infectious * a * mean(psi)
infectious * a
}

effective_biting_rates <- function(a, .pi, p_bitten) {
Expand All @@ -235,7 +233,7 @@ calculate_infectious <- function(species, solvers, variables, parameters) {
)
)
}
calculate_infectious_compartmental(solver_get_states(solvers[[species]]))
calculate_infectious_compartmental(solvers[[species]]$get_states())
}

calculate_infectious_individual <- function(
Expand Down
Loading
Loading