Skip to content

Commit

Permalink
Merge pull request #321 from mrc-ide/vivax_competing_hazards_main_hyp…
Browse files Browse the repository at this point in the history
…nozoites

Add hypnozoites to the P.v model
  • Loading branch information
RJSheppard authored Oct 22, 2024
2 parents 08bceff + da381b9 commit a328fb3
Show file tree
Hide file tree
Showing 15 changed files with 647 additions and 222 deletions.
30 changes: 21 additions & 9 deletions R/biting_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ create_biting_process <- function(
function(timestep) {
# Calculate combined EIR
age <- get_age(variables$birth$get_values(), timestep)
bitten_humans <- simulate_bites(
bitten <- simulate_bites(
renderer,
solvers,
models,
Expand All @@ -52,7 +52,8 @@ create_biting_process <- function(
simulate_infection(
variables,
events,
bitten_humans,
bitten$bitten_humans,
bitten$n_bites_per_person,
age,
parameters,
timestep,
Expand All @@ -78,6 +79,7 @@ simulate_bites <- function(
mixing_index = 1
) {
bitten_humans <- individual::Bitset$new(parameters$human_population)
n_bites_per_person <- numeric(0)

human_infectivity <- variables$infectivity$get_values()
if (parameters$tbv) {
Expand Down Expand Up @@ -146,13 +148,24 @@ simulate_bites <- function(

renderer$render(paste0('EIR_', species_name), species_eir, timestep)
EIR <- EIR + species_eir
expected_bites <- species_eir * mean(psi)
if(parameters$parasite == "falciparum"){
# p.f model factors eir by psi
expected_bites <- species_eir * mean(psi)
} else if (parameters$parasite == "vivax"){
# p.v model standardises biting rate het to eir
expected_bites <- species_eir
}

if (expected_bites > 0) {
n_bites <- rpois(1, expected_bites)
if (n_bites > 0) {
bitten_humans$insert(
fast_weighted_sample(n_bites, lambda)
)
bitten <- fast_weighted_sample(n_bites, lambda)
bitten_humans$insert(bitten)
renderer$render('n_bitten', bitten_humans$size(), timestep)
if(parameters$parasite == "vivax"){
# p.v must pass through the number of bites per person
n_bites_per_person <- tabulate(bitten, nbins = length(lambda))
}
}
}

Expand Down Expand Up @@ -202,9 +215,8 @@ simulate_bites <- function(
)
}
}

renderer$render('n_bitten', bitten_humans$size(), timestep)
bitten_humans

list(bitten_humans = bitten_humans, n_bites_per_person = n_bites_per_person)
}


Expand Down
11 changes: 7 additions & 4 deletions R/competing_hazards.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ CompetingOutcome <- R6::R6Class(

self$target <- individual::Bitset$new(size)
self$rates <- NULL
self$args <- NULL
},
set_rates = function(target, rates){
set_rates = function(target, rates, ...){
stopifnot(target$size() == length(rates))

self$target$copy_from(target)
self$rates <- rates
self$args <- list(...)
},
execute = function(t, target){
private$targeted_process(t, target)
do.call(private$targeted_process, c(t, list(target), self$args))
},
reset = function() {
self$target$clear()
self$rates <- NULL
self$args <- NULL
},
target = NULL,
rates = NULL
rates = NULL,
args = NULL
)
)

Expand Down
Loading

0 comments on commit a328fb3

Please sign in to comment.