-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Antimalarial resistance/etf #263
Merged
+1,333
−48
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d8930d8
Opened sub-branch of feat/antimalarial_resistance for developing the …
8efb863
Added first iteration of the set_antimalarial_resistance() function d…
tbreweric 74a2a3b
Updated the set_antimalarial_resistance() function to allow for multi…
acf145e
Removed the else{} arguments on the checks, condensed the first check…
856ec1e
Added additional section for testing different versions of ETF versio…
da94206
removed the extra versions of calculate_treated() from human_infectio…
571a20c
removed all but resistance first, efficacy second version of calculat…
tbreweric bfb6aa0
Deleting the development script from the branch (will store developme…
tbreweric 02e4916
Amended the calculate_treated() function to remove the loop when assi…
tbreweric 7be84ee
Added check to number of clinical_infections in calculate_treated() a…
tbreweric fea9da2
Removed typos/spaces from antimalarial_resistance.R. Added check for …
0b1adb6
removed comments from calculate_treated() function
tbreweric 731899e
removed unnecessary spacing and comments from the calculate_treated()…
tbreweric 578c9e5
Create test-antimalarial-resistance.R and added six tests for the set…
tbreweric ded0251
Added test file for new antimalarial resistance functions and added n…
tbreweric d4db8f9
Commiting all changes recommended by Pete/Giovanni except those that …
tbreweric 11e61e1
Commiting the final set of changes and corrections in response to com…
tbreweric de29495
Implemented the second round of changes requested in the pull request
4d75b2e
Implented the second round of changes requested in the pull request
d51bbf7
Re-adding the changes recommended by Pete following a reversion to 4d…
tbreweric 2adf823
Corrected drugs documentation for get_antimalarial_resistance_paramet…
tbreweric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#' @title Parameterise antimalarial resistance | ||
#' @description | ||
#' Parameterise antimalarial resistance | ||
#' | ||
#' @param parameters the model parameters | ||
#' @param drug the index of the drug which resistance is being set, as set by the set_drugs() function, in the parameter list | ||
#' @param timesteps vector of time steps for each update to resistance proportion and resistance outcome probability | ||
#' @param artemisinin_resistance vector of updates to the proportions of infections that are artemisinin resistant at time t | ||
#' @param partner_drug_resistance vector of updates to the proportions of infections that are partner-drug resistant at time t | ||
#' @param slow_parasite_clearance_prob vector of updates to the proportion of artemisinin-resistant infections that result in early treatment failure | ||
#' @param early_treatment_failure_prob vector of updates to the proportion of artemisinin-resistant infections that result in slow parasite clearance | ||
#' @param late_clinical_failure_prob vector of updates to the proportion of partner-drug-resistant infections that result in late clinical failure | ||
#' @param late_parasitological_prob vector of updates to the proportion of partner-drug-resistant infections that result in late parasitological failure | ||
#' @param reinfection_prob vector of updates to the proportion of partner-drug-resistant infections that result in reinfection during prophylaxis | ||
#' @param slow_parasite_clearance_time single value representing the mean time individual's experiencing slow parasite clearance reside in the treated state | ||
#' @export | ||
set_antimalarial_resistance <- function(parameters, | ||
drug, | ||
timesteps, | ||
artemisinin_resistance, | ||
partner_drug_resistance, | ||
slow_parasite_clearance_prob, | ||
early_treatment_failure_prob, | ||
late_clinical_failure_prob, | ||
late_parasitological_prob, | ||
reinfection_prob, | ||
slow_parasite_clearance_time) { | ||
|
||
if(any(c(length(artemisinin_resistance), | ||
length(partner_drug_resistance), | ||
length(slow_parasite_clearance_prob), | ||
length(early_treatment_failure_prob), | ||
length(late_clinical_failure_prob), | ||
length(late_parasitological_prob), | ||
length(reinfection_prob)) != length(timesteps))) { | ||
stop("Length of one or more resistance parameter vectors does not match time steps specified for update") | ||
} | ||
|
||
if(any(artemisinin_resistance < 0 | artemisinin_resistance > 1 | | ||
partner_drug_resistance < 0 | partner_drug_resistance > 1)) { | ||
stop("Artemisinin and partner-drug resistance proportions must fall between 0 and 1") | ||
} | ||
|
||
if(any(slow_parasite_clearance_prob < 0 | slow_parasite_clearance_prob > 1 | | ||
early_treatment_failure_prob < 0 | early_treatment_failure_prob > 1 | | ||
late_clinical_failure_prob < 0 | late_clinical_failure_prob > 1 | | ||
late_parasitological_prob < 0 | late_parasitological_prob > 1 | | ||
reinfection_prob < 0 | reinfection_prob > 1)) { | ||
stop("Resistance outcome probabilities must fall between 0 and 1") | ||
} | ||
|
||
if(length(slow_parasite_clearance_time) != 1) { | ||
stop("Error: length of slow_parasite_clearance_time not equal to 1") | ||
} | ||
|
||
if(slow_parasite_clearance_time <= 0) { | ||
stop("Error: slow_parasite_clearance_time is non-positive") | ||
} | ||
|
||
parameters$antimalarial_resistance <- TRUE | ||
|
||
n_drugs <- length(parameters$drug_efficacy) | ||
|
||
if (drug < 1 | drug > n_drugs) { | ||
stop('Drug index is invalid, please set drugs using set_drugs') | ||
} | ||
|
||
drug_index <- which(parameters$antimalarial_resistance_drug == drug) | ||
|
||
if (length(drug_index) == 0) { | ||
drug_index <- length(parameters$antimalarial_resistance_drug) + 1 | ||
} | ||
|
||
parameters$antimalarial_resistance_drug[[drug_index]] <- drug | ||
parameters$antimalarial_resistance_timesteps[[drug_index]] <- timesteps | ||
parameters$prop_artemisinin_resistant[[drug_index]] <- artemisinin_resistance | ||
parameters$prop_partner_drug_resistant[[drug_index]] <- partner_drug_resistance | ||
parameters$slow_parasite_clearance_prob[[drug_index]] <- slow_parasite_clearance_prob | ||
parameters$early_treatment_failure_prob[[drug_index]] <- early_treatment_failure_prob | ||
parameters$late_clinical_failure_prob[[drug_index]] <- late_clinical_failure_prob | ||
parameters$late_parasitological_failure_prob[[drug_index]] <- late_parasitological_prob | ||
parameters$reinfection_during_prophylaxis[[drug_index]] <- reinfection_prob | ||
parameters$dt_slow_parasite_clearance[[drug_index]] <- slow_parasite_clearance_time | ||
|
||
return(parameters) | ||
|
||
} | ||
|
||
#' @title Retrieve resistance parameters | ||
#' @description | ||
#' Retrieve the resistance parameters associated with the drug each individual receiving clinical | ||
#' treatment has been administered in the current time step. | ||
#' | ||
#' @param parameters the model parameters | ||
#' @param drugs vector of integers representing the drugs administered to each individual receiving treatment | ||
#' @param timestep the current time step | ||
get_antimalarial_resistance_parameters <- function(parameters, drugs, timestep) { | ||
|
||
if(!parameters$antimalarial_resistance) { | ||
stop("Error: Antimalarial resistance has not been parameterised; antimalarial_resistance = FALSE") | ||
} | ||
|
||
blank_vector <- numeric(length = length(drugs)) | ||
artemisinin_resistance_proportion <- blank_vector | ||
partner_drug_resistance_proportion <- blank_vector | ||
slow_parasite_clearance_probability <- blank_vector | ||
early_treatment_failure_probability <- blank_vector | ||
late_clinical_failure_probability <- blank_vector | ||
late_parasitological_failure_probability <- blank_vector | ||
reinfection_during_prophylaxis_probability <- blank_vector | ||
dt_slow_parasite_clearance <- rep(parameters$dt, length = length(drugs)) | ||
|
||
for(i in seq_along(parameters$antimalarial_resistance_drug)) { | ||
drug <- parameters$antimalarial_resistance_drug[[i]] | ||
treated_with_drug <- which(drugs == drug) | ||
resistance_timestep <- match_timestep(ts = parameters$antimalarial_resistance_timesteps[[i]], t = timestep) | ||
artemisinin_resistance_proportion[treated_with_drug] <- parameters$prop_artemisinin_resistant[[i]][resistance_timestep] | ||
partner_drug_resistance_proportion[treated_with_drug] <- parameters$prop_partner_drug_resistant[[i]][resistance_timestep] | ||
slow_parasite_clearance_probability[treated_with_drug] <- parameters$slow_parasite_clearance_prob[[i]][resistance_timestep] | ||
early_treatment_failure_probability[treated_with_drug] <- parameters$early_treatment_failure_prob[[i]][resistance_timestep] | ||
late_clinical_failure_probability[treated_with_drug] <- parameters$late_clinical_failure_prob[[i]][resistance_timestep] | ||
late_parasitological_failure_probability[treated_with_drug] <- parameters$late_parasitological_failure_prob[[i]][resistance_timestep] | ||
reinfection_during_prophylaxis_probability[treated_with_drug] <- parameters$reinfection_during_prophylaxis[[i]][resistance_timestep] | ||
dt_slow_parasite_clearance[treated_with_drug] <- parameters$dt_slow_parasite_clearance[[i]] | ||
} | ||
|
||
resistance_parameters <- list() | ||
resistance_parameters$artemisinin_resistance_proportion <- artemisinin_resistance_proportion | ||
resistance_parameters$partner_drug_resistance_proportion <- partner_drug_resistance_proportion | ||
resistance_parameters$slow_parasite_clearance_probability <- slow_parasite_clearance_probability | ||
resistance_parameters$early_treatment_failure_probability <- early_treatment_failure_probability | ||
resistance_parameters$late_clinical_failure_probability <- late_clinical_failure_probability | ||
resistance_parameters$late_parasitological_failure_probability <- late_parasitological_failure_probability | ||
resistance_parameters$reinfection_during_prophylaxis_probability <- reinfection_during_prophylaxis_probability | ||
resistance_parameters$dt_slow_parasite_clearance <- dt_slow_parasite_clearance | ||
|
||
return(resistance_parameters) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to be adding this to dev, inferring that the user can set things like reinfection prob, when they actually have no impact?
Not sure best practice here, should they be removed or have warnings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My plan was to merge to feat/antimalarial_resistance, develop each of the five different resistance outcomes individually on their own branches from feat/antimalarial_resistance, consolidate them on feat_antimalarial_resistance, and then merge to dev.
I initially opted to do this to because I was new to the model & GitHub, but now that I'm more comfortable with both I'm happy to do something more efficient . So if it is better to merge this branch to dev, and then branch from/merge back to dev to build in each additional resistance outcome then I'm happy to do that instead!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested we merge each outcome into dev directly. Since this seems to work in isolation, we can put it through automated tests earlier, we will have smaller PRs (with dev) and won't fall behind dev waiting for all 5 to be implemented.
And I agree, we should have an error if someone tries to use an unimplemented feature!