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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Generated by roxygen2: do not edit by hand

export(AL_params)
export(AL_params_falciparum)
export(CQ_PQ_params_vivax)
export(CQ_params_vivax)
export(DHA_PQP_params)
export(DHA_PQP_params_falciparum)
export(SP_AQ_params)
export(SP_AQ_params_falciparum)
export(arab_params)
export(create_pev_profile)
export(fun_params)
Expand Down
59 changes: 55 additions & 4 deletions R/drug_parameters.R
Original file line number Diff line number Diff line change
@@ -1,44 +1,95 @@
#' @title Preset parameters for the DHA-PQP drug
#' @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_falciparum <- c(.95, 0.09434, 4.4, 28.1)

#' @title Preset parameters for the DHA-PQP drug
#' @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
#' @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_falciparum <- c(.95, 0.05094, 11.3, 10.6)

#' @title Preset parameters for the AL drug
#' @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
#' @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_falciparum <- c(0.9, 0.32, 4.3, 38.1)

#' @title Preset parameters for the SP-AQ drug
#' @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 acting on 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)

#' @title Preset parameters for the CQ-PQ drug acting on 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 acting on 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
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) {
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))
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'
)

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
43 changes: 41 additions & 2 deletions R/human_infection.R
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,33 @@ 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){

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

ls_drug <- variables$ls_drug$get_values(bite_infections)
ls_medicated <- (ls_drug > 0)
ls_medicated[ls_drug > 0] <- !is.na(parameters$drug_hypnozoite_efficacy[ls_drug])
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 expect this to fail? Since length(ls_medicated[ls_drug > 0]) is less than or equal to length(ls_drug). If some people are not medicated then there'll be a weird assignment here. Is this tested for?

Suggested change
ls_medicated[ls_drug > 0] <- !is.na(parameters$drug_hypnozoite_efficacy[ls_drug])
ls_medicated <- ls_medicated & !is.na(parameters$drug_hypnozoite_efficacy[ls_drug])

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 see what you're saying. An issue is that some of ls_drug will be 0 (if no drugs have been assigned to the individual), which means that !is.na(parameters$drug_hypnozoite_efficacy[ls_drug]) may not have the same length as ls_medicated (as far as I can work it out). I've taken a look to make sure it's doing what it's supposed to do, with a few tests to check it through.


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]
)
}
}

# 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
)
}
}
Expand Down Expand Up @@ -729,6 +749,15 @@ calculate_treated <- function(
)
}

# Update liver stage drug effects
if(length(parameters$drug_hynozoite_efficacy) > 0){
Copy link
Member

Choose a reason for hiding this comment

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

Are both ifs required here?
If successfully_treated$successfully_treated_hypnozoites$size() > 0 wouldn't length(parameters$drug_hynozoite_efficacy) > 0 by definition?

Copy link
Member Author

Choose a reason for hiding this comment

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

The way I've coded it means that successfully_treated$successfully_treated_hypnozoites is only generated when length(parameters$drug_hynozoite_efficacy) > 0. So it doesn't exist for falciparum, or for vivax when non hypnozoite drugs are being used (e.g., just CQ).

Copy link
Member

Choose a reason for hiding this comment

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

This might be avoidable if all vivax drugs have that parameter (see other comment)?

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 +837,16 @@ calculate_successful_treatments <- function(
successfully_treated = successfully_treated)

}

if(length(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(length(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
)

}
}
2 changes: 1 addition & 1 deletion R/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ create_processes <- function(
immunity_process = create_exponential_decay_process(variables$ica,
parameters$rc)
)

if(parameters$parasite == "falciparum"){
processes <- c(
processes,
Expand Down
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(length(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
21 changes: 21 additions & 0 deletions man/AL_params_falciparum.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.

21 changes: 21 additions & 0 deletions man/DHA_PQP_params_falciparum.Rd

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

21 changes: 21 additions & 0 deletions man/SP_AQ_params_falciparum.Rd

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

Loading
Loading