Skip to content

Commit

Permalink
update examples (#13)
Browse files Browse the repository at this point in the history
* run styler

* run styler on package

* temp remove R folder

* Create parameter.R

* Update NAMESPACE

* ud doc

* ud documentation for cod-generation

* ud distribution documentation

* ud output documentation

* ud

* ud uncertainty documentation

* ud local sensitivity documentation

* Create efast-functions.R

* move list structure generation to functions where they are used instead of passing them from runEFAST

* rename evaluation lists

* Update efast documentation

* up efast documentation

* move functions used by multiple methods from sobol script

* temp revert to fix run NaN errors

* Update efast-functions.R

* Update efast-functions.R

* Update efast-functions.R

* ud efast documentation

* Update utilities.R

* ud su functions

* ud

* ud

* unused function

* document morris

* ud

* ud

* ud

* Create app.R

* ud

* ud

* add number labels to morris plot

* add uncertainty plots to GUI

* rename gsa bar plot function

* ud

* ud

* use distribution objects

* ctrl-i

* Update lowry-functions.R

* Update app.R

* ud - remove export lowry, only bar graphs for gsa

* Update morris-functions.R

* Update morris-functions.R

* ud examples, merge midazolam

* Create example2-UV-filters.R

* ud

* Create example4-itraconazole.R

* ud

* Update example-UV-filters.R

* Update example-UV-filters.R

* Update app.R

* ud

* Delete pltGSABarGraph.Rd

* Update appveyor.yml
  • Loading branch information
abdullahhamadeh authored Nov 6, 2024
1 parent 71b2993 commit 383f636
Show file tree
Hide file tree
Showing 31 changed files with 187,788 additions and 432 deletions.
6 changes: 2 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
export(LogNormalDistribution)
export(LogUniformDistribution)
export(NormalDistribution)
export(SADistribution)
export(SAOutput)
export(SAParameter)
export(UniformDistribution)
export(distribution)
export(generateLowryPlot)
export(generateEFASTBarGraph)
export(generateMorrisPlot)
export(generateSobolBarGraph)
export(generateTornadoPlot)
export(getParameterListForUncertaintyAnalysis)
export(pltGSABarGraph)
export(runEFAST)
export(runGUI)
export(runMorris)
Expand Down
317 changes: 169 additions & 148 deletions R/app.R

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion R/distribution.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' @title SADistribution
#' @description R6 class defining a statistical distribution object
#' @export
SADistribution <- R6::R6Class(classname = "SADistribution")

#' @title UniformDistribution
Expand Down
86 changes: 78 additions & 8 deletions R/lowry-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
#' @description Function to generate a Lowry plot of Sobol or EFAST sensitivity analysis results.
#' @param gsaResultsDataframe Sobol or EFAST results returned by the `runSobol` or `runFAST` functions, respectively.
#' @return A list of ggplot Lowry plots, one corresponding to each output path/PK parameter combination.
#' @export
generateLowryPlot <- function(gsaResultsDataframe) {
plotList <- list()

for (op in unique(gsaResultsDataframe[["Output"]])) {
plotList[[op]] <- list()
for (pk in unique(gsaResultsDataframe[["PK"]][gsaResultsDataframe[["Output"]] == op])) {
df <- gsaResultsDataframe[gsaResultsDataframe$Output == op & gsaResultsDataframe$PK == pk, ]
outputDisplayName <- unique(df$OutputDisplayName)
outputDisplayName <- unique(df$OutputDisplayName)[1]
plotList[[op]][[pk]] <- getLowryPlot(df, outputDisplayName, pk)
}
}
Expand All @@ -31,9 +30,7 @@ getLowryPlot <- function(df, outputDisplayName, pk) {
df$ParameterRanks <- sapply(df$Parameter, function(par) {
which(sortedParameters == par)
})

df$Measure <- factor(df$Measure, levels = c("Total", "FirstOrder"))

dfFirstOrder <- df[df$Measure == "FirstOrder", ][sortedParameterOrder, ]
dfTotal <- df[df$Measure == "Total", ][sortedParameterOrder, ]

Expand Down Expand Up @@ -108,12 +105,59 @@ getLowryPlot <- function(df, outputDisplayName, pk) {
return(plt)
}

#' @title pltGSABarGraph



#' @title generateSobolBarGraph
#' @description Function to generate a bar graph of Sobol sensitivity analysis results.
#' @param gsaResultsDataframe Sobol results returned by the `runSobol` function.
#' @return A list of ggplot bar graphs, one corresponding to each output path/PK parameter combination.
#' @export
generateSobolBarGraph <- function(gsaResultsDataframe) {
plotList <- generateGSABarGraph(gsaResultsDataframe = gsaResultsDataframe, plottingFunction = getSobolBarGraph)
return(plotList)
}



#' @title generateEFASTBarGraph
#' @description Function to generate a bar graph of EFAST sensitivity analysis results.
#' @param gsaResultsDataframe EFAST results returned by the `runEFAST` function.
#' @return A list of ggplot bar graphs, one corresponding to each output path/PK parameter combination.
#' @export
generateEFASTBarGraph <- function(gsaResultsDataframe) {
plotList <- generateGSABarGraph(gsaResultsDataframe = gsaResultsDataframe, plottingFunction = getEFASTBarGraph)
return(plotList)
}


#' @title generateGSABarGraph
#' @description Function to generate a bar graph of Sobol or EFAST sensitivity analysis results.
#' @param df Sobol or EFAST results returned by the `runSobol` or `runFAST` functions, respectively.
#' @param gsaResultsDataframe Sobol or EFAST results returned by the `runSobol` or `runEFAST` functions, respectively.
#' @param plottingFunction The name of the function to use for plotting. Choose either `getSobolBarGraph` for Sobol results or `getEFASTBarGraph` for EFAST results.
#' @return A list of ggplot bar graphs, one corresponding to each output path/PK parameter combination.
generateGSABarGraph <- function(gsaResultsDataframe,plottingFunction) {
plotList <- list()
for (op in unique(gsaResultsDataframe[["Output"]])) {
plotList[[op]] <- list()
for (pk in unique(gsaResultsDataframe[["PK"]][gsaResultsDataframe[["Output"]] == op])) {
df <- gsaResultsDataframe[gsaResultsDataframe$Output == op & gsaResultsDataframe$PK == pk, ]
outputDisplayName <- unique(df$OutputDisplayName)[1]
plotList[[op]][[pk]] <- plottingFunction(df, outputDisplayName, pk)
}
}
return(plotList)
}



#' @title generateBarGraph
#' @description Function to generate a bar graph of Sobol or EFAST sensitivity analysis results.
#' @param df Sobol or EFAST results dataframe.
#' @param outputDisplayName String. The display name of the output.
#' @param pk String. The name of the PK parameter
#' @return A list of ggplot bar graph plots, one corresponding to each output path/PK parameter combination.
#' @export
pltGSABarGraph <- function(df) {
getGSABarGraph <- function(df, outputDisplayName, pk) {
parameterOrder <- df[df$Measure == "FirstOrder", ]$Parameter[order(-df$Value[df$Measure == "FirstOrder"])]
df$Parameter <- factor(df$Parameter, levels = parameterOrder)
plt <- ggplot(data = df) +
Expand All @@ -137,3 +181,29 @@ pltGSABarGraph <- function(df) {
plt <- plt + scale_x_discrete(labels = xlabels)
return(plt)
}


#' @title getSobolBarGraph
#' @description Function to generate a bar graph of Sobol sensitivity analysis results.
#' @param df Sobol results dataframe.
#' @param outputDisplayName String. The display name of the output.
#' @param pk String. The name of the PK parameter
#' @return A list of ggplot bar graph plots, one corresponding to each output path/PK parameter combination.
getSobolBarGraph <- function(df, outputDisplayName, pk) {
plt <- getGSABarGraph(df, outputDisplayName, pk)
plt <- plt + ggtitle(label = paste("Sobol sensitivity"), subtitle = paste0("Output: ", outputDisplayName, "\nPK: ", pk))
return(plt)
}

#' @title getEFASTBarGraph
#' @description Function to generate a bar graph of EFAST sensitivity analysis results.
#' @param df EFAST results dataframe.
#' @param outputDisplayName String. The display name of the output.
#' @param pk String. The name of the PK parameter
#' @return A list of ggplot bar graph plots, one corresponding to each output path/PK parameter combination.
getEFASTBarGraph <- function(df, outputDisplayName, pk) {
plt <- getGSABarGraph(df, outputDisplayName, pk)
plt <- plt + ggtitle(label = paste("EFAST sensitivity"), subtitle = paste0("Output: ", outputDisplayName, "\nPK: ", pk))
return(plt)
}

21 changes: 15 additions & 6 deletions R/morris-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,28 @@ runMorris <- function(simulation,
#' @title generateMorrisPlot
#' @description Function to generate a plot of Morris sensitivity analysis.
#' @param morrisResults Morris sensitivity results returned by `runMorris` function.
#' @param logPlot Logical setting. The Morris results are plotted on a logarithmic scale if `TRUE`.
#' @return A list of ggplots of Morris sensitivity analysis results, one corresponding to each output path/PK parameter combination.
#' @export
generateMorrisPlot <- function(morrisResults) {
generateMorrisPlot <- function(morrisResults, logPlot = FALSE) {
pltFn <- function(x){x}
if(logPlot){
pltFn <- log10
}
morrisPlots <- list()
for (outputPath in unique(morrisResults$Output)) {
morrisPlots[[outputPath]] <- list()
for (pk in unique(morrisResults[morrisResults$Output == outputPath, ]$PK)) {
df <- morrisResults[morrisResults$Output == outputPath & morrisResults$PK == pk, ]

plt <- ggplot2::ggplot(data = df, mapping = aes(x = mustar, y = stdv, color = Parameter, label = Parameter)) +
ggplot2::geom_point() +
ggplot2::labs(x = paste0("\u03bc", "*"), y = "\u03c3", title = "Morris plot", subtitle = paste0("Output ", outputPath, "\nPK: ", pk)) +
geom_text(hjust = 0, vjust = 0)
df <- df[rev(order(df$rankingNorm)),]
df$label <- seq_along(df$Parameter)
df$label <- as.factor(df$label)
df$legendLabel <- sapply( 1:nrow(df) , function(nn){ paste0( df$label[nn] , ": " , df$Parameter[nn] ) } )
plt <- ggplot2::ggplot(data = df, mapping = aes(x = pltFn(mustar), y = pltFn(stdv), color = label, label = label)) +
ggplot2::geom_point(size = 2) +
ggplot2::labs(x = paste0("\u03bc", "*"), y = "\u03c3", title = "Morris sensitivity", subtitle = paste0("Output: ", outputPath, "\nPK: ", pk)) +
ggplot2::scale_color_discrete(name = "Parameter" , labels = df$legendLabel) +
ggplot2::geom_text(hjust = 0, vjust = 0,size = 6,show.legend = FALSE)
morrisPlots[[outputPath]][[pk]] <- plt
}
}
Expand Down
1 change: 0 additions & 1 deletion R/su-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ getSensitivityClass <- function(sensitivityValue) {
#' @param simulation The simulation object which contains parameters at paths `parameterPaths`.
#' @param variationRange The variation range used to define the log-uniform distribution of the parameters in `parameterPaths`.
#' @return A list of `SAParameter` objects.
#' @export
getParameterListForUncertaintyAnalysis <- function(parameterPaths, simulation, variationRange = 0.1) {
parameters <- list()

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ init:
install:
- ps: Bootstrap
- git submodule update --init --recursive
- ps: cinst pandoc --no-progress
- ps: choco install pandoc --no-progress
- ps: $env:Path += ";C:\Program Files (x86)\Pandoc\"

environment:
Expand Down
68 changes: 0 additions & 68 deletions examples/efast-DDI-Rifampicin-Midazolam-example.R

This file was deleted.

8 changes: 4 additions & 4 deletions examples/efast-simple-example.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ parametersList <- list(
path = tree$Comp$X1$path,
displayName = "X1",
unit = ospUnits$Dimensionless$Unitless,
parameterDistribution = distribution$Uniform(minimum = 0,maximum = 1)
parameterDistribution = UniformDistribution$new(minimum = 0,maximum = 1)
),
SAParameter$new(simulation = sim,
path = tree$Comp$X2$path,
displayName = "X2",
unit = ospUnits$Dimensionless$Unitless,
parameterDistribution = distribution$Uniform(minimum = 0,maximum = 1)
parameterDistribution = UniformDistribution$new(minimum = 0,maximum = 1)
),
SAParameter$new(simulation = sim,
path = tree$Comp$X3$path,
displayName = "X3",
unit = ospUnits$Dimensionless$Unitless,
parameterDistribution = distribution$Uniform(minimum = 0,maximum = 1)
parameterDistribution = UniformDistribution$new(minimum = 0,maximum = 1)
),
SAParameter$new(simulation = sim,
path = tree$Comp$X4$path,
displayName = "X4",
unit = ospUnits$Dimensionless$Unitless,
parameterDistribution = distribution$Uniform(minimum = 0,maximum = 1)
parameterDistribution = UniformDistribution$new(minimum = 0,maximum = 1)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ parametersList <- list(
path = tree$`Midazolam-CYP3A4-Optimized`$Km$path,
displayName = "Km",
unit = ospUnits$`Concentration [molar]`$`µmol/l`,
parameterDistribution = distribution$LogUniform(minimum = 2,maximum = 8)
parameterDistribution = LogUniformDistribution$new(minimum = 2,maximum = 8)
),
SAParameter$new(simulation = sim,
path = tree$`Midazolam-CYP3A4-Optimized`$kcat$path,
displayName = "kcat",
unit = ospUnits$`Inversed time`$`1/min`,
parameterDistribution = distribution$LogUniform(minimum = 8.76/2,maximum = 8.76*2)
parameterDistribution = LogUniformDistribution$new(minimum = 8.76/2,maximum = 8.76*2)
),
SAParameter$new(simulation = sim,
path = tree$Midazolam$Lipophilicity$path,
displayName = "Lipophilicity",
unit = ospUnits$`Log Units`$`Log Units`,
parameterDistribution = distribution$Uniform(minimum = 2,maximum = 4)
parameterDistribution = UniformDistribution$new(minimum = 2,maximum = 4)
),
SAParameter$new(simulation = sim,
path = tree$Midazolam$`Fraction unbound (plasma, reference value)`$path,
displayName = "fu",
unit = ospUnits$Dimensionless$Unitless,
parameterDistribution = distribution$Uniform(minimum = 0.01,maximum = 0.05)
parameterDistribution = UniformDistribution$new(minimum = 0.01,maximum = 0.05)
),
SAParameter$new(simulation = sim,
path = tree$Rifampicin$`CYP3A4-Templeton 2011`$EC50$path,
displayName = "EC50",
unit = ospUnits$`Concentration [molar]`$`µmol/l`,
parameterDistribution = distribution$LogUniform(minimum = 0.34*0.5,maximum = 0.34/0.5)
parameterDistribution = LogUniformDistribution$new(minimum = 0.34*0.5,maximum = 0.34/0.5)
),
SAParameter$new(simulation = sim,
path = tree$Rifampicin$`CYP3A4-Templeton 2011`$Emax$path,
displayName = "Emax",
unit = ospUnits$Dimensionless$Unitless,
parameterDistribution = distribution$LogUniform(minimum = 9*0.5,maximum = 9/0.5)
parameterDistribution = LogUniformDistribution$new(minimum = 9*0.5,maximum = 9/0.5)
)
)

Expand All @@ -54,9 +54,7 @@ Y$addPKParameter(standardPKParameter = "C_max")
Y$addPKParameter(standardPKParameter = "AUC_inf")
outputList <- list(Y)

numberOfSamples <- 100

#****** RUN THE SENSITIVITY AND UNCERTAINTY ANALYSIS.
#Run local sensitivity analysis and uncertainty analysis
su <- runSU(simulation = sim,
DDIsimulation = DDIsim,
customParameters = parametersList,
Expand All @@ -68,7 +66,35 @@ su <- runSU(simulation = sim,
sensitivityThreshold = 0,
#Uncertainty analysis parameters:
runUncertaintyAnalysis = TRUE,
numberOfUncertaintyAnalysisSamples = numberOfSamples,
numberOfUncertaintyAnalysisSamples = 100,
quantiles = c(0.05,0.25,0.5,0.75,0.95))

generateAndSaveSUSummaryDf(suResults = su,savePath = "data/su-DDI-summary-DF.xlsx")
localSensitivityPlts <- generateTornadoPlot(sensitivityDataFrame = suResults$Results,generateForUncertaintyAnalysis = FALSE)
uncertaintyPlts <- generateTornadoPlot(sensitivityDataFrame = suResults$Results,generateForUncertaintyAnalysis = TRUE)


#Run Morris sensitivity analysis
morrisResults <- runMorris(simulation = sim,
DDIsimulation = DDIsim,
parameters = parametersList,
outputs = outputList,
numberOfSamples = 100)
morrisPlts <- generateMorrisPlot(morrisResults$Results)


#Run Sobol sensitivity analysis
sobolResults <- runSobol(simulation = sim,
DDIsimulation = DDIsim,
parameters = parametersList,
outputs = outputList,
numberOfSamples = 1000)
sobolPlts <- generateSobolBarGraph(gsaResultsDataframe = sobolResults$Results)


#Run EFAST sensitivity analysis
efastResultsDf <- runEFAST(simulation = sim,
DDIsimulation = DDIsim,
parameters = parametersList,
outputs = outputList,
numberOfResamples = 1)
efastPlts <- generateEFASTBarGraph(gsaResultsDataframe = efastResultsDf$Results)
Loading

0 comments on commit 383f636

Please sign in to comment.