Skip to content

Commit

Permalink
run styler on package
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahhamadeh committed Apr 23, 2024
1 parent 238bfbb commit 6a4d5d4
Show file tree
Hide file tree
Showing 15 changed files with 1,114 additions and 970 deletions.
124 changes: 69 additions & 55 deletions R/code-generation.R
Original file line number Diff line number Diff line change
@@ -1,70 +1,86 @@
distributionStringsFnsList <- list(Uniform = function(parameter){ paste0("distribution$Uniform(minimum = ",parameter$distribution$minimum,", maximum = ",parameter$distribution$maximum, ")") },
LogUniform = function(parameter){ paste0("distribution$LogUniform(minimum = ",parameter$distribution$minimum,", maximum = ",parameter$distribution$maximum, ")") },
Normal = function(parameter){ paste0("distribution$Normal(mean = ",parameter$distribution$mean,", stdv = ",parameter$distribution$stdv, ")") },
LogNormal = function(parameter){ paste0("distribution$LogNormal(mean = ",parameter$distribution$mean,", CV = ",parameter$distribution$CV, ")") })
distributionStringsFnsList <- list(
Uniform = function(parameter) {
paste0("distribution$Uniform(minimum = ", parameter$distribution$minimum, ", maximum = ", parameter$distribution$maximum, ")")
},
LogUniform = function(parameter) {
paste0("distribution$LogUniform(minimum = ", parameter$distribution$minimum, ", maximum = ", parameter$distribution$maximum, ")")
},
Normal = function(parameter) {
paste0("distribution$Normal(mean = ", parameter$distribution$mean, ", stdv = ", parameter$distribution$stdv, ")")
},
LogNormal = function(parameter) {
paste0("distribution$LogNormal(mean = ", parameter$distribution$mean, ", CV = ", parameter$distribution$CV, ")")
}
)

generateParameterCode <- function(path, displayName, unit, parameterDistribution) {
code <- sprintf(
"parametersList[[\"%s\"]] <- SAParameter$new(simulation = simulation, path = \"%s\", displayName = \"%s\", unit = \"%s\", parameterDistribution = %s)",
path , path, displayName, unit, parameterDistribution
path, path, displayName, unit, parameterDistribution
)
return(code)
}

