From fb7c8932f7c0c040bd58c0048414e2ed098b9fb8 Mon Sep 17 00:00:00 2001 From: rjs11 Date: Mon, 9 Dec 2024 16:41:17 +0000 Subject: [PATCH] Liver stage drug parameters (the final three on vivax parameter set) are now set explicitly. The vivax drug set must now therefore by a vector of 7, 4 is not allowed. When there is not a liver-stage efficacy or prophylaxis effect, we set the final three parameters to 0. --- R/drug_parameters.R | 18 ++++-------------- R/human_infection.R | 6 +++--- R/mda_processes.R | 2 +- R/variables.R | 2 +- man/CQ_params_vivax.Rd | 2 +- tests/testthat/test-vivax.R | 16 +--------------- 6 files changed, 11 insertions(+), 35 deletions(-) diff --git a/R/drug_parameters.R b/R/drug_parameters.R index 10591913..b21e685e 100644 --- a/R/drug_parameters.R +++ b/R/drug_parameters.R @@ -24,7 +24,8 @@ SP_AQ_params <- c(0.9, 0.32, 4.3, 38.1) #' @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) +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), @@ -69,24 +70,13 @@ set_drugs <- function(parameters, 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 ( - all(drugs[[drug]] == CQ_params_vivax)){ - warning("P. vivax drug parameters are being applied to P. falciparum", - call. = FALSE) } } } else if (parameters$parasite == "vivax"){ for (drug in seq_along(drugs)) { - if(!length(drugs[[drug]]) %in% c(4, 7)){ - warning(paste0("Drug ", drug, " has incorrect number of P. vivax drug parameters. The number of parameters should be 4, for blood stage treatment only, or 7, for radical cure."), + 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) - } else if(length(drugs[[drug]]) == 4){ - if(all(drugs[[drug]] == AL_params) | - all(drugs[[drug]] == DHA_PQP_params) | - all(drugs[[drug]] == SP_AQ_params)){ - warning("P. falciparum drug parameters are being applied to P. vivax.", - call. = FALSE) - } } } } diff --git a/R/human_infection.R b/R/human_infection.R index 10eb1085..d9ab452e 100644 --- a/R/human_infection.R +++ b/R/human_infection.R @@ -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) @@ -555,7 +555,7 @@ ls_treatment_prophylaxis_efficacy <- function( ## drug prophylaxis may limit formation of new hypnozoite batches ls_prophylaxis <- rep(0, bite_infections$size()) - if(length(parameters$drug_hypnozoite_efficacy) > 0){ + if(any(parameters$drug_hypnozoite_efficacy > 0)){ ls_drug <- variables$ls_drug$get_values(bite_infections) ls_medicated <- ls_drug > 0 @@ -861,7 +861,7 @@ calculate_successful_treatments <- function( } - if(length(parameters$drug_hypnozoite_efficacy) > 0){ + 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( diff --git a/R/mda_processes.R b/R/mda_processes.R index dd782ba7..46c1975a 100644 --- a/R/mda_processes.R +++ b/R/mda_processes.R @@ -139,7 +139,7 @@ update_mass_drug_admin <- function( } # Update liver stage drug effects - if(length(parameters$drug_hypnozoite_efficacy) > 0){ + 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) diff --git a/R/variables.R b/R/variables.R index a2f81e0d..29b627d2 100644 --- a/R/variables.R +++ b/R/variables.R @@ -288,7 +288,7 @@ 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){ + if(any(parameters$drug_hypnozoite_efficacy > 0)){ ls_drug <- individual::IntegerVariable$new(rep(0, size)) ls_drug_time <- individual::IntegerVariable$new(rep(-1, size)) } diff --git a/man/CQ_params_vivax.Rd b/man/CQ_params_vivax.Rd index 05cf7955..e7010e58 100644 --- a/man/CQ_params_vivax.Rd +++ b/man/CQ_params_vivax.Rd @@ -5,7 +5,7 @@ \alias{CQ_params_vivax} \title{Preset parameters for the CQ drug (P. vivax)} \format{ -An object of class \code{numeric} of length 4. +An object of class \code{numeric} of length 7. } \usage{ CQ_params_vivax diff --git a/tests/testthat/test-vivax.R b/tests/testthat/test-vivax.R index 2840fe44..b2b9a861 100644 --- a/tests/testthat/test-vivax.R +++ b/tests/testthat/test-vivax.R @@ -316,7 +316,6 @@ test_that('relapses are recognised with division between bite infections and rel }) test_that('Drug functions provide warnings if applied incorrectly', { - expect_warning( get_parameters(parasite = "falciparum") |> set_drugs(drugs = list(c(1,2,3,4,5))), @@ -326,21 +325,8 @@ test_that('Drug functions provide warnings if applied incorrectly', { expect_warning( get_parameters(parasite = "vivax") |> set_drugs(drugs = list(c(1,2,3,4,5))), - "Drug 1 has incorrect number of P. vivax drug parameters. The number of parameters should be 4, for blood stage treatment only, or 7, for radical cure." - ) - - expect_warning( - get_parameters(parasite = "falciparum") |> - set_drugs(drugs = list(CQ_params_vivax)), - regexp = "P. vivax drug parameters are being applied to P. falciparum" + "Drug 1 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." ) - - expect_warning( - get_parameters(parasite = "vivax") |> - set_drugs(drugs = list(AL_params)), - "P. falciparum drug parameters are being applied to P. vivax" - ) - }) test_that('Liver stage prophylaxis functions correctly', {