Skip to content

Commit

Permalink
Merge pull request #248 from mrc-ide/vivax_asymp_infectivity
Browse files Browse the repository at this point in the history
Vivax asymp infectivity
  • Loading branch information
RJSheppard authored Jul 21, 2023
2 parents 4862423 + d132d7b commit 7e5af02
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 18 deletions.
22 changes: 16 additions & 6 deletions R/human_infection.R
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,22 @@ schedule_infections <- function(
}

if(to_infect_asym$size() > 0) {
update_to_asymptomatic_infection(
variables,
parameters,
timestep,
to_infect_asym
)
if(parameters$parasite == "falciparum"){ ## P. falciparum has an age-dependent asymptomatic infectivity
update_to_asymptomatic_infection(
variables,
parameters,
timestep,
to_infect_asym
)
} else if (parameters$parasite == "vivax"){ ## P. vivax has a constant asymptomatic infectivity
update_infection(
variables$state,
'A',
variables$infectivity,
parameters$ca,
to_infect_asym
)
}
}
}

Expand Down
23 changes: 17 additions & 6 deletions R/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,23 @@ create_processes <- function(
mixing_index
),
create_mortality_process(variables, events, renderer, parameters),
create_asymptomatic_progression_process(
variables$state,
parameters$dd,
variables,
parameters
),
if(parameters$parasite == "falciparum"){ ## P. falciparum has an age-dependent asymptomatic infectivity
create_asymptomatic_progression_process(
variables$state,
parameters$dd,
variables,
parameters
)
} else if (parameters$parasite == "vivax"){ ## P. vivax has a constant asymptomatic infectivity
create_progression_process(
variables$state,
'D',
'A',
parameters$da,
variables$infectivity,
parameters$ca
)
},
create_progression_process(
variables$state,
'A',
Expand Down
13 changes: 8 additions & 5 deletions R/variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,14 @@ create_variables <- function(parameters) {

# Set the initial infectivity values for each individual
infectivity_values[diseased] <- parameters$cd
infectivity_values[asymptomatic] <- asymptomatic_infectivity(
initial_age[asymptomatic],
id$get_values(asymptomatic),
parameters
)
if(parameters$parasite == "falciparum"){ ## P. falciparum has an age-dependent asymptomatic infectivity
infectivity_values[asymptomatic] <- asymptomatic_infectivity(
initial_age[asymptomatic],
id$get_values(asymptomatic),
parameters)
} else if (parameters$parasite == "vivax"){ ## P. vivax has a constant asymptomatic infectivity
infectivity_values[asymptomatic] <- parameters$ca
}
infectivity_values[subpatent] <- parameters$cu

# Initialise the infectivity variable
Expand Down
1 change: 0 additions & 1 deletion data-raw/parasite_parameters.csv
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ vivax,av,2493.41,TO BE REMOVED: NOT VIVAX: Job 4: Immunity/severity
vivax,gammav,2.91282,TO BE REMOVED: NOT VIVAX: Job 4: Immunity/severity
vivax,cd,0.8,
vivax,ca,0.1,
vivax,gamma1,1.82425,TO BE REMOVED: NOT VIVAX: Job 1: asymptomatic infectivity
vivax,cu,0.035,
vivax,ct,0.4,
vivax,de,10,
Expand Down
90 changes: 90 additions & 0 deletions tests/testthat/test-vivax.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,93 @@ test_that('Test difference between falciparum and vivax parameter lists', {
expect_true(all(names(vivax_parameters[!names(vivax_parameters) %in% names(falciparum_parameters)]) %in%
c("du_max","du_min","ku","au50","b","phi0lm","phi1lm","ic0lm","kclm","d0","ca","init_idm","f","gammal")))
})

test_that('Test age structure should not change vivax infectivity', {

# Set all individuals to asymptomatic
# And ID immunity to not 0 (ID impacts age-specific asymptomatic infectivity)
parameters <- get_parameters(overrides = list(s_proportion = 0,
d_proportion = 0,
a_proportion = 1,
u_proportion = 0,
t_proportion = 0,
init_id = 0.5))

vivax_parameters <- get_parameters(parasite = "vivax",
overrides = list(s_proportion = 0,
d_proportion = 0,
a_proportion = 1,
u_proportion = 0,
t_proportion = 0,
init_id = 0.5))

# Generate different age structure
year <- 365
ages <- round(c(0.083333, 1, 5, 10, 15, 20, 25, 30, 35, 40, 45,
50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 200) * year)

deathrates <- rep(.1, length(ages)) / 365

dem_parameters <- set_demography(
parameters,
agegroups = ages,
timesteps = 0,
deathrates = matrix(deathrates, nrow = 1)
)

vivax_dem_parameters <- set_demography(
vivax_parameters,
agegroups = ages,
timesteps = 0,
deathrates = matrix(deathrates, nrow = 1)
)

# vivax asymptomatic infectivity should equal ca
expect_true(all(
c(create_variables(vivax_parameters)$infectivity$get_values(),
create_variables(vivax_dem_parameters)$infectivity$get_values())==vivax_parameters$ca))

# falciparum asymptomatic infectivity should not equal ca
expect_false(any(
c(create_variables(parameters)$infectivity$get_values(),
create_variables(dem_parameters)$infectivity$get_values())==vivax_parameters$ca))

# falciparum asymptomatic infectivity should change with age structure
expect_false(any(
c(create_variables(parameters)$infectivity$get_values() == create_variables(dem_parameters)$infectivity$get_values())))
})

test_that('vivax schedule_infections correctly schedules new infections', {
parameters <- get_parameters(list(human_population = 20), parasite = "vivax")
variables <- create_variables(parameters)

infections <- individual::Bitset$new(20)$insert(1:20)
clinical_infections <- individual::Bitset$new(20)$insert(5:15)
treated <- individual::Bitset$new(20)$insert(7:12)

infection_mock <- mockery::mock()

mockery::stub(schedule_infections, 'update_infection', infection_mock)

schedule_infections(
variables,
clinical_infections,
treated,
infections,
parameters,
42
)

actual_infected <- mockery::mock_args(infection_mock)[[1]][[5]]$to_vector()
actual_asymp_infected <- mockery::mock_args(infection_mock)[[2]][[5]]$to_vector()

expect_equal(
actual_infected,
c(5, 6, 13, 14, 15)
)

expect_equal(
actual_asymp_infected,
c(1, 2, 3, 4, 16, 17, 18, 19, 20)
)
})

0 comments on commit 7e5af02

Please sign in to comment.