generateOutputCode <- function(path, displayName,pkParameterList) {
generateOutputCode <- function(path, displayName, pkParameterList) {
code <- sprintf(
"outputsList[[\"%s\"]] <- SAOutput$new(simulation = simulation, path = \"%s\", displayName = \"%s\")\n",
path, path, displayName
)
for (pk in pkParameterList){
code <- paste0(code,
sprintf("outputsList[[\"%s\"]]$addPKParameter(standardPKParameter = \"%s\",pkParameterDisplayName = NULL, startTime = NULL, endTime = NULL)\n",path,pk) )
for (pk in pkParameterList) {
code <- paste0(
code,
sprintf("outputsList[[\"%s\"]]$addPKParameter(standardPKParameter = \"%s\",pkParameterDisplayName = NULL, startTime = NULL, endTime = NULL)\n", path, pk)
)
}
return(code)
}



writeParametersAndOutputsToFile <- function(parametersList,outputsList) {
writeParametersAndOutputsToFile <- function(parametersList, outputsList) {
code <- NULL
#PREAMBLE
# PREAMBLE
code <- append(x = code, values = "rm(list = ls())")
code <- append(x = code, values = "library(ospsuite.globalsensitivity)")
code <- append(x = code, values = "\n")
code <- append(x = code, values = "### REPLACE BELOW WITH CORRECT PKML FILE PATHS")
code <- append(x = code, values = "simulationFilePath = 'PATH/TO/PKML/SIMULATION.pkml'")
code <- append(x = code, values = "simulation <- loadSimulation(simulationFilePath)")
code <- append(x = code, values = "DDIsimulationFilePath <- NULL #'PATH/TO/PKML/DDI/SIMULATION.pkml'")
code <- append(x = code, values = "simulation <- loadSimulation(simulationFilePath)")
code <- append(x = code, values = "DDIsimulationFilePath <- NULL #'PATH/TO/PKML/DDI/SIMULATION.pkml'")
code <- append(x = code, values = "DDIsimulation <- NULL")
code <- append(x = code, values = "if(!is.null(DDIsimulationFilePath)){DDIsimulation <- loadSimulation(DDIsimulationFilePath)}")
code <- append(x = code, values = "\n")

#PARAMETERS
code <- append(x = code, values = "### Set parameters")
code <- append(x = code, values = "parametersList <- list()")
# PARAMETERS
code <- append(x = code, values = "### Set parameters")
code <- append(x = code, values = "parametersList <- list()")
parametersCode <- list()
for (n in seq_along(parametersList)){
code <- append(x = code, values = paste0("# ",parametersList[[n]]$path))
parametersCode <- generateParameterCode(path = parametersList[[n]]$path,
displayName = parametersList[[n]]$displayName,
unit = parametersList[[n]]$unit,
parameterDistribution = distributionStringsFnsList[[parametersList[[n]]$distribution$type]](parametersList[[n]]))
code <- append(x = code, values = parametersCode)
for (n in seq_along(parametersList)) {
code <- append(x = code, values = paste0("# ", parametersList[[n]]$path))
parametersCode <- generateParameterCode(
path = parametersList[[n]]$path,
displayName = parametersList[[n]]$displayName,
unit = parametersList[[n]]$unit,
parameterDistribution = distributionStringsFnsList[[parametersList[[n]]$distribution$type]](parametersList[[n]])
)
code <- append(x = code, values = parametersCode)
}
code <- append(x = code, values = "\n")
code <- append(x = code, values = "\n")

#OUTPUTS
code <- append(x = code, values = "### Set outputs")
code <- append(x = code, values = "outputsList <- list()")
# OUTPUTS
code <- append(x = code, values = "### Set outputs")
code <- append(x = code, values = "outputsList <- list()")
outputsCode <- list()
for (n in seq_along(outputsList)){
code <- append(x = code, values = paste0("# ",outputsList[[n]]$path))
outputsCode <- generateOutputCode(path = outputsList[[n]]$path,
displayName = outputsList[[n]]$displayName,
pkParameterList = outputsList[[n]]$pkParameterList)
code <- append(x = code, values = outputsCode)
for (n in seq_along(outputsList)) {
code <- append(x = code, values = paste0("# ", outputsList[[n]]$path))
outputsCode <- generateOutputCode(
path = outputsList[[n]]$path,
displayName = outputsList[[n]]$displayName,
pkParameterList = outputsList[[n]]$pkParameterList
)
code <- append(x = code, values = outputsCode)
}
code <- append(x = code, values = "\n")
code <- append(x = code, values = "\n")
return(code)
}

Expand All @@ -75,44 +91,42 @@ writeSUFunctionToFile <- function(runUncertaintyCheckbox,
numberOfStepsNumericInput,
quantilesTestInput,
numberOfUncertaintySamples,
runParallel){
runParallel) {
code <- NULL
code <- append(x = code, values = "### Run Sensitivity and uncertainty analysis")
code <- append(x = code, values = paste0("suResults <- runSU(simulation = simulation,
code <- append(x = code, values = "### Run Sensitivity and uncertainty analysis")
code <- append(x = code, values = paste0("suResults <- runSU(simulation = simulation,
DDIsimulation = DDIsimulation,
customParameters = parametersList,
outputs = outputsList,
runUncertaintyAnalysis = ",runUncertaintyCheckbox,",
evaluateForAllParameters = ",runSensitivityAnalysisForAllParameters,",
sensitivityThreshold = ",sensitivityThreshold,",
variationRange = ",variationRangeNumericInput,",
numberOfSensitivityAnalysisSteps = ",numberOfStepsNumericInput,",
quantiles = ", paste0("c(", quantilesTestInput ,")") ,",
runUncertaintyAnalysis = ", runUncertaintyCheckbox, ",
evaluateForAllParameters = ", runSensitivityAnalysisForAllParameters, ",
sensitivityThreshold = ", sensitivityThreshold, ",
variationRange = ", variationRangeNumericInput, ",
numberOfSensitivityAnalysisSteps = ", numberOfStepsNumericInput, ",
quantiles = ", paste0("c(", quantilesTestInput, ")"), ",
saveFolder = getwd(),
numberOfUncertaintyAnalysisSamples = ",numberOfUncertaintySamples,",
numberOfUncertaintyAnalysisSamples = ", numberOfUncertaintySamples, ",
runParallel = TRUE)"))
return(code)
}

writeSobolSensitivityFunctionToFile <- function(numberOfSamplesGSA){
writeSobolSensitivityFunctionToFile <- function(numberOfSamplesGSA) {
code <- NULL
code <- append(x = code, values = "### Run Sobol sensitivity")
code <- append(x = code, values = paste0("sobolResults <- runSobol(simulation = simulation, DDIsimulation = DDIsimulation, parameters = parametersList, outputs = outputsList, numberOfSamples = ",numberOfSamplesGSA,")"))
code <- append(x = code, values = "### Run Sobol sensitivity")
code <- append(x = code, values = paste0("sobolResults <- runSobol(simulation = simulation, DDIsimulation = DDIsimulation, parameters = parametersList, outputs = outputsList, numberOfSamples = ", numberOfSamplesGSA, ")"))
return(code)
}

writeEFASTSensitivityFunctionToFile <- function(numberOfReSamplesEFAST){
writeEFASTSensitivityFunctionToFile <- function(numberOfReSamplesEFAST) {
code <- NULL
code <- append(x = code, values = "### Run EFAST sensitivity")
code <- append(x = code, values = paste0("EFASTResults <- runEFAST(simulation = simulation, DDIsimulation = DDIsimulation, parameters = parametersList, outputs = outputsList, numberOfResamples = ",numberOfReSamplesEFAST,")"))
code <- append(x = code, values = "### Run EFAST sensitivity")
code <- append(x = code, values = paste0("EFASTResults <- runEFAST(simulation = simulation, DDIsimulation = DDIsimulation, parameters = parametersList, outputs = outputsList, numberOfResamples = ", numberOfReSamplesEFAST, ")"))
return(code)
}

writeMorrisSensitivityFunctionToFile <- function(numberOfSamples){
writeMorrisSensitivityFunctionToFile <- function(numberOfSamples) {
code <- NULL
code <- append(x = code, values = "### Run Morris sensitivity")
code <- append(x = code, values = paste0("morrisResults <- runMorris(simulation = simulation, DDIsimulation = DDIsimulation, parameters = parametersList, outputs = outputsList, numberOfSamples = ",numberOfSamples,")"))
code <- append(x = code, values = "### Run Morris sensitivity")
code <- append(x = code, values = paste0("morrisResults <- runMorris(simulation = simulation, DDIsimulation = DDIsimulation, parameters = parametersList, outputs = outputsList, numberOfSamples = ", numberOfSamples, ")"))
return(code)
}


Loading

0 comments on commit 6a4d5d4

Please sign in to comment.