Skip to content

Commit

Permalink
Hynozoite batches are now modelled, including formation via bite infe…
Browse files Browse the repository at this point in the history
…ctions, decay of hypnozoite batches, new infections via relapse and the reseting of batch number to 0 for new births.

A hypnozoite batch variable is created.

The vivax model considers the number of new bites an individual receives (in contrast to whether an individual has been bitten regardless of number of bites, as currently in the P. falciparum model) to calculate the infection rates. This is now captured in bitten_humans, which is now a list that also includes n_bites_each.

The vivax model does not factor the eir by the population level biting heterogeneity (although it does use the heterogeneity to distribute biting, but retains the overall total biting according to the EIR). biting_rate.R

In vivax, we track bites in all individuals, not just SAU as in falciparum. This is because new hypnozoite batches can occur in any human state, regardless of whether this results in a new infection.

The number of bites is considered in calculating probability of a new infection.

To calculate the infection rates for vivax, we take the biting infection rates and add them to the relapse rate. We also save the relative rates in the competing hazards object to resolve these competing hazards later.

A new function to resolve between bites and relapse infections is created. For each bite we increase the number of batches - with capacity for prophylaxis to be added at a future step. We also cap the total number of batches.

We add a hypnozoite batch decay process. Note that this process differs from the immunity decay processes. We work in discrete outputs (you can't have a fractional batch). We also work in the probability that an individual experiences a single loss, rather than loss at the hypnozoite level.

When an individual dies, we reset the hypnozoite batches back to 0.

We now render number of relapses, average hypnozoite batch number and the number of individuals with hypnozoite batches. We may also output these by specified age groups.

Added a test to check relapses occur as expected and expanded the p.v vignette.
  • Loading branch information
RJSheppard committed Sep 19, 2024
1 parent 39949ff commit 1916fa1
Show file tree
Hide file tree
Showing 14 changed files with 394 additions and 128 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: 10 additions & 1 deletion R/competing_hazards.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,31 @@ CompetingOutcome <- R6::R6Class(

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

self$target$copy_from(target)
self$rates <- rates
},
set_relative_rates = function(target, relative_rates){
stopifnot(target$size() == length(relative_rates))

self$target$copy_from(target)
self$relative_rates <- relative_rates
},
execute = function(t, target){
private$targeted_process(t, target)
},
reset = function() {
self$target$clear()
self$rates <- NULL
self$relative_rates <- NULL
},
target = NULL,
rates = NULL
rates = NULL,
relative_rates = NULL
)
)

Expand Down
Loading

0 comments on commit 1916fa1

Please sign in to comment.