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

Vivax competing hazards main drugs #330

Merged
merged 7 commits into from
Jan 31, 2025
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(AL_params)
export(CQ_PQ_params_vivax)
export(CQ_TQ_params_vivax)
export(CQ_params_vivax)
export(DHA_PQP_params)
export(SP_AQ_params)
export(arab_params)
Expand Down
63 changes: 56 additions & 7 deletions R/drug_parameters.R
Original file line number Diff line number Diff line change
@@ -1,44 +1,93 @@
#' @title Preset parameters for the DHA-PQP drug
#' @title Preset parameters for the DHA-PQP drug (P. falciparum)
#' @description From SI of Commun. 5:5606 doi: 10.1038/ncomms6606 (2014)
#' @details Use a vector of preset parameters for the DHA-PQP drug (dihydroartemisinin-piperaquine)
#' @details Default parameters, from L to R, are: drug_efficacy: 0.95, drug_rel_c: 0.09434, drug_prophylaxis_shape: 4.4, drug_prophylaxis_scale: 28.1
#' @export
DHA_PQP_params <- c(.95, 0.09434, 4.4, 28.1)

#' @title Preset parameters for the AL drug
#' @title Preset parameters for the AL drug (P. falciparum)
#' @description From SI of Commun. 5:5606 doi: 10.1038/ncomms6606 (2014)
#' @details Use a vector of preset parameters for the AL drug (artemether-lumefantrine)
#' @details Default parameters, from L to R, are: drug_efficacy: 0.95, drug_rel_c: 0.05094, drug_prophylaxis_shape: 11.3, drug_prophylaxis_scale: 10.6
#' @export
AL_params <- c(.95, 0.05094, 11.3, 10.6)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to keep the non-species specific drugs? Backward compatability?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would lean towards keeping AL_params and removing AL_params_falciparum. Bumping the version and getting everyone to change their code is not convenient

#' @title Preset parameters for the SP-AQ drug
#' @title Preset parameters for the SP-AQ drug (P. falciparum)
#' @details Use a vector of preset parameters for the SP-AQ drug (sulphadoxine-pyrimethamine and amodiaquine)
#' @details Default parameters, from L to R, are: drug_efficacy: 0.9, drug_rel_c: 0.32, drug_prophylaxis_shape: 4.3, drug_prophylaxis_scale: 38.1
#' @export
SP_AQ_params <- c(0.9, 0.32, 4.3, 38.1)

#' @title Preset parameters for the CQ drug (P. vivax)
#' @description Efficacy from SI of Nekkab et al., DOI: 10.1371/journal.pmed.1003535 (2021),
#' shape and scale consistent with a longer prophylaxis time: 28 days, decreasing gradually
#' @details Use a vector of preset parameters for the CQ drug (chloroquine) acting on P. vivax
#' @details Default parameters, from L to R, are: drug_efficacy: 0.899, drug_rel_c: 0.5, drug_prophylaxis_shape: 20, drug_prophylaxis_scale: 5
#' @export
CQ_params_vivax <- c(0.899, 0.5, 5, 20, 0, 0, 0)


#' @title Preset parameters for the CQ-PQ drug (P. vivax)
#' @description Efficacy from SI of Nekkab et al., DOI: 10.1371/journal.pmed.1003535 (2021),
#' BS shape and scale consistent with a longer prophylaxis time: 28 days, decreasing gradually,
#' LS shape are scale consistent with a 7 day PQ treatment, with rapid decay.
#' @details Use a vector of preset parameters for the CQ-PQ drug (chloroquine and primaquine) acting on P. vivax
#' @details Default parameters, from L to R, are: drug_efficacy: 0.948, drug_rel_c: 0.5, drug_prophylaxis_shape: 5, drug_prophylaxis_scale: 20,
#' drug_hypnozoite_efficacy: 0.713, drug_hypnozoite_prophylaxis_shape: 10, drug_hypnozoite_prophylaxis_scale: 5.5
#' @export
CQ_PQ_params_vivax <- c(0.948, 0.5, 5, 20, 0.713, 10, 5.5)

#' @title Preset parameters for the CQ-TQ drug (P. vivax)
#' @description Efficacy from SI of Nekkab et al., DOI: 10.1371/journal.pmed.1003535 (2021),
#' BS shape and scale consistent with a longer prophylaxis time: 28 days, decreasing gradually,
#' LS shape are scale consistent with a single TQ treatment, with longer prophylaxis: 45 days.
#' @details Use a vector of preset parameters for the CQ-TQ drug (chloroquine and tafenoquine) acting on P. vivax
#' @details Default parameters, from L to R, are: drug_efficacy: 1, drug_rel_c: 0.5, drug_prophylaxis_shape: 5, drug_prophylaxis_scale: 20,
#' drug_hypnozoite_efficacy: 0.713, drug_hypnozoite_prophylaxis_shape: 5.5, drug_hypnozoite_prophylaxis_scale: 30
#' @export
CQ_TQ_params_vivax <- c(1, 0.5, 5, 20, 0.713, 5, 30)

#' @title Parameterise drugs to use in the model
#'
#' @param parameters the model parameters
#' @param drugs a list of drug parameters, can be set using presets
#' @export
set_drugs <- function(parameters, drugs) {
stopifnot(is.list(drugs))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any validation we could do here to validate if parameters$parasite == vivax that the correct drugs are used? Or do all drugs make sense for all parasites?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spoke with Pete about this a while ago, and we came to a place of hoping that people would use their good sense to choose which parameter sets to apply for each species. While drug parameters are parasite-specific, there might be circumstances where someone would want to see what happens if the same drug is applied to both species. I've added a few warnings to flag where people might do something strange while maintaining flexibility. I could change some of the warnings to errors (e.g., the length of the parameter inputs) if we think that's important.

stopifnot("is.list(drugs) is not TRUE" = is.list(drugs))
keys <- c(
'drug_efficacy',
'drug_rel_c',
'drug_prophylaxis_shape',
'drug_prophylaxis_scale'
'drug_prophylaxis_scale',
# hypnozoite parameters
'drug_hypnozoite_efficacy',
'drug_hypnozoite_prophylaxis_shape',
'drug_hypnozoite_prophylaxis_scale'
)

if(parameters$parasite == "falciparum"){
for (drug in seq_along(drugs)) {
if(length(drugs[[drug]]) != 4){
warning(paste0("Drug ", drug, " has incorrect number of P. falciparum drug parameters. The number of parameters should be 4."),
call. = FALSE)
}
}
} else if (parameters$parasite == "vivax"){
for (drug in seq_along(drugs)) {
if(length(drugs[[drug]]) != 7){
warning(paste0("Drug ", drug, " has incorrect number of P. vivax drug parameters. The number of parameters should be 7 for radical cure. To assign a blood stage drug only, set the liver stage drug parameters to 0: see CQ_params_vivax for an example."),
call. = FALSE)
}
}
}

for (drug in seq_along(drugs)) {
for (i in seq_along(drugs[[drug]])) {
parameters[[keys[[i]]]] <- c(parameters[[keys[[i]]]], drugs[[drug]][[i]])
parameters[[keys[[i]]]][drug] <- drugs[[drug]][[i]]
}
}
parameters
}

#' @title Parameterise clinical treatment
#'
#' @param parameters the model parameters
Expand Down
68 changes: 65 additions & 3 deletions R/human_infection.R
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ relapse_bite_infection_hazard_resolution <- function(
timestep
){

if(variables$hypnozoites$get_index_of(0)$not(T)$and(infected_humans)$size()>0){
if(variables$hypnozoites$get_index_of(0)$not(T)$and(infected_humans)$size() > 0){

hypnozoite_humans <- variables$hypnozoites$get_index_of(0)$not(T)
potential_relapse_index <- bitset_index(hypnozoite_humans, infected_humans)
Expand Down Expand Up @@ -519,17 +519,60 @@ relapse_bite_infection_hazard_resolution <- function(
## all bitten humans with an infectious bite (incorporating prophylaxis) get a new batch of hypnozoites
if(bite_infections$size()>0){

ls_prophylaxis <- ls_treatment_prophylaxis_efficacy(
bite_infections,
variables,
parameters,
timestep
)

# make sure batches are capped
current_batches <- variables$hypnozoites$get_values(bite_infections)
new_hypnozoite_batch_formed <- bitset_at(bite_infections, bernoulli_multi_p(1 - ls_prophylaxis))
current_batches <- variables$hypnozoites$get_values(new_hypnozoite_batch_formed)
new_batch_number <- pmin(current_batches + 1, parameters$kmax)

variables$hypnozoites$queue_update(
new_batch_number,
bite_infections
new_hypnozoite_batch_formed
)
}
}

#' @title Calculate protection from formation of new hypnozoite batches due to liver stage drug prophylaxis
#' @description This function calculates the probability that liver stage drug prophylaxis will
#' protect each individual from the formation of new hynozoite batches
#' @param bite_infections a vector of individuals with prospective formation of new hypnozoite batches
#' @param variables a list of all of the model variables
#' @param parameters model parameters
#' @param timestep current timestep
#' @noRd
ls_treatment_prophylaxis_efficacy <- function(
bite_infections,
variables,
parameters,
timestep
){

## drug prophylaxis may limit formation of new hypnozoite batches
ls_prophylaxis <- rep(0, bite_infections$size())
if(any(parameters$drug_hypnozoite_efficacy > 0)){

ls_drug <- variables$ls_drug$get_values(bite_infections)
ls_medicated <- ls_drug > 0

if (any(ls_medicated)) {
ls_drug <- ls_drug[ls_medicated]
ls_drug_time <- variables$ls_drug_time$get_values(bite_infections)[ls_medicated]
ls_prophylaxis[ls_medicated] <- weibull_survival(
timestep - ls_drug_time,
parameters$drug_hypnozoite_prophylaxis_shape[ls_drug],
parameters$drug_hypnozoite_prophylaxis_scale[ls_drug]
)
}
}
ls_prophylaxis
}

#' @title Calculate light microscopy detectable infections (p.v only)
#' @description
#' Sample light microscopy detectable infections from all infections
Expand Down Expand Up @@ -729,6 +772,15 @@ calculate_treated <- function(
)
}

# Update liver stage drug effects
if(parameters$parasite == "vivax"){
if(successfully_treated$successfully_treated_hypnozoites$size() > 0){
variables$hypnozoites$queue_update(0, successfully_treated$successfully_treated_hypnozoites)
variables$ls_drug$queue_update(drug, successfully_treated$successfully_treated_hypnozoites)
variables$ls_drug_time$queue_update(timestep, successfully_treated$successfully_treated_hypnozoites)
}
}

successfully_treated$successfully_treated

}
Expand Down Expand Up @@ -808,6 +860,16 @@ calculate_successful_treatments <- function(
successfully_treated = successfully_treated)

}

if(any(parameters$drug_hypnozoite_efficacy > 0)){
effectively_treated_hypnozoites_index <- bernoulli_multi_p(parameters$drug_hypnozoite_efficacy[drugs])
successfully_treated_hypnozoites <- bitset_at(target, effectively_treated_hypnozoites_index)
successfully_treated_list <- c(
successfully_treated_list,
successfully_treated_hypnozoites = successfully_treated_hypnozoites
)
}

successfully_treated_list
}

Expand Down
9 changes: 9 additions & 0 deletions R/mda_processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ update_mass_drug_admin <- function(
variables$drug_time$queue_update(timestep, target$successfully_treated)

}

# Update liver stage drug effects
if(any(parameters$drug_hypnozoite_efficacy > 0)){
if(target$successfully_treated_hypnozoites$size() > 0){
variables$hypnozoites$queue_update(0, target$successfully_treated_hypnozoites)
variables$ls_drug$queue_update(drug, target$successfully_treated_hypnozoites)
variables$ls_drug_time$queue_update(timestep, target$successfully_treated_hypnozoites)
}
}
}

#' @title Calculate asymptomatic detectable individuals
Expand Down
3 changes: 3 additions & 0 deletions R/parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ get_parameters <- function(overrides = list(), parasite = "falciparum") {
drug_rel_c = numeric(0),
drug_prophylaxis_shape = numeric(0),
drug_prophylaxis_scale = numeric(0),
drug_hypnozoite_efficacy = numeric(0),
drug_hypnozoite_prophylaxis_shape = numeric(0),
drug_hypnozoite_prophylaxis_scale = numeric(0),
clinical_treatment_drugs = list(),
clinical_treatment_timesteps = list(),
clinical_treatment_coverages = list(),
Expand Down
1 change: 0 additions & 1 deletion R/pmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,5 @@ create_pmc_process <- function(
timestep,
drug
)

}
}
7 changes: 7 additions & 0 deletions R/variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#' * infectivity - The onward infectiousness to mosquitos
#' * drug - The last prescribed drug
#' * drug_time - The timestep of the last drug
#' * ls_drug - The last prescribed drug
#' * ls_drug_time - The timestep of the last drug
#'
#' Antimalarial resistance variables are:
#' * dt - the delay for humans to move from state Tr to state S
Expand Down Expand Up @@ -286,6 +288,11 @@ create_variables <- function(parameters) {
drug <- individual::IntegerVariable$new(rep(0, size))
drug_time <- individual::IntegerVariable$new(rep(-1, size))

if(any(parameters$drug_hypnozoite_efficacy > 0)){
ls_drug <- individual::IntegerVariable$new(rep(0, size))
ls_drug_time <- individual::IntegerVariable$new(rep(-1, size))
}

last_pev_timestep <- individual::IntegerVariable$new(rep(-1, size))
last_eff_pev_timestep <- individual::IntegerVariable$new(rep(-1, size))
pev_profile <- individual::IntegerVariable$new(rep(-1, size))
Expand Down
2 changes: 1 addition & 1 deletion man/AL_params.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/CQ_PQ_params_vivax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/CQ_TQ_params_vivax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/CQ_params_vivax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/DHA_PQP_params.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/SP_AQ_params.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/arab_params.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading