Skip to content

Commit

Permalink
Merge pull request #250 from mrc-ide/vivax_subpatent_duration
Browse files Browse the repository at this point in the history
Vivax subpatent duration
  • Loading branch information
RJSheppard authored Sep 27, 2023
2 parents 37aa34f + 492b909 commit b34c68b
Show file tree
Hide file tree
Showing 15 changed files with 507 additions and 159 deletions.
34 changes: 34 additions & 0 deletions R/disease_progression.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,37 @@ update_to_asymptomatic_infection <- function(
)
}
}

#' @title Sub-patent progression for vivax model
#' @description
#' randomly selects individuals to clear sub-patent infections based on impact of
#' individual immunity to detectability
#'
#' @param state the human state variable
#' @param variables the available human variables
#' @param parameters model parameters
#' @noRd
create_subpatent_progression_process <- function(
state,
variables,
parameters
){
function(timestep) {
## Get recovery rates for each subpatent individual
subpatent_index <- state$get_index_of("U")
rate <- anti_parasite_immunity(
parameters$du_min, parameters$du_max, parameters$au50, parameters$ku,
variables$id$get_values(index = subpatent_index),
variables$idm$get_values(index = subpatent_index))
## Get individuals who are going to change
to_move <- subpatent_index$sample(1/rate)
# update individuals and infectivity
update_infection(
state,
to_state = "S",
infectivity = variables$infectivity,
new_infectivity = 0,
to_move
)
}
}
79 changes: 70 additions & 9 deletions R/human_infection.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,33 @@ simulate_infection <- function(
parameters$ud
)
}

if(parameters$parasite == "falciparum"){
clinical_infections <- calculate_clinical_infections(
variables,
infected_humans,
parameters,
renderer,
timestep
)
} else if (parameters$parasite == "vivax"){
patent_infections <- calculate_patent_infections(
variables,
infected_humans,
parameters,
renderer,
timestep
)

clinical_infections <- calculate_clinical_infections(
variables,
patent_infections,
parameters,
renderer,
timestep
)
}

clinical_infections <- calculate_clinical_infections(
variables,
infected_humans,
parameters,
renderer,
timestep
)

update_severe_disease(
timestep,
Expand Down Expand Up @@ -175,15 +194,51 @@ calculate_infections <- function(
infected
}

#' @title Calculate clinical infections
#' @title Calculate patent infections (vivax only)
#' @description
#' Sample clinical infections from all infections
#' Sample patent infections from all infections
#' @param variables a list of all of the model variables
#' @param infections bitset of infected humans
#' @param parameters model parameters
#' @param renderer model render
#' @param timestep current timestep
#' @noRd
calculate_patent_infections <- function(
variables,
infections,
parameters,
renderer,
timestep
) {
id <- variables$id$get_values(infections)
idm <- variables$idm$get_values(infections)
philm <- anti_parasite_immunity(
min = parameters$du_min, max = parameters$du_max, a50 = parameters$au50,
k = parameters$ku, id = id, idm = idm)
patent_infections <- bitset_at(infections, bernoulli_multi_p(philm))
incidence_renderer(
variables$birth,
renderer,
patent_infections,
infections,
philm,
'inc_patent_',
parameters$patent_incidence_rendering_min_ages,
parameters$patent_incidence_rendering_max_ages,
timestep
)
patent_infections
}

#' @title Calculate clinical infections
#' @description
#' Sample clinical infections from all infections or patent infections (vivax)
#' @param variables a list of all of the model variables
#' @param infections bitset of infected/patent humans
#' @param parameters model parameters
#' @param renderer model render
#' @param timestep current timestep
#' @noRd
calculate_clinical_infections <- function(
variables,
infections,
Expand Down Expand Up @@ -458,3 +513,9 @@ blood_immunity <- function(ib, parameters) {
(1 + (ib / parameters$ib0) ** parameters$kb)
)
}

# Implemented from White et al., 2018 - Supplementary Information
anti_parasite_immunity <- function(min, max, a50, k, id, idm){
min + (max - min) / (
1 + ((id + idm) / a50) ** k)
}
20 changes: 13 additions & 7 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,28 @@
#' * n: number of humans between an inclusive age range at this timestep. This
#' defaults to n_730_3650. Other age ranges can be set with
#' prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters.
#' * n_detect: number of humans with an infection detectable by microscopy between an inclusive age range at this timestep. This
#' defaults to n_detect_730_3650. Other age ranges can be set with
#' * n_detect_pcr: number of humans with an infection detectable by pcr between an inclusive age range at this timestep. This
#' defaults to n_detect_pcr_730_3650. Other age ranges can be set with
#' prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters.
#' * p_detect: the sum of probabilities of detection by microscopy between an
#' * n_detect_lm: number of humans with an infection detectable by light microscopy between an inclusive age range at this timestep. This
#' defaults to n_detect_lm_730_3650. Other age ranges can be set with
#' prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters.
#' * p_detect_lm: the sum of probabilities of detection by light microscopy between an
#' inclusive age range at this timestep. This
#' defaults to p_detect_730_3650. Other age ranges can be set with
#' defaults to p_detect_lm_730_3650. Other age ranges can be set with
#' prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters.
#' * n_severe: number of humans with a severe infection between an inclusive
#' age range at this timestep. Age ranges can be set with
#' severe_prevalence_rendering_min_ages and severe_prevalence_rendering_max_ages parameters.
#' * n_inc: number of new infections for humans between an inclusive age range at this timestep.
#' incidence columns can be set with
#' incidence_rendering_min_ages and incidence_rendering_max_ages parameters.
#' * p_inc: sum of probabilities of infection for humans between an inclusive age range at this timestep.
#' incidence columns can be set with
#' incidence_rendering_min_ages and incidence_rendering_max_ages parameters.
#' * n_inc_patent: number of new patent infections for humans between an inclusive age range at this timestep.
#' patent incidence columns can be set with
#' patent_incidence_rendering_min_ages and patent_incidence_rendering_max_ages parameters.
#' * p_inc_patent: sub of probabilities of patent infection for humans between an inclusive age range at this timestep.
#' patent incidence columns can be set with
#' patent_incidence_rendering_min_ages and patent_incidence_rendering_max_ages parameters.
#' * n_inc_clinical: number of new clinical infections for humans between an inclusive age range at this timestep.
#' clinical incidence columns can be set with
#' clinical_incidence_rendering_min_ages and clinical_incidence_rendering_max_ages parameters.
Expand Down
5 changes: 5 additions & 0 deletions R/mortality_processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ sample_maternal_immunity <- function(variables, target, timestep, parameters) {
birth_ivm <- variables$ica$get_values(mothers) * parameters$pvm
variables$icm$queue_update(birth_icm, target_group)
variables$ivm$queue_update(birth_ivm, target_group)

if(parameters$parasite == "vivax"){
birth_idm <- variables$id$get_values(mothers) * parameters$pcm
variables$idm$queue_update(birth_idm, target_group)
}
}
}
}
Expand Down
Loading

0 comments on commit b34c68b

Please sign in to comment